feat(FE-170): enhance RecordingForm to include kandang_id from lookup and simplify product labels

This commit is contained in:
rstubryan
2025-11-12 22:13:17 +07:00
parent c7022ee200
commit 0e7c178736
@@ -329,8 +329,19 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
limit: '100',
location_id: selectedLocation.value.toString(),
});
// Add kandang_id parameter if available from lookup
if (projectFlockKandangLookup?.kandang?.id) {
params.append(
'kandang_id',
projectFlockKandangLookup.kandang.id.toString()
);
} else if (selectedKandang) {
params.append('kandang_id', selectedKandang.value.toString());
}
return `${ProductWarehouseApi.basePath}?${params.toString()}`;
}, [selectedLocation, selectedKandang]);
}, [selectedLocation, selectedKandang, projectFlockKandangLookup]);
const depletionProductsUrl = useMemo(() => {
if (!selectedLocation || !selectedKandang) return null;
@@ -339,8 +350,19 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
limit: '100',
location_id: selectedLocation.value.toString(),
});
// Add kandang_id parameter if available from lookup
if (projectFlockKandangLookup?.kandang?.id) {
params.append(
'kandang_id',
projectFlockKandangLookup.kandang.id.toString()
);
} else if (selectedKandang) {
params.append('kandang_id', selectedKandang.value.toString());
}
return `${ProductWarehouseApi.basePath}?${params.toString()}`;
}, [selectedLocation, selectedKandang]);
}, [selectedLocation, selectedKandang, projectFlockKandangLookup]);
const today = new Date().toISOString().split('T')[0];
const existingRecordingsUrl = useMemo(() => {
@@ -367,8 +389,18 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
limit: '100',
location_id: selectedLocation.value.toString(),
});
if (projectFlockKandangLookup?.kandang?.id) {
params.append(
'kandang_id',
projectFlockKandangLookup.kandang.id.toString()
);
} else if (selectedKandang) {
params.append('kandang_id', selectedKandang.value.toString());
}
return `${ProductWarehouseApi.basePath}?${params.toString()}`;
}, [selectedLocation, selectedKandang]);
}, [selectedLocation, selectedKandang, projectFlockKandangLookup]);
const { data: eggProductsData, isLoading: isLoadingEggProducts } = useSWR(
eggProductsUrl,
@@ -486,7 +518,6 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
const options: OptionType[] = [];
if (isResponseSuccess(stockProducts) && selectedKandang) {
stockProducts.data.forEach((product) => {
const warehouse = product.warehouse;
const hasPakanFlag = product.product.flags?.includes('PAKAN');
const hasOvkFlag = product.product.flags?.includes('OVK');
@@ -494,7 +525,7 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
if (hasPakanFlag || hasOvkFlag) {
options.push({
value: product.id,
label: `${product.product.name} - ${warehouse?.name || 'Unknown Warehouse'} (Stok: ${product.quantity.toLocaleString('en-US')})`,
label: product.product.name,
});
}
});
@@ -514,7 +545,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.warehouse?.name || 'Unknown'} (Stok: ${stock.product_warehouse.quantity?.toLocaleString('en-US') || 0})`,
label: stock.product_warehouse.product.name,
});
}
}
@@ -538,7 +569,7 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
) {
options.push({
value: product.id,
label: `${product.product.name} - ${product.warehouse?.name || 'Unknown Warehouse'}`,
label: product.product.name,
});
}
});
@@ -556,7 +587,7 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
if (!existingOption) {
options.push({
value: depletion.product_warehouse_id,
label: `${depletion.product_warehouse.product.name} - ${depletion.product_warehouse.warehouse?.name || 'Unknown'}`,
label: depletion.product_warehouse.product.name,
});
}
}
@@ -582,7 +613,7 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
) {
options.push({
value: product.id,
label: `${product.product.name} - ${product.warehouse?.name || 'Unknown Warehouse'} (Stok: ${product.quantity.toLocaleString('en-US')})`,
label: product.product.name,
});
}
});
@@ -597,7 +628,7 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
if (!existingOption) {
options.push({
value: egg.product_warehouse_id,
label: `${egg.product_warehouse.product.name} - ${egg.product_warehouse.warehouse?.name || 'Unknown'} (Stok: ${egg.product_warehouse.quantity?.toLocaleString('en-US') || 0})`,
label: egg.product_warehouse.product.name,
});
}
}
@@ -767,7 +798,7 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
const isAlreadyRecorded = recordedProjectFlockKandangIds.has(
projectFlockKandangLookup.project_flock_kandang_id
);
let color: 'neutral' | 'success' | 'warning' | 'error' = 'neutral';
let color: 'neutral' | 'success' | 'warning' | 'error';
if (isAlreadyRecorded) {
color = 'warning';