mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 13:32:00 +00:00
feat(FE): Add project flock closing modal and zustand store
This commit is contained in:
@@ -37,6 +37,7 @@ import ProjectFlockConfirmationModal from './ProjectFlockConfirmationModal';
|
||||
import { useProjectFlockStore } from '@/stores/production/project-flock/project-flock.store';
|
||||
import { ProjectFlockFormValues } from './form/ProjectFlockForm.schema';
|
||||
import { useChickinStore } from '@/stores/production/chickin/chickin.store';
|
||||
import { useProjectFlockClosingStore } from '@/stores/production/project-flock-closing/project-flock-closing.store';
|
||||
|
||||
const RowOptionsMenu = ({
|
||||
props,
|
||||
@@ -195,6 +196,7 @@ const ProjectFlockTable = ({ refresh }: { refresh?: () => void }) => {
|
||||
const confirmModal = useModal();
|
||||
const successModal = useModal();
|
||||
const chickinApproveModal = useModal();
|
||||
const closingModal = useModal();
|
||||
const [approvalAction, setApprovalAction] = useState<'APPROVED' | 'REJECTED'>(
|
||||
'APPROVED'
|
||||
);
|
||||
@@ -210,6 +212,15 @@ const ProjectFlockTable = ({ refresh }: { refresh?: () => void }) => {
|
||||
setChickinApproveLoading,
|
||||
} = useChickinStore();
|
||||
|
||||
const {
|
||||
isClosingModalOpen,
|
||||
isKandangClosed,
|
||||
isClosingLoading,
|
||||
closingCallback,
|
||||
closeClosingModal,
|
||||
setClosingLoading,
|
||||
} = useProjectFlockClosingStore();
|
||||
|
||||
// ===== Fetch Data =====
|
||||
const {
|
||||
data: projectFlocks,
|
||||
@@ -309,6 +320,14 @@ const ProjectFlockTable = ({ refresh }: { refresh?: () => void }) => {
|
||||
}
|
||||
}, [isChickinApproveModalOpen, chickinApproveModal]);
|
||||
|
||||
useEffect(() => {
|
||||
if (isClosingModalOpen) {
|
||||
closingModal.openModal();
|
||||
} else {
|
||||
closingModal.closeModal();
|
||||
}
|
||||
}, [isClosingModalOpen, closingModal]);
|
||||
|
||||
useEffect(() => {
|
||||
if (isSuccess) {
|
||||
successModal.openModal();
|
||||
@@ -1025,6 +1044,45 @@ const ProjectFlockTable = ({ refresh }: { refresh?: () => void }) => {
|
||||
isLoading: isChickinApproveLoading,
|
||||
}}
|
||||
/>
|
||||
|
||||
{/* Project Flock Closing Modal */}
|
||||
<ConfirmationModal
|
||||
ref={closingModal.ref}
|
||||
type='error'
|
||||
text={
|
||||
!isKandangClosed
|
||||
? 'Apakah kamu yakin ingin mengakhiri project ini ? *Pastikan persediaan produk di gudang terkait sudah kosong, dan BOP sudah selesai'
|
||||
: 'Apakah kamu yakin ingin membuka kembali project ini ? *Project ini akan kembali ke status aktif'
|
||||
}
|
||||
className={{
|
||||
modal: 'z-9999',
|
||||
}}
|
||||
secondaryButton={{
|
||||
text: 'Tidak',
|
||||
onClick: () => {
|
||||
closeClosingModal();
|
||||
closingModal.closeModal();
|
||||
},
|
||||
}}
|
||||
primaryButton={{
|
||||
text: 'Ya',
|
||||
color: 'error',
|
||||
isLoading: isClosingLoading,
|
||||
onClick: async () => {
|
||||
if (closingCallback) {
|
||||
setClosingLoading(true);
|
||||
try {
|
||||
await closingCallback(!isKandangClosed ? 'close' : 'unclose');
|
||||
} finally {
|
||||
setClosingLoading(false);
|
||||
closeClosingModal();
|
||||
closingModal.closeModal();
|
||||
refreshProjectFlocks();
|
||||
}
|
||||
}
|
||||
},
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user