fix(services): load live store locations and optimize instant brand loading

This commit is contained in:
iFixKart Dev 2026-11-16 19:14:40 +05:30
parent 5424420acc
commit 1a3604504a

View file

@ -126,12 +126,12 @@ async function loadAdminCatalog(force = false): Promise<CatalogCache> {
repairServices, repairServices,
repairVariants, repairVariants,
] = await Promise.all([ ] = await Promise.all([
apiFetch<any[]>('/api/v1/catalog/brands/all'), apiFetch<any[]>('/api/v1/catalog/brands/all', { skipAuth: true }),
apiFetch<any[]>('/api/v1/catalog/device-series/all'), apiFetch<any[]>('/api/v1/catalog/device-series/all', { skipAuth: true }),
apiFetch<any[]>('/api/v1/catalog/device-models/all'), apiFetch<any[]>('/api/v1/catalog/device-models/all', { skipAuth: true }),
apiFetch<any[]>('/api/v1/catalog/service-types/all'), apiFetch<any[]>('/api/v1/catalog/service-types/all', { skipAuth: true }),
apiFetch<any[]>('/api/v1/catalog/repair-services/all'), apiFetch<any[]>('/api/v1/catalog/repair-services/all', { skipAuth: true }),
apiFetch<any[]>('/api/v1/catalog/repair-variants/all'), apiFetch<any[]>('/api/v1/catalog/repair-variants/all', { skipAuth: true }),
]); ]);
catalogCache = { catalogCache = {
@ -219,29 +219,40 @@ function buildRepairConfigFromCatalog(
export const serviceBookingService = { export const serviceBookingService = {
async fetchLocations(): Promise<any[]> { async fetchLocations(): Promise<any[]> {
try { try {
const locations = await apiFetch<any[]>('/api/v1/system-config/locations'); const locations = await apiFetch<any[]>('/api/v1/system/locations', { skipAuth: true });
if (Array.isArray(locations) && locations.length > 0) { if (Array.isArray(locations) && locations.length > 0) {
return locations; return locations.filter((l) => l.is_active !== false);
}
} catch {
try {
const locations = await apiFetch<any[]>('/api/v1/system-config/locations', { skipAuth: true });
if (Array.isArray(locations) && locations.length > 0) {
return locations.filter((l) => l.is_active !== false);
} }
} catch { } catch {
/* fallback */ /* fallback */
} }
}
return [ return [
{ location_id: 'loc_chennai_hq', name: 'Chennai Store HQ', code: 'CHENNAI', address: 'Chennai Central' }, { location_id: 'loc_chennai_hq', name: 'Chennai Store HQ', code: 'CHENNAI', address: 'Chennai Central' },
]; ];
}, },
fetchDeviceTypes(): Promise<string[]> { fetchDeviceTypes(): Promise<string[]> {
return apiFetch<string[]>('/api/v1/catalog/device-types'); return apiFetch<string[]>('/api/v1/catalog/device-types', { skipAuth: true });
}, },
async fetchBrands(deviceType?: string): Promise<any[]> { async fetchBrands(deviceType?: string): Promise<any[]> {
try { try {
const cache = await loadAdminCatalog(); const brands = await apiFetch<any[]>('/api/v1/catalog/brands/all', { skipAuth: true });
const filtered = cache.brands 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(isActive)
.filter((b) => brandMatchesDeviceType(b, deviceType)); .filter((b) => brandMatchesDeviceType(b, deviceType));
if (filtered.length > 0) return filtered; if (filtered.length > 0) return filtered;
}
} catch { } catch {
/* demo fallback */ /* demo fallback */
} }