mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-21 22:05:45 +00:00
feat(FE): Add chickin delete functionality with modal confirmation
This commit is contained in:
@@ -23,7 +23,7 @@ const ChickinLogsView = ({
|
||||
rawDataApprovals: BaseApproval[];
|
||||
}) => {
|
||||
const [chickinErrorMessage, setChickinErrorMessage] = useState('');
|
||||
const { openChickinApproveModal } = useChickinStore();
|
||||
const { openChickinApproveModal, openChickinDeleteModal } = useChickinStore();
|
||||
|
||||
const handleClickApprove = () => {
|
||||
openChickinApproveModal(initialValues, async (notes?: string) => {
|
||||
@@ -44,6 +44,21 @@ const ChickinLogsView = ({
|
||||
});
|
||||
};
|
||||
|
||||
const handleDeleteChickin = (chickinId: number) => {
|
||||
openChickinDeleteModal(chickinId, async () => {
|
||||
const deleteRes = await ChickinApi.delete(chickinId);
|
||||
|
||||
if (isResponseSuccess(deleteRes)) {
|
||||
toast.success(deleteRes?.message || 'Chickin berhasil dihapus');
|
||||
afterSubmit && afterSubmit();
|
||||
}
|
||||
|
||||
if (isResponseError(deleteRes)) {
|
||||
toast.error(deleteRes?.message || 'Gagal menghapus chickin');
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className='px-4 pb-4 flex flex-col gap-4'>
|
||||
@@ -86,14 +101,30 @@ const ChickinLogsView = ({
|
||||
<div className='text-lg font-semibold'>
|
||||
Chick In #{index + 1} - {latestApproval?.step_number}
|
||||
</div>
|
||||
<PillBadge
|
||||
content={
|
||||
isApproved ? 'Disetujui' : isPending ? 'Pending' : '-'
|
||||
}
|
||||
color={
|
||||
isApproved ? 'green' : isPending ? 'yellow' : 'gray'
|
||||
}
|
||||
/>
|
||||
<div className='flex flex-row gap-2 items-center'>
|
||||
<PillBadge
|
||||
content={
|
||||
isApproved ? 'Disetujui' : isPending ? 'Pending' : '-'
|
||||
}
|
||||
color={
|
||||
isApproved ? 'green' : isPending ? 'yellow' : 'gray'
|
||||
}
|
||||
/>
|
||||
|
||||
{isApproved && (
|
||||
<Button
|
||||
color='error'
|
||||
className='w-fit text-sm text-base-100 rounded-lg shadow-sm btn-xs!'
|
||||
onClick={() => handleDeleteChickin(chickin.id)}
|
||||
>
|
||||
<Icon
|
||||
icon='heroicons:trash-solid'
|
||||
width={10}
|
||||
height={10}
|
||||
/>
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Tanggal Chick In */}
|
||||
@@ -169,6 +200,7 @@ const ChickinLogsView = ({
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -200,6 +200,7 @@ const ProjectFlockTable = ({ refresh }: { refresh?: () => void }) => {
|
||||
const confirmModal = useModal();
|
||||
const successModal = useModal();
|
||||
const chickinApproveModal = useModal();
|
||||
const chickinDeleteModal = useModal();
|
||||
const closingModal = useModal();
|
||||
const [approvalAction, setApprovalAction] = useState<'APPROVED' | 'REJECTED'>(
|
||||
'APPROVED'
|
||||
@@ -214,6 +215,11 @@ const ProjectFlockTable = ({ refresh }: { refresh?: () => void }) => {
|
||||
chickinApproveCallback,
|
||||
closeChickinApproveModal,
|
||||
setChickinApproveLoading,
|
||||
isChickinDeleteModalOpen,
|
||||
isChickinDeleteLoading,
|
||||
chickinDeleteCallback,
|
||||
closeChickinDeleteModal,
|
||||
setChickinDeleteLoading,
|
||||
} = useChickinStore();
|
||||
|
||||
const {
|
||||
@@ -478,6 +484,14 @@ const ProjectFlockTable = ({ refresh }: { refresh?: () => void }) => {
|
||||
}
|
||||
}, [isChickinApproveModalOpen, chickinApproveModal]);
|
||||
|
||||
useEffect(() => {
|
||||
if (isChickinDeleteModalOpen) {
|
||||
chickinDeleteModal.openModal();
|
||||
} else {
|
||||
chickinDeleteModal.closeModal();
|
||||
}
|
||||
}, [isChickinDeleteModalOpen, chickinDeleteModal]);
|
||||
|
||||
useEffect(() => {
|
||||
if (isClosingModalOpen) {
|
||||
closingModal.openModal();
|
||||
@@ -1208,6 +1222,38 @@ const ProjectFlockTable = ({ refresh }: { refresh?: () => void }) => {
|
||||
}}
|
||||
/>
|
||||
|
||||
{/* Chickin Delete Modal */}
|
||||
<ConfirmationModal
|
||||
ref={chickinDeleteModal.ref}
|
||||
type='error'
|
||||
text='Apakah anda yakin ingin menghapus data chick in ini?'
|
||||
secondaryButton={{
|
||||
text: 'Tidak',
|
||||
onClick: () => {
|
||||
closeChickinDeleteModal();
|
||||
},
|
||||
}}
|
||||
className={{
|
||||
modal: 'z-9999',
|
||||
}}
|
||||
primaryButton={{
|
||||
text: 'Ya',
|
||||
color: 'error',
|
||||
isLoading: isChickinDeleteLoading,
|
||||
onClick: async () => {
|
||||
if (chickinDeleteCallback) {
|
||||
setChickinDeleteLoading(true);
|
||||
try {
|
||||
await chickinDeleteCallback();
|
||||
} finally {
|
||||
setChickinDeleteLoading(false);
|
||||
closeChickinDeleteModal();
|
||||
}
|
||||
}
|
||||
},
|
||||
}}
|
||||
/>
|
||||
|
||||
{/* Filter Modal */}
|
||||
<Modal
|
||||
ref={filterModal.ref}
|
||||
|
||||
Reference in New Issue
Block a user