mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-25 15:55:48 +00:00
refactor(FE): Refactor to use is_laying instead of
`project_flock_category`
This commit is contained in:
@@ -107,12 +107,9 @@ const RowOptionsMenu = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const isRecordingEditable = (recording: Recording) => {
|
const isRecordingEditable = (recording: Recording) => {
|
||||||
const category = recording.project_flock?.project_flock_category;
|
|
||||||
const isTransition = recording.is_transition;
|
|
||||||
|
|
||||||
const restriction = getRecordingRestriction(
|
const restriction = getRecordingRestriction(
|
||||||
category || 'GROWING',
|
recording.is_laying,
|
||||||
isTransition
|
recording.is_transition
|
||||||
);
|
);
|
||||||
|
|
||||||
if (restriction.isLocked) {
|
if (restriction.isLocked) {
|
||||||
@@ -122,10 +119,7 @@ const RowOptionsMenu = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const getRecordingRestrictionInfo = (recording: Recording) => {
|
const getRecordingRestrictionInfo = (recording: Recording) => {
|
||||||
const category = recording.project_flock?.project_flock_category;
|
return getRecordingRestriction(recording.is_laying, recording.is_transition);
|
||||||
const isTransition = recording.is_transition;
|
|
||||||
|
|
||||||
return getRecordingRestriction(category || 'GROWING', isTransition);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const isApproved = isRecordingApproved(props.row.original);
|
const isApproved = isRecordingApproved(props.row.original);
|
||||||
@@ -790,11 +784,10 @@ const RecordingTable = () => {
|
|||||||
{
|
{
|
||||||
header: 'Kategori',
|
header: 'Kategori',
|
||||||
cell: (props) => {
|
cell: (props) => {
|
||||||
const category =
|
const isLaying = props.row.original.is_laying;
|
||||||
props.row.original.project_flock?.project_flock_category;
|
|
||||||
const isTransition = props.row.original.is_transition;
|
const isTransition = props.row.original.is_transition;
|
||||||
if (!category) return '-';
|
const category = isLaying ? 'LAYING' : 'GROWING';
|
||||||
const color = category === 'LAYING' ? 'info' : 'warning';
|
const color = isLaying ? 'info' : 'warning';
|
||||||
return (
|
return (
|
||||||
<div className='flex flex-col gap-1'>
|
<div className='flex flex-col gap-1'>
|
||||||
<StatusBadge color={color} text={formatTitleCase(category)} />
|
<StatusBadge color={color} text={formatTitleCase(category)} />
|
||||||
|
|||||||
@@ -473,21 +473,21 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
}, [initialValues]);
|
}, [initialValues]);
|
||||||
|
|
||||||
const recordingRestriction = useMemo(() => {
|
const recordingRestriction = useMemo(() => {
|
||||||
const category =
|
const isLaying =
|
||||||
initialValues?.project_flock?.project_flock_category ||
|
initialValues?.is_laying ??
|
||||||
projectFlockKandangLookup?.project_flock?.category ||
|
(projectFlockKandangLookup?.project_flock?.category === 'LAYING' ||
|
||||||
projectFlockKandangDetail?.project_flock?.category ||
|
projectFlockKandangDetail?.project_flock?.category === 'LAYING' ||
|
||||||
'GROWING';
|
false);
|
||||||
|
|
||||||
const isTransition = initialValues?.is_transition ?? false;
|
const isTransition = initialValues?.is_transition ?? false;
|
||||||
|
|
||||||
const currentFlockCategory = projectFlockKandangDetail?.project_flock
|
const currentIsLaying =
|
||||||
?.category as 'GROWING' | 'LAYING' | undefined;
|
projectFlockKandangDetail?.project_flock?.category === 'LAYING';
|
||||||
|
|
||||||
return getRecordingRestriction(
|
return getRecordingRestriction(
|
||||||
category as 'GROWING' | 'LAYING',
|
isLaying,
|
||||||
isTransition,
|
isTransition,
|
||||||
type === 'edit' ? currentFlockCategory : undefined
|
type === 'edit' ? currentIsLaying : undefined
|
||||||
);
|
);
|
||||||
}, [
|
}, [
|
||||||
initialValues,
|
initialValues,
|
||||||
@@ -500,16 +500,13 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
(recording?: Recording) => {
|
(recording?: Recording) => {
|
||||||
if (!recording) return true;
|
if (!recording) return true;
|
||||||
|
|
||||||
const category = recording.project_flock?.project_flock_category;
|
const currentIsLaying =
|
||||||
const isTransition = recording.is_transition;
|
projectFlockKandangDetail?.project_flock?.category === 'LAYING';
|
||||||
|
|
||||||
const currentFlockCategory = projectFlockKandangDetail?.project_flock
|
|
||||||
?.category as 'GROWING' | 'LAYING' | undefined;
|
|
||||||
|
|
||||||
const restriction = getRecordingRestriction(
|
const restriction = getRecordingRestriction(
|
||||||
category || 'GROWING',
|
recording.is_laying,
|
||||||
isTransition,
|
recording.is_transition,
|
||||||
currentFlockCategory
|
currentIsLaying
|
||||||
);
|
);
|
||||||
|
|
||||||
if (restriction.isLocked) {
|
if (restriction.isLocked) {
|
||||||
@@ -627,14 +624,12 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
}, [approvedProjectFlockKandangsData]);
|
}, [approvedProjectFlockKandangsData]);
|
||||||
|
|
||||||
const isLayingCategory =
|
const isLayingCategory =
|
||||||
initialValues?.project_flock?.project_flock_category === 'LAYING' ||
|
initialValues?.is_laying ??
|
||||||
projectFlockKandangLookup?.project_flock?.category === 'LAYING' ||
|
(projectFlockKandangLookup?.project_flock?.category === 'LAYING' ||
|
||||||
projectFlockKandangDetail?.project_flock?.category === 'LAYING';
|
projectFlockKandangDetail?.project_flock?.category === 'LAYING' ||
|
||||||
|
false);
|
||||||
|
|
||||||
const isGrowingCategory =
|
const isGrowingCategory = !isLayingCategory;
|
||||||
initialValues?.project_flock?.project_flock_category === 'GROWING' ||
|
|
||||||
projectFlockKandangLookup?.project_flock?.category === 'GROWING' ||
|
|
||||||
projectFlockKandangDetail?.project_flock?.category === 'GROWING';
|
|
||||||
|
|
||||||
const recordingApprovalLines = useMemo(() => {
|
const recordingApprovalLines = useMemo(() => {
|
||||||
if (isLayingCategory) {
|
if (isLayingCategory) {
|
||||||
@@ -2003,15 +1998,10 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
<p className='font-semibold'>
|
<p className='font-semibold'>
|
||||||
<Badge
|
<Badge
|
||||||
variant='soft'
|
variant='soft'
|
||||||
color={
|
color={initialValues.is_laying ? 'info' : 'warning'}
|
||||||
initialValues.project_flock
|
|
||||||
?.project_flock_category === 'LAYING'
|
|
||||||
? 'info'
|
|
||||||
: 'warning'
|
|
||||||
}
|
|
||||||
size='sm'
|
size='sm'
|
||||||
>
|
>
|
||||||
{initialValues.project_flock?.project_flock_category}
|
{initialValues.is_laying ? 'LAYING' : 'GROWING'}
|
||||||
</Badge>
|
</Badge>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
@@ -2148,9 +2138,7 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
{type === 'detail' && initialValues && (
|
{type === 'detail' && initialValues && (
|
||||||
<div
|
<div
|
||||||
className={`grid gap-6 mb-6 grid-cols-1 ${
|
className={`grid gap-6 mb-6 grid-cols-1 ${
|
||||||
initialValues.project_flock?.project_flock_category === 'LAYING'
|
initialValues.is_laying ? 'xl:grid-cols-3' : 'xl:grid-cols-2'
|
||||||
? 'xl:grid-cols-3'
|
|
||||||
: 'xl:grid-cols-2'
|
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
{/* FCR Section */}
|
{/* FCR Section */}
|
||||||
@@ -2241,8 +2229,7 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
{/* Egg Production Section - Only for LAYING category */}
|
{/* Egg Production Section - Only for LAYING category */}
|
||||||
{type === 'detail' &&
|
{type === 'detail' &&
|
||||||
initialValues &&
|
initialValues &&
|
||||||
initialValues.project_flock?.project_flock_category ===
|
initialValues.is_laying && (
|
||||||
'LAYING' && (
|
|
||||||
<div className='border border-gray-200 rounded-lg bg-white'>
|
<div className='border border-gray-200 rounded-lg bg-white'>
|
||||||
<div className='px-4 py-3 border-b border-gray-200'>
|
<div className='px-4 py-3 border-b border-gray-200'>
|
||||||
<span className='card-title font-bold text-xl'>
|
<span className='card-title font-bold text-xl'>
|
||||||
|
|||||||
@@ -7,11 +7,11 @@ export type RecordingRestriction = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const getRecordingRestriction = (
|
export const getRecordingRestriction = (
|
||||||
category: 'GROWING' | 'LAYING',
|
isLaying: boolean,
|
||||||
isTransition: boolean,
|
isTransition: boolean,
|
||||||
currentCategory?: 'GROWING' | 'LAYING'
|
currentIsLaying?: boolean
|
||||||
): RecordingRestriction => {
|
): RecordingRestriction => {
|
||||||
if (currentCategory === 'LAYING' && category === 'GROWING') {
|
if (currentIsLaying && !isLaying) {
|
||||||
return {
|
return {
|
||||||
canEditStock: false,
|
canEditStock: false,
|
||||||
canEditDepletion: false,
|
canEditDepletion: false,
|
||||||
@@ -22,7 +22,7 @@ export const getRecordingRestriction = (
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (category === 'GROWING') {
|
if (!isLaying) {
|
||||||
if (isTransition) {
|
if (isTransition) {
|
||||||
return {
|
return {
|
||||||
canEditStock: true,
|
canEditStock: true,
|
||||||
|
|||||||
+1
@@ -50,6 +50,7 @@ export type BaseRecording = {
|
|||||||
record_datetime: string;
|
record_datetime: string;
|
||||||
day: number;
|
day: number;
|
||||||
is_transition: boolean;
|
is_transition: boolean;
|
||||||
|
is_laying: boolean;
|
||||||
} & ProductionMetrics;
|
} & ProductionMetrics;
|
||||||
|
|
||||||
export type RecordingDepletion = {
|
export type RecordingDepletion = {
|
||||||
|
|||||||
Reference in New Issue
Block a user