rev: hapus kegiatan
Deskripsi: - hapus data pada saat status batal pada fitur kegiatan dan tugas divisi No Issues
This commit is contained in:
@@ -144,4 +144,14 @@ export const funAddFileTask = async (path: string, data: FormData) => {
|
||||
body: data,
|
||||
});
|
||||
return await response.json().catch(() => null);
|
||||
};
|
||||
|
||||
export const funDeleteTask = async (path: string) => {
|
||||
const response = await fetch(`/api/task/${path}/lainnya`, {
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
return await response.json().catch(() => null);
|
||||
};
|
||||
@@ -7,12 +7,13 @@ import { useShallowEffect } from "@mantine/hooks";
|
||||
import { useParams, useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import toast from "react-hot-toast";
|
||||
import { FaFileCirclePlus, FaPencil, FaUsers } from "react-icons/fa6";
|
||||
import { FaFileCirclePlus, FaPencil, FaTrash, FaUsers } from "react-icons/fa6";
|
||||
import { HiMenu } from "react-icons/hi";
|
||||
import { IoAddCircle } from "react-icons/io5";
|
||||
import { MdCancel } from "react-icons/md";
|
||||
import { funGetTaskDivisionById } from "../lib/api_task";
|
||||
import { funDeleteTask, funGetTaskDivisionById } from "../lib/api_task";
|
||||
import { useWibuRealtime } from "wibu-realtime";
|
||||
import LayoutModal from "@/module/_global/layout/layout_modal";
|
||||
|
||||
export default function NavbarDetailDivisionTask() {
|
||||
const router = useRouter()
|
||||
@@ -24,6 +25,8 @@ export default function NavbarDetailDivisionTask() {
|
||||
const memberDivision = useHookstate(globalIsMemberDivision)
|
||||
const tema = useHookstate(TEMA)
|
||||
const [reason, setReason] = useState("")
|
||||
const [loadingModal, setLoadingModal] = useState(false)
|
||||
const [openModal, setOpenModal] = useState(false)
|
||||
const [dataRealTime, setDataRealtime] = useWibuRealtime({
|
||||
WIBU_REALTIME_TOKEN: keyWibu,
|
||||
project: "sdm"
|
||||
@@ -45,6 +48,29 @@ export default function NavbarDetailDivisionTask() {
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteDataProject() {
|
||||
try {
|
||||
setLoadingModal(true)
|
||||
const res = await funDeleteTask(param.detail);
|
||||
if (res.success) {
|
||||
setDataRealtime([{
|
||||
category: "tugas-delete",
|
||||
id: param.detail,
|
||||
}])
|
||||
toast.success(res.message)
|
||||
router.push("/division/" + param.id + "/task")
|
||||
} else {
|
||||
toast.error(res.message)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
toast.error("Gagal menghapus data tugas divisi, coba lagi nanti");
|
||||
} finally {
|
||||
setLoadingModal(false)
|
||||
setOpenModal(false)
|
||||
}
|
||||
}
|
||||
|
||||
useShallowEffect(() => {
|
||||
getOneData();
|
||||
}, [param.detail])
|
||||
@@ -54,6 +80,13 @@ export default function NavbarDetailDivisionTask() {
|
||||
if (dataRealTime && dataRealTime.some((i: any) => (i.category == 'tugas-detail' || i.category == 'tugas-detail-status') && i.id == param.detail)) {
|
||||
getOneData()
|
||||
}
|
||||
|
||||
if (dataRealTime && dataRealTime.some((i: any) => i.category == 'tugas-delete' && i.id == param.detail)) {
|
||||
toast.error("Data telah dihapus, anda akan beralih ke halaman list tugas divisi")
|
||||
setTimeout(() => {
|
||||
router.push("/division/" + param.id + "/task")
|
||||
}, 1000)
|
||||
}
|
||||
}, [dataRealTime])
|
||||
|
||||
return (
|
||||
@@ -156,23 +189,39 @@ export default function NavbarDetailDivisionTask() {
|
||||
<Text c={reason == null ? tema.get().utama : "gray"} ta='center'>Edit</Text>
|
||||
</Box>
|
||||
</Flex>
|
||||
{
|
||||
reason == null ?
|
||||
<Flex justify={'center'} align={'center'} direction={'column'}
|
||||
style={{
|
||||
cursor: 'pointer'
|
||||
}}
|
||||
onClick={() => {
|
||||
reason == null ?
|
||||
router.push(param.detail + '/cancel')
|
||||
: null
|
||||
}} >
|
||||
<Box>
|
||||
<MdCancel size={30} color={reason == null ? tema.get().utama : "gray"} />
|
||||
</Box>
|
||||
<Box>
|
||||
<Text c={reason == null ? tema.get().utama : "gray"} ta='center'>Batal</Text>
|
||||
</Box>
|
||||
</Flex>
|
||||
:
|
||||
<Flex justify={'center'} align={'center'} direction={'column'}
|
||||
style={{
|
||||
cursor: 'pointer'
|
||||
}}
|
||||
onClick={() => { setOpenModal(true) }} >
|
||||
<Box>
|
||||
<FaTrash size={30} color={tema.get().utama} />
|
||||
</Box>
|
||||
<Box>
|
||||
<Text c={tema.get().utama} ta='center'>Hapus</Text>
|
||||
</Box>
|
||||
</Flex>
|
||||
}
|
||||
|
||||
<Flex justify={'center'} align={'center'} direction={'column'}
|
||||
style={{
|
||||
cursor: 'pointer'
|
||||
}}
|
||||
onClick={() => {
|
||||
reason == null ?
|
||||
router.push(param.detail + '/cancel')
|
||||
: null
|
||||
}} >
|
||||
<Box>
|
||||
<MdCancel size={30} color={reason == null ? tema.get().utama : "gray"} />
|
||||
</Box>
|
||||
<Box>
|
||||
<Text c={reason == null ? tema.get().utama : "gray"} ta='center'>Batal</Text>
|
||||
</Box>
|
||||
</Flex>
|
||||
</> : <></>
|
||||
|
||||
}
|
||||
@@ -182,6 +231,10 @@ export default function NavbarDetailDivisionTask() {
|
||||
</Stack>
|
||||
</Box>
|
||||
</LayoutDrawer>
|
||||
|
||||
<LayoutModal loading={loadingModal} opened={openModal} onClose={() => setOpenModal(false)}
|
||||
description="Apakah Anda yakin ingin menghapus tugas divisi ini?"
|
||||
onYes={(val) => { val ? deleteDataProject() : setOpenModal(false) }} />
|
||||
</>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user