Add traslations
This commit is contained in:
@@ -57,27 +57,30 @@ export const InitialStockEntryStep: React.FC<InitialStockEntryStepProps> = ({
|
||||
|
||||
// Merge existing stock from backend on mount
|
||||
useEffect(() => {
|
||||
if (stockData?.items && products.length > 0) {
|
||||
console.log('🔄 Merging backend stock data into initial stock entry state...', { itemsCount: stockData.items.length });
|
||||
if (!stockData?.items || products.length === 0) return;
|
||||
|
||||
let hasChanges = false;
|
||||
const updatedProducts = products.map(p => {
|
||||
const existingStock = stockData?.items?.find(s => s.ingredient_id === p.id);
|
||||
if (existingStock && p.initialStock !== existingStock.current_quantity) {
|
||||
hasChanges = true;
|
||||
return {
|
||||
...p,
|
||||
initialStock: existingStock.current_quantity
|
||||
};
|
||||
}
|
||||
return p;
|
||||
});
|
||||
console.log('🔄 Merging backend stock data into initial stock entry state...', { itemsCount: stockData.items.length });
|
||||
|
||||
if (hasChanges) {
|
||||
setProducts(updatedProducts);
|
||||
let hasChanges = false;
|
||||
const updatedProducts = products.map(p => {
|
||||
const existingStock = stockData.items.find(s => s.ingredient_id === p.id);
|
||||
|
||||
// Only merge if user hasn't entered value yet
|
||||
if (existingStock && p.initialStock === undefined) {
|
||||
hasChanges = true;
|
||||
return {
|
||||
...p,
|
||||
initialStock: existingStock.current_quantity
|
||||
};
|
||||
}
|
||||
return p;
|
||||
});
|
||||
|
||||
if (hasChanges) {
|
||||
setProducts(updatedProducts);
|
||||
onUpdate?.({ productsWithStock: updatedProducts });
|
||||
}
|
||||
}, [stockData, products]); // Run when stock data changes or products list is initialized
|
||||
}, [stockData]); // Only depend on stockData to avoid infinite loop
|
||||
|
||||
const ingredients = products.filter(p => p.type === 'ingredient');
|
||||
const finishedProducts = products.filter(p => p.type === 'finished_product');
|
||||
|
||||
Reference in New Issue
Block a user