mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-25 15:55:48 +00:00
feat(FE-170,174): add depletion products handling and update select input options in daily recording form
This commit is contained in:
@@ -95,6 +95,15 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
return `${ProductWarehouseApi.basePath}?${params.toString()}`;
|
return `${ProductWarehouseApi.basePath}?${params.toString()}`;
|
||||||
}, [selectedLocation]);
|
}, [selectedLocation]);
|
||||||
|
|
||||||
|
const depletionProductsUrl = useMemo(() => {
|
||||||
|
if (!selectedLocation) return null;
|
||||||
|
const params = new URLSearchParams({
|
||||||
|
search: '',
|
||||||
|
location_id: selectedLocation.value.toString(),
|
||||||
|
});
|
||||||
|
return `${ProductWarehouseApi.basePath}?${params.toString()}`;
|
||||||
|
}, [selectedLocation]);
|
||||||
|
|
||||||
const today = new Date().toISOString().split('T')[0];
|
const today = new Date().toISOString().split('T')[0];
|
||||||
const existingRecordingsUrl = useMemo(() => {
|
const existingRecordingsUrl = useMemo(() => {
|
||||||
return `${RecordingApi.basePath}?record_date=${today}`;
|
return `${RecordingApi.basePath}?record_date=${today}`;
|
||||||
@@ -176,6 +185,9 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
ProductWarehouseApi.getAllFetcher
|
ProductWarehouseApi.getAllFetcher
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const { data: depletionProductsData, isLoading: isLoadingDepletionProducts } =
|
||||||
|
useSWR(depletionProductsUrl, ProductWarehouseApi.getAllFetcher);
|
||||||
|
|
||||||
// ===== DATA PROCESSING =====
|
// ===== DATA PROCESSING =====
|
||||||
const locationOptions = useMemo(() => {
|
const locationOptions = useMemo(() => {
|
||||||
if (!isResponseSuccess(locations)) return [];
|
if (!isResponseSuccess(locations)) return [];
|
||||||
@@ -271,6 +283,28 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
return options;
|
return options;
|
||||||
}, [stockProducts, initialValues, type]);
|
}, [stockProducts, initialValues, type]);
|
||||||
|
|
||||||
|
const depletionProducts = useMemo(() => {
|
||||||
|
const options: OptionType[] = [];
|
||||||
|
if (isResponseSuccess(depletionProductsData)) {
|
||||||
|
depletionProductsData.data.forEach((product) => {
|
||||||
|
const productName = product.product.name;
|
||||||
|
|
||||||
|
if (
|
||||||
|
productName === 'Ayam Mati' ||
|
||||||
|
productName === 'Ayam Culling' ||
|
||||||
|
productName === 'Ayam Afkir'
|
||||||
|
) {
|
||||||
|
options.push({
|
||||||
|
value: product.id,
|
||||||
|
label: product.product.name,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return options;
|
||||||
|
}, [depletionProductsData]);
|
||||||
|
|
||||||
// ===== FORM HANDLERS =====
|
// ===== FORM HANDLERS =====
|
||||||
const {
|
const {
|
||||||
deleteModal,
|
deleteModal,
|
||||||
@@ -1447,7 +1481,7 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
<td>
|
<td>
|
||||||
<SelectInput
|
<SelectInput
|
||||||
value={
|
value={
|
||||||
unifiedStockProducts.find(
|
depletionProducts.find(
|
||||||
(product) =>
|
(product) =>
|
||||||
product.value === depletion.product_warehouse_id
|
product.value === depletion.product_warehouse_id
|
||||||
) || null
|
) || null
|
||||||
@@ -1459,9 +1493,9 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
|||||||
option?.value || 0
|
option?.value || 0
|
||||||
);
|
);
|
||||||
}}
|
}}
|
||||||
options={unifiedStockProducts}
|
options={depletionProducts}
|
||||||
placeholder='Pilih Kondisi'
|
placeholder='Pilih Kondisi'
|
||||||
isLoading={isLoadingStockProducts}
|
isLoading={isLoadingDepletionProducts}
|
||||||
isError={
|
isError={
|
||||||
isRepeaterInputError(
|
isRepeaterInputError(
|
||||||
'depletions',
|
'depletions',
|
||||||
|
|||||||
Reference in New Issue
Block a user