mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 21:41:57 +00:00
feat(FE-170,175): update RecordingForm to include selectedKandang in product URL generation and options filtering
This commit is contained in:
@@ -322,7 +322,7 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
||||
: undefined;
|
||||
|
||||
const stockProductsUrl = useMemo(() => {
|
||||
if (!selectedLocation) return null;
|
||||
if (!selectedLocation || !selectedKandang) return null;
|
||||
const params = new URLSearchParams({
|
||||
flags: 'PAKAN,OVK',
|
||||
search: '',
|
||||
@@ -330,17 +330,17 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
||||
location_id: selectedLocation.value.toString(),
|
||||
});
|
||||
return `${ProductWarehouseApi.basePath}?${params.toString()}`;
|
||||
}, [selectedLocation]);
|
||||
}, [selectedLocation, selectedKandang]);
|
||||
|
||||
const depletionProductsUrl = useMemo(() => {
|
||||
if (!selectedLocation) return null;
|
||||
if (!selectedLocation || !selectedKandang) return null;
|
||||
const params = new URLSearchParams({
|
||||
search: '',
|
||||
limit: '100',
|
||||
location_id: selectedLocation.value.toString(),
|
||||
});
|
||||
return `${ProductWarehouseApi.basePath}?${params.toString()}`;
|
||||
}, [selectedLocation]);
|
||||
}, [selectedLocation, selectedKandang]);
|
||||
|
||||
const today = new Date().toISOString().split('T')[0];
|
||||
const existingRecordingsUrl = useMemo(() => {
|
||||
@@ -361,12 +361,14 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
||||
useSWR(depletionProductsUrl, ProductWarehouseApi.getAllFetcher);
|
||||
|
||||
const eggProductsUrl = useMemo(() => {
|
||||
if (!selectedLocation || !selectedKandang) return null;
|
||||
const params = new URLSearchParams({
|
||||
search: 'telur',
|
||||
limit: '100',
|
||||
location_id: selectedLocation.value.toString(),
|
||||
});
|
||||
return `${ProductWarehouseApi.basePath}?${params.toString()}`;
|
||||
}, [selectedLocation]);
|
||||
}, [selectedLocation, selectedKandang]);
|
||||
|
||||
const { data: eggProductsData, isLoading: isLoadingEggProducts } = useSWR(
|
||||
eggProductsUrl,
|
||||
@@ -482,24 +484,17 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
||||
|
||||
const unifiedStockProducts = useMemo(() => {
|
||||
const options: OptionType[] = [];
|
||||
if (isResponseSuccess(stockProducts)) {
|
||||
if (isResponseSuccess(stockProducts) && selectedKandang) {
|
||||
stockProducts.data.forEach((product) => {
|
||||
const warehouse = product.warehouse;
|
||||
product.quantity.toLocaleString('en-US');
|
||||
const hasPakanFlag = product.product.flags?.includes('PAKAN');
|
||||
const hasOvkFlag = product.product.flags?.includes('OVK');
|
||||
|
||||
if (hasPakanFlag) {
|
||||
// Only include products that are in the same location as the selected kandang
|
||||
if (hasPakanFlag || hasOvkFlag) {
|
||||
options.push({
|
||||
value: product.id,
|
||||
label: `${product.product.name} - ${warehouse?.name || ''}`,
|
||||
});
|
||||
}
|
||||
|
||||
if (hasOvkFlag) {
|
||||
options.push({
|
||||
value: product.id,
|
||||
label: `${product.product.name} - ${warehouse?.name || ''}`,
|
||||
label: `${product.product.name} - ${warehouse?.name || 'Unknown Warehouse'} (Stok: ${product.quantity.toLocaleString('en-US')})`,
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -519,7 +514,7 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
||||
if (!existingOption) {
|
||||
options.push({
|
||||
value: stock.product_warehouse_id,
|
||||
label: `${stock.product_warehouse.product.name} - ${stock.product_warehouse.product?.sku || ''}`,
|
||||
label: `${stock.product_warehouse.product.name} - ${stock.product_warehouse.warehouse?.name || 'Unknown'} (Stok: ${stock.product_warehouse.quantity?.toLocaleString('en-US') || 0})`,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -527,14 +522,15 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
||||
}
|
||||
|
||||
return options;
|
||||
}, [stockProducts, initialValues, type]);
|
||||
}, [stockProducts, initialValues, type, selectedKandang]);
|
||||
|
||||
const depletionProducts = useMemo(() => {
|
||||
const options: OptionType[] = [];
|
||||
if (isResponseSuccess(depletionProductsData)) {
|
||||
if (isResponseSuccess(depletionProductsData) && selectedKandang) {
|
||||
depletionProductsData.data.forEach((product) => {
|
||||
const productName = product.product.name;
|
||||
|
||||
// Filter for depletion-related products (culling, mati, afkir)
|
||||
if (
|
||||
productName.toLowerCase().includes('culling') ||
|
||||
productName.toLowerCase().includes('mati') ||
|
||||
@@ -542,7 +538,7 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
||||
) {
|
||||
options.push({
|
||||
value: product.id,
|
||||
label: product.product.name,
|
||||
label: `${product.product.name} - ${product.warehouse?.name || 'Unknown Warehouse'}`,
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -560,7 +556,7 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
||||
if (!existingOption) {
|
||||
options.push({
|
||||
value: depletion.product_warehouse_id,
|
||||
label: depletion.product_warehouse.product.name,
|
||||
label: `${depletion.product_warehouse.product.name} - ${depletion.product_warehouse.warehouse?.name || 'Unknown'}`,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -568,14 +564,15 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
||||
}
|
||||
|
||||
return options;
|
||||
}, [depletionProductsData, initialValues, type]);
|
||||
}, [depletionProductsData, initialValues, type, selectedKandang]);
|
||||
|
||||
const eggProducts = useMemo(() => {
|
||||
const options: OptionType[] = [];
|
||||
if (isResponseSuccess(eggProductsData)) {
|
||||
if (isResponseSuccess(eggProductsData) && selectedKandang) {
|
||||
eggProductsData.data.forEach((product) => {
|
||||
const productName = product.product.name;
|
||||
|
||||
// Filter for egg-related products
|
||||
if (
|
||||
productName.toLowerCase().includes('telur') ||
|
||||
productName.toLowerCase().includes('egg') ||
|
||||
@@ -585,7 +582,7 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
||||
) {
|
||||
options.push({
|
||||
value: product.id,
|
||||
label: product.product.name,
|
||||
label: `${product.product.name} - ${product.warehouse?.name || 'Unknown Warehouse'} (Stok: ${product.quantity.toLocaleString('en-US')})`,
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -600,7 +597,7 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
||||
if (!existingOption) {
|
||||
options.push({
|
||||
value: egg.product_warehouse_id,
|
||||
label: egg.product_warehouse.product.name,
|
||||
label: `${egg.product_warehouse.product.name} - ${egg.product_warehouse.warehouse?.name || 'Unknown'} (Stok: ${egg.product_warehouse.quantity?.toLocaleString('en-US') || 0})`,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -608,7 +605,7 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
||||
}
|
||||
|
||||
return options;
|
||||
}, [eggProductsData, initialValues, type]);
|
||||
}, [eggProductsData, initialValues, type, selectedKandang]);
|
||||
|
||||
const isLayingCategory =
|
||||
initialValues?.project_flock_category === 'LAYING' ||
|
||||
|
||||
Reference in New Issue
Block a user