From d0ff67595013f8865e9b5105ac20af54f6b77d4c Mon Sep 17 00:00:00 2001 From: amaliadwiy Date: Thu, 20 Nov 2025 16:09:36 +0800 Subject: [PATCH] upd: dashboard admin Deskripsi - edit upload ttd setting desa No Issues --- src/components/DesaSetting.tsx | 83 ++++++++++++++++--- .../dashboard/setting/detail_setting_page.tsx | 8 +- src/server/lib/rename-file.ts | 12 +++ src/server/lib/seafile.ts | 2 +- src/server/routes/pengaduan_route.ts | 16 +++- 5 files changed, 96 insertions(+), 25 deletions(-) create mode 100644 src/server/lib/rename-file.ts diff --git a/src/components/DesaSetting.tsx b/src/components/DesaSetting.tsx index d136937..c7871d3 100644 --- a/src/components/DesaSetting.tsx +++ b/src/components/DesaSetting.tsx @@ -1,8 +1,10 @@ import apiFetch from "@/lib/apiFetch"; import { ActionIcon, + Anchor, Button, Divider, + FileInput, Flex, Group, Input, @@ -10,7 +12,7 @@ import { Stack, Table, Title, - Tooltip, + Tooltip } from "@mantine/core"; import { useDisclosure, useShallowEffect } from "@mantine/hooks"; import { IconEdit } from "@tabler/icons-react"; @@ -22,6 +24,7 @@ export default function DesaSetting() { const [btnDisable, setBtnDisable] = useState(false); const [btnLoading, setBtnLoading] = useState(false); const [opened, { open, close }] = useDisclosure(false); + const [img, setImg] = useState() const { data, mutate, isLoading } = useSWR("/", () => apiFetch.api["configuration-desa"].list.get(), ); @@ -39,7 +42,31 @@ export default function DesaSetting() { async function handleEdit() { try { setBtnLoading(true); - const res = await apiFetch.api["configuration-desa"].edit.post(dataEdit); + + let finalData = { ...dataEdit }; // ← buffer data terbaru + + if (dataEdit.name === "TTD") { + const resImg = await apiFetch.api.pengaduan.upload.post({ file: img }); + + if (resImg.status === 200) { + finalData = { + ...finalData, + value: resImg.data?.filename || "" + }; + + setDataEdit(finalData); // update state + } else { + return notification({ + title: "Error", + message: "Failed to upload image", + type: "error", + }); + } + } + + + const res = await apiFetch.api["configuration-desa"].edit.post(finalData); + if (res.status === 200) { mutate(); close(); @@ -67,6 +94,7 @@ export default function DesaSetting() { } } + function chooseEdit({ data, }: { @@ -100,18 +128,35 @@ export default function DesaSetting() { opened={opened} onClose={close} title={"Edit"} - centered overlayProps={{ backgroundOpacity: 0.55, blur: 3 }} > - - - onValidation({ kat: "value", value: e.target.value }) - } - /> - + { + dataEdit.name == "TTD" + ? + ( + + { setImg(e) }} + /> + + ) + : + ( + + + onValidation({ kat: "value", value: e.target.value }) + } + /> + + ) + } +