diff --git a/src/components/pages/production/recording/form/RecordingForm.tsx b/src/components/pages/production/recording/form/RecordingForm.tsx index 226acd20..3a1bd01f 100644 --- a/src/components/pages/production/recording/form/RecordingForm.tsx +++ b/src/components/pages/production/recording/form/RecordingForm.tsx @@ -483,11 +483,19 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => { }, [initialValues, projectFlockKandangLookup]); const recordingRestriction = useMemo(() => { - const isLaying = - initialValues?.is_laying ?? - projectFlockKandangLookup?.is_laying ?? - (projectFlockKandangDetail?.project_flock?.category === 'LAYING' || - false); + // Determine isLaying - check both is_laying flag AND category + let isLaying: boolean; + if (initialValues?.is_laying !== undefined) { + isLaying = initialValues.is_laying; + } else if (projectFlockKandangLookup) { + isLaying = + projectFlockKandangLookup.is_laying || + projectFlockKandangLookup.project_flock?.category === 'LAYING'; + } else { + isLaying = + projectFlockKandangDetail?.project_flock?.category === 'LAYING' || + false; + } const isTransition = initialValues?.is_transition ?? @@ -636,10 +644,29 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => { return approvedProjectFlockKandangsData.data; }, [approvedProjectFlockKandangsData]); - const isLayingCategory = - initialValues?.is_laying ?? - projectFlockKandangLookup?.is_laying ?? - (projectFlockKandangDetail?.project_flock?.category === 'LAYING' || false); + const isLayingCategory = useMemo(() => { + // Priority 1: initialValues (for edit/detail mode) + if (initialValues?.is_laying !== undefined) { + return initialValues.is_laying; + } + + // Priority 2: projectFlockKandangLookup (for add mode with lookup) + if (projectFlockKandangLookup) { + return ( + projectFlockKandangLookup.is_laying || + projectFlockKandangLookup.project_flock?.category === 'LAYING' + ); + } + + // Priority 3: projectFlockKandangDetail (fallback for edit/detail mode) + return ( + projectFlockKandangDetail?.project_flock?.category === 'LAYING' || false + ); + }, [ + initialValues?.is_laying, + projectFlockKandangLookup, + projectFlockKandangDetail, + ]); const isGrowingCategory = !isLayingCategory;