From 57b089d2f12384e5a7affd6683ef65b0ccb04379 Mon Sep 17 00:00:00 2001 From: Lucieo Date: Mon, 26 Feb 2024 16:12:58 +0000 Subject: [PATCH] Exclude days from calendar (#90) --- web/components/Account/Place/Schedule.tsx | 3 ++ .../Places/Admin/CampaignDatePicker.tsx | 31 ++++++++++++++----- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/web/components/Account/Place/Schedule.tsx b/web/components/Account/Place/Schedule.tsx index ffc117c1..013bae69 100644 --- a/web/components/Account/Place/Schedule.tsx +++ b/web/components/Account/Place/Schedule.tsx @@ -30,6 +30,9 @@ export const StyleWrapper = styled.div` margin: 3px 2px 3px 2px; mix-blend-mode: multiply; } + .fc-daygrid-event-harness { + top: 0 !important; + } ` const Schedule = ({ isCampaignMode }: { isCampaignMode?: boolean }) => { diff --git a/web/components/Campaign/Places/Admin/CampaignDatePicker.tsx b/web/components/Campaign/Places/Admin/CampaignDatePicker.tsx index 2f6917af..46190794 100644 --- a/web/components/Campaign/Places/Admin/CampaignDatePicker.tsx +++ b/web/components/Campaign/Places/Admin/CampaignDatePicker.tsx @@ -14,18 +14,39 @@ import InputMultiSelect from '~components/InputMultiSelect' import { Control } from 'react-hook-form' import { getDay } from 'date-fns' +const getExcludedDates = (events) => { + const dates = [] + events.map((event) => { + if (event?.extendedProps?.type === 'period') { + const start = new Date(event.start) + const end = new Date(event.end) + const interval = { start, end } + const days = eachDayOfInterval(interval) + dates.push(...days) + } else { + dates.push(new Date(event.start)) + } + }) + return dates +} + const getEndDate = ( startDate: Date, offWeekDays: number[], duration: number, + excludedDates: Date[], ) => { + console.log(excludedDates) let endDate = new Date(startDate) let selectedDays = 1 const exclude_days = [] if (offWeekDays.length < 7) { { while (selectedDays < duration + 1) { - if (offWeekDays.includes(getDay(endDate))) { + if ( + offWeekDays.includes(getDay(endDate)) || + excludedDates.some((date) => isSameDay(date, endDate)) + ) { exclude_days.push(endDate.toString()) } else { selectedDays++ @@ -68,13 +89,6 @@ const CampaignDatePicker = ({ control }: { control?: Control }) => { end: event.end, }), ) - // Prevent user from selecting a start day to close from other period - total.push( - eachDayOfInterval({ - start: subDays(event.start, currentCampaign.duration - 1), - end: event.start, - }), - ) } else if (event.extendedProps.type === 'day') { total.push(event.start) } else if ( @@ -97,6 +111,7 @@ const CampaignDatePicker = ({ control }: { control?: Control }) => { new Date(start), offWeekDays, currentCampaign?.duration, + getExcludedDates(oldEvents), ) setValue('end', endDate)