feat: update service booking API and services page
This commit is contained in:
parent
66804c60a2
commit
3667f7a6a2
2 changed files with 64 additions and 1 deletions
|
|
@ -122,6 +122,11 @@ export default function ServiceBookingPage() {
|
||||||
const [selectedCategory, setSelectedCategory] = useState<any | null>(null);
|
const [selectedCategory, setSelectedCategory] = useState<any | null>(null);
|
||||||
const [selectedVariant, setSelectedVariant] = useState<any | null>(null);
|
const [selectedVariant, setSelectedVariant] = useState<any | null>(null);
|
||||||
|
|
||||||
|
// Store Location State
|
||||||
|
const [locationsList, setLocationsList] = useState<any[]>([]);
|
||||||
|
const [selectedLocation, setSelectedLocation] = useState<any | null>(null);
|
||||||
|
const [loadingLocations, setLoadingLocations] = useState(false);
|
||||||
|
|
||||||
// Scheduling State
|
// Scheduling State
|
||||||
const [targetDate, setTargetDate] = useState<string>(new Date().toISOString().split('T')[0]);
|
const [targetDate, setTargetDate] = useState<string>(new Date().toISOString().split('T')[0]);
|
||||||
const [availableSlots, setAvailableSlots] = useState<AvailableSlot[]>([]);
|
const [availableSlots, setAvailableSlots] = useState<AvailableSlot[]>([]);
|
||||||
|
|
@ -228,6 +233,25 @@ export default function ServiceBookingPage() {
|
||||||
void loadDeviceTypes();
|
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
|
// Load Brands when Device Type changes
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!deviceType) return;
|
if (!deviceType) return;
|
||||||
|
|
@ -455,6 +479,8 @@ export default function ServiceBookingPage() {
|
||||||
customer_name: custName.trim() || undefined,
|
customer_name: custName.trim() || undefined,
|
||||||
customer_email: custEmail.trim() || undefined,
|
customer_email: custEmail.trim() || undefined,
|
||||||
device_type: deviceType,
|
device_type: deviceType,
|
||||||
|
location_id: selectedLocation?.location_id,
|
||||||
|
location_name: selectedLocation?.name || selectedLocation?.code,
|
||||||
brand_id: liveCatalogId(selectedBrand?.brand_id),
|
brand_id: liveCatalogId(selectedBrand?.brand_id),
|
||||||
series_id: liveCatalogId(selectedSeries?.series_id),
|
series_id: liveCatalogId(selectedSeries?.series_id),
|
||||||
model_id: liveCatalogId(selectedModel.model_id),
|
model_id: liveCatalogId(selectedModel.model_id),
|
||||||
|
|
@ -811,6 +837,26 @@ export default function ServiceBookingPage() {
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||||
|
<FormSelect
|
||||||
|
label="Store Location"
|
||||||
|
placeholder={
|
||||||
|
loadingLocations ? 'Loading locations...' : 'Select store location'
|
||||||
|
}
|
||||||
|
value={selectedLocation?.location_id || ''}
|
||||||
|
loading={loadingLocations}
|
||||||
|
disabled={loadingLocations || locationsList.length === 0}
|
||||||
|
searchable
|
||||||
|
options={locationsList.map((loc) => ({
|
||||||
|
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);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
<FormSelect
|
<FormSelect
|
||||||
label="Brand"
|
label="Brand"
|
||||||
placeholder={
|
placeholder={
|
||||||
|
|
@ -976,7 +1022,7 @@ export default function ServiceBookingPage() {
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<div className="flex justify-end pt-1">
|
<div className="flex justify-end pt-1">
|
||||||
<button type="submit" disabled={!selectedVariant} className={primaryBtn}>
|
<button type="submit" disabled={!selectedVariant || !selectedLocation} className={primaryBtn}>
|
||||||
<span>Proceed to schedule slot</span>
|
<span>Proceed to schedule slot</span>
|
||||||
<ArrowRight className="w-4 h-4" />
|
<ArrowRight className="w-4 h-4" />
|
||||||
</button>
|
</button>
|
||||||
|
|
@ -987,6 +1033,7 @@ export default function ServiceBookingPage() {
|
||||||
<div className="lg:sticky lg:top-28 bg-gray-50 border border-gray-100 rounded-xl p-4 space-y-3">
|
<div className="lg:sticky lg:top-28 bg-gray-50 border border-gray-100 rounded-xl p-4 space-y-3">
|
||||||
<h3 className="text-[13px] font-bold text-[#1a1a1a]">Booking summary</h3>
|
<h3 className="text-[13px] font-bold text-[#1a1a1a]">Booking summary</h3>
|
||||||
{[
|
{[
|
||||||
|
['Store Location', selectedLocation?.name || selectedLocation?.code],
|
||||||
['Device', formatDeviceTypeLabel(deviceType)],
|
['Device', formatDeviceTypeLabel(deviceType)],
|
||||||
['Brand', selectedBrand?.name],
|
['Brand', selectedBrand?.name],
|
||||||
['Series', selectedSeries?.name],
|
['Series', selectedSeries?.name],
|
||||||
|
|
|
||||||
|
|
@ -74,6 +74,8 @@ export interface ServiceBookingPayload {
|
||||||
scheduled_end: string;
|
scheduled_end: string;
|
||||||
} | null;
|
} | null;
|
||||||
device_type?: string;
|
device_type?: string;
|
||||||
|
location_id?: string;
|
||||||
|
location_name?: string;
|
||||||
brand_id?: string;
|
brand_id?: string;
|
||||||
series_id?: string;
|
series_id?: string;
|
||||||
model_id?: string;
|
model_id?: string;
|
||||||
|
|
@ -214,6 +216,20 @@ function buildRepairConfigFromCatalog(
|
||||||
}
|
}
|
||||||
|
|
||||||
export const serviceBookingService = {
|
export const serviceBookingService = {
|
||||||
|
async fetchLocations(): Promise<any[]> {
|
||||||
|
try {
|
||||||
|
const locations = await apiFetch<any[]>('/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<string[]> {
|
fetchDeviceTypes(): Promise<string[]> {
|
||||||
return apiFetch<string[]>('/api/v1/catalog/device-types');
|
return apiFetch<string[]>('/api/v1/catalog/device-types');
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue