diff --git a/src/components/pages/production/chickin/form/tabs/ChickLogsView.tsx b/src/components/pages/production/chickin/form/tabs/ChickLogsView.tsx
index bdffda33..acb8c18b 100644
--- a/src/components/pages/production/chickin/form/tabs/ChickLogsView.tsx
+++ b/src/components/pages/production/chickin/form/tabs/ChickLogsView.tsx
@@ -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 (
<>
@@ -86,14 +101,30 @@ const ChickinLogsView = ({
Chick In #{index + 1} - {latestApproval?.step_number}
-
+
+
+
+ {isApproved && (
+
+ )}
+
{/* Tanggal Chick In */}
diff --git a/src/components/pages/production/project-flock/ProjectFlockTable.tsx b/src/components/pages/production/project-flock/ProjectFlockTable.tsx
index 1ae56fa2..bdc271a6 100644
--- a/src/components/pages/production/project-flock/ProjectFlockTable.tsx
+++ b/src/components/pages/production/project-flock/ProjectFlockTable.tsx
@@ -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 */}
+ {
+ 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 */}
{
+ if (
+ recording.executed_at &&
+ recording.project_flock?.project_flock_category === 'GROWING'
+ ) {
+ return false;
+ }
+ return true;
+ };
+
const isApproved = isRecordingApproved(props.row.original);
const isRejected = isRecordingRejected(props.row.original);
+ const isEditable = isRecordingEditable(props.row.original);
return (
@@ -138,18 +149,20 @@ const RowOptionsMenu = ({
View Details
-
-
-
+ {isEditable && (
+
+
+
+ )}
{!isApproved && !isRejected && (
)}
-
-
-
+ {isEditable && (
+
+
+
+ )}
diff --git a/src/components/pages/production/recording/form/RecordingForm.tsx b/src/components/pages/production/recording/form/RecordingForm.tsx
index fd3a818d..af4ab78b 100644
--- a/src/components/pages/production/recording/form/RecordingForm.tsx
+++ b/src/components/pages/production/recording/form/RecordingForm.tsx
@@ -272,6 +272,16 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
return recording?.approval?.action === 'REJECTED';
}, []);
+ const isRecordingEditable = useCallback((recording?: Recording) => {
+ if (
+ recording?.executed_at &&
+ recording?.project_flock?.project_flock_category === 'GROWING'
+ ) {
+ return false;
+ }
+ return true;
+ }, []);
+
// ===== PAYLOAD CREATION HELPERS =====
const createGrowingPayload = useCallback(
(values: RecordingGrowingFormValues) => {
@@ -2990,42 +3000,46 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
{/* Left side - Detail & Edit actions */}
- {type === 'detail' && deleteRecordingClickHandler && (
-
-
-
- )}
- {type === 'detail' && initialValues && (
-
-
-
- )}
+ {type === 'detail' &&
+ deleteRecordingClickHandler &&
+ isRecordingEditable(initialValues) && (
+
+
+
+ )}
+ {type === 'detail' &&
+ initialValues &&
+ isRecordingEditable(initialValues) && (
+
+
+
+ )}
{/* Right side actions */}
diff --git a/src/components/pages/production/transfer-to-laying/TransferToLayingConfirmationModal.tsx b/src/components/pages/production/transfer-to-laying/TransferToLayingConfirmationModal.tsx
index 2975a865..555c1667 100644
--- a/src/components/pages/production/transfer-to-laying/TransferToLayingConfirmationModal.tsx
+++ b/src/components/pages/production/transfer-to-laying/TransferToLayingConfirmationModal.tsx
@@ -50,12 +50,18 @@ const TransferToLayingConfirmationModalTable = ({
transferToLayingForm?: TransferToLayingFormValues;
transferToLayingId?: number;
}) => {
+ const isValidId =
+ transferToLayingId !== undefined &&
+ transferToLayingId !== null &&
+ !isNaN(transferToLayingId) &&
+ transferToLayingId > 0;
+
const { data: transferToLaying, isLoading: isLoadingTransferToLaying } =
useSWR(
- transferToLayingId
+ isValidId
? ['detail-transfer-to-laying', String(transferToLayingId)]
: undefined,
- ([id]) => TransferToLayingApi.getSingle(Number(id))
+ ([, id]) => TransferToLayingApi.getSingle(Number(id))
);
const confirmationTableColumns: ColumnDef
[] =
@@ -273,12 +279,16 @@ const TransferToLayingConfirmationModal = ({
{transferToLayingIds &&
!transferToLayingForm &&
- transferToLayingIds.map((transferToLayingId, idx) => (
-
- ))}
+ transferToLayingIds
+ .filter(
+ (id) => id !== undefined && id !== null && !isNaN(id) && id > 0
+ )
+ .map((transferToLayingId, idx) => (
+
+ ))}
{withNote && (