Skip to content

Scheduling infrastructure for absolutely everyone.

Implement minimum booking notice

Alex van Andel4368ad02894e
diff --git a/components/booking/AvailableTimes.tsx b/components/booking/AvailableTimes.tsx
index 64cb4dd0e71..e2d6af3e900 100644
--- a/components/booking/AvailableTimes.tsx
+++ b/components/booking/AvailableTimes.tsx
@@ -7,6 +7,7 @@ const AvailableTimes = ({
date,
eventLength,
eventTypeId,
+ minimumBookingNotice,
workingHours,
timeFormat,
user,
@@ -20,6 +21,7 @@ const AvailableTimes = ({
eventLength,
workingHours,
organizerTimeZone,
+ minimumBookingNotice,
});
return (
diff --git a/components/booking/DatePicker.tsx b/components/booking/DatePicker.tsx
index b49b887e34f..c6a49fa0c84 100644
--- a/components/booking/DatePicker.tsx
+++ b/components/booking/DatePicker.tsx
@@ -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
diff --git a/lib/slots.ts b/lib/slots.ts
index 3c0d45a15b1..957d084b107 100644
--- a/lib/slots.ts
+++ b/lib/slots.ts
@@ -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);
diff --git a/pages/[user]/[type].tsx b/pages/[user]/[type].tsx
index 04cdbd76a04..222db31e08a 100644
--- a/pages/[user]/[type].tsx
+++ b/pages/[user]/[type].tsx
@@ -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",
]
);
diff --git a/prisma/schema.prisma b/prisma/schema.prisma
index 83aed7249a9..409c68af400 100644
--- a/prisma/schema.prisma
+++ b/prisma/schema.prisma
@@ -31,6 +31,7 @@ model EventType {
periodDays Int?
periodCountCalendarDays Boolean?
requiresConfirmation Boolean @default(false)
+ minimumBookingNotice Int @default(120)
}
model Credential {