fix: move address fields from settings to top-level facility object
continuous-integration/drone/push Build is passing Details

The API now returns address at facility.address instead of facility.settings.address, and uses field names like address_line_1 and zip instead of line_1 and postal_code. Updated the ClubProfile type and form to match.
master
Guillermo Pages 1 month ago
parent 94a1979201
commit ff50bdfa2c

@ -106,14 +106,14 @@ export default function ClubProfileTab({ clubId, onUpdate }: ClubProfileTabProps
const prof = result.data;
setProfile(prof);
// Populate form - read from settings structure
// Populate form - read from top-level address and settings.contact
setName(prof.name);
setTimezone(prof.timezone);
setAddressLine1(prof.settings?.address?.line_1 || '');
setAddressLine2(prof.settings?.address?.line_2 || '');
setCity(prof.settings?.address?.city || '');
setPostalCode(prof.settings?.address?.postal_code || '');
setCountry(prof.settings?.address?.country || '');
setAddressLine1(prof.address?.address_line_1 || '');
setAddressLine2(prof.address?.address_line_2 || '');
setCity(prof.address?.city || '');
setPostalCode(prof.address?.zip || '');
setCountry(prof.address?.country || '');
setPhone(prof.settings?.contact?.phone || '');
setEmail(prof.settings?.contact?.email || '');
setWebsite(prof.settings?.contact?.website || '');
@ -160,31 +160,28 @@ export default function ClubProfileTab({ clubId, onUpdate }: ClubProfileTabProps
setError(null);
setSuccess(false);
// Build settings structure, preserving existing settings
const updatedSettings = {
...profile?.settings,
// Build request with top-level address and settings.contact
const request: ClubProfileUpdateRequest = {
name: name.trim(),
timezone,
address: {
...profile?.settings?.address,
line_1: addressLine1.trim() || undefined,
line_2: addressLine2.trim() || undefined,
address_line_1: addressLine1.trim() || undefined,
address_line_2: addressLine2.trim() || undefined,
city: city.trim() || undefined,
postal_code: postalCode.trim() || undefined,
zip: postalCode.trim() || undefined,
country: country.trim() || undefined,
},
contact: {
...profile?.settings?.contact,
phone: phone.trim() || undefined,
email: email.trim() || undefined,
website: website.trim() || undefined,
settings: {
...profile?.settings,
contact: {
...profile?.settings?.contact,
phone: phone.trim() || undefined,
email: email.trim() || undefined,
website: website.trim() || undefined,
},
},
};
const request: ClubProfileUpdateRequest = {
name: name.trim(),
timezone,
settings: updatedSettings,
};
const result = await updateClubProfile(clubId, request);
if (result.success) {
@ -218,14 +215,14 @@ export default function ClubProfileTab({ clubId, onUpdate }: ClubProfileTabProps
function handleCancel() {
if (!profile) return;
// Reset form to original values - read from settings structure
// Reset form to original values - read from top-level address and settings.contact
setName(profile.name);
setTimezone(profile.timezone);
setAddressLine1(profile.settings?.address?.line_1 || '');
setAddressLine2(profile.settings?.address?.line_2 || '');
setCity(profile.settings?.address?.city || '');
setPostalCode(profile.settings?.address?.postal_code || '');
setCountry(profile.settings?.address?.country || '');
setAddressLine1(profile.address?.address_line_1 || '');
setAddressLine2(profile.address?.address_line_2 || '');
setCity(profile.address?.city || '');
setPostalCode(profile.address?.zip || '');
setCountry(profile.address?.country || '');
setPhone(profile.settings?.contact?.phone || '');
setEmail(profile.settings?.contact?.email || '');
setWebsite(profile.settings?.contact?.website || '');

@ -341,14 +341,15 @@ export function getMockClubProfile(clubId: number): ClubProfile {
facility_id: clubId,
name: 'Central Padel',
timezone: 'Europe/London',
address: {
address_line_1: '123 High Street',
address_line_2: 'Building A',
city: 'London',
zip: 'SW1A 1AA',
canton: null,
country: 'United Kingdom',
},
settings: {
address: {
line_1: '123 High Street',
line_2: 'Building A',
city: 'London',
postal_code: 'SW1A 1AA',
country: 'United Kingdom',
},
contact: {
phone: '+44 20 1234 5678',
email: 'info@centralpadel.com',

@ -56,13 +56,6 @@ export interface CourtDependencies {
}
export interface ClubProfileSettings {
address?: {
line_1?: string;
line_2?: string;
city?: string;
postal_code?: string;
country?: string;
};
contact?: {
phone?: string;
email?: string;
@ -76,6 +69,14 @@ export interface ClubProfile {
facility_id: number;
name: string;
timezone: string; // IANA timezone
address?: {
address_line_1?: string | null;
address_line_2?: string | null;
city?: string | null;
zip?: string | null;
canton?: string | null;
country?: string | null;
};
settings?: ClubProfileSettings;
created_at: string; // ISO 8601 timestamp
updated_at: string; // ISO 8601 timestamp
@ -84,6 +85,14 @@ export interface ClubProfile {
export interface ClubProfileUpdateRequest {
name?: string;
timezone?: string;
address?: {
address_line_1?: string;
address_line_2?: string;
city?: string;
zip?: string;
canton?: string;
country?: string;
};
settings?: ClubProfileSettings;
}

Loading…
Cancel
Save