diff --git a/src/pages/scr/dashboard/pengaduan/detail_page.tsx b/src/pages/scr/dashboard/pengaduan/detail_page.tsx index 0be588d..144a88e 100644 --- a/src/pages/scr/dashboard/pengaduan/detail_page.tsx +++ b/src/pages/scr/dashboard/pengaduan/detail_page.tsx @@ -1,3 +1,4 @@ +import notification from "@/components/notificationGlobal"; import apiFetch from "@/lib/apiFetch"; import { Anchor, @@ -17,7 +18,7 @@ import { Textarea, Title, } from "@mantine/core"; -import { useDisclosure } from "@mantine/hooks"; +import { useDisclosure, useShallowEffect } from "@mantine/hooks"; import { IconAlignJustified, IconCategory, @@ -25,14 +26,15 @@ import { IconInfoTriangle, IconMapPin, IconMessageReport, + IconPhone, IconPhotoScan, IconUser, } from "@tabler/icons-react"; +import type { User } from "generated/prisma"; import _ from "lodash"; -import { useState } from "react"; +import { useEffect, useState } from "react"; import { useLocation } from "react-router-dom"; import useSwr from "swr"; -import { useShallowEffect } from "@mantine/hooks"; export default function DetailPengaduanPage() { const { search } = useLocation(); @@ -55,7 +57,7 @@ export default function DetailPengaduanPage() { - + { mutate(); }} /> @@ -67,24 +69,57 @@ export default function DetailPengaduanPage() { ); } -function DetailDataPengaduan({ data }: { data: any }) { +function DetailDataPengaduan({ data, onAction }: { data: any, onAction: () => void }) { const [opened, { open, close }] = useDisclosure(false); const [catModal, setCatModal] = useState<"tolak" | "terima">("tolak"); const [imageSrc, setImageSrc] = useState(null); const [openedModalImage, { open: openModalImage, close: closeModalImage }] = useDisclosure(false); + const [keterangan, setKeterangan] = useState(""); + const [host, setHost] = useState(null); - // async function handleLihatGambar() { - // const res = await apiFetch.api.pengaduan.image.get({ - // query: { - // fileName: "57d5ce89-7d18-4244-9f4c-ca21b70adb7e", - // }, - // }); - // console.error("client", res); - // // const blob = await res.data?.blob(); - // // setImageSrc(URL.createObjectURL(blob!)); - // // openModalImage(); - // } + useEffect(() => { + async function fetchHost() { + const { data } = await apiFetch.api.user.find.get(); + setHost(data?.user ?? null); + } + fetchHost(); + }, []); + + const handleKonfirmasi = async (cat: "terima" | "tolak") => { + try { + const res = await apiFetch.api.pengaduan["update-status"].post({ + id: data?.id, + status: cat == 'tolak' ? 'ditolak' : data.status == 'antrian' ? 'diterima' : data.status == 'diterima' ? 'dikerjakan' : 'selesai', + keterangan: keterangan, + idUser: host?.id ?? "" + }); + + if (res?.status === 200) { + onAction(); + close(); + notification({ + title: "Success", + message: "Success update pengaduan", + type: "success", + }); + } else { + notification({ + title: "Error", + message: "Failed to update pengaduan", + type: "error", + }); + } + + } catch (error) { + console.error(error); + notification({ + title: "Error", + message: "Failed to update pengaduan", + type: "error", + }); + } + } return ( <> @@ -94,7 +129,6 @@ function DetailDataPengaduan({ data }: { data: any }) { opened={opened} onClose={close} title={"Konfirmasi"} - centered overlayProps={{ backgroundOpacity: 0.55, blur: 3 }} > @@ -104,25 +138,25 @@ function DetailDataPengaduan({ data }: { data: any }) { Anda yakin ingin menolak pengaduan ini? Berikan alasan penolakan -