Add service listing and customer booking flow in app
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
import { api } from './client';
|
||||
import type { Booking, BookingStatus } from './types';
|
||||
|
||||
export type CreateBookingPayload = {
|
||||
customerId: string;
|
||||
businessId: string;
|
||||
businessServiceId: string;
|
||||
scheduledAt: string;
|
||||
note?: string | null;
|
||||
};
|
||||
|
||||
export function fetchBookings(params?: {
|
||||
businessId?: string;
|
||||
status?: BookingStatus;
|
||||
}) {
|
||||
const search = new URLSearchParams();
|
||||
if (params?.businessId) search.set('businessId', params.businessId);
|
||||
if (params?.status) search.set('status', params.status);
|
||||
const query = search.toString();
|
||||
return api<Booking[]>(`/bookings${query ? `?${query}` : ''}`);
|
||||
}
|
||||
|
||||
export function createBooking(payload: CreateBookingPayload) {
|
||||
return api<Booking>('/bookings', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
}
|
||||
|
||||
export function cancelBooking(id: string) {
|
||||
return api<Booking>(`/bookings/${id}/cancel`, { method: 'POST' });
|
||||
}
|
||||
|
||||
export function confirmBooking(id: string) {
|
||||
return api<Booking>(`/bookings/${id}/confirm`, { method: 'POST' });
|
||||
}
|
||||
@@ -82,3 +82,28 @@ export type BusinessService = {
|
||||
isActive: boolean;
|
||||
serviceTemplate?: ServiceTemplate;
|
||||
};
|
||||
|
||||
export type BookingStatus =
|
||||
| 'pending'
|
||||
| 'confirmed'
|
||||
| 'cancelled'
|
||||
| 'completed';
|
||||
|
||||
export type Booking = {
|
||||
id: string;
|
||||
customerId: string;
|
||||
businessId: string;
|
||||
businessServiceId: string;
|
||||
scheduledAt: string;
|
||||
status: BookingStatus;
|
||||
note: string | null;
|
||||
createdAt?: string;
|
||||
updatedAt?: string;
|
||||
customer?: {
|
||||
id: string;
|
||||
mobile: string;
|
||||
fullName: string | null;
|
||||
};
|
||||
business?: Business;
|
||||
businessService?: BusinessService;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user