diff --git a/src/components/KategoriPengaduan.tsx b/src/components/KategoriPengaduan.tsx
index ffd3f54..6fdbf00 100644
--- a/src/components/KategoriPengaduan.tsx
+++ b/src/components/KategoriPengaduan.tsx
@@ -9,24 +9,27 @@ import {
Modal,
Stack,
Table,
+ Text,
Title,
Tooltip
} from "@mantine/core";
import { useDisclosure, useShallowEffect } from "@mantine/hooks";
-import { IconEdit, IconPlus } from "@tabler/icons-react";
+import { IconEdit, IconPlus, IconTrash } from "@tabler/icons-react";
import { useState } from "react";
import useSWR from "swr";
import notification from "./notificationGlobal";
export default function KategoriPengaduan() {
+ const [openedDelete, { open: openDelete, close: closeDelete }] = useDisclosure(false);
const [btnDisable, setBtnDisable] = useState(true);
const [btnLoading, setBtnLoading] = useState(false);
const [opened, { open, close }] = useDisclosure(false);
const [openedTambah, { open: openTambah, close: closeTambah }] = useDisclosure(false);
+ const [dataDelete, setDataDelete] = useState("")
const { data, mutate, isLoading } = useSWR("/", () =>
apiFetch.api.pengaduan.category.get(),
);
- const list = data?.data || [];
+ const list = data?.data?.data || [];
const [dataEdit, setDataEdit] = useState({
id: "",
name: "",
@@ -58,7 +61,7 @@ export default function KategoriPengaduan() {
})
}
} catch (error) {
- console.log(error);
+ console.error(error);
notification({
title: "Error",
message: "Failed to create category",
@@ -89,7 +92,7 @@ export default function KategoriPengaduan() {
})
}
} catch (error) {
- console.log(error);
+ console.error(error);
notification({
title: "Error",
message: "Failed to edit category",
@@ -121,6 +124,37 @@ export default function KategoriPengaduan() {
}
}
+ async function handleDelete() {
+ try {
+ setBtnLoading(true);
+ const res = await apiFetch.api.pengaduan.category.delete.post({ id: dataDelete });
+ if (res.status === 200) {
+ mutate();
+ closeDelete();
+ notification({
+ title: "Success",
+ message: "Your category have been deleted",
+ type: "success",
+ })
+ } else {
+ notification({
+ title: "Error",
+ message: "Failed to delete category",
+ type: "error",
+ })
+ }
+ } catch (error) {
+ console.error(error);
+ notification({
+ title: "Error",
+ message: "Failed to delete category",
+ type: "error",
+ })
+ } finally {
+ setBtnLoading(false);
+ }
+ }
+
useShallowEffect(() => {
if (dataEdit.name.length > 0) {
setBtnDisable(false);
@@ -182,6 +216,29 @@ export default function KategoriPengaduan() {
+ {/* Modal Delete */}
+
+
+
+ Apakah anda yakin ingin menghapus kategori ini?
+
+
+
+
+
+
+
+
+
@@ -212,16 +269,32 @@ export default function KategoriPengaduan() {
{v.name}
-
- chooseEdit({ data: v })}
- >
-
-
-
+
+
+ chooseEdit({ data: v })}
+ >
+
+
+
+
+ {
+ setDataDelete(v.id)
+ openDelete()
+ }}
+ >
+
+
+
+
))}