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,
repairVariants,
] = await Promise.all([
apiFetch<any[]>('/api/v1/catalog/brands/all'),
apiFetch<any[]>('/api/v1/catalog/device-series/all'),
apiFetch<any[]>('/api/v1/catalog/device-models/all'),
apiFetch<any[]>('/api/v1/catalog/service-types/all'),
apiFetch<any[]>('/api/v1/catalog/repair-services/all'),
apiFetch<any[]>('/api/v1/catalog/repair-variants/all'),
apiFetch<any[]>('/api/v1/catalog/brands/all', { skipAuth: true }),
apiFetch<any[]>('/api/v1/catalog/device-series/all', { skipAuth: true }),
apiFetch<any[]>('/api/v1/catalog/device-models/all', { skipAuth: true }),
apiFetch<any[]>('/api/v1/catalog/service-types/all', { skipAuth: true }),
apiFetch<any[]>('/api/v1/catalog/repair-services/all', { skipAuth: true }),
apiFetch<any[]>('/api/v1/catalog/repair-variants/all', { skipAuth: true }),
]);
catalogCache = {
@ -219,29 +219,40 @@ function buildRepairConfigFromCatalog(
export const serviceBookingService = {
async fetchLocations(): Promise<any[]> {
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) {
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 {
/* fallback */
}
}
return [
{ location_id: 'loc_chennai_hq', name: 'Chennai Store HQ', code: 'CHENNAI', address: 'Chennai Central' },
];
},
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[]> {
try {
const cache = await loadAdminCatalog();
const filtered = cache.brands
const brands = await apiFetch<any[]>('/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 */
}