Fix new Frontend 10
This commit is contained in:
@@ -67,11 +67,20 @@ const OnboardingPage: React.FC<OnboardingPageProps> = ({ user, onComplete }) =>
|
||||
});
|
||||
|
||||
const { createTenant, isLoading: tenantLoading } = useTenant();
|
||||
const { startTrainingJob, getTrainingJobStatus } = useTraining();
|
||||
const { startTrainingJob } = useTraining({ disablePolling: true });
|
||||
const { uploadSalesHistory, validateSalesData } = useData();
|
||||
|
||||
// WebSocket connection for real-time training updates
|
||||
const { status, jobUpdates, connect, disconnect, isConnected } = useTrainingWebSocket(trainingJobId || 'pending');
|
||||
const {
|
||||
status,
|
||||
jobUpdates,
|
||||
connect,
|
||||
disconnect,
|
||||
isConnected,
|
||||
lastMessage,
|
||||
tenantId: resolvedTenantId,
|
||||
wsUrl
|
||||
} = useTrainingWebSocket(trainingJobId || 'pending', tenantId);
|
||||
|
||||
const steps = [
|
||||
{ id: 1, title: 'Datos de Panadería', icon: Store },
|
||||
@@ -86,20 +95,27 @@ const OnboardingPage: React.FC<OnboardingPageProps> = ({ user, onComplete }) =>
|
||||
if (jobUpdates.length > 0) {
|
||||
const latestUpdate = jobUpdates[0];
|
||||
|
||||
// Update training progress based on WebSocket messages
|
||||
if (latestUpdate.type === 'training_progress') {
|
||||
console.log('📨 Processing WebSocket Update:', latestUpdate);
|
||||
|
||||
// Handle the message structure from your test script
|
||||
const messageType = latestUpdate.type;
|
||||
const data = latestUpdate.data || {};
|
||||
|
||||
if (messageType === 'progress' || messageType === 'training_progress') {
|
||||
console.log('📊 Progress update:', data);
|
||||
setTrainingProgress(prev => ({
|
||||
...prev,
|
||||
progress: latestUpdate.progress || 0,
|
||||
currentStep: latestUpdate.current_step || 'Procesando...',
|
||||
productsCompleted: latestUpdate.products_completed || 0,
|
||||
productsTotal: latestUpdate.products_total || prev.productsTotal,
|
||||
estimatedTimeRemaining: latestUpdate.estimated_time_remaining || 0,
|
||||
progress: data.progress || 0,
|
||||
currentStep: data.current_step || 'Procesando...',
|
||||
productsCompleted: data.products_completed || 0,
|
||||
productsTotal: data.products_total || prev.productsTotal,
|
||||
estimatedTimeRemaining: data.estimated_time_remaining || 0,
|
||||
status: 'running'
|
||||
}));
|
||||
} else if (latestUpdate.type === 'training_completed') {
|
||||
} else if (messageType === 'completed' || messageType === 'training_completed') {
|
||||
console.log('🎉 Training completed via WebSocket!');
|
||||
setTrainingProgress(prev => ({
|
||||
...prev,
|
||||
...prev,
|
||||
progress: 100,
|
||||
status: 'completed',
|
||||
currentStep: 'Entrenamiento completado',
|
||||
@@ -111,13 +127,26 @@ const OnboardingPage: React.FC<OnboardingPageProps> = ({ user, onComplete }) =>
|
||||
setCurrentStep(5);
|
||||
}, 2000);
|
||||
|
||||
} else if (latestUpdate.type === 'training_failed' || latestUpdate.type === 'training_error') {
|
||||
} else if (messageType === 'failed' || messageType === 'training_failed' || messageType === 'training_error') {
|
||||
console.error('❌ Training failed via WebSocket:', latestUpdate);
|
||||
setTrainingProgress(prev => ({
|
||||
...prev,
|
||||
status: 'failed',
|
||||
error: latestUpdate.error || 'Error en el entrenamiento',
|
||||
error: data.error || 'Error en el entrenamiento',
|
||||
currentStep: 'Error en el entrenamiento'
|
||||
}));
|
||||
} else if (messageType === 'heartbeat') {
|
||||
console.log('💓 Heartbeat received');
|
||||
} else if (messageType === 'initial_status') {
|
||||
console.log('ℹ️ Initial status:', data);
|
||||
setTrainingProgress(prev => ({
|
||||
...prev,
|
||||
progress: data.progress || prev.progress,
|
||||
status: data.status || prev.status,
|
||||
currentStep: data.current_step || prev.currentStep
|
||||
}));
|
||||
} else {
|
||||
console.log('🔍 Unhandled message type:', messageType, data);
|
||||
}
|
||||
}
|
||||
}, [jobUpdates]);
|
||||
|
||||
Reference in New Issue
Block a user