Fix new Frontend 8
This commit is contained in:
@@ -7,6 +7,7 @@ import { useState, useCallback } from 'react';
|
|||||||
import { dataService } from '../services';
|
import { dataService } from '../services';
|
||||||
import type {
|
import type {
|
||||||
SalesData,
|
SalesData,
|
||||||
|
SalesValidationResult,
|
||||||
SalesDataQuery,
|
SalesDataQuery,
|
||||||
SalesImportResult,
|
SalesImportResult,
|
||||||
DashboardStats,
|
DashboardStats,
|
||||||
@@ -52,7 +53,7 @@ export const useData = () => {
|
|||||||
const validateSalesData = useCallback(async (
|
const validateSalesData = useCallback(async (
|
||||||
tenantId: string,
|
tenantId: string,
|
||||||
file: File
|
file: File
|
||||||
): Promise<SalesImportResult> => {
|
): Promise<SalesValidationResult> => {
|
||||||
try {
|
try {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
setError(null);
|
setError(null);
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import { apiClient } from '../client';
|
|||||||
import { RequestTimeouts } from '../client/config';
|
import { RequestTimeouts } from '../client/config';
|
||||||
import type {
|
import type {
|
||||||
SalesData,
|
SalesData,
|
||||||
|
SalesValidationResult,
|
||||||
SalesDataQuery,
|
SalesDataQuery,
|
||||||
SalesDataImport,
|
SalesDataImport,
|
||||||
SalesImportResult,
|
SalesImportResult,
|
||||||
@@ -60,7 +61,7 @@ export class DataService {
|
|||||||
async validateSalesData(
|
async validateSalesData(
|
||||||
tenantId: string,
|
tenantId: string,
|
||||||
file: File
|
file: File
|
||||||
): Promise<SalesImportResult> {
|
): Promise<SalesValidationResult> {
|
||||||
const fileName = file.name.toLowerCase();
|
const fileName = file.name.toLowerCase();
|
||||||
let fileFormat: string;
|
let fileFormat: string;
|
||||||
|
|
||||||
@@ -75,11 +76,12 @@ export class DataService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return apiClient.upload(
|
return apiClient.upload(
|
||||||
`/tenants/${tenantId}/sales/validate`,
|
`/tenants/${tenantId}/sales/import/validate`,
|
||||||
file,
|
file,
|
||||||
{
|
{
|
||||||
file_format: fileFormat,
|
file_format: fileFormat,
|
||||||
validate_only: true,
|
validate_only: true,
|
||||||
|
source: 'onboarding_upload',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
timeout: RequestTimeouts.MEDIUM,
|
timeout: RequestTimeouts.MEDIUM,
|
||||||
|
|||||||
@@ -18,6 +18,16 @@ export interface SalesData {
|
|||||||
external_factors?: ExternalFactors;
|
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 {
|
export interface ExternalFactors {
|
||||||
weather_temperature?: number;
|
weather_temperature?: number;
|
||||||
weather_precipitation?: number;
|
weather_precipitation?: number;
|
||||||
|
|||||||
@@ -126,14 +126,13 @@ const OnboardingPage: React.FC<OnboardingPageProps> = ({ user, onComplete }) =>
|
|||||||
// Step 2.1: First validate the CSV data
|
// Step 2.1: First validate the CSV data
|
||||||
toast.loading('Validando datos del archivo CSV...', { id: 'csv-validation' });
|
toast.loading('Validando datos del archivo CSV...', { id: 'csv-validation' });
|
||||||
|
|
||||||
|
// Check validation result
|
||||||
const validationResult = await validateSalesData(tenantId, bakeryData.csvFile);
|
const validationResult = await validateSalesData(tenantId, bakeryData.csvFile);
|
||||||
|
|
||||||
toast.dismiss('csv-validation');
|
// Check validation result using the correct field names
|
||||||
|
if (!validationResult.is_valid) { // ← Changed from .success to .is_valid
|
||||||
// Check validation result
|
|
||||||
if (!validationResult.success) {
|
|
||||||
// Validation failed - show errors but let user decide
|
// 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;
|
const hasMoreErrors = validationResult.errors && validationResult.errors.length > 3;
|
||||||
|
|
||||||
toast.error(
|
toast.error(
|
||||||
@@ -151,7 +150,7 @@ const OnboardingPage: React.FC<OnboardingPageProps> = ({ user, onComplete }) =>
|
|||||||
toast.warn(`CSV validado con ${validationResult.warnings.length} advertencias. Continuando con la subida...`);
|
toast.warn(`CSV validado con ${validationResult.warnings.length} advertencias. Continuando con la subida...`);
|
||||||
console.warn('CSV validation warnings:', validationResult.warnings);
|
console.warn('CSV validation warnings:', validationResult.warnings);
|
||||||
} else {
|
} 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
|
// Step 2.2: Now upload the validated CSV
|
||||||
|
|||||||
Reference in New Issue
Block a user