mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-24 15:25:46 +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 isRecordingEditable = (recording: Recording) => {
|
||||||
|
const currentIsLaying =
|
||||||
|
recording.project_flock?.project_flock_category === 'LAYING';
|
||||||
|
|
||||||
const restriction = getRecordingRestriction(
|
const restriction = getRecordingRestriction(
|
||||||
recording.is_laying,
|
recording.is_laying,
|
||||||
recording.is_transition
|
recording.is_transition,
|
||||||
|
currentIsLaying
|
||||||
);
|
);
|
||||||
|
|
||||||
if (restriction.isLocked) {
|
if (restriction.isLocked) {
|
||||||
@@ -119,9 +123,13 @@ const RowOptionsMenu = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const getRecordingRestrictionInfo = (recording: Recording) => {
|
const getRecordingRestrictionInfo = (recording: Recording) => {
|
||||||
|
const currentIsLaying =
|
||||||
|
recording.project_flock?.project_flock_category === 'LAYING';
|
||||||
|
|
||||||
return getRecordingRestriction(
|
return getRecordingRestriction(
|
||||||
recording.is_laying,
|
recording.is_laying,
|
||||||
recording.is_transition
|
recording.is_transition,
|
||||||
|
currentIsLaying
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -545,27 +545,24 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
type,
|
type,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const isRecordingEditable = useCallback(
|
const isRecordingEditable = useCallback((recording?: Recording) => {
|
||||||
(recording?: Recording) => {
|
if (!recording) return true;
|
||||||
if (!recording) return true;
|
|
||||||
|
|
||||||
const currentIsLaying =
|
const currentIsLaying =
|
||||||
projectFlockKandangDetail?.project_flock?.category === 'LAYING';
|
recording.project_flock?.project_flock_category === 'LAYING';
|
||||||
|
|
||||||
const restriction = getRecordingRestriction(
|
const restriction = getRecordingRestriction(
|
||||||
recording.is_laying,
|
recording.is_laying,
|
||||||
recording.is_transition,
|
recording.is_transition,
|
||||||
currentIsLaying
|
currentIsLaying
|
||||||
);
|
);
|
||||||
|
|
||||||
if (restriction.isLocked) {
|
if (restriction.isLocked) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
},
|
}, []);
|
||||||
[projectFlockKandangDetail]
|
|
||||||
);
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
options: stockProductOptions,
|
options: stockProductOptions,
|
||||||
|
|||||||
@@ -22,16 +22,17 @@ export const getRecordingRestriction = (
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isLaying) {
|
if (isTransition && !isLaying) {
|
||||||
if (isTransition) {
|
return {
|
||||||
return {
|
canEditStock: true,
|
||||||
canEditStock: true,
|
canEditDepletion: false,
|
||||||
canEditDepletion: false,
|
canEditEgg: false,
|
||||||
canEditEgg: false,
|
isLocked: false,
|
||||||
isLocked: false,
|
lockReason: undefined,
|
||||||
lockReason: undefined,
|
};
|
||||||
};
|
}
|
||||||
}
|
|
||||||
|
if (!isLaying && !isTransition) {
|
||||||
return {
|
return {
|
||||||
canEditStock: true,
|
canEditStock: true,
|
||||||
canEditDepletion: true,
|
canEditDepletion: true,
|
||||||
@@ -40,21 +41,21 @@ export const getRecordingRestriction = (
|
|||||||
lockReason: undefined,
|
lockReason: undefined,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
if (isLaying && !isTransition) {
|
||||||
if (isTransition) {
|
|
||||||
return {
|
return {
|
||||||
canEditStock: false,
|
canEditStock: true,
|
||||||
canEditDepletion: true,
|
canEditDepletion: true,
|
||||||
canEditEgg: false,
|
canEditEgg: true,
|
||||||
isLocked: false,
|
isLocked: false,
|
||||||
lockReason: undefined,
|
lockReason: undefined,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
canEditStock: true,
|
canEditStock: false,
|
||||||
canEditDepletion: true,
|
canEditDepletion: false,
|
||||||
canEditEgg: true,
|
canEditEgg: false,
|
||||||
isLocked: false,
|
isLocked: true,
|
||||||
lockReason: undefined,
|
lockReason: 'Kondisi transisi tidak valid',
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user