Implement minimum booking notice

This commit is contained in:
Alex van Andel 2021-07-22 22:52:27 +00:00
parent 7ad0ce17c5
commit 4368ad0289
5 changed files with 20 additions and 5 deletions

View file

@ -7,6 +7,7 @@ const AvailableTimes = ({
date,
eventLength,
eventTypeId,
minimumBookingNotice,
workingHours,
timeFormat,
user,
@ -20,6 +21,7 @@ const AvailableTimes = ({
eventLength,
workingHours,
organizerTimeZone,
minimumBookingNotice,
});
return (

View file

@ -23,6 +23,7 @@ const DatePicker = ({
periodEndDate,
periodDays,
periodCountCalendarDays,
minimumBookingNotice,
}) => {
const [calendar, setCalendar] = useState([]);
const [selectedMonth, setSelectedMonth] = useState<number>();
@ -77,6 +78,7 @@ const DatePicker = ({
!getSlots({
inviteeDate: date,
frequency: eventLength,
minimumBookingNotice,
workingHours,
organizerTimeZone,
}).length
@ -93,6 +95,7 @@ const DatePicker = ({
!getSlots({
inviteeDate: date,
frequency: eventLength,
minimumBookingNotice,
workingHours,
organizerTimeZone,
}).length
@ -106,6 +109,7 @@ const DatePicker = ({
!getSlots({
inviteeDate: date,
frequency: eventLength,
minimumBookingNotice,
workingHours,
organizerTimeZone,
}).length

View file

@ -1,7 +1,6 @@
import dayjs, { Dayjs } from "dayjs";
import utc from "dayjs/plugin/utc";
import timezone from "dayjs/plugin/timezone";
dayjs.extend(utc);
dayjs.extend(timezone);
@ -119,9 +118,15 @@ const getSlots = ({
workingHours,
organizerTimeZone,
}: GetSlots): Dayjs[] => {
const startTime = dayjs().utcOffset(inviteeDate.utcOffset()).isSame(inviteeDate, "day")
? inviteeDate.hour() * 60 + inviteeDate.minute() + (minimumBookingNotice || 0)
: 0;
// current date in invitee tz
const currentDate = dayjs().utcOffset(inviteeDate.utcOffset());
const startDate = currentDate.add(minimumBookingNotice, "minutes"); // + minimum notice period
// when the invitee date is not the same as the current date, reset the date to the start of day
if (inviteeDate.date() !== currentDate.date()) {
inviteeDate = inviteeDate.startOf("day");
}
const startTime = startDate.isAfter(inviteeDate) ? inviteeDate.hour() * 60 + inviteeDate.minute() : 0;
const inviteeBounds = inviteeBoundary(startTime, inviteeDate.utcOffset(), frequency);

View file

@ -167,14 +167,16 @@ export default function Type(props): Type {
organizerTimeZone={props.eventType.timeZone || props.user.timeZone}
inviteeTimeZone={timeZone()}
eventLength={props.eventType.length}
minimumBookingNotice={props.eventType.minimumBookingNotice}
/>
{selectedDate && (
<AvailableTimes
workingHours={props.workingHours}
timeFormat={timeFormat}
organizerTimeZone={props.eventType.timeZone || props.user.timeZone}
eventLength={props.eventType.length}
minimumBookingNotice={props.eventType.minimumBookingNotice}
eventTypeId={props.eventType.id}
eventLength={props.eventType.length}
date={selectedDate}
user={props.user}
/>
@ -238,6 +240,7 @@ export const getServerSideProps: GetServerSideProps = async (context: GetServerS
"periodStartDate",
"periodEndDate",
"periodCountCalendarDays",
"minimumBookingNotice",
]
);

View file

@ -31,6 +31,7 @@ model EventType {
periodDays Int?
periodCountCalendarDays Boolean?
requiresConfirmation Boolean @default(false)
minimumBookingNotice Int @default(120)
}
model Credential {