From 12aead7b34ef4eca6199bf3808a6d73fef936d3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Boduro=C4=9Flu?= <80620802+burakboduroglu@users.noreply.github.com> Date: Thu, 23 Jul 2026 20:31:52 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=97=91=EF=B8=8F=20allow=20questio?= =?UTF-8?q?n=20askers=20and=20moderators=20to=20delete=20pool=20questions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - add question deletion button to question list items for question askers and teacher+ moderators - update question detail view to allow question askers and teacher+ moderators to delete questions regardless of status - add confirmation dialog before deleting pool questions --- src/pages/question-detail-page.tsx | 18 +++++---- src/pages/questions-page.tsx | 61 ++++++++++++++++++++++++++---- 2 files changed, 64 insertions(+), 15 deletions(-) diff --git a/src/pages/question-detail-page.tsx b/src/pages/question-detail-page.tsx index 16a5d17..4ff8c99 100644 --- a/src/pages/question-detail-page.tsx +++ b/src/pages/question-detail-page.tsx @@ -105,18 +105,20 @@ function QuestionDetailContent() { {new Date(q().asked_at).toLocaleString()} - -
- +
+ -
- + + + + +
{error() &&

{error()}

} diff --git a/src/pages/questions-page.tsx b/src/pages/questions-page.tsx index 357099a..a9a3c09 100644 --- a/src/pages/questions-page.tsx +++ b/src/pages/questions-page.tsx @@ -1,6 +1,6 @@ import { For, Show, Suspense, createEffect, createResource, createSignal, lazy } from "solid-js"; import { Link, useLocation, useNavigate, useSearch } from "@tanstack/solid-router"; -import { getQuestions, postQuestion } from "@/api/shared"; +import { getQuestions, postQuestion, deleteQuestionById } from "@/api/shared"; import { getSettings } from "@/api/settings"; import { formatApiError } from "@/api/client"; import { RouteGuard } from "@/components/layout/route-guard"; @@ -9,11 +9,13 @@ import { PageSpinner } from "@/components/ui/page-spinner"; import { EmptyState } from "@/components/ui/empty-state"; import { Button } from "@/components/ui/button"; import { FormDialog } from "@/components/ui/form-dialog"; +import { ConfirmDialog } from "@/components/ui/confirm-dialog"; import { Label } from "@/components/ui/label"; import { Input } from "@/components/ui/input"; import { Textarea } from "@/components/ui/textarea"; -import { IconPlus, IconClock, IconCheck, IconPhoto, IconX, IconEdit } from "@/components/ui/icons"; +import { IconPlus, IconClock, IconCheck, IconPhoto, IconX, IconEdit, IconTrash } from "@/components/ui/icons"; import { personLabel } from "@/lib/person"; +import { hasMinRole } from "@/lib/roles"; import { ErrorAlert } from "@/components/ui/error-alert"; import { showToast } from "@/components/ui/toast"; @@ -48,12 +50,31 @@ function QuestionsContent() { ); const [askOpen, setAskOpen] = createSignal(location().searchStr.includes("action=new")); + const [questionToDelete, setQuestionToDelete] = createSignal(null); + createEffect(() => { if (location().searchStr.includes("action=new")) { setAskOpen(true); } }); + const canDelete = (question: any) => + question.asker.id === auth.user()?.id || hasMinRole(auth.user()?.role, "teacher"); + + const handleDeleteConfirmed = async () => { + const q = questionToDelete(); + if (!q) return; + try { + await deleteQuestionById(q.id); + showToast({ title: t("common.deleted") }); + setQuestionToDelete(null); + refetch(); + } catch (err: unknown) { + showToast({ title: formatApiError(err) }); + setQuestionToDelete(null); + } + }; + return (
{(question) => ( - -
+
+

{question.title}

@@ -114,16 +135,34 @@ function QuestionsContent() { • {new Date(question.asked_at).toLocaleDateString()}
-
-
+ + +
{t("pool.pending")}} > {t("pool.approved")} + + + +
- +
)}
@@ -143,6 +182,14 @@ function QuestionsContent() { }} /> + + !open && setQuestionToDelete(null)} + title={t("common.delete")} + description="Bu soruyu silmek istediğinizden emin misiniz?" + onConfirm={handleDeleteConfirmed} + />
); }