Feat/cal 95/date range on event types (#353)

* add edit links to events on dashboard

* fit elements on screen for mobile

* initialize components for consistent text styles

* add more fine grained width/height settings

* add higher level setting for when an event is available

- db: add supporting values to period allow setting an amount of days,
 a range, or unlimited number days an event is available

* fix issue where periodDates are null

* return minimal required data, handle date parsing

* [ui] limit booking days based on user period settings

* api: validate user period settings

* [db] migration for event type period settings
This commit is contained in:
Femi Odugbesan authored and GitHub committed 2021-07-15 09:10:26 -05:00
1 parent ecd0360d9a
commit 45689059c7
42 files changed
+1455 -380

No files matched your search

+5
View File
@@ -49,6 +49,11 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
},
})),
},
periodType: req.body.periodType,
periodDays: req.body.periodDays,
periodStartDate: req.body.periodStartDate,
periodEndDate: req.body.periodEndDate,
periodCountCalendarDays: req.body.periodCountCalendarDays,
};
if (req.method == "POST") {
+66
View File
@@ -12,6 +12,14 @@ import merge from "lodash.merge";
import dayjs from "dayjs";
import logger from "../../../lib/logger";
import utc from "dayjs/plugin/utc";
import timezone from "dayjs/plugin/timezone";
import dayjsBusinessDays from "dayjs-business-days";
dayjs.extend(dayjsBusinessDays);
dayjs.extend(utc);
dayjs.extend(timezone);
const translator = short();
const log = logger.getChildLogger({ prefix: ["[api] book:user"] });
@@ -49,6 +57,32 @@ function isAvailable(busyTimes, time, length) {
return t;
}
function isOutOfBounds(
time: dayjs.ConfigType,
{ periodType, periodDays, periodCountCalendarDays, periodStartDate, periodEndDate, timeZone }
): boolean {
const date = dayjs(time);
switch (periodType) {
case "rolling": {
const periodRollingEndDay = periodCountCalendarDays
? dayjs().tz(timeZone).add(periodDays, "days").endOf("day")
: dayjs().tz(timeZone).businessDaysAdd(periodDays, "days").endOf("day");
return date.endOf("day").isAfter(periodRollingEndDay);
}
case "range": {
const periodRangeStartDay = dayjs(periodStartDate).tz(timeZone).endOf("day");
const periodRangeEndDay = dayjs(periodEndDate).tz(timeZone).endOf("day");
return date.endOf("day").isBefore(periodRangeStartDay) || date.endOf("day").isAfter(periodRangeEndDay);
}
case "unlimited":
default:
return false;
}
}
interface GetLocationRequestFromIntegrationRequest {
location: string;
}
@@ -166,6 +200,11 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
eventName: true,
title: true,
length: true,
periodType: true,
periodDays: true,
periodStartDate: true,
periodEndDate: true,
periodCountCalendarDays: true,
},
});
@@ -228,6 +267,33 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
return res.status(400).json(error);
}
let timeOutOfBounds = false;
try {
timeOutOfBounds = isOutOfBounds(req.body.start, {
periodType: selectedEventType.periodType,
periodDays: selectedEventType.periodDays,
periodEndDate: selectedEventType.periodEndDate,
periodStartDate: selectedEventType.periodStartDate,
periodCountCalendarDays: selectedEventType.periodCountCalendarDays,
timeZone: currentUser.timeZone,
});
} catch {
log.debug({
message: "Unable set timeOutOfBounds. Using false. ",
});
}
if (timeOutOfBounds) {
const error = {
errorCode: "BookingUserUnAvailable",
message: `${currentUser.name} is unavailable at this time.`,
};
log.debug(`Booking ${user} failed`, error);
return res.status(400).json(error);
}
let results = [];
let referencesToCreate = [];