Extract weekend detection logic to shared utility
- Created isWeekend() function in utils/date.ts - Replaced inline weekend detection logic in availability page - More reusable and testable
This commit is contained in:
parent
1497a81cd5
commit
64eeaadd28
2 changed files with 11 additions and 3 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, formatDisplayDate, getDateRange, formatTimeString } from "../../utils/date";
|
||||
import { formatDate, formatDisplayDate, getDateRange, formatTimeString, isWeekend } from "../../utils/date";
|
||||
|
||||
const { slotDurationMinutes, maxAdvanceDays, minAdvanceDays } = constants.booking;
|
||||
|
||||
|
|
@ -260,7 +260,7 @@ export default function AdminAvailabilityPage() {
|
|||
const hasSlots = slots.length > 0;
|
||||
const isSource = copySource === dateStr;
|
||||
const isTarget = copyTargets.has(dateStr);
|
||||
const isWeekend = date.getDay() === 0 || date.getDay() === 6;
|
||||
const isWeekendDate = isWeekend(date);
|
||||
|
||||
return (
|
||||
<div
|
||||
|
|
@ -271,7 +271,7 @@ export default function AdminAvailabilityPage() {
|
|||
...(hasSlots ? styles.dayCardActive : {}),
|
||||
...(isSource ? styles.dayCardSource : {}),
|
||||
...(isTarget ? styles.dayCardTarget : {}),
|
||||
...(isWeekend ? styles.dayCardWeekend : {}),
|
||||
...(isWeekendDate ? styles.dayCardWeekend : {}),
|
||||
}}
|
||||
onClick={() => {
|
||||
if (copySource) {
|
||||
|
|
|
|||
|
|
@ -74,3 +74,11 @@ export function getDateRange(minAdvanceDays: number, maxAdvanceDays: number): Da
|
|||
return dates;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a date is a weekend (Saturday or Sunday).
|
||||
*/
|
||||
export function isWeekend(date: Date): boolean {
|
||||
const day = date.getDay();
|
||||
return day === 0 || day === 6;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue