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;
|
||||
}, [
|
||||
initialValues,
|
||||
@@ -1053,6 +1061,8 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
||||
selectedLocation,
|
||||
selectedProjectFlock,
|
||||
selectedKandang,
|
||||
recordingRestriction.canEditStock,
|
||||
recordingRestriction.canEditDepletion,
|
||||
]);
|
||||
|
||||
const formik = useFormik<
|
||||
@@ -2443,7 +2453,9 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Stocks Table */}
|
||||
{/* Stocks Table - Only show if can edit stock or has data */}
|
||||
{(recordingRestriction.canEditStock ||
|
||||
(type === 'detail' && formik.values.stocks?.length > 0)) && (
|
||||
<Card
|
||||
title='Stok Persediaan'
|
||||
className={{
|
||||
@@ -2469,7 +2481,8 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
||||
) => {
|
||||
if (e.target.checked) {
|
||||
setSelectedStocks(
|
||||
formik.values.stocks?.map((_, idx) => idx) ?? []
|
||||
formik.values.stocks?.map((_, idx) => idx) ??
|
||||
[]
|
||||
);
|
||||
} else {
|
||||
setSelectedStocks([]);
|
||||
@@ -2544,7 +2557,8 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
||||
) || null
|
||||
}
|
||||
onChange={(selectedOption) => {
|
||||
const option = selectedOption as OptionType | null;
|
||||
const option =
|
||||
selectedOption as OptionType | null;
|
||||
formik.setFieldValue(
|
||||
`stocks.${idx}.product_warehouse_id`,
|
||||
option?.value || 0
|
||||
@@ -2694,6 +2708,7 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
||||
</div>
|
||||
)}
|
||||
</Card>
|
||||
)}
|
||||
|
||||
{/* Transition Warning Banner -- MOVED UP -- */}
|
||||
{isTransitionPeriod && (
|
||||
|
||||
Reference in New Issue
Block a user