Fix new Frontend 8
This commit is contained in:
@@ -7,6 +7,7 @@ import { useState, useCallback } from 'react';
|
||||
import { dataService } from '../services';
|
||||
import type {
|
||||
SalesData,
|
||||
SalesValidationResult,
|
||||
SalesDataQuery,
|
||||
SalesImportResult,
|
||||
DashboardStats,
|
||||
@@ -52,7 +53,7 @@ export const useData = () => {
|
||||
const validateSalesData = useCallback(async (
|
||||
tenantId: string,
|
||||
file: File
|
||||
): Promise<SalesImportResult> => {
|
||||
): Promise<SalesValidationResult> => {
|
||||
try {
|
||||
setIsLoading(true);
|
||||
setError(null);
|
||||
|
||||
@@ -8,6 +8,7 @@ import { apiClient } from '../client';
|
||||
import { RequestTimeouts } from '../client/config';
|
||||
import type {
|
||||
SalesData,
|
||||
SalesValidationResult,
|
||||
SalesDataQuery,
|
||||
SalesDataImport,
|
||||
SalesImportResult,
|
||||
@@ -60,7 +61,7 @@ export class DataService {
|
||||
async validateSalesData(
|
||||
tenantId: string,
|
||||
file: File
|
||||
): Promise<SalesImportResult> {
|
||||
): Promise<SalesValidationResult> {
|
||||
const fileName = file.name.toLowerCase();
|
||||
let fileFormat: string;
|
||||
|
||||
@@ -75,11 +76,12 @@ export class DataService {
|
||||
}
|
||||
|
||||
return apiClient.upload(
|
||||
`/tenants/${tenantId}/sales/validate`,
|
||||
`/tenants/${tenantId}/sales/import/validate`,
|
||||
file,
|
||||
{
|
||||
file_format: fileFormat,
|
||||
validate_only: true,
|
||||
source: 'onboarding_upload',
|
||||
},
|
||||
{
|
||||
timeout: RequestTimeouts.MEDIUM,
|
||||
|
||||
@@ -18,6 +18,16 @@ export interface SalesData {
|
||||
external_factors?: ExternalFactors;
|
||||
}
|
||||
|
||||
export interface SalesValidationResult {
|
||||
is_valid: boolean;
|
||||
total_records: number;
|
||||
valid_records: number;
|
||||
invalid_records: number;
|
||||
errors: ValidationError[];
|
||||
warnings: ValidationError[];
|
||||
summary: Record<string, any>;
|
||||
}
|
||||
|
||||
export interface ExternalFactors {
|
||||
weather_temperature?: number;
|
||||
weather_precipitation?: number;
|
||||
|
||||
@@ -125,15 +125,14 @@ const OnboardingPage: React.FC<OnboardingPageProps> = ({ user, onComplete }) =>
|
||||
try {
|
||||
// Step 2.1: First validate the CSV data
|
||||
toast.loading('Validando datos del archivo CSV...', { id: 'csv-validation' });
|
||||
|
||||
const validationResult = await validateSalesData(tenantId, bakeryData.csvFile);
|
||||
|
||||
toast.dismiss('csv-validation');
|
||||
|
||||
|
||||
// Check validation result
|
||||
if (!validationResult.success) {
|
||||
const validationResult = await validateSalesData(tenantId, bakeryData.csvFile);
|
||||
|
||||
// Check validation result using the correct field names
|
||||
if (!validationResult.is_valid) { // ← Changed from .success to .is_valid
|
||||
// Validation failed - show errors but let user decide
|
||||
const errorMessages = validationResult.errors?.slice(0, 3).join(', ') || 'Errores de validación';
|
||||
const errorMessages = validationResult.errors?.slice(0, 3).map(e => e.message || 'Unknown error').join(', ') || 'Errores de validación';
|
||||
const hasMoreErrors = validationResult.errors && validationResult.errors.length > 3;
|
||||
|
||||
toast.error(
|
||||
@@ -145,13 +144,13 @@ const OnboardingPage: React.FC<OnboardingPageProps> = ({ user, onComplete }) =>
|
||||
// Don't proceed with upload if validation fails
|
||||
throw new Error('Validación del CSV falló');
|
||||
}
|
||||
|
||||
|
||||
// Validation passed - show summary and proceed
|
||||
if (validationResult.warnings && validationResult.warnings.length > 0) {
|
||||
toast.warn(`CSV validado con ${validationResult.warnings.length} advertencias. Continuando con la subida...`);
|
||||
console.warn('CSV validation warnings:', validationResult.warnings);
|
||||
} else {
|
||||
toast.success('CSV validado correctamente. Procediendo con la subida...');
|
||||
toast.success(`CSV validado correctamente. ${validationResult.valid_records} de ${validationResult.total_records} registros válidos.`);
|
||||
}
|
||||
|
||||
// Step 2.2: Now upload the validated CSV
|
||||
|
||||
Reference in New Issue
Block a user