diff --git a/app/services/page.tsx b/app/services/page.tsx index b3b3fc4..e857f10 100644 --- a/app/services/page.tsx +++ b/app/services/page.tsx @@ -122,6 +122,11 @@ export default function ServiceBookingPage() { const [selectedCategory, setSelectedCategory] = useState(null); const [selectedVariant, setSelectedVariant] = useState(null); + // Store Location State + const [locationsList, setLocationsList] = useState([]); + const [selectedLocation, setSelectedLocation] = useState(null); + const [loadingLocations, setLoadingLocations] = useState(false); + // Scheduling State const [targetDate, setTargetDate] = useState(new Date().toISOString().split('T')[0]); const [availableSlots, setAvailableSlots] = useState([]); @@ -228,6 +233,25 @@ export default function ServiceBookingPage() { void loadDeviceTypes(); }, []); + // Fetch Store Locations + useEffect(() => { + const loadLocations = async () => { + setLoadingLocations(true); + try { + const locs = await serviceBookingService.fetchLocations(); + setLocationsList(locs); + if (locs.length > 0) { + setSelectedLocation(locs[0]); + } + } catch { + /* fallback */ + } finally { + setLoadingLocations(false); + } + }; + void loadLocations(); + }, []); + // Load Brands when Device Type changes useEffect(() => { if (!deviceType) return; @@ -455,6 +479,8 @@ export default function ServiceBookingPage() { customer_name: custName.trim() || undefined, customer_email: custEmail.trim() || undefined, device_type: deviceType, + location_id: selectedLocation?.location_id, + location_name: selectedLocation?.name || selectedLocation?.code, brand_id: liveCatalogId(selectedBrand?.brand_id), series_id: liveCatalogId(selectedSeries?.series_id), model_id: liveCatalogId(selectedModel.model_id), @@ -811,6 +837,26 @@ export default function ServiceBookingPage() {
+ ({ + value: loc.location_id, + label: loc.name || loc.code || 'Store Location', + hint: loc.code ? `[${loc.code}]` : undefined, + }))} + onChange={(value) => { + const loc = locationsList.find((l) => l.location_id === value); + if (loc) setSelectedLocation(loc); + }} + /> + - @@ -987,6 +1033,7 @@ export default function ServiceBookingPage() {

Booking summary

{[ + ['Store Location', selectedLocation?.name || selectedLocation?.code], ['Device', formatDeviceTypeLabel(deviceType)], ['Brand', selectedBrand?.name], ['Series', selectedSeries?.name], diff --git a/services/api/serviceBooking.ts b/services/api/serviceBooking.ts index a2509b5..0482e4f 100644 --- a/services/api/serviceBooking.ts +++ b/services/api/serviceBooking.ts @@ -74,6 +74,8 @@ export interface ServiceBookingPayload { scheduled_end: string; } | null; device_type?: string; + location_id?: string; + location_name?: string; brand_id?: string; series_id?: string; model_id?: string; @@ -214,6 +216,20 @@ function buildRepairConfigFromCatalog( } export const serviceBookingService = { + async fetchLocations(): Promise { + try { + const locations = await apiFetch('/api/v1/system-config/locations'); + if (Array.isArray(locations) && locations.length > 0) { + return locations; + } + } catch { + /* fallback */ + } + return [ + { location_id: 'loc_chennai_hq', name: 'Chennai Store HQ', code: 'CHENNAI', address: 'Chennai Central' }, + ]; + }, + fetchDeviceTypes(): Promise { return apiFetch('/api/v1/catalog/device-types'); },