Skip to content

Commit

Permalink
Exclude days from calendar (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucieo authored Feb 26, 2024
1 parent afeb08b commit 57b089d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
3 changes: 3 additions & 0 deletions web/components/Account/Place/Schedule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => {
Expand Down
31 changes: 23 additions & 8 deletions web/components/Campaign/Places/Admin/CampaignDatePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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++
Expand Down Expand Up @@ -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 (
Expand All @@ -97,6 +111,7 @@ const CampaignDatePicker = ({ control }: { control?: Control }) => {
new Date(start),
offWeekDays,
currentCampaign?.duration,
getExcludedDates(oldEvents),
)

setValue('end', endDate)
Expand Down

0 comments on commit 57b089d

Please sign in to comment.