refactor(FE): Refactor to use is_laying instead of

`project_flock_category`
This commit is contained in:
rstubryan
2026-03-09 13:59:24 +07:00
parent ea25417e8d
commit ed34a99117
4 changed files with 34 additions and 53 deletions
@@ -107,12 +107,9 @@ const RowOptionsMenu = ({
};
const isRecordingEditable = (recording: Recording) => {
const category = recording.project_flock?.project_flock_category;
const isTransition = recording.is_transition;
const restriction = getRecordingRestriction(
category || 'GROWING',
isTransition
recording.is_laying,
recording.is_transition
);
if (restriction.isLocked) {
@@ -122,10 +119,7 @@ const RowOptionsMenu = ({
};
const getRecordingRestrictionInfo = (recording: Recording) => {
const category = recording.project_flock?.project_flock_category;
const isTransition = recording.is_transition;
return getRecordingRestriction(category || 'GROWING', isTransition);
return getRecordingRestriction(recording.is_laying, recording.is_transition);
};
const isApproved = isRecordingApproved(props.row.original);
@@ -790,11 +784,10 @@ const RecordingTable = () => {
{
header: 'Kategori',
cell: (props) => {
const category =
props.row.original.project_flock?.project_flock_category;
const isLaying = props.row.original.is_laying;
const isTransition = props.row.original.is_transition;
if (!category) return '-';
const color = category === 'LAYING' ? 'info' : 'warning';
const category = isLaying ? 'LAYING' : 'GROWING';
const color = isLaying ? 'info' : 'warning';
return (
<div className='flex flex-col gap-1'>
<StatusBadge color={color} text={formatTitleCase(category)} />
@@ -473,21 +473,21 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
}, [initialValues]);
const recordingRestriction = useMemo(() => {
const category =
initialValues?.project_flock?.project_flock_category ||
projectFlockKandangLookup?.project_flock?.category ||
projectFlockKandangDetail?.project_flock?.category ||
'GROWING';
const isLaying =
initialValues?.is_laying ??
(projectFlockKandangLookup?.project_flock?.category === 'LAYING' ||
projectFlockKandangDetail?.project_flock?.category === 'LAYING' ||
false);
const isTransition = initialValues?.is_transition ?? false;
const currentFlockCategory = projectFlockKandangDetail?.project_flock
?.category as 'GROWING' | 'LAYING' | undefined;
const currentIsLaying =
projectFlockKandangDetail?.project_flock?.category === 'LAYING';
return getRecordingRestriction(
category as 'GROWING' | 'LAYING',
isLaying,
isTransition,
type === 'edit' ? currentFlockCategory : undefined
type === 'edit' ? currentIsLaying : undefined
);
}, [
initialValues,
@@ -500,16 +500,13 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
(recording?: Recording) => {
if (!recording) return true;
const category = recording.project_flock?.project_flock_category;
const isTransition = recording.is_transition;
const currentFlockCategory = projectFlockKandangDetail?.project_flock
?.category as 'GROWING' | 'LAYING' | undefined;
const currentIsLaying =
projectFlockKandangDetail?.project_flock?.category === 'LAYING';
const restriction = getRecordingRestriction(
category || 'GROWING',
isTransition,
currentFlockCategory
recording.is_laying,
recording.is_transition,
currentIsLaying
);
if (restriction.isLocked) {
@@ -627,14 +624,12 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
}, [approvedProjectFlockKandangsData]);
const isLayingCategory =
initialValues?.project_flock?.project_flock_category === 'LAYING' ||
projectFlockKandangLookup?.project_flock?.category === 'LAYING' ||
projectFlockKandangDetail?.project_flock?.category === 'LAYING';
initialValues?.is_laying ??
(projectFlockKandangLookup?.project_flock?.category === 'LAYING' ||
projectFlockKandangDetail?.project_flock?.category === 'LAYING' ||
false);
const isGrowingCategory =
initialValues?.project_flock?.project_flock_category === 'GROWING' ||
projectFlockKandangLookup?.project_flock?.category === 'GROWING' ||
projectFlockKandangDetail?.project_flock?.category === 'GROWING';
const isGrowingCategory = !isLayingCategory;
const recordingApprovalLines = useMemo(() => {
if (isLayingCategory) {
@@ -2003,15 +1998,10 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
<p className='font-semibold'>
<Badge
variant='soft'
color={
initialValues.project_flock
?.project_flock_category === 'LAYING'
? 'info'
: 'warning'
}
color={initialValues.is_laying ? 'info' : 'warning'}
size='sm'
>
{initialValues.project_flock?.project_flock_category}
{initialValues.is_laying ? 'LAYING' : 'GROWING'}
</Badge>
</p>
</div>
@@ -2148,9 +2138,7 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
{type === 'detail' && initialValues && (
<div
className={`grid gap-6 mb-6 grid-cols-1 ${
initialValues.project_flock?.project_flock_category === 'LAYING'
? 'xl:grid-cols-3'
: 'xl:grid-cols-2'
initialValues.is_laying ? 'xl:grid-cols-3' : 'xl:grid-cols-2'
}`}
>
{/* FCR Section */}
@@ -2241,8 +2229,7 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
{/* Egg Production Section - Only for LAYING category */}
{type === 'detail' &&
initialValues &&
initialValues.project_flock?.project_flock_category ===
'LAYING' && (
initialValues.is_laying && (
<div className='border border-gray-200 rounded-lg bg-white'>
<div className='px-4 py-3 border-b border-gray-200'>
<span className='card-title font-bold text-xl'>
@@ -7,11 +7,11 @@ export type RecordingRestriction = {
};
export const getRecordingRestriction = (
category: 'GROWING' | 'LAYING',
isLaying: boolean,
isTransition: boolean,
currentCategory?: 'GROWING' | 'LAYING'
currentIsLaying?: boolean
): RecordingRestriction => {
if (currentCategory === 'LAYING' && category === 'GROWING') {
if (currentIsLaying && !isLaying) {
return {
canEditStock: false,
canEditDepletion: false,
@@ -22,7 +22,7 @@ export const getRecordingRestriction = (
};
}
if (category === 'GROWING') {
if (!isLaying) {
if (isTransition) {
return {
canEditStock: true,
+1
View File
@@ -50,6 +50,7 @@ export type BaseRecording = {
record_datetime: string;
day: number;
is_transition: boolean;
is_laying: boolean;
} & ProductionMetrics;
export type RecordingDepletion = {