upd: pengajuan surat
Deskripsi: - form edit data pelengkap No Issues
This commit is contained in:
@@ -712,7 +712,7 @@ function DataUpdate({
|
||||
(n: any) => n.key === item.key,
|
||||
)?.value,
|
||||
)
|
||||
: parseTanggalID(item.value)
|
||||
: parseTanggalID(item.value)
|
||||
}
|
||||
/>
|
||||
) : (
|
||||
|
||||
@@ -2,7 +2,9 @@ import ModalFile from "@/components/ModalFile";
|
||||
import ModalSurat from "@/components/ModalSurat";
|
||||
import notification from "@/components/notificationGlobal";
|
||||
import apiFetch from "@/lib/apiFetch";
|
||||
import { parseTanggalID } from "@/server/lib/stringToDate";
|
||||
import {
|
||||
ActionIcon,
|
||||
Anchor,
|
||||
Badge,
|
||||
Button,
|
||||
@@ -14,24 +16,31 @@ import {
|
||||
Group,
|
||||
List,
|
||||
Modal,
|
||||
Select,
|
||||
Spoiler,
|
||||
Stack,
|
||||
Table,
|
||||
Text,
|
||||
Textarea,
|
||||
TextInput,
|
||||
ThemeIcon,
|
||||
Title,
|
||||
Tooltip
|
||||
} from "@mantine/core";
|
||||
import { DateInput } from "@mantine/dates";
|
||||
import { useDisclosure, useShallowEffect } from "@mantine/hooks";
|
||||
import {
|
||||
IconAlignJustified,
|
||||
IconCheck,
|
||||
IconEdit,
|
||||
IconFileCertificate,
|
||||
IconFileCheck,
|
||||
IconInfoCircle,
|
||||
IconMessageReport,
|
||||
IconPhone,
|
||||
IconUser,
|
||||
} from "@tabler/icons-react";
|
||||
import dayjs from "dayjs";
|
||||
import type { User } from "generated/prisma";
|
||||
import type { JsonValue } from "generated/prisma/runtime/library";
|
||||
import _ from "lodash";
|
||||
@@ -93,6 +102,7 @@ function DetailDataPengajuan({
|
||||
dataText: any;
|
||||
onAction: () => void;
|
||||
}) {
|
||||
|
||||
const [opened, { open, close }] = useDisclosure(false);
|
||||
const [catModal, setCatModal] = useState<"tolak" | "terima">("tolak");
|
||||
const [keterangan, setKeterangan] = useState("");
|
||||
@@ -103,6 +113,9 @@ function DetailDataPengajuan({
|
||||
const [permissions, setPermissions] = useState<JsonValue[]>([]);
|
||||
const [viewImg, setViewImg] = useState({ file: "", folder: "" });
|
||||
const [uploading, setUploading] = useState({ ok: false, file: "" });
|
||||
const [editValue, setEditValue] = useState({ id: "", jenis: "", val: "", option: null as any, type: "", key: "" })
|
||||
const [openEdit, setOpenEdit] = useState(false)
|
||||
const [loadingUpdate, setLoadingUpdate] = useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
async function fetchHost() {
|
||||
@@ -215,6 +228,43 @@ function DetailDataPengajuan({
|
||||
}
|
||||
};
|
||||
|
||||
async function updateDataText() {
|
||||
try {
|
||||
setLoadingUpdate(true)
|
||||
const res = await apiFetch.api.pelayanan["update-data-pelengkap"].post({
|
||||
id: editValue.id,
|
||||
value: editValue.val,
|
||||
jenis: editValue.key,
|
||||
idUser: host?.id ?? "",
|
||||
})
|
||||
|
||||
if (res?.status === 200) {
|
||||
notification({
|
||||
title: "Success",
|
||||
message: "Success update data",
|
||||
type: "success",
|
||||
})
|
||||
} else {
|
||||
notification({
|
||||
title: "Error",
|
||||
message: "Failed to update data",
|
||||
type: "error",
|
||||
})
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
notification({
|
||||
title: "Error",
|
||||
message: "Failed to update data",
|
||||
type: "error",
|
||||
})
|
||||
} finally {
|
||||
setLoadingUpdate(false)
|
||||
setOpenEdit(false)
|
||||
onAction()
|
||||
}
|
||||
}
|
||||
|
||||
useShallowEffect(() => {
|
||||
if (viewImg) {
|
||||
setOpenedPreviewFile(true);
|
||||
@@ -231,9 +281,86 @@ function DetailDataPengajuan({
|
||||
}
|
||||
}, [uploading]);
|
||||
|
||||
function FieldLabel({ label, hint }: { label: string; hint?: string }) {
|
||||
return (
|
||||
<Group justify="apart" gap="xs" align="center">
|
||||
<Text fw={600}>{label}</Text>
|
||||
{hint && (
|
||||
<Tooltip label={hint} withArrow>
|
||||
<ActionIcon size={24} variant="subtle">
|
||||
<IconInfoCircle size={16} />
|
||||
</ActionIcon>
|
||||
</Tooltip>
|
||||
)}
|
||||
</Group>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
{/* MODAL EDIT DATA PELENGKAP */}
|
||||
<Modal
|
||||
opened={openEdit}
|
||||
onClose={() => setOpenEdit(false)}
|
||||
title={"Edit"}
|
||||
overlayProps={{ backgroundOpacity: 0.55, blur: 3 }}
|
||||
>
|
||||
<Stack gap="ld">
|
||||
{editValue.type == "enum" ? (
|
||||
<Select
|
||||
allowDeselect={false}
|
||||
label={<FieldLabel label={editValue.jenis} />}
|
||||
data={editValue.option ?? []}
|
||||
placeholder={editValue.jenis}
|
||||
onChange={(e) => { setEditValue({ ...editValue, val: e ?? "" }) }}
|
||||
value={editValue.val}
|
||||
/>
|
||||
) : editValue.type == "date" ? (
|
||||
<DateInput
|
||||
locale="id"
|
||||
valueFormat="DD MMMM YYYY"
|
||||
label={<FieldLabel label={editValue.jenis} />}
|
||||
placeholder={editValue.jenis}
|
||||
onChange={(e) => {
|
||||
const formatted = e
|
||||
? dayjs(e).locale("id").format("DD MMMM YYYY")
|
||||
: "";
|
||||
setEditValue({
|
||||
...editValue,
|
||||
val: formatted
|
||||
})
|
||||
}}
|
||||
value={
|
||||
editValue.val
|
||||
? parseTanggalID(editValue.val)
|
||||
: parseTanggalID(editValue.val)
|
||||
}
|
||||
/>
|
||||
) : (
|
||||
<TextInput
|
||||
label={<FieldLabel label={editValue.jenis} />}
|
||||
placeholder={editValue.jenis}
|
||||
type={editValue.type}
|
||||
onChange={(e) => { setEditValue({ ...editValue, val: e.target.value }) }}
|
||||
value={editValue.val}
|
||||
/>
|
||||
)}
|
||||
<Group justify="center" grow>
|
||||
<Button variant="light" onClick={() => { setOpenEdit(false) }}>
|
||||
Batal
|
||||
</Button>
|
||||
<Button
|
||||
variant="filled"
|
||||
onClick={updateDataText}
|
||||
disabled={loadingUpdate || !editValue.val}
|
||||
loading={loadingUpdate}
|
||||
>
|
||||
Simpan
|
||||
</Button>
|
||||
</Group>
|
||||
</Stack>
|
||||
</Modal>
|
||||
|
||||
<ModalFile
|
||||
open={openedPreviewFile && !_.isEmpty(viewImg.file)}
|
||||
onClose={() => {
|
||||
@@ -413,7 +540,25 @@ function DetailDataPengajuan({
|
||||
</Table.Td>
|
||||
<Table.Td>:</Table.Td>
|
||||
<Table.Td style={{ width: "85%" }}>
|
||||
{_.upperFirst(item.value)}
|
||||
<Flex
|
||||
gap="md"
|
||||
justify="flex-start"
|
||||
align="center"
|
||||
direction="row"
|
||||
>
|
||||
<Text>
|
||||
{_.upperFirst(item.value)}
|
||||
</Text>
|
||||
<ActionIcon
|
||||
variant="subtle"
|
||||
aria-label="Edit"
|
||||
onClick={() => {
|
||||
setEditValue({ id: item.id, val: item.value, type: item.type, option: item.options, jenis: item.jenis, key: item.key })
|
||||
setOpenEdit(true)
|
||||
}}>
|
||||
<IconEdit size={16} />
|
||||
</ActionIcon>
|
||||
</Flex>
|
||||
</Table.Td>
|
||||
</Table.Tr>
|
||||
))}
|
||||
|
||||
@@ -308,7 +308,11 @@ const PelayananRoute = new Elysia({
|
||||
})
|
||||
|
||||
const dataTextCategory = (data?.CategoryPelayanan?.dataPelengkap ?? []) as {
|
||||
name: string;
|
||||
type: string;
|
||||
options?: {
|
||||
label: string,
|
||||
value: string
|
||||
}[]; name: string;
|
||||
desc: string;
|
||||
key: string;
|
||||
}[];
|
||||
@@ -327,7 +331,10 @@ const PelayananRoute = new Elysia({
|
||||
return {
|
||||
id: item.id,
|
||||
jenis: nama,
|
||||
key: ref?.key,
|
||||
value: item.value,
|
||||
type: ref?.type ?? "",
|
||||
options: ref?.options ?? [],
|
||||
order: ref?.order ?? Infinity,
|
||||
};
|
||||
})
|
||||
@@ -1050,6 +1057,73 @@ const PelayananRoute = new Elysia({
|
||||
description: `tool untuk update data pengajuan pelayanan surat`,
|
||||
}
|
||||
})
|
||||
.post("/update-data-pelengkap", async ({ body }) => {
|
||||
const { id, value, jenis, idUser } = body
|
||||
|
||||
const dataPelengkap = await prisma.dataTextPelayanan.findUnique({
|
||||
where: {
|
||||
id
|
||||
},
|
||||
select: {
|
||||
idPengajuanLayanan: true,
|
||||
PelayananAjuan: {
|
||||
select: {
|
||||
status: true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
if (!dataPelengkap) {
|
||||
return { success: false, message: 'data pelengkap surat tidak ditemukan' }
|
||||
}
|
||||
|
||||
const upd = await prisma.dataTextPelayanan.update({
|
||||
where: {
|
||||
id
|
||||
},
|
||||
data: {
|
||||
value: value,
|
||||
}
|
||||
})
|
||||
|
||||
const history = await prisma.historyPelayanan.create({
|
||||
data: {
|
||||
idPengajuanLayanan: dataPelengkap.idPengajuanLayanan,
|
||||
deskripsi: `Pengajuan surat diupdate oleh user (data yg diupdate: ${jenis})`,
|
||||
status: dataPelengkap.PelayananAjuan.status,
|
||||
idUser
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
return { success: true, message: 'data pelengkap surat sudah diperbarui' }
|
||||
|
||||
}, {
|
||||
body: t.Object({
|
||||
id: t.String({
|
||||
error: "id harus diisi",
|
||||
description: "ID yang ingin diupdate"
|
||||
}),
|
||||
value: t.String({
|
||||
error: "value harus diisi",
|
||||
description: "Value yang ingin diupdate"
|
||||
}),
|
||||
jenis: t.String({
|
||||
error: "jenis harus diisi",
|
||||
description: "Jenis data yang ingin diupdate"
|
||||
}),
|
||||
idUser: t.String({
|
||||
error: "idUser harus diisi",
|
||||
description: "ID user yang melakukan update"
|
||||
})
|
||||
}),
|
||||
detail: {
|
||||
summary: "Update Data Pelengkap Pengajuan Pelayanan Surat oleh user admin",
|
||||
description: `tool untuk update data pelengkap pengajuan pelayanan surat oleh user admin`,
|
||||
}
|
||||
})
|
||||
.get("/list", async ({ query }) => {
|
||||
const { take, page, search, status } = query
|
||||
const skip = !page ? 0 : (Number(page) - 1) * (!take ? 10 : Number(take))
|
||||
|
||||
Reference in New Issue
Block a user