feat: Implement resource booking functionality
- Add service timeline builder for appointments to manage available slots. - Create a hook to fetch resource booking services with effective durations. - Develop ResourceBookingSlotController to handle API requests for resource booking slots. - Implement ResourceBookingSlotService to calculate available time slots based on resource occupancy and service durations. - Add tests for resource appointment creation and booking slot functionality to ensure correct behavior and edge cases.
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
import { useMemo } from 'react';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { api } from '../lib/api';
|
||||
import type { ApiResponse } from '../lib/api';
|
||||
import type { BookingService } from './useDoctorBookingServices';
|
||||
import type { ResourceServiceOffering } from '../types';
|
||||
|
||||
/**
|
||||
* سرویسهای قابلِ رزروِ یک منبع، به همان شکلِ سرویسهای پزشک.
|
||||
*
|
||||
* نگاشت عمدی است: فرمِ انتخاب سرویس (`ServiceSlotPicker`) یک قرارداد دارد — بخش،
|
||||
* نام، مدت — و ساختنِ نسخهٔ دومش برای منبع یعنی دو فرم که با هم درمیروند.
|
||||
*
|
||||
* مدتِ مؤثر مبناست نه `duration_minutes` خام: خالیبودنِ ستون یعنی «ارث از سطح
|
||||
* بالاتر»، و نمایشش بهصورت صفر همان دستگاه را بیمدت نشان میداد.
|
||||
*/
|
||||
export function useResourceBookingServices(resourceUuid: string | null | undefined) {
|
||||
const q = useQuery<ApiResponse<ResourceServiceOffering[]>>({
|
||||
queryKey: ['resource-services', resourceUuid],
|
||||
queryFn: () => api.get(`/api/v1/resource/${resourceUuid}/services`),
|
||||
enabled: !!resourceUuid,
|
||||
});
|
||||
|
||||
const services: BookingService[] = useMemo(
|
||||
() => (q.data?.data ?? [])
|
||||
.filter(o => o.active && o.service_section)
|
||||
.map(o => ({
|
||||
uuid: o.service_uuid,
|
||||
name: o.service_name,
|
||||
duration_minutes: o.effective_duration_minutes,
|
||||
price_rials: o.effective_price_rials,
|
||||
service_section: o.service_section!,
|
||||
})),
|
||||
[q.data],
|
||||
);
|
||||
|
||||
return { services, isLoading: q.isLoading };
|
||||
}
|
||||
Reference in New Issue
Block a user