Extract duplicate date range helpers to shared utility
- Created getDateRange() function in utils/date.ts - Replaced getBookableDates() and getDateRange() duplicates - Both booking and availability pages now use shared function - Function accepts minAdvanceDays and maxAdvanceDays as parameters
This commit is contained in:
parent
208278bddb
commit
5c396e62ec
3 changed files with 21 additions and 30 deletions
|
|
@ -8,7 +8,7 @@ import { Header } from "../components/Header";
|
|||
import { useRequireAuth } from "../hooks/useRequireAuth";
|
||||
import { components } from "../generated/api";
|
||||
import constants from "../../../shared/constants.json";
|
||||
import { formatDate, formatTime } from "../utils/date";
|
||||
import { formatDate, formatTime, getDateRange } from "../utils/date";
|
||||
|
||||
const { slotDurationMinutes, maxAdvanceDays, minAdvanceDays, noteMaxLength } = constants.booking;
|
||||
|
||||
|
|
@ -16,18 +16,6 @@ type BookableSlot = components["schemas"]["BookableSlot"];
|
|||
type AvailableSlotsResponse = components["schemas"]["AvailableSlotsResponse"];
|
||||
type AppointmentResponse = components["schemas"]["AppointmentResponse"];
|
||||
|
||||
// Get date range for booking (tomorrow to +30 days)
|
||||
function getBookableDates(): Date[] {
|
||||
const dates: Date[] = [];
|
||||
const today = new Date();
|
||||
for (let i = minAdvanceDays; i <= maxAdvanceDays; i++) {
|
||||
const d = new Date(today);
|
||||
d.setDate(today.getDate() + i);
|
||||
dates.push(d);
|
||||
}
|
||||
return dates;
|
||||
}
|
||||
|
||||
const styles: Record<string, React.CSSProperties> = {
|
||||
main: {
|
||||
minHeight: "100vh",
|
||||
|
|
@ -244,7 +232,7 @@ export default function BookingPage() {
|
|||
const [error, setError] = useState<string | null>(null);
|
||||
const [successMessage, setSuccessMessage] = useState<string | null>(null);
|
||||
|
||||
const dates = getBookableDates();
|
||||
const dates = getDateRange(minAdvanceDays, maxAdvanceDays);
|
||||
|
||||
const fetchSlots = useCallback(async (date: Date) => {
|
||||
setIsLoadingSlots(true);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue