rev: hapus kegiatan

Deskripsi:
- hapus data pada saat status batal pada fitur kegiatan dan tugas divisi

No Issues
This commit is contained in:
amel
2025-02-04 17:19:17 +08:00
parent bcd9e98518
commit 6836ea9f09
8 changed files with 262 additions and 48 deletions

View File

@@ -1,17 +1,18 @@
'use client'
import { globalRole, keyWibu, LayoutDrawer, LayoutNavbarNew, TEMA } from '@/module/_global';
import LayoutModal from '@/module/_global/layout/layout_modal';
import { useHookstate } from '@hookstate/core';
import { ActionIcon, Box, Flex, SimpleGrid, Stack, Text } from '@mantine/core';
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 { useWibuRealtime } from 'wibu-realtime';
import { funGetOneProjectById } from '../lib/api_project';
import { funDeleteProject, funGetOneProjectById } from '../lib/api_project';
import { globalIsMemberProject } from '../lib/val_project';
export default function NavbarDetailProject() {
@@ -24,6 +25,8 @@ export default function NavbarDetailProject() {
const memberProject = useHookstate(globalIsMemberProject)
const tema = useHookstate(TEMA)
const [reason, setReason] = useState("")
const [openModal, setOpenModal] = useState(false)
const [loadingModal, setLoadingModal] = useState(false)
const [dataRealTime, setDataRealtime] = useWibuRealtime({
WIBU_REALTIME_TOKEN: keyWibu,
project: "sdm"
@@ -39,10 +42,32 @@ export default function NavbarDetailProject() {
} else {
toast.error(res.message);
}
} catch (error) {
console.error(error);
toast.error("Gagal mendapatkan data Kegiatan, coba lagi nanti");
toast.error("Gagal mendapatkan data kegiatan, coba lagi nanti");
}
}
async function deleteDataProject() {
try {
setLoadingModal(true)
const res = await funDeleteProject(param.id);
if (res.success) {
setDataRealtime([{
category: "project-delete",
id: param.id,
}])
toast.success(res.message)
router.push("/project")
} else {
toast.error(res.message)
}
} catch (error) {
console.error(error);
toast.error("Gagal menghapus data kegiatan, coba lagi nanti");
} finally {
setLoadingModal(false)
setOpenModal(false)
}
}
@@ -54,6 +79,13 @@ export default function NavbarDetailProject() {
if (dataRealTime && dataRealTime.some((i: any) => (i.category == 'project-detail' || i.category == 'project-detail-status') && i.id == param.id)) {
getOneData()
}
if (dataRealTime && dataRealTime.some((i: any) => (i.category == 'project-delete') && i.id == param.id)) {
toast.error("Data telah dihapus, anda akan beralih ke halaman list kegiatan")
setTimeout(() => {
router.push("/project")
}, 1000)
}
}, [dataRealTime])
return (
@@ -158,24 +190,34 @@ export default function NavbarDetailProject() {
<Text c={reason == null ? tema.get().utama : "gray"} ta='center'>Edit</Text>
</Box>
</Flex>
<Flex justify={'center'} align={'center'} direction={'column'}
style={{
cursor: 'pointer'
}}
onClick={() => {
reason == null ?
router.push(param.id + '/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>
{
reason == null ?
<Flex justify={'center'} align={'center'} direction={'column'} style={{ cursor: 'pointer' }}
onClick={() => {
reason == null ?
router.push(param.id + '/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>
}
</>
}
@@ -183,6 +225,10 @@ export default function NavbarDetailProject() {
</Stack>
</Box>
</LayoutDrawer>
<LayoutModal loading={loadingModal} opened={openModal} onClose={() => setOpenModal(false)}
description="Apakah Anda yakin ingin menghapus kegiatan ini?"
onYes={(val) => { val ? deleteDataProject() : setOpenModal(false) }} />
</>
);
}