mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 05:22:02 +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()}`;
|
||||
}, [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 existingRecordingsUrl = useMemo(() => {
|
||||
return `${RecordingApi.basePath}?record_date=${today}`;
|
||||
@@ -176,6 +185,9 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
||||
ProductWarehouseApi.getAllFetcher
|
||||
);
|
||||
|
||||
const { data: depletionProductsData, isLoading: isLoadingDepletionProducts } =
|
||||
useSWR(depletionProductsUrl, ProductWarehouseApi.getAllFetcher);
|
||||
|
||||
// ===== DATA PROCESSING =====
|
||||
const locationOptions = useMemo(() => {
|
||||
if (!isResponseSuccess(locations)) return [];
|
||||
@@ -271,6 +283,28 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
||||
return options;
|
||||
}, [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 =====
|
||||
const {
|
||||
deleteModal,
|
||||
@@ -1447,7 +1481,7 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
||||
<td>
|
||||
<SelectInput
|
||||
value={
|
||||
unifiedStockProducts.find(
|
||||
depletionProducts.find(
|
||||
(product) =>
|
||||
product.value === depletion.product_warehouse_id
|
||||
) || null
|
||||
@@ -1459,9 +1493,9 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
||||
option?.value || 0
|
||||
);
|
||||
}}
|
||||
options={unifiedStockProducts}
|
||||
options={depletionProducts}
|
||||
placeholder='Pilih Kondisi'
|
||||
isLoading={isLoadingStockProducts}
|
||||
isLoading={isLoadingDepletionProducts}
|
||||
isError={
|
||||
isRepeaterInputError(
|
||||
'depletions',
|
||||
|
||||
Reference in New Issue
Block a user