diff --git a/src/App.tsx b/src/App.tsx
index 774136b..69863ef 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -1,7 +1,7 @@
import "@mantine/core/styles.css";
-import "@mantine/notifications/styles.css";
import "@mantine/dates/styles.css";
import { Notifications } from "@mantine/notifications";
+import "@mantine/notifications/styles.css";
import { MantineProvider } from "@mantine/core";
import AppRoutes from "./AppRoutes";
diff --git a/src/components/DesaSetting.tsx b/src/components/DesaSetting.tsx
new file mode 100644
index 0000000..fa9e3f3
--- /dev/null
+++ b/src/components/DesaSetting.tsx
@@ -0,0 +1,157 @@
+import apiFetch from "@/lib/apiFetch";
+import {
+ ActionIcon,
+ Button,
+ Divider,
+ Flex,
+ Group,
+ Input,
+ Modal,
+ Stack,
+ Table,
+ Title,
+ Tooltip
+} from "@mantine/core";
+import { useDisclosure, useShallowEffect } from "@mantine/hooks";
+import { IconEdit } from "@tabler/icons-react";
+import { useState } from "react";
+import useSWR from "swr";
+import notification from "./notificationGlobal";
+
+export default function DesaSetting() {
+ const [btnDisable, setBtnDisable] = useState(false);
+ const [btnLoading, setBtnLoading] = useState(false);
+ const [opened, { open, close }] = useDisclosure(false);
+ const { data, mutate, isLoading } = useSWR("/", () =>
+ apiFetch.api["configuration-desa"].list.get(),
+ );
+ const list = data?.data || [];
+ const [dataEdit, setDataEdit] = useState({
+ id: "",
+ value: "",
+ name: "",
+ });
+
+ useShallowEffect(() => {
+ mutate();
+ }, []);
+
+ async function handleEdit() {
+ try {
+ setBtnLoading(true);
+ const res = await apiFetch.api["configuration-desa"].edit.post(dataEdit);
+ if (res.status === 200) {
+ mutate();
+ close();
+ notification({
+ title: "Success",
+ message: "Your settings have been saved",
+ type: "success",
+ })
+ } else {
+ notification({
+ title: "Error",
+ message: "Failed to edit configuration",
+ type: "error",
+ })
+ }
+ } catch (error) {
+ console.log(error);
+ notification({
+ title: "Error",
+ message: "Failed to edit configuration",
+ type: "error",
+ })
+ } finally {
+ setBtnLoading(false);
+ }
+ }
+
+ function chooseEdit({ data }: { data: { id: string, value: string, name: string } }) {
+ setDataEdit(data);
+ open();
+ }
+
+ function onValidation({ kat, value }: { kat: 'value', value: string }) {
+ if (value.length < 1) {
+ setBtnDisable(true);
+ } else {
+ setBtnDisable(false);
+ }
+
+ if (kat === 'value') {
+ setDataEdit({ ...dataEdit, value: value });
+ }
+ }
+
+ useShallowEffect(() => {
+ if (dataEdit.value.length > 0) {
+ setBtnDisable(false);
+ }
+ }, [dataEdit.id]);
+
+ return (
+ <>
+
+
+
+ onValidation({ kat: 'value', value: e.target.value })} />
+
+
+
+
+
+
+
+
+
+
+ Pengaturan Desa
+
+
+
+
+
+
+
+ Nama
+ Value
+ Aksi
+
+
+
+ {list?.map((v: any) => (
+
+ {v.name}
+ {v.value}
+
+
+ chooseEdit({ data: v })}
+ >
+
+
+
+
+
+ ))}
+
+
+
+
+ >
+ );
+}
diff --git a/src/components/notificationGlobal.ts b/src/components/notificationGlobal.ts
new file mode 100644
index 0000000..2363a8a
--- /dev/null
+++ b/src/components/notificationGlobal.ts
@@ -0,0 +1,38 @@
+import { showNotification } from "@mantine/notifications";
+
+export default function notification({ title, message, type }: { title: string, message: string, type: "success" | "error" | "warning" | "info" }) {
+ switch (type) {
+ case "success":
+ return showNotification({
+ title,
+ message,
+ color: "green",
+ autoClose: 3000,
+ })
+ break;
+ case "error":
+ return showNotification({
+ title,
+ message,
+ color: "red",
+ autoClose: 3000,
+ })
+ break;
+ case "warning":
+ return showNotification({
+ title,
+ message,
+ color: "orange",
+ autoClose: 3000,
+ })
+ break;
+ case "info":
+ return showNotification({
+ title,
+ message,
+ color: "blue",
+ autoClose: 3000,
+ })
+ break;
+ }
+}
\ No newline at end of file
diff --git a/src/index.tsx b/src/index.tsx
index 7f6390e..202417e 100644
--- a/src/index.tsx
+++ b/src/index.tsx
@@ -1,3 +1,4 @@
+import cors from "@elysiajs/cors";
import Swagger from "@elysiajs/swagger";
import Elysia from "elysia";
import html from "./index.html";
@@ -14,7 +15,7 @@ import PelayananRoute from "./server/routes/pelayanan_surat_route";
import PengaduanRoute from "./server/routes/pengaduan_route";
import TestRoute from "./server/routes/test";
import UserRoute from "./server/routes/user_route";
-import cors from "@elysiajs/cors";
+import ConfigurationDesaRoute from "./server/routes/configuration_desa_route";
const Docs = new Elysia({
tags: ["docs"],
@@ -30,6 +31,7 @@ const Api = new Elysia({
})
.use(PengaduanRoute)
.use(PelayananRoute)
+ .use(ConfigurationDesaRoute)
.use(TestRoute)
.use(apiAuth)
.use(ApiKeyRoute)
diff --git a/src/pages/scr/dashboard/setting/detail_setting_page.tsx b/src/pages/scr/dashboard/setting/detail_setting_page.tsx
index ec6e714..230e5ae 100644
--- a/src/pages/scr/dashboard/setting/detail_setting_page.tsx
+++ b/src/pages/scr/dashboard/setting/detail_setting_page.tsx
@@ -1,150 +1,171 @@
-import { Button, Card, Container, Divider, Flex, Grid, Group, Input, NavLink, Stack, Table, Title } from "@mantine/core";
-import { IconCircleOff, IconGauge, IconHome2 } from "@tabler/icons-react";
+import DesaSetting from "@/components/DesaSetting";
+import {
+ Button,
+ Card,
+ Container,
+ Divider,
+ Flex,
+ Grid,
+ Group,
+ Input,
+ NavLink,
+ Stack,
+ Table,
+ Title,
+} from "@mantine/core";
+import {
+ IconBuildingBank,
+ IconCategory2,
+ IconMailSpark,
+ IconUserCog,
+} from "@tabler/icons-react";
import { useLocation } from "react-router-dom";
export default function DetailSettingPage() {
- const { search } = useLocation();
- const query = new URLSearchParams(search);
- const type = query.get("type");
+ const { search } = useLocation();
+ const query = new URLSearchParams(search);
+ const type = query.get("type");
- return (
-
-
-
-
- }
- active={type === "profile" || !type}
- />
- }
- active={type === "cat-pengaduan"}
- />
- }
- active={type === "cat-pelayanan"}
- />
- }
- active={type === "desa"}
- />
-
-
-
-
- {type === "cat-pengaduan"
- ?
- : type === "cat-pelayanan"
- ?
- : type === "desa"
- ?
- : }
-
-
-
-
- );
+ return (
+
+
+
+
+ }
+ active={type === "profile" || !type}
+ />
+ }
+ active={type === "cat-pengaduan"}
+ />
+ }
+ active={type === "cat-pelayanan"}
+ />
+ }
+ active={type === "desa"}
+ />
+
+
+
+
+ {type === "cat-pengaduan" ? (
+
+ ) : type === "cat-pelayanan" ? (
+
+ ) : type === "desa" ? (
+
+ ) : (
+
+ )}
+
+
+
+
+ );
}
function ProfilePage() {
- return (
+ return (
+
+
+
+ Profile Pengguna
+
+
+
+
-
-
- Profile Pengguna
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
- )
+
+ );
}
function KategoriPengaduanPage() {
- const elements = [
- { position: 6, mass: 12.011, symbol: "C", name: "Carbon" },
- { position: 7, mass: 14.007, symbol: "N", name: "Nitrogen" },
- { position: 39, mass: 88.906, symbol: "Y", name: "Yttrium" },
- { position: 56, mass: 137.33, symbol: "Ba", name: "Barium" },
- { position: 58, mass: 140.12, symbol: "Ce", name: "Cerium" },
- ];
+ const elements = [
+ { position: 6, mass: 12.011, symbol: "C", name: "Carbon" },
+ { position: 7, mass: 14.007, symbol: "N", name: "Nitrogen" },
+ { position: 39, mass: 88.906, symbol: "Y", name: "Yttrium" },
+ { position: 56, mass: 137.33, symbol: "Ba", name: "Barium" },
+ { position: 58, mass: 140.12, symbol: "Ce", name: "Cerium" },
+ ];
- const rows = elements.map((element) => (
-
- {element.position}
- {element.name}
- {element.symbol}
- {element.mass}
-
- ));
- return (
+ const rows = elements.map((element) => (
+
+ {element.position}
+ {element.name}
+ {element.symbol}
+ {element.mass}
+
+ ));
+ return (
+
+
+
+ Kategori Pengaduan
+
+
+
+
-
-
- Kategori Pengaduan
-
-
-
-
-
-
-
-
- Tanggal
- Deskripsi
- Status
- User
-
-
- {rows}
-
-
+
+
+
+ Tanggal
+ Deskripsi
+ Status
+ User
+
+
+ {rows}
+
- )
+
+ );
}
diff --git a/src/server/routes/configuration_desa_route.ts b/src/server/routes/configuration_desa_route.ts
new file mode 100644
index 0000000..f6142f3
--- /dev/null
+++ b/src/server/routes/configuration_desa_route.ts
@@ -0,0 +1,48 @@
+import Elysia, { t } from "elysia";
+import { prisma } from "../lib/prisma";
+
+const ConfigurationDesaRoute = new Elysia({
+ prefix: "configuration-desa",
+ tags: ["configuration-desa"],
+})
+
+ .get("/list", async () => {
+ const data = await prisma.configuration.findMany({
+ orderBy: {
+ name: "asc"
+ }
+ })
+
+ return data
+ }, {
+ detail: {
+ summary: "List Konfigurasi",
+ description: `tool untuk mendapatkan list konfigurasi`,
+ }
+ })
+ .post("/edit", async ({ body }) => {
+ const { id, value } = body
+
+ await prisma.configuration.update({
+ where: {
+ id,
+ },
+ data: {
+ value,
+ }
+ })
+
+ return { success: true, message: 'konfigurasi sudah diperbarui' }
+ }, {
+ body: t.Object({
+ id: t.String({ minLength: 1, error: "id harus diisi" }),
+ value: t.String({ minLength: 1, error: "value harus diisi" }),
+ }),
+ detail: {
+ summary: "edit konfigurasi desa",
+ description: `tool untuk edit konfigurasi desa`
+ }
+ })
+ ;
+
+export default ConfigurationDesaRoute