Add traslations
This commit is contained in:
@@ -2,7 +2,7 @@ import React, { useState, useEffect } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Button } from '../../../ui/Button';
|
||||
import { useCurrentTenant } from '../../../../stores/tenant.store';
|
||||
import { useCreateIngredient, useIngredients } from '../../../../api/hooks/inventory';
|
||||
import { useCreateIngredient, useBulkCreateIngredients, useIngredients } from '../../../../api/hooks/inventory';
|
||||
import { useImportSalesData } from '../../../../api/hooks/sales';
|
||||
import type { ProductSuggestionResponse, IngredientCreate } from '../../../../api/types/inventory';
|
||||
import { ProductType, UnitOfMeasure, IngredientCategory, ProductCategory } from '../../../../api/types/inventory';
|
||||
@@ -140,6 +140,7 @@ export const InventoryReviewStep: React.FC<InventoryReviewStepProps> = ({
|
||||
|
||||
// API hooks
|
||||
const createIngredientMutation = useCreateIngredient();
|
||||
const bulkCreateIngredientsMutation = useBulkCreateIngredients();
|
||||
const importSalesMutation = useImportSalesData();
|
||||
const { data: existingIngredients } = useIngredients(tenantId);
|
||||
|
||||
@@ -333,26 +334,61 @@ export const InventoryReviewStep: React.FC<InventoryReviewStepProps> = ({
|
||||
|
||||
console.log(`📦 Inventory processing: ${itemsToCreate.length} to create, ${existingMatches.length} already exist.`);
|
||||
|
||||
// STEP 1: Create new inventory items in parallel
|
||||
const createPromises = itemsToCreate.map((item, index) => {
|
||||
const ingredientData: IngredientCreate = {
|
||||
name: item.name,
|
||||
product_type: item.product_type,
|
||||
category: item.category,
|
||||
unit_of_measure: item.unit_of_measure as UnitOfMeasure,
|
||||
};
|
||||
// STEP 1: Create new inventory items using bulk API (with fallback to individual creates)
|
||||
let newlyCreatedIngredients: any[] = [];
|
||||
|
||||
return createIngredientMutation.mutateAsync({
|
||||
tenantId,
|
||||
ingredientData,
|
||||
}).catch(error => {
|
||||
console.error(`❌ Failed to create ingredient "${item.name}":`, error);
|
||||
throw error;
|
||||
});
|
||||
});
|
||||
if (itemsToCreate.length > 0) {
|
||||
try {
|
||||
// Try bulk creation first (more efficient)
|
||||
const ingredientsData: IngredientCreate[] = itemsToCreate.map(item => ({
|
||||
name: item.name,
|
||||
product_type: item.product_type,
|
||||
category: item.category,
|
||||
unit_of_measure: item.unit_of_measure as UnitOfMeasure,
|
||||
}));
|
||||
|
||||
const newlyCreatedIngredients = await Promise.all(createPromises);
|
||||
console.log('✅ New inventory items created successfully');
|
||||
const bulkResult = await bulkCreateIngredientsMutation.mutateAsync({
|
||||
tenantId,
|
||||
ingredients: ingredientsData,
|
||||
});
|
||||
|
||||
// Extract successfully created ingredients
|
||||
newlyCreatedIngredients = bulkResult.results
|
||||
.filter(r => r.success && r.ingredient)
|
||||
.map(r => r.ingredient!);
|
||||
|
||||
console.log(`✅ Bulk creation: ${bulkResult.total_created}/${bulkResult.total_requested} items created successfully`);
|
||||
|
||||
// Log any failures
|
||||
if (bulkResult.total_failed > 0) {
|
||||
const failures = bulkResult.results.filter(r => !r.success);
|
||||
console.warn(`⚠️ ${bulkResult.total_failed} items failed:`, failures.map(f => f.error));
|
||||
}
|
||||
} catch (bulkError) {
|
||||
console.warn('⚠️ Bulk create failed, falling back to individual creates:', bulkError);
|
||||
|
||||
// Fallback: Create items individually in parallel
|
||||
const createPromises = itemsToCreate.map((item, index) => {
|
||||
const ingredientData: IngredientCreate = {
|
||||
name: item.name,
|
||||
product_type: item.product_type,
|
||||
category: item.category,
|
||||
unit_of_measure: item.unit_of_measure as UnitOfMeasure,
|
||||
};
|
||||
|
||||
return createIngredientMutation.mutateAsync({
|
||||
tenantId,
|
||||
ingredientData,
|
||||
}).catch(error => {
|
||||
console.error(`❌ Failed to create ingredient "${item.name}":`, error);
|
||||
throw error;
|
||||
});
|
||||
});
|
||||
|
||||
newlyCreatedIngredients = await Promise.all(createPromises);
|
||||
console.log('✅ Fallback: New inventory items created successfully via individual requests');
|
||||
}
|
||||
}
|
||||
|
||||
// STEP 2: Import sales data (only if file was uploaded)
|
||||
let salesImported = false;
|
||||
@@ -467,10 +503,10 @@ export const InventoryReviewStep: React.FC<InventoryReviewStepProps> = ({
|
||||
<span className="text-3xl group-hover:scale-110 transition-transform">{template.icon}</span>
|
||||
<div className="flex-1 min-w-0">
|
||||
<h4 className="font-medium text-[var(--text-primary)] mb-1">
|
||||
{template.name}
|
||||
{t(`setup_wizard:inventory.templates.${template.id}`, template.name)}
|
||||
</h4>
|
||||
<p className="text-xs text-[var(--text-secondary)] mb-2">
|
||||
{template.description}
|
||||
{t(`setup_wizard:inventory.templates.${template.id}-desc`, template.description)}
|
||||
</p>
|
||||
<p className="text-xs text-purple-600 dark:text-purple-400 font-medium">
|
||||
{template.items.length} {t('inventory:templates.items', 'ingredientes')}
|
||||
|
||||
Reference in New Issue
Block a user