mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-25 15:55:48 +00:00
refactor(FE): Restrict stock and depletion edits based on permissions
This commit is contained in:
@@ -1043,6 +1043,14 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!recordingRestriction.canEditStock) {
|
||||||
|
baseValues.stocks = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!recordingRestriction.canEditDepletion) {
|
||||||
|
baseValues.depletions = [];
|
||||||
|
}
|
||||||
|
|
||||||
return baseValues;
|
return baseValues;
|
||||||
}, [
|
}, [
|
||||||
initialValues,
|
initialValues,
|
||||||
@@ -1053,6 +1061,8 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
selectedLocation,
|
selectedLocation,
|
||||||
selectedProjectFlock,
|
selectedProjectFlock,
|
||||||
selectedKandang,
|
selectedKandang,
|
||||||
|
recordingRestriction.canEditStock,
|
||||||
|
recordingRestriction.canEditDepletion,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const formik = useFormik<
|
const formik = useFormik<
|
||||||
@@ -2443,7 +2453,9 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Stocks Table */}
|
{/* Stocks Table - Only show if can edit stock or has data */}
|
||||||
|
{(recordingRestriction.canEditStock ||
|
||||||
|
(type === 'detail' && formik.values.stocks?.length > 0)) && (
|
||||||
<Card
|
<Card
|
||||||
title='Stok Persediaan'
|
title='Stok Persediaan'
|
||||||
className={{
|
className={{
|
||||||
@@ -2469,7 +2481,8 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
) => {
|
) => {
|
||||||
if (e.target.checked) {
|
if (e.target.checked) {
|
||||||
setSelectedStocks(
|
setSelectedStocks(
|
||||||
formik.values.stocks?.map((_, idx) => idx) ?? []
|
formik.values.stocks?.map((_, idx) => idx) ??
|
||||||
|
[]
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
setSelectedStocks([]);
|
setSelectedStocks([]);
|
||||||
@@ -2544,7 +2557,8 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
) || null
|
) || null
|
||||||
}
|
}
|
||||||
onChange={(selectedOption) => {
|
onChange={(selectedOption) => {
|
||||||
const option = selectedOption as OptionType | null;
|
const option =
|
||||||
|
selectedOption as OptionType | null;
|
||||||
formik.setFieldValue(
|
formik.setFieldValue(
|
||||||
`stocks.${idx}.product_warehouse_id`,
|
`stocks.${idx}.product_warehouse_id`,
|
||||||
option?.value || 0
|
option?.value || 0
|
||||||
@@ -2694,6 +2708,7 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</Card>
|
</Card>
|
||||||
|
)}
|
||||||
|
|
||||||
{/* Transition Warning Banner -- MOVED UP -- */}
|
{/* Transition Warning Banner -- MOVED UP -- */}
|
||||||
{isTransitionPeriod && (
|
{isTransitionPeriod && (
|
||||||
|
|||||||
Reference in New Issue
Block a user