mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 13:32:00 +00:00
refactor(FE): Refactor isLaying logic for clarity and reuse
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user