mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 13:32:00 +00:00
fix: recording wont accept ovk
This commit is contained in:
@@ -1277,6 +1277,18 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// In migration mode (edit), the form field `product_warehouse_id` must hold
|
||||||
|
// the master product ID (what the dropdown options use as `value`), not the
|
||||||
|
// PW entity ID returned by the API. The API response has the product ID
|
||||||
|
// nested at stock.product_warehouse.product_id.
|
||||||
|
if (isMigrationMode && type === 'edit' && initialValues?.stocks?.length) {
|
||||||
|
baseValues.stocks = initialValues.stocks.map((stock) => ({
|
||||||
|
product_warehouse_id:
|
||||||
|
stock.product_warehouse?.product_id ?? stock.product_warehouse_id,
|
||||||
|
qty: stock.usage_amount ?? '',
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
if (!recordingRestriction.canEditStock) {
|
if (!recordingRestriction.canEditStock) {
|
||||||
baseValues.stocks = [];
|
baseValues.stocks = [];
|
||||||
}
|
}
|
||||||
@@ -1297,6 +1309,7 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
selectedKandang,
|
selectedKandang,
|
||||||
recordingRestriction.canEditStock,
|
recordingRestriction.canEditStock,
|
||||||
recordingRestriction.canEditDepletion,
|
recordingRestriction.canEditDepletion,
|
||||||
|
isMigrationMode,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const formik = useFormik<
|
const formik = useFormik<
|
||||||
@@ -1408,6 +1421,20 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// When migration mode activates after formik has initialized (SWR timing race),
|
||||||
|
// push the corrected stock values (product_id, not PW entity id) into the form.
|
||||||
|
useEffect(() => {
|
||||||
|
if (type !== 'edit' || !isMigrationMode || !initialValues?.stocks?.length)
|
||||||
|
return;
|
||||||
|
const migrationStocks = initialValues.stocks.map((stock) => ({
|
||||||
|
product_warehouse_id:
|
||||||
|
stock.product_warehouse?.product_id ?? stock.product_warehouse_id,
|
||||||
|
qty: stock.usage_amount ?? '',
|
||||||
|
}));
|
||||||
|
formik.setFieldValue('stocks', migrationStocks);
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, [isMigrationMode]); // intentionally shallow — only run when migration mode flips
|
||||||
|
|
||||||
// ===== HELPER FUNCTIONS =====
|
// ===== HELPER FUNCTIONS =====
|
||||||
const { setFieldValue } = formik;
|
const { setFieldValue } = formik;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user