|
|
|
|
@@ -13,11 +13,12 @@ import {
|
|
|
|
|
XMarkIcon
|
|
|
|
|
} from '@heroicons/react/24/outline';
|
|
|
|
|
|
|
|
|
|
// Real API services imports
|
|
|
|
|
// Updated imports in onboarding.tsx
|
|
|
|
|
import {
|
|
|
|
|
TenantUser,
|
|
|
|
|
} from '@/api/services';
|
|
|
|
|
|
|
|
|
|
TenantCreate,
|
|
|
|
|
TenantInfo
|
|
|
|
|
} from '@/api/services';
|
|
|
|
|
|
|
|
|
|
import api from '@/api/services';
|
|
|
|
|
|
|
|
|
|
@@ -30,14 +31,27 @@ const OnboardingPage = () => {
|
|
|
|
|
const [notification, setNotification] = useState(null);
|
|
|
|
|
const [currentTenantId, setCurrentTenantId] = useState(null);
|
|
|
|
|
const [formData, setFormData] = useState({
|
|
|
|
|
// User registration fields
|
|
|
|
|
full_name: '',
|
|
|
|
|
email: '',
|
|
|
|
|
password: '',
|
|
|
|
|
confirm_password: '',
|
|
|
|
|
|
|
|
|
|
// Bakery/Tenant fields - matching TenantCreate interface
|
|
|
|
|
bakery_name: '',
|
|
|
|
|
address: '',
|
|
|
|
|
city: 'Madrid',
|
|
|
|
|
postal_code: '',
|
|
|
|
|
phone: '', // Will use default if empty
|
|
|
|
|
business_type: 'individual_bakery' as 'individual_bakery' | 'central_workshop',
|
|
|
|
|
|
|
|
|
|
// Optional fields
|
|
|
|
|
latitude: undefined as number | undefined,
|
|
|
|
|
longitude: undefined as number | undefined,
|
|
|
|
|
subscription_plan: undefined as string | undefined,
|
|
|
|
|
settings: undefined as Record<string, any> | undefined,
|
|
|
|
|
|
|
|
|
|
// Additional form fields
|
|
|
|
|
has_nearby_schools: false,
|
|
|
|
|
has_nearby_offices: false,
|
|
|
|
|
selected_products: ['Pan de molde', 'Croissants', 'Magdalenas'],
|
|
|
|
|
@@ -45,7 +59,6 @@ const OnboardingPage = () => {
|
|
|
|
|
trainingStatus: 'pending',
|
|
|
|
|
trainingTaskId: null,
|
|
|
|
|
trainingProgress: 0,
|
|
|
|
|
business_type: 'bakery'
|
|
|
|
|
});
|
|
|
|
|
const [errors, setErrors] = useState({});
|
|
|
|
|
const [uploadValidation, setUploadValidation] = useState(null);
|
|
|
|
|
@@ -138,6 +151,17 @@ const OnboardingPage = () => {
|
|
|
|
|
if (!formData.bakery_name.trim()) newErrors.bakery_name = 'Nombre de panadería requerido';
|
|
|
|
|
if (!formData.address.trim()) newErrors.address = 'Dirección requerida';
|
|
|
|
|
if (!formData.postal_code.trim()) newErrors.postal_code = 'Código postal requerido';
|
|
|
|
|
if (!formData.email.trim()) newErrors.email = 'Email requerido'; // Email is required for TenantCreate
|
|
|
|
|
|
|
|
|
|
// Validate business_type is one of the allowed values
|
|
|
|
|
if (!['individual_bakery', 'central_workshop'].includes(formData.business_type)) {
|
|
|
|
|
newErrors.business_type = 'Tipo de negocio inválido';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Optional: Validate phone format if provided (will use default if empty)
|
|
|
|
|
if (formData.phone && !formData.phone.match(/^(\+34|34)?[67][0-9]{8}$/)) {
|
|
|
|
|
newErrors.phone = 'Formato de teléfono inválido';
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
if (!formData.salesFile) newErrors.salesFile = 'Archivo de ventas requerido';
|
|
|
|
|
@@ -165,21 +189,26 @@ const OnboardingPage = () => {
|
|
|
|
|
const user = await api.auth.register(userData);
|
|
|
|
|
showNotification('success', 'Usuario creado', 'Cuenta registrada exitosamente.');
|
|
|
|
|
|
|
|
|
|
} else if (currentStep === 2) {
|
|
|
|
|
// Register bakery using real tenant service
|
|
|
|
|
const bakeryData = {
|
|
|
|
|
name: formData.bakery_name,
|
|
|
|
|
business_type: formData.business_type,
|
|
|
|
|
address: formData.address,
|
|
|
|
|
city: formData.city,
|
|
|
|
|
postal_code: formData.postal_code,
|
|
|
|
|
phone: formData.phone || '+34600000000' // Default phone if not provided
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const tenant = await api.tenant.registerBakery(bakeryData);
|
|
|
|
|
setCurrentTenantId(tenant.id);
|
|
|
|
|
showNotification('success', 'Panadería registrada', 'Información guardada correctamente.');
|
|
|
|
|
|
|
|
|
|
} else if (currentStep === 2) {
|
|
|
|
|
// Register bakery using real tenant service with proper TenantCreate interface
|
|
|
|
|
const bakeryData: TenantCreate = {
|
|
|
|
|
name: formData.bakery_name,
|
|
|
|
|
email: formData.email, // Required field from TenantCreate interface
|
|
|
|
|
phone: formData.phone || '+34600000000', // Required field with default
|
|
|
|
|
address: formData.address,
|
|
|
|
|
business_type: formData.business_type as 'individual_bakery' | 'central_workshop',
|
|
|
|
|
// Optional fields that could be added based on form data
|
|
|
|
|
latitude: formData.latitude, // if you have coordinates
|
|
|
|
|
longitude: formData.longitude, // if you have coordinates
|
|
|
|
|
subscription_plan: formData.subscription_plan, // if selected
|
|
|
|
|
settings: formData.settings // if any initial settings
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// The response will be typed as TenantInfo
|
|
|
|
|
const tenant: TenantInfo = await api.tenant.registerBakery(bakeryData);
|
|
|
|
|
setCurrentTenantId(tenant.id);
|
|
|
|
|
showNotification('success', 'Panadería registrada', 'Información guardada correctamente.');
|
|
|
|
|
|
|
|
|
|
} else if (currentStep === 3) {
|
|
|
|
|
// Upload and validate sales data using real data service
|
|
|
|
|
if (formData.salesFile) {
|
|
|
|
|
|