diff --git a/services/api/serviceBooking.ts b/services/api/serviceBooking.ts index bb10261..95c3f5f 100644 --- a/services/api/serviceBooking.ts +++ b/services/api/serviceBooking.ts @@ -126,12 +126,12 @@ async function loadAdminCatalog(force = false): Promise { repairServices, repairVariants, ] = await Promise.all([ - apiFetch('/api/v1/catalog/brands/all'), - apiFetch('/api/v1/catalog/device-series/all'), - apiFetch('/api/v1/catalog/device-models/all'), - apiFetch('/api/v1/catalog/service-types/all'), - apiFetch('/api/v1/catalog/repair-services/all'), - apiFetch('/api/v1/catalog/repair-variants/all'), + apiFetch('/api/v1/catalog/brands/all', { skipAuth: true }), + apiFetch('/api/v1/catalog/device-series/all', { skipAuth: true }), + apiFetch('/api/v1/catalog/device-models/all', { skipAuth: true }), + apiFetch('/api/v1/catalog/service-types/all', { skipAuth: true }), + apiFetch('/api/v1/catalog/repair-services/all', { skipAuth: true }), + apiFetch('/api/v1/catalog/repair-variants/all', { skipAuth: true }), ]); catalogCache = { @@ -219,12 +219,19 @@ function buildRepairConfigFromCatalog( export const serviceBookingService = { async fetchLocations(): Promise { try { - const locations = await apiFetch('/api/v1/system-config/locations'); + const locations = await apiFetch('/api/v1/system/locations', { skipAuth: true }); if (Array.isArray(locations) && locations.length > 0) { - return locations; + return locations.filter((l) => l.is_active !== false); } } catch { - /* fallback */ + try { + const locations = await apiFetch('/api/v1/system-config/locations', { skipAuth: true }); + if (Array.isArray(locations) && locations.length > 0) { + return locations.filter((l) => l.is_active !== false); + } + } catch { + /* fallback */ + } } return [ { location_id: 'loc_chennai_hq', name: 'Chennai Store HQ', code: 'CHENNAI', address: 'Chennai Central' }, @@ -232,16 +239,20 @@ export const serviceBookingService = { }, fetchDeviceTypes(): Promise { - return apiFetch('/api/v1/catalog/device-types'); + return apiFetch('/api/v1/catalog/device-types', { skipAuth: true }); }, async fetchBrands(deviceType?: string): Promise { try { - const cache = await loadAdminCatalog(); - const filtered = cache.brands - .filter(isActive) - .filter((b) => brandMatchesDeviceType(b, deviceType)); - if (filtered.length > 0) return filtered; + const brands = await apiFetch('/api/v1/catalog/brands/all', { skipAuth: true }); + if (Array.isArray(brands) && brands.length > 0) { + // Kick off background cache of the rest of the catalog for smooth series/model selection + void loadAdminCatalog().catch(() => {}); + const filtered = brands + .filter(isActive) + .filter((b) => brandMatchesDeviceType(b, deviceType)); + if (filtered.length > 0) return filtered; + } } catch { /* demo fallback */ }