feat: add chat topic

This commit is contained in:
2026-06-03 17:08:59 +03:30
parent 4d67af0bfc
commit 07cbeec816
9 changed files with 359 additions and 17 deletions
+20 -2
View File
@@ -10,6 +10,7 @@ import {
ConfirmDialog,
Field,
Input,
Textarea,
Select,
Modal,
PageHeader,
@@ -25,6 +26,7 @@ interface Category {
interface SubCategory {
id: number;
name?: string;
description?: string | null;
category_id?: number;
category?: { id?: number; name?: string };
}
@@ -39,6 +41,7 @@ export default function SubCategoriesPage() {
const [saving, setSaving] = useState(false);
const [name, setName] = useState("");
const [description, setDescription] = useState("");
const [categoryId, setCategoryId] = useState("");
const [deleting, setDeleting] = useState<SubCategory | null>(null);
@@ -47,6 +50,7 @@ export default function SubCategoriesPage() {
function openCreate() {
setEditing(null);
setName("");
setDescription("");
setCategoryId("");
setOpen(true);
}
@@ -54,6 +58,7 @@ export default function SubCategoriesPage() {
function openEdit(row: SubCategory) {
setEditing(row);
setName(row.name ?? "");
setDescription(row.description ?? "");
setCategoryId(
row.category_id != null
? String(row.category_id)
@@ -72,14 +77,14 @@ export default function SubCategoriesPage() {
// Update is JSON on /sub-categories/:id
await apiFetch(`/sub-categories/${editing.id}`, {
method: "PUT",
body: { name, category_id: categoryId },
body: { name, category_id: categoryId, description },
});
toast.success("زیر‌دسته ویرایش شد.");
} else {
// Create is multipart on /sub-categories
await apiFetch("/sub-categories", {
method: "POST",
body: toFormData({ category_id: categoryId, name }),
body: toFormData({ category_id: categoryId, name, description }),
});
toast.success("زیر‌دسته افزوده شد.");
}
@@ -115,6 +120,11 @@ export default function SubCategoriesPage() {
header: "دسته‌بندی والد",
render: (r) => r.category?.name ?? "—",
},
{
key: "description",
header: "توضیحات",
render: (r) => r.description || "—",
},
];
return (
@@ -202,6 +212,14 @@ export default function SubCategoriesPage() {
autoFocus
/>
</Field>
<Field label="توضیحات">
<Textarea
value={description}
onChange={(e) => setDescription(e.target.value)}
placeholder="توضیح کوتاه درباره این زیر‌دسته"
/>
</Field>
</form>
</Modal>