mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 13:32:00 +00:00
refactor(FE): Refactor recording restriction logic for clarity and
accuracy
This commit is contained in:
@@ -107,9 +107,13 @@ const RowOptionsMenu = ({
|
||||
};
|
||||
|
||||
const isRecordingEditable = (recording: Recording) => {
|
||||
const currentIsLaying =
|
||||
recording.project_flock?.project_flock_category === 'LAYING';
|
||||
|
||||
const restriction = getRecordingRestriction(
|
||||
recording.is_laying,
|
||||
recording.is_transition
|
||||
recording.is_transition,
|
||||
currentIsLaying
|
||||
);
|
||||
|
||||
if (restriction.isLocked) {
|
||||
@@ -119,9 +123,13 @@ const RowOptionsMenu = ({
|
||||
};
|
||||
|
||||
const getRecordingRestrictionInfo = (recording: Recording) => {
|
||||
const currentIsLaying =
|
||||
recording.project_flock?.project_flock_category === 'LAYING';
|
||||
|
||||
return getRecordingRestriction(
|
||||
recording.is_laying,
|
||||
recording.is_transition
|
||||
recording.is_transition,
|
||||
currentIsLaying
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -545,27 +545,24 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
||||
type,
|
||||
]);
|
||||
|
||||
const isRecordingEditable = useCallback(
|
||||
(recording?: Recording) => {
|
||||
if (!recording) return true;
|
||||
const isRecordingEditable = useCallback((recording?: Recording) => {
|
||||
if (!recording) return true;
|
||||
|
||||
const currentIsLaying =
|
||||
projectFlockKandangDetail?.project_flock?.category === 'LAYING';
|
||||
const currentIsLaying =
|
||||
recording.project_flock?.project_flock_category === 'LAYING';
|
||||
|
||||
const restriction = getRecordingRestriction(
|
||||
recording.is_laying,
|
||||
recording.is_transition,
|
||||
currentIsLaying
|
||||
);
|
||||
const restriction = getRecordingRestriction(
|
||||
recording.is_laying,
|
||||
recording.is_transition,
|
||||
currentIsLaying
|
||||
);
|
||||
|
||||
if (restriction.isLocked) {
|
||||
return false;
|
||||
}
|
||||
if (restriction.isLocked) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
},
|
||||
[projectFlockKandangDetail]
|
||||
);
|
||||
return true;
|
||||
}, []);
|
||||
|
||||
const {
|
||||
options: stockProductOptions,
|
||||
|
||||
@@ -22,16 +22,17 @@ export const getRecordingRestriction = (
|
||||
};
|
||||
}
|
||||
|
||||
if (!isLaying) {
|
||||
if (isTransition) {
|
||||
return {
|
||||
canEditStock: true,
|
||||
canEditDepletion: false,
|
||||
canEditEgg: false,
|
||||
isLocked: false,
|
||||
lockReason: undefined,
|
||||
};
|
||||
}
|
||||
if (isTransition && !isLaying) {
|
||||
return {
|
||||
canEditStock: true,
|
||||
canEditDepletion: false,
|
||||
canEditEgg: false,
|
||||
isLocked: false,
|
||||
lockReason: undefined,
|
||||
};
|
||||
}
|
||||
|
||||
if (!isLaying && !isTransition) {
|
||||
return {
|
||||
canEditStock: true,
|
||||
canEditDepletion: true,
|
||||
@@ -40,21 +41,21 @@ export const getRecordingRestriction = (
|
||||
lockReason: undefined,
|
||||
};
|
||||
}
|
||||
|
||||
if (isTransition) {
|
||||
if (isLaying && !isTransition) {
|
||||
return {
|
||||
canEditStock: false,
|
||||
canEditStock: true,
|
||||
canEditDepletion: true,
|
||||
canEditEgg: false,
|
||||
canEditEgg: true,
|
||||
isLocked: false,
|
||||
lockReason: undefined,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
canEditStock: true,
|
||||
canEditDepletion: true,
|
||||
canEditEgg: true,
|
||||
isLocked: false,
|
||||
lockReason: undefined,
|
||||
canEditStock: false,
|
||||
canEditDepletion: false,
|
||||
canEditEgg: false,
|
||||
isLocked: true,
|
||||
lockReason: 'Kondisi transisi tidak valid',
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user