From 01ad88adf9bb5858d970cd2a2122096b0a78dcd7 Mon Sep 17 00:00:00 2001 From: AmirmahdiNourkazemi Date: Tue, 30 Jun 2026 14:09:15 +0330 Subject: [PATCH] fix: slider --- app/dashboard/sliders/page.tsx | 71 ++++++++++++++++++++++------------ 1 file changed, 46 insertions(+), 25 deletions(-) diff --git a/app/dashboard/sliders/page.tsx b/app/dashboard/sliders/page.tsx index 354b592..7ee06cc 100644 --- a/app/dashboard/sliders/page.tsx +++ b/app/dashboard/sliders/page.tsx @@ -16,6 +16,9 @@ import { Textarea, } from "@/components/ui"; import { EditIcon, PlusIcon, TrashIcon } from "@/components/icons"; +import { ImagePicker } from "@/components/ImagePicker"; +import { MediaPreview } from "@/components/MediaPreview"; +import { pickUrl, IMAGE_KEYS } from "@/lib/media"; import { toFa } from "@/lib/utils"; interface SliderAction { @@ -29,10 +32,12 @@ interface Slider { description?: string; url?: string; action?: SliderAction; + image_id?: number | null; + image?: unknown; } const ACTION_TYPES = [ - { value: "screen", label: "صفحه (screen)" }, + { value: "navigation", label: "صفحه (navigation)" }, { value: "link", label: "لینک (link)" }, ]; @@ -46,7 +51,9 @@ export default function SlidersPage() { const [description, setDescription] = useState(""); const [url, setUrl] = useState(""); const [actionPath, setActionPath] = useState(""); - const [actionType, setActionType] = useState("screen"); + const [actionType, setActionType] = useState("navigation"); + const [imageId, setImageId] = useState(null); + const [imageFile, setImageFile] = useState(null); const [saving, setSaving] = useState(false); const [deleting, setDeleting] = useState(null); @@ -58,7 +65,9 @@ export default function SlidersPage() { setDescription(""); setUrl(""); setActionPath(""); - setActionType("screen"); + setActionType("navigation"); + setImageId(null); + setImageFile(null); setOpen(true); } function openEdit(row: Slider) { @@ -67,7 +76,9 @@ export default function SlidersPage() { setDescription(row.description ?? ""); setUrl(row.url ?? ""); setActionPath(row.action?.path ?? ""); - setActionType(row.action?.type ?? "screen"); + setActionType(row.action?.type ?? "navigation"); + setImageId(row.image_id ?? null); + setImageFile(null); setOpen(true); } @@ -75,30 +86,22 @@ export default function SlidersPage() { e.preventDefault(); setSaving(true); try { + // Multipart for both (so an image file can be uploaded). Bracket keys + // build the nested action object; update uses POST /slider/:id. + const body = toFormData({ + title, + description, + url, + "action[path]": actionPath, + "action[type]": actionType, + image_id: imageId, + image: imageFile, + }); if (editing) { - // Update is JSON on /slider/:id with a nested action object. - await apiFetch(`/slider/${editing.id}`, { - method: "PUT", - body: { - title, - description, - url, - action: { path: actionPath, type: actionType }, - }, - }); + await apiFetch(`/slider/${editing.id}`, { method: "POST", body }); toast.success("اسلایدر ویرایش شد."); } else { - // Create is multipart with literal bracket keys for the nested action. - await apiFetch("/slider", { - method: "POST", - body: toFormData({ - title, - description, - "action[path]": actionPath, - "action[type]": actionType, - url, - }), - }); + await apiFetch("/slider", { method: "POST", body }); toast.success("اسلایدر افزوده شد."); } setOpen(false); @@ -127,6 +130,14 @@ export default function SlidersPage() { const columns: Column[] = [ { key: "id", header: "شناسه", render: (r) => toFa(r.id), className: "w-24" }, + { + key: "image", + header: "تصویر", + className: "w-20", + render: (r) => ( + + ), + }, { key: "title", header: "عنوان", render: (r) => r.title ?? "—" }, { key: "description", @@ -224,6 +235,16 @@ export default function SlidersPage() { /> + + + +