2025-12-19 13:10:24 +01:00
|
|
|
|
import React, { useState, useEffect } from 'react';
|
2025-12-25 18:59:56 +01:00
|
|
|
|
import { useTranslation } from 'react-i18next';
|
2025-11-12 15:34:10 +01:00
|
|
|
|
import { Button, Input } from '../../../ui';
|
|
|
|
|
|
import { AddressAutocomplete } from '../../../ui/AddressAutocomplete';
|
2025-12-19 13:10:24 +01:00
|
|
|
|
import { useRegisterBakery, useTenant, useUpdateTenant } from '../../../../api/hooks/tenant';
|
|
|
|
|
|
import { BakeryRegistration, TenantUpdate } from '../../../../api/types/tenant';
|
2025-11-12 15:34:10 +01:00
|
|
|
|
import { AddressResult } from '../../../../services/api/geocodingApi';
|
|
|
|
|
|
import { useWizardContext } from '../context';
|
2025-11-12 14:48:46 +00:00
|
|
|
|
import { poiContextApi } from '../../../../services/api/poiContextApi';
|
2025-09-08 17:19:00 +02:00
|
|
|
|
|
|
|
|
|
|
interface RegisterTenantStepProps {
|
|
|
|
|
|
onNext: () => void;
|
|
|
|
|
|
onPrevious: () => void;
|
|
|
|
|
|
onComplete: (data?: any) => void;
|
|
|
|
|
|
isFirstStep: boolean;
|
|
|
|
|
|
isLastStep: boolean;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-18 13:26:32 +01:00
|
|
|
|
// Map bakeryType to business_model
|
|
|
|
|
|
const getBakeryBusinessModel = (bakeryType: string | null): string => {
|
|
|
|
|
|
switch (bakeryType) {
|
|
|
|
|
|
case 'production':
|
|
|
|
|
|
return 'central_baker_satellite'; // Production-focused bakery
|
|
|
|
|
|
case 'retail':
|
|
|
|
|
|
return 'retail_bakery'; // Retail/finishing bakery
|
|
|
|
|
|
case 'mixed':
|
|
|
|
|
|
return 'hybrid_bakery'; // Mixed model (enterprise or hybrid)
|
|
|
|
|
|
default:
|
|
|
|
|
|
return 'individual_bakery'; // Default fallback
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-09-08 17:19:00 +02:00
|
|
|
|
export const RegisterTenantStep: React.FC<RegisterTenantStepProps> = ({
|
|
|
|
|
|
onComplete,
|
|
|
|
|
|
isFirstStep
|
|
|
|
|
|
}) => {
|
2025-12-25 18:59:56 +01:00
|
|
|
|
const { t } = useTranslation();
|
2025-11-12 15:34:10 +01:00
|
|
|
|
const wizardContext = useWizardContext();
|
2025-12-19 13:10:24 +01:00
|
|
|
|
const tenantId = wizardContext.state.tenantId;
|
2025-12-18 13:26:32 +01:00
|
|
|
|
|
|
|
|
|
|
// Check if user is enterprise tier for conditional labels
|
|
|
|
|
|
const subscriptionTier = localStorage.getItem('subscription_tier');
|
|
|
|
|
|
const isEnterprise = subscriptionTier === 'enterprise';
|
|
|
|
|
|
|
|
|
|
|
|
// Get business_model from wizard context's bakeryType
|
|
|
|
|
|
const businessModel = getBakeryBusinessModel(wizardContext.state.bakeryType);
|
|
|
|
|
|
|
2025-09-08 17:19:00 +02:00
|
|
|
|
const [formData, setFormData] = useState<BakeryRegistration>({
|
|
|
|
|
|
name: '',
|
|
|
|
|
|
address: '',
|
|
|
|
|
|
postal_code: '',
|
|
|
|
|
|
phone: '',
|
|
|
|
|
|
city: 'Madrid',
|
|
|
|
|
|
business_type: 'bakery',
|
2025-12-18 13:26:32 +01:00
|
|
|
|
business_model: businessModel
|
2025-09-08 17:19:00 +02:00
|
|
|
|
});
|
|
|
|
|
|
|
2025-12-19 13:10:24 +01:00
|
|
|
|
// Fetch existing tenant data if we have a tenantId (persistence)
|
|
|
|
|
|
const { data: existingTenant, isLoading: isLoadingTenant } = useTenant(tenantId || '');
|
|
|
|
|
|
|
|
|
|
|
|
// Update formData when existing tenant data is fetched
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
if (existingTenant) {
|
|
|
|
|
|
console.log('🔄 Populating RegisterTenantStep with existing data:', existingTenant);
|
|
|
|
|
|
setFormData({
|
|
|
|
|
|
name: existingTenant.name,
|
|
|
|
|
|
address: existingTenant.address,
|
|
|
|
|
|
postal_code: existingTenant.postal_code,
|
|
|
|
|
|
phone: existingTenant.phone || '',
|
|
|
|
|
|
city: existingTenant.city,
|
|
|
|
|
|
business_type: existingTenant.business_type,
|
|
|
|
|
|
business_model: existingTenant.business_model || businessModel
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// Update location in context if available from tenant
|
|
|
|
|
|
// Note: Backend might not store lat/lon directly in Tenant table in all versions,
|
|
|
|
|
|
// but if we had them or if we want to re-trigger geocoding, we'd handle it here.
|
|
|
|
|
|
}
|
|
|
|
|
|
}, [existingTenant, businessModel]);
|
|
|
|
|
|
|
2025-12-18 13:26:32 +01:00
|
|
|
|
// Update business_model when bakeryType changes in context
|
2025-12-19 13:10:24 +01:00
|
|
|
|
useEffect(() => {
|
2025-12-18 13:26:32 +01:00
|
|
|
|
const newBusinessModel = getBakeryBusinessModel(wizardContext.state.bakeryType);
|
|
|
|
|
|
if (newBusinessModel !== formData.business_model) {
|
|
|
|
|
|
setFormData(prev => ({
|
|
|
|
|
|
...prev,
|
|
|
|
|
|
business_model: newBusinessModel
|
|
|
|
|
|
}));
|
|
|
|
|
|
}
|
|
|
|
|
|
}, [wizardContext.state.bakeryType, formData.business_model]);
|
|
|
|
|
|
|
2025-09-08 17:19:00 +02:00
|
|
|
|
const [errors, setErrors] = useState<Record<string, string>>({});
|
|
|
|
|
|
const registerBakery = useRegisterBakery();
|
2025-12-19 13:10:24 +01:00
|
|
|
|
const updateTenant = useUpdateTenant();
|
2025-09-08 17:19:00 +02:00
|
|
|
|
|
|
|
|
|
|
const handleInputChange = (field: keyof BakeryRegistration, value: string) => {
|
|
|
|
|
|
setFormData(prev => ({
|
|
|
|
|
|
...prev,
|
|
|
|
|
|
[field]: value
|
|
|
|
|
|
}));
|
2025-10-15 16:12:49 +02:00
|
|
|
|
|
2025-09-08 17:19:00 +02:00
|
|
|
|
if (errors[field]) {
|
|
|
|
|
|
setErrors(prev => ({
|
|
|
|
|
|
...prev,
|
|
|
|
|
|
[field]: ''
|
|
|
|
|
|
}));
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-11-12 15:34:10 +01:00
|
|
|
|
const handleAddressSelect = (address: AddressResult) => {
|
2025-10-15 16:12:49 +02:00
|
|
|
|
setFormData(prev => ({
|
|
|
|
|
|
...prev,
|
2025-11-12 15:34:10 +01:00
|
|
|
|
address: address.display_name,
|
|
|
|
|
|
city: address.address.city || address.address.municipality || address.address.suburb || prev.city,
|
|
|
|
|
|
postal_code: address.address.postcode || prev.postal_code,
|
2025-10-15 16:12:49 +02:00
|
|
|
|
}));
|
2025-11-12 15:34:10 +01:00
|
|
|
|
};
|
2025-10-15 16:12:49 +02:00
|
|
|
|
|
2025-11-12 15:34:10 +01:00
|
|
|
|
const handleCoordinatesChange = (lat: number, lon: number) => {
|
|
|
|
|
|
// Store coordinates in the wizard context immediately
|
|
|
|
|
|
// This allows the POI detection step to access location information when it's available
|
|
|
|
|
|
wizardContext.updateLocation({ latitude: lat, longitude: lon });
|
|
|
|
|
|
console.log('Coordinates captured and stored:', { latitude: lat, longitude: lon });
|
2025-10-15 16:12:49 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
2025-09-08 17:19:00 +02:00
|
|
|
|
const validateForm = () => {
|
|
|
|
|
|
const newErrors: Record<string, string> = {};
|
|
|
|
|
|
|
|
|
|
|
|
// Required fields according to backend BakeryRegistration schema
|
|
|
|
|
|
if (!formData.name.trim()) {
|
2025-12-25 18:59:56 +01:00
|
|
|
|
newErrors.name = t('onboarding:steps.tenant_registration.validation.name_required');
|
2025-09-08 17:19:00 +02:00
|
|
|
|
} else if (formData.name.length < 2 || formData.name.length > 200) {
|
2025-12-25 18:59:56 +01:00
|
|
|
|
newErrors.name = t('onboarding:steps.tenant_registration.validation.name_length');
|
2025-09-08 17:19:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!formData.address.trim()) {
|
2025-12-25 18:59:56 +01:00
|
|
|
|
newErrors.address = t('onboarding:steps.tenant_registration.validation.address_required');
|
2025-09-08 17:19:00 +02:00
|
|
|
|
} else if (formData.address.length < 10 || formData.address.length > 500) {
|
2025-12-25 18:59:56 +01:00
|
|
|
|
newErrors.address = t('onboarding:steps.tenant_registration.validation.address_length');
|
2025-09-08 17:19:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!formData.postal_code.trim()) {
|
2025-12-25 18:59:56 +01:00
|
|
|
|
newErrors.postal_code = t('onboarding:steps.tenant_registration.validation.postal_code_required');
|
2025-09-08 17:19:00 +02:00
|
|
|
|
} else if (!/^\d{5}$/.test(formData.postal_code)) {
|
2025-12-25 18:59:56 +01:00
|
|
|
|
newErrors.postal_code = t('onboarding:steps.tenant_registration.validation.postal_code_format');
|
2025-09-08 17:19:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!formData.phone.trim()) {
|
2025-12-25 18:59:56 +01:00
|
|
|
|
newErrors.phone = t('onboarding:steps.tenant_registration.validation.phone_required');
|
2025-09-08 17:19:00 +02:00
|
|
|
|
} else if (formData.phone.length < 9 || formData.phone.length > 20) {
|
2025-12-25 18:59:56 +01:00
|
|
|
|
newErrors.phone = t('onboarding:steps.tenant_registration.validation.phone_length');
|
2025-09-08 17:19:00 +02:00
|
|
|
|
} else {
|
|
|
|
|
|
// Basic Spanish phone validation
|
|
|
|
|
|
const phone = formData.phone.replace(/[\s\-\(\)]/g, '');
|
|
|
|
|
|
const patterns = [
|
|
|
|
|
|
/^(\+34|0034|34)?[6789]\d{8}$/, // Mobile
|
|
|
|
|
|
/^(\+34|0034|34)?9\d{8}$/ // Landline
|
|
|
|
|
|
];
|
|
|
|
|
|
if (!patterns.some(pattern => pattern.test(phone))) {
|
2025-12-25 18:59:56 +01:00
|
|
|
|
newErrors.phone = t('onboarding:steps.tenant_registration.validation.phone_format');
|
2025-09-08 17:19:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
setErrors(newErrors);
|
|
|
|
|
|
return Object.keys(newErrors).length === 0;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const handleSubmit = async () => {
|
|
|
|
|
|
if (!validateForm()) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-19 13:10:24 +01:00
|
|
|
|
console.log('📝 Submitting tenant data:', {
|
|
|
|
|
|
isUpdate: !!tenantId,
|
2025-12-18 13:26:32 +01:00
|
|
|
|
bakeryType: wizardContext.state.bakeryType,
|
|
|
|
|
|
business_model: formData.business_model,
|
|
|
|
|
|
formData
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2025-09-08 17:19:00 +02:00
|
|
|
|
try {
|
2025-12-19 13:10:24 +01:00
|
|
|
|
let tenant;
|
|
|
|
|
|
if (tenantId) {
|
|
|
|
|
|
// Update existing tenant
|
|
|
|
|
|
const updateData: TenantUpdate = {
|
|
|
|
|
|
name: formData.name,
|
|
|
|
|
|
address: formData.address,
|
|
|
|
|
|
phone: formData.phone,
|
|
|
|
|
|
business_type: formData.business_type,
|
|
|
|
|
|
business_model: formData.business_model
|
|
|
|
|
|
};
|
|
|
|
|
|
tenant = await updateTenant.mutateAsync({ tenantId, updateData });
|
|
|
|
|
|
console.log('✅ Tenant updated successfully:', tenant.id);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
// Create new tenant
|
|
|
|
|
|
tenant = await registerBakery.mutateAsync(formData);
|
|
|
|
|
|
console.log('✅ Tenant registered successfully:', tenant.id);
|
|
|
|
|
|
}
|
2025-11-12 15:34:10 +01:00
|
|
|
|
|
2025-11-12 14:48:46 +00:00
|
|
|
|
// Trigger POI detection in the background (non-blocking)
|
|
|
|
|
|
// This replaces the removed POI Detection step
|
2026-01-12 22:15:11 +01:00
|
|
|
|
// POI detection will be cached for 90 days and reused during training
|
2025-11-12 14:48:46 +00:00
|
|
|
|
const bakeryLocation = wizardContext.state.bakeryLocation;
|
|
|
|
|
|
if (bakeryLocation?.latitude && bakeryLocation?.longitude && tenant.id) {
|
2026-01-12 22:15:11 +01:00
|
|
|
|
console.log(`🔍 Triggering background POI detection for tenant ${tenant.id}...`);
|
|
|
|
|
|
|
2025-11-12 14:48:46 +00:00
|
|
|
|
// Run POI detection asynchronously without blocking the wizard flow
|
2026-01-12 22:15:11 +01:00
|
|
|
|
// This ensures POI data is ready before the training step
|
2025-11-12 14:48:46 +00:00
|
|
|
|
poiContextApi.detectPOIs(
|
|
|
|
|
|
tenant.id,
|
|
|
|
|
|
bakeryLocation.latitude,
|
|
|
|
|
|
bakeryLocation.longitude,
|
2026-01-12 22:15:11 +01:00
|
|
|
|
false // force_refresh = false, will use cache if available
|
2025-11-12 14:48:46 +00:00
|
|
|
|
).then((result) => {
|
2026-01-12 22:15:11 +01:00
|
|
|
|
const source = result.source || 'unknown';
|
|
|
|
|
|
console.log(`✅ POI detection completed for tenant ${tenant.id} (source: ${source})`);
|
|
|
|
|
|
|
|
|
|
|
|
if (result.poi_context) {
|
|
|
|
|
|
const totalPois = result.poi_context.total_pois_detected || 0;
|
|
|
|
|
|
const relevantCategories = result.poi_context.relevant_categories?.length || 0;
|
|
|
|
|
|
console.log(`📍 POI Summary: ${totalPois} POIs detected, ${relevantCategories} relevant categories`);
|
|
|
|
|
|
}
|
2025-11-14 07:23:56 +01:00
|
|
|
|
|
|
|
|
|
|
// Phase 3: Handle calendar suggestion if available
|
|
|
|
|
|
if (result.calendar_suggestion) {
|
|
|
|
|
|
const suggestion = result.calendar_suggestion;
|
|
|
|
|
|
console.log(`📊 Calendar suggestion available:`, {
|
|
|
|
|
|
calendar: suggestion.calendar_name,
|
|
|
|
|
|
confidence: `${suggestion.confidence_percentage}%`,
|
|
|
|
|
|
should_auto_assign: suggestion.should_auto_assign
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// Store suggestion in wizard context for later use
|
|
|
|
|
|
// Frontend can show this in settings or a notification later
|
|
|
|
|
|
if (suggestion.confidence_percentage >= 75) {
|
|
|
|
|
|
console.log(`✅ High confidence suggestion: ${suggestion.calendar_name} (${suggestion.confidence_percentage}%)`);
|
|
|
|
|
|
// TODO: Show notification to admin about high-confidence suggestion
|
|
|
|
|
|
} else {
|
|
|
|
|
|
console.log(`📋 Lower confidence suggestion: ${suggestion.calendar_name} (${suggestion.confidence_percentage}%)`);
|
|
|
|
|
|
// TODO: Store for later review in settings
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-11-12 14:48:46 +00:00
|
|
|
|
}).catch((error) => {
|
2026-01-12 22:15:11 +01:00
|
|
|
|
console.warn('⚠️ Background POI detection failed (non-blocking):', error);
|
|
|
|
|
|
console.warn('Training will continue without POI features if detection is not complete.');
|
|
|
|
|
|
// This is non-critical - training service will continue without POI features
|
2025-11-12 14:48:46 +00:00
|
|
|
|
});
|
2026-01-12 22:15:11 +01:00
|
|
|
|
} else {
|
|
|
|
|
|
console.warn('⚠️ Cannot trigger POI detection: missing location data or tenant ID');
|
2025-11-12 14:48:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Update the wizard context with tenant info
|
2025-11-12 15:34:10 +01:00
|
|
|
|
onComplete({
|
|
|
|
|
|
tenant,
|
|
|
|
|
|
tenantId: tenant.id,
|
|
|
|
|
|
bakeryLocation: wizardContext.state.bakeryLocation
|
|
|
|
|
|
});
|
2025-09-08 17:19:00 +02:00
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error('Error registering bakery:', error);
|
2025-12-25 18:59:56 +01:00
|
|
|
|
setErrors({ submit: t('onboarding:steps.tenant_registration.errors.register') });
|
2025-09-08 17:19:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
2025-12-19 13:10:24 +01:00
|
|
|
|
<div className="space-y-6 md:space-y-8">
|
|
|
|
|
|
{/* Informational header */}
|
|
|
|
|
|
<div className="bg-gradient-to-r from-[var(--color-primary)]/10 to-[var(--color-primary)]/5 border-l-4 border-[var(--color-primary)] rounded-lg p-4 md:p-5">
|
|
|
|
|
|
<div className="flex items-start gap-3">
|
|
|
|
|
|
<div className="text-2xl flex-shrink-0">{isEnterprise ? '🏭' : '🏪'}</div>
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<h3 className="font-semibold text-[var(--text-primary)] mb-1">
|
2025-12-25 18:59:56 +01:00
|
|
|
|
{t(isEnterprise
|
|
|
|
|
|
? 'onboarding:steps.tenant_registration.header.title_enterprise'
|
|
|
|
|
|
: 'onboarding:steps.tenant_registration.header.title'
|
|
|
|
|
|
)}
|
2025-12-19 13:10:24 +01:00
|
|
|
|
</h3>
|
|
|
|
|
|
<p className="text-sm text-[var(--text-secondary)]">
|
2025-12-25 18:59:56 +01:00
|
|
|
|
{t(isEnterprise
|
|
|
|
|
|
? 'onboarding:steps.tenant_registration.header.description_enterprise'
|
|
|
|
|
|
: 'onboarding:steps.tenant_registration.header.description'
|
|
|
|
|
|
)}
|
2025-12-19 13:10:24 +01:00
|
|
|
|
</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-5 md:gap-6">
|
|
|
|
|
|
<div className="transform transition-all duration-200 hover:scale-[1.01]">
|
|
|
|
|
|
<Input
|
2025-12-25 18:59:56 +01:00
|
|
|
|
label={t(isEnterprise
|
|
|
|
|
|
? 'onboarding:steps.tenant_registration.fields.business_name_enterprise'
|
|
|
|
|
|
: 'onboarding:steps.tenant_registration.fields.business_name'
|
|
|
|
|
|
)}
|
|
|
|
|
|
placeholder={t(isEnterprise
|
|
|
|
|
|
? 'onboarding:steps.tenant_registration.placeholders.business_name_enterprise'
|
|
|
|
|
|
: 'onboarding:steps.tenant_registration.placeholders.business_name'
|
|
|
|
|
|
)}
|
2025-12-19 13:10:24 +01:00
|
|
|
|
value={formData.name}
|
|
|
|
|
|
onChange={(e) => handleInputChange('name', e.target.value)}
|
|
|
|
|
|
error={errors.name}
|
|
|
|
|
|
isRequired
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div className="transform transition-all duration-200 hover:scale-[1.01]">
|
|
|
|
|
|
<Input
|
2025-12-25 18:59:56 +01:00
|
|
|
|
label={t('onboarding:steps.tenant_registration.fields.phone')}
|
2025-12-19 13:10:24 +01:00
|
|
|
|
type="tel"
|
2025-12-25 18:59:56 +01:00
|
|
|
|
placeholder={t('onboarding:steps.tenant_registration.placeholders.phone')}
|
2025-12-19 13:10:24 +01:00
|
|
|
|
value={formData.phone}
|
|
|
|
|
|
onChange={(e) => handleInputChange('phone', e.target.value)}
|
|
|
|
|
|
error={errors.phone}
|
|
|
|
|
|
isRequired
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div className="md:col-span-2 transform transition-all duration-200 hover:scale-[1.01] relative z-20">
|
|
|
|
|
|
<label className="block text-sm font-semibold text-[var(--text-primary)] mb-2 flex items-center gap-2">
|
|
|
|
|
|
<span className="text-lg">📍</span>
|
2025-12-25 18:59:56 +01:00
|
|
|
|
{t('onboarding:steps.tenant_registration.fields.address')} <span className="text-red-500">*</span>
|
2025-11-12 15:34:10 +01:00
|
|
|
|
</label>
|
|
|
|
|
|
<AddressAutocomplete
|
2025-09-08 17:19:00 +02:00
|
|
|
|
value={formData.address}
|
2025-12-25 18:59:56 +01:00
|
|
|
|
placeholder={t(isEnterprise
|
|
|
|
|
|
? 'onboarding:steps.tenant_registration.placeholders.address_enterprise'
|
|
|
|
|
|
: 'onboarding:steps.tenant_registration.placeholders.address'
|
|
|
|
|
|
)}
|
2025-11-12 15:34:10 +01:00
|
|
|
|
onAddressSelect={(address) => {
|
|
|
|
|
|
console.log('Selected:', address.display_name);
|
|
|
|
|
|
handleAddressSelect(address);
|
2025-10-15 16:12:49 +02:00
|
|
|
|
}}
|
2025-11-12 15:34:10 +01:00
|
|
|
|
onCoordinatesChange={handleCoordinatesChange}
|
|
|
|
|
|
countryCode="es"
|
|
|
|
|
|
required
|
2025-09-08 17:19:00 +02:00
|
|
|
|
/>
|
2025-11-12 15:34:10 +01:00
|
|
|
|
{errors.address && (
|
2025-12-19 13:10:24 +01:00
|
|
|
|
<div className="mt-2 text-sm text-red-600 flex items-center gap-1.5 animate-shake">
|
|
|
|
|
|
<span>⚠️</span>
|
2025-11-12 15:34:10 +01:00
|
|
|
|
{errors.address}
|
2025-10-15 16:12:49 +02:00
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
2025-09-08 17:19:00 +02:00
|
|
|
|
</div>
|
|
|
|
|
|
|
2025-12-19 13:10:24 +01:00
|
|
|
|
<div className="transform transition-all duration-200 hover:scale-[1.01]">
|
|
|
|
|
|
<Input
|
2025-12-25 18:59:56 +01:00
|
|
|
|
label={t('onboarding:steps.tenant_registration.fields.postal_code')}
|
|
|
|
|
|
placeholder={t('onboarding:steps.tenant_registration.placeholders.postal_code')}
|
2025-12-19 13:10:24 +01:00
|
|
|
|
value={formData.postal_code}
|
|
|
|
|
|
onChange={(e) => handleInputChange('postal_code', e.target.value)}
|
|
|
|
|
|
error={errors.postal_code}
|
|
|
|
|
|
isRequired
|
|
|
|
|
|
maxLength={5}
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div className="transform transition-all duration-200 hover:scale-[1.01]">
|
|
|
|
|
|
<Input
|
2025-12-25 18:59:56 +01:00
|
|
|
|
label={t('onboarding:steps.tenant_registration.fields.city')}
|
|
|
|
|
|
placeholder={t('onboarding:steps.tenant_registration.placeholders.city')}
|
2025-12-19 13:10:24 +01:00
|
|
|
|
value={formData.city}
|
|
|
|
|
|
onChange={(e) => handleInputChange('city', e.target.value)}
|
|
|
|
|
|
error={errors.city}
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
2025-09-08 17:19:00 +02:00
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
{errors.submit && (
|
2025-12-19 13:10:24 +01:00
|
|
|
|
<div className="bg-gradient-to-r from-[var(--color-error)]/10 to-[var(--color-error)]/5 border-l-4 border-[var(--color-error)] rounded-lg p-4 animate-shake">
|
|
|
|
|
|
<div className="flex items-start gap-3">
|
|
|
|
|
|
<span className="text-2xl flex-shrink-0">⚠️</span>
|
|
|
|
|
|
<div>
|
2025-12-25 18:59:56 +01:00
|
|
|
|
<h4 className="font-semibold text-[var(--color-error)] mb-1">
|
|
|
|
|
|
{t('onboarding:steps.tenant_registration.errors.register_title')}
|
|
|
|
|
|
</h4>
|
2025-12-19 13:10:24 +01:00
|
|
|
|
<p className="text-sm text-[var(--text-secondary)]">{errors.submit}</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
2025-09-08 17:19:00 +02:00
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
|
2025-12-19 13:10:24 +01:00
|
|
|
|
<div className="flex justify-end pt-4 border-t-2 border-[var(--border-color)]/50">
|
2025-09-08 17:19:00 +02:00
|
|
|
|
<Button
|
|
|
|
|
|
onClick={handleSubmit}
|
2025-12-19 13:10:24 +01:00
|
|
|
|
isLoading={registerBakery.isPending || updateTenant.isPending}
|
2025-12-25 18:59:56 +01:00
|
|
|
|
loadingText={t(tenantId
|
|
|
|
|
|
? 'onboarding:steps.tenant_registration.loading.updating'
|
|
|
|
|
|
: (isEnterprise
|
|
|
|
|
|
? 'onboarding:steps.tenant_registration.loading.creating_enterprise'
|
|
|
|
|
|
: 'onboarding:steps.tenant_registration.loading.creating'
|
|
|
|
|
|
)
|
|
|
|
|
|
)}
|
2025-09-08 17:19:00 +02:00
|
|
|
|
size="lg"
|
2025-12-19 13:10:24 +01:00
|
|
|
|
className="w-full sm:w-auto sm:min-w-[280px] text-base font-semibold transform transition-all duration-300 hover:scale-105 shadow-lg"
|
2025-09-08 17:19:00 +02:00
|
|
|
|
>
|
2025-12-25 18:59:56 +01:00
|
|
|
|
{t(tenantId
|
|
|
|
|
|
? (isEnterprise
|
|
|
|
|
|
? 'onboarding:steps.tenant_registration.buttons.update_enterprise'
|
|
|
|
|
|
: 'onboarding:steps.tenant_registration.buttons.update'
|
|
|
|
|
|
)
|
|
|
|
|
|
: (isEnterprise
|
|
|
|
|
|
? 'onboarding:steps.tenant_registration.buttons.create_enterprise'
|
|
|
|
|
|
: 'onboarding:steps.tenant_registration.buttons.create'
|
|
|
|
|
|
)
|
|
|
|
|
|
)}
|
2025-09-08 17:19:00 +02:00
|
|
|
|
</Button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
);
|
|
|
|
|
|
};
|