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,26 +8,14 @@ import { Header } from "../../components/Header";
|
|||
import { useRequireAuth } from "../../hooks/useRequireAuth";
|
||||
import { components } from "../../generated/api";
|
||||
import constants from "../../../../shared/constants.json";
|
||||
import { formatDate, formatDisplayDate } from "../../utils/date";
|
||||
import { formatDate, formatDisplayDate, getDateRange } from "../../utils/date";
|
||||
|
||||
const { slotDurationMinutes, maxAdvanceDays } = constants.booking;
|
||||
const { slotDurationMinutes, maxAdvanceDays, minAdvanceDays } = constants.booking;
|
||||
|
||||
type AvailabilityDay = components["schemas"]["AvailabilityDay"];
|
||||
type AvailabilityResponse = components["schemas"]["AvailabilityResponse"];
|
||||
type TimeSlot = components["schemas"]["TimeSlot"];
|
||||
|
||||
// Helper to get next N days starting from tomorrow
|
||||
function getDateRange(): Date[] {
|
||||
const dates: Date[] = [];
|
||||
const today = new Date();
|
||||
for (let i = 1; i <= maxAdvanceDays; i++) {
|
||||
const d = new Date(today);
|
||||
d.setDate(today.getDate() + i);
|
||||
dates.push(d);
|
||||
}
|
||||
return dates;
|
||||
}
|
||||
|
||||
// Generate time options for dropdowns (15-min intervals)
|
||||
// Moved outside component since slotDurationMinutes is a constant
|
||||
function generateTimeOptions(slotDurationMinutes: number): string[] {
|
||||
|
|
@ -64,10 +52,10 @@ export default function AdminAvailabilityPage() {
|
|||
const [copyTargets, setCopyTargets] = useState<Set<string>>(new Set());
|
||||
const [isCopying, setIsCopying] = useState(false);
|
||||
|
||||
const dates = getDateRange();
|
||||
const dates = getDateRange(minAdvanceDays, maxAdvanceDays);
|
||||
|
||||
const fetchAvailability = useCallback(async () => {
|
||||
const dateRange = getDateRange();
|
||||
const dateRange = getDateRange(minAdvanceDays, maxAdvanceDays);
|
||||
if (!dateRange.length) return;
|
||||
|
||||
try {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue