refactor(FE): Improve transition and laying state handling in

RecordingForm
This commit is contained in:
rstubryan
2026-03-09 15:03:42 +07:00
parent ace6633f79
commit 0929461ec5
2 changed files with 17 additions and 9 deletions
@@ -469,17 +469,24 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
// ===== TRANSITION RESTRICTION LOGIC ===== // ===== TRANSITION RESTRICTION LOGIC =====
const isTransitionPeriod = useMemo(() => { const isTransitionPeriod = useMemo(() => {
return initialValues?.is_transition ?? false; return (
}, [initialValues]); initialValues?.is_transition ??
projectFlockKandangLookup?.is_transition ??
false
);
}, [initialValues, projectFlockKandangLookup]);
const recordingRestriction = useMemo(() => { const recordingRestriction = useMemo(() => {
const isLaying = const isLaying =
initialValues?.is_laying ?? initialValues?.is_laying ??
(projectFlockKandangLookup?.project_flock?.category === 'LAYING' || projectFlockKandangLookup?.is_laying ??
projectFlockKandangDetail?.project_flock?.category === 'LAYING' || projectFlockKandangDetail?.project_flock?.category === 'LAYING' ||
false); false;
const isTransition = initialValues?.is_transition ?? false; const isTransition =
initialValues?.is_transition ??
projectFlockKandangLookup?.is_transition ??
false;
const currentIsLaying = const currentIsLaying =
projectFlockKandangDetail?.project_flock?.category === 'LAYING'; projectFlockKandangDetail?.project_flock?.category === 'LAYING';
@@ -625,9 +632,9 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
const isLayingCategory = const isLayingCategory =
initialValues?.is_laying ?? initialValues?.is_laying ??
(projectFlockKandangLookup?.project_flock?.category === 'LAYING' || projectFlockKandangLookup?.is_laying ??
projectFlockKandangDetail?.project_flock?.category === 'LAYING' || projectFlockKandangDetail?.project_flock?.category === 'LAYING' ||
false); false;
const isGrowingCategory = !isLayingCategory; const isGrowingCategory = !isLayingCategory;
+1
View File
@@ -75,6 +75,7 @@ export type ProjectFlockKandangLookup = {
population: number; population: number;
chick_in_date: string; chick_in_date: string;
is_transition: boolean; is_transition: boolean;
is_laying: boolean;
}; };
export type ProjectFlockAvailableQuantity = { export type ProjectFlockAvailableQuantity = {