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]);
|
}, [initialValues, projectFlockKandangLookup]);
|
||||||
|
|
||||||
const recordingRestriction = useMemo(() => {
|
const recordingRestriction = useMemo(() => {
|
||||||
const isLaying =
|
// Determine isLaying - check both is_laying flag AND category
|
||||||
initialValues?.is_laying ??
|
let isLaying: boolean;
|
||||||
projectFlockKandangLookup?.is_laying ??
|
if (initialValues?.is_laying !== undefined) {
|
||||||
(projectFlockKandangDetail?.project_flock?.category === 'LAYING' ||
|
isLaying = initialValues.is_laying;
|
||||||
false);
|
} else if (projectFlockKandangLookup) {
|
||||||
|
isLaying =
|
||||||
|
projectFlockKandangLookup.is_laying ||
|
||||||
|
projectFlockKandangLookup.project_flock?.category === 'LAYING';
|
||||||
|
} else {
|
||||||
|
isLaying =
|
||||||
|
projectFlockKandangDetail?.project_flock?.category === 'LAYING' ||
|
||||||
|
false;
|
||||||
|
}
|
||||||
|
|
||||||
const isTransition =
|
const isTransition =
|
||||||
initialValues?.is_transition ??
|
initialValues?.is_transition ??
|
||||||
@@ -636,10 +644,29 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
return approvedProjectFlockKandangsData.data;
|
return approvedProjectFlockKandangsData.data;
|
||||||
}, [approvedProjectFlockKandangsData]);
|
}, [approvedProjectFlockKandangsData]);
|
||||||
|
|
||||||
const isLayingCategory =
|
const isLayingCategory = useMemo(() => {
|
||||||
initialValues?.is_laying ??
|
// Priority 1: initialValues (for edit/detail mode)
|
||||||
projectFlockKandangLookup?.is_laying ??
|
if (initialValues?.is_laying !== undefined) {
|
||||||
(projectFlockKandangDetail?.project_flock?.category === 'LAYING' || false);
|
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;
|
const isGrowingCategory = !isLayingCategory;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user