mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 13:32:00 +00:00
feat(FE-137): enhance stock product selection in RecordingForm with initial values support
This commit is contained in:
@@ -552,35 +552,67 @@ const RecordingForm = ({ type = 'add', initialValues }: RecordingFormProps) => {
|
||||
|
||||
// Memoized unified products for stock selection
|
||||
const unifiedStockProducts = useMemo(() => {
|
||||
if (!isResponseSuccess(stockProducts)) return [];
|
||||
const options: OptionType[] = [];
|
||||
|
||||
stockProducts.data.forEach((product) => {
|
||||
const warehouse = product.warehouse;
|
||||
const stockText = product.quantity.toLocaleString('id-ID');
|
||||
// Add products from API stockProducts
|
||||
if (isResponseSuccess(stockProducts)) {
|
||||
stockProducts.data.forEach((product) => {
|
||||
const warehouse = product.warehouse;
|
||||
const stockText = product.quantity.toLocaleString('id-ID');
|
||||
|
||||
// Check if product has any of the flags
|
||||
const hasPakanFlag = product.product.flags?.includes('PAKAN');
|
||||
const hasOvkFlag = product.product.flags?.includes('OVK');
|
||||
// Check if product has any of the flags
|
||||
const hasPakanFlag = product.product.flags?.includes('PAKAN');
|
||||
const hasOvkFlag = product.product.flags?.includes('OVK');
|
||||
|
||||
// Add products with warehouse and location grouping in label (similar to projectFlockKandangOptions pattern)
|
||||
if (hasPakanFlag) {
|
||||
options.push({
|
||||
value: product.id,
|
||||
label: `[PAKAN] ${product.product.name} - ${warehouse?.name || ''} (${stockText})`
|
||||
});
|
||||
}
|
||||
// Add products with warehouse and location grouping in label (similar to projectFlockKandangOptions pattern)
|
||||
if (hasPakanFlag) {
|
||||
options.push({
|
||||
value: product.id,
|
||||
label: `[PAKAN] ${product.product.name} - ${warehouse?.name || ''} (${stockText})`
|
||||
});
|
||||
}
|
||||
|
||||
if (hasOvkFlag) {
|
||||
options.push({
|
||||
value: product.id,
|
||||
label: `[OVK] ${product.product.name} - ${warehouse?.name || ''} (${stockText})`
|
||||
});
|
||||
}
|
||||
});
|
||||
if (hasOvkFlag) {
|
||||
options.push({
|
||||
value: product.id,
|
||||
label: `[OVK] ${product.product.name} - ${warehouse?.name || ''} (${stockText})`
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Add existing stock products from initialValues (for detail/edit mode)
|
||||
if (initialValues && 'stocks' in initialValues && initialValues.stocks && type !== 'add') {
|
||||
const initialValuesWithStocks = initialValues as Recording & {
|
||||
stocks?: Array<{
|
||||
product_warehouse_id: number;
|
||||
usage_amount: number;
|
||||
notes: string;
|
||||
product_warehouse?: {
|
||||
id: number;
|
||||
product_id: number;
|
||||
product_name: string;
|
||||
warehouse_id: number;
|
||||
warehouse_name: string;
|
||||
};
|
||||
}>;
|
||||
};
|
||||
|
||||
initialValuesWithStocks.stocks?.forEach((stock) => {
|
||||
if (stock.product_warehouse && stock.product_warehouse.product_name) {
|
||||
const existingOption = options.find(opt => opt.value === stock.product_warehouse_id);
|
||||
if (!existingOption) {
|
||||
options.push({
|
||||
value: stock.product_warehouse_id,
|
||||
label: `${stock.product_warehouse.product_name} - ${stock.product_warehouse.warehouse_name}`
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return options;
|
||||
}, [stockProducts, getProjectFlockLocation()]);
|
||||
}, [stockProducts, getProjectFlockLocation(), initialValues, type]);
|
||||
|
||||
|
||||
// Handle stock usage amount change - simplified following MovementForm pattern
|
||||
|
||||
Reference in New Issue
Block a user