Implement minimum booking notice
This commit is contained in:
parent
7ad0ce17c5
commit
4368ad0289
5 changed files with 20 additions and 5 deletions
|
@ -7,6 +7,7 @@ const AvailableTimes = ({
|
||||||
date,
|
date,
|
||||||
eventLength,
|
eventLength,
|
||||||
eventTypeId,
|
eventTypeId,
|
||||||
|
minimumBookingNotice,
|
||||||
workingHours,
|
workingHours,
|
||||||
timeFormat,
|
timeFormat,
|
||||||
user,
|
user,
|
||||||
|
@ -20,6 +21,7 @@ const AvailableTimes = ({
|
||||||
eventLength,
|
eventLength,
|
||||||
workingHours,
|
workingHours,
|
||||||
organizerTimeZone,
|
organizerTimeZone,
|
||||||
|
minimumBookingNotice,
|
||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -23,6 +23,7 @@ const DatePicker = ({
|
||||||
periodEndDate,
|
periodEndDate,
|
||||||
periodDays,
|
periodDays,
|
||||||
periodCountCalendarDays,
|
periodCountCalendarDays,
|
||||||
|
minimumBookingNotice,
|
||||||
}) => {
|
}) => {
|
||||||
const [calendar, setCalendar] = useState([]);
|
const [calendar, setCalendar] = useState([]);
|
||||||
const [selectedMonth, setSelectedMonth] = useState<number>();
|
const [selectedMonth, setSelectedMonth] = useState<number>();
|
||||||
|
@ -77,6 +78,7 @@ const DatePicker = ({
|
||||||
!getSlots({
|
!getSlots({
|
||||||
inviteeDate: date,
|
inviteeDate: date,
|
||||||
frequency: eventLength,
|
frequency: eventLength,
|
||||||
|
minimumBookingNotice,
|
||||||
workingHours,
|
workingHours,
|
||||||
organizerTimeZone,
|
organizerTimeZone,
|
||||||
}).length
|
}).length
|
||||||
|
@ -93,6 +95,7 @@ const DatePicker = ({
|
||||||
!getSlots({
|
!getSlots({
|
||||||
inviteeDate: date,
|
inviteeDate: date,
|
||||||
frequency: eventLength,
|
frequency: eventLength,
|
||||||
|
minimumBookingNotice,
|
||||||
workingHours,
|
workingHours,
|
||||||
organizerTimeZone,
|
organizerTimeZone,
|
||||||
}).length
|
}).length
|
||||||
|
@ -106,6 +109,7 @@ const DatePicker = ({
|
||||||
!getSlots({
|
!getSlots({
|
||||||
inviteeDate: date,
|
inviteeDate: date,
|
||||||
frequency: eventLength,
|
frequency: eventLength,
|
||||||
|
minimumBookingNotice,
|
||||||
workingHours,
|
workingHours,
|
||||||
organizerTimeZone,
|
organizerTimeZone,
|
||||||
}).length
|
}).length
|
||||||
|
|
13
lib/slots.ts
13
lib/slots.ts
|
@ -1,7 +1,6 @@
|
||||||
import dayjs, { Dayjs } from "dayjs";
|
import dayjs, { Dayjs } from "dayjs";
|
||||||
import utc from "dayjs/plugin/utc";
|
import utc from "dayjs/plugin/utc";
|
||||||
import timezone from "dayjs/plugin/timezone";
|
import timezone from "dayjs/plugin/timezone";
|
||||||
|
|
||||||
dayjs.extend(utc);
|
dayjs.extend(utc);
|
||||||
dayjs.extend(timezone);
|
dayjs.extend(timezone);
|
||||||
|
|
||||||
|
@ -119,9 +118,15 @@ const getSlots = ({
|
||||||
workingHours,
|
workingHours,
|
||||||
organizerTimeZone,
|
organizerTimeZone,
|
||||||
}: GetSlots): Dayjs[] => {
|
}: GetSlots): Dayjs[] => {
|
||||||
const startTime = dayjs().utcOffset(inviteeDate.utcOffset()).isSame(inviteeDate, "day")
|
// current date in invitee tz
|
||||||
? inviteeDate.hour() * 60 + inviteeDate.minute() + (minimumBookingNotice || 0)
|
const currentDate = dayjs().utcOffset(inviteeDate.utcOffset());
|
||||||
: 0;
|
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);
|
const inviteeBounds = inviteeBoundary(startTime, inviteeDate.utcOffset(), frequency);
|
||||||
|
|
||||||
|
|
|
@ -167,14 +167,16 @@ export default function Type(props): Type {
|
||||||
organizerTimeZone={props.eventType.timeZone || props.user.timeZone}
|
organizerTimeZone={props.eventType.timeZone || props.user.timeZone}
|
||||||
inviteeTimeZone={timeZone()}
|
inviteeTimeZone={timeZone()}
|
||||||
eventLength={props.eventType.length}
|
eventLength={props.eventType.length}
|
||||||
|
minimumBookingNotice={props.eventType.minimumBookingNotice}
|
||||||
/>
|
/>
|
||||||
{selectedDate && (
|
{selectedDate && (
|
||||||
<AvailableTimes
|
<AvailableTimes
|
||||||
workingHours={props.workingHours}
|
workingHours={props.workingHours}
|
||||||
timeFormat={timeFormat}
|
timeFormat={timeFormat}
|
||||||
organizerTimeZone={props.eventType.timeZone || props.user.timeZone}
|
organizerTimeZone={props.eventType.timeZone || props.user.timeZone}
|
||||||
eventLength={props.eventType.length}
|
minimumBookingNotice={props.eventType.minimumBookingNotice}
|
||||||
eventTypeId={props.eventType.id}
|
eventTypeId={props.eventType.id}
|
||||||
|
eventLength={props.eventType.length}
|
||||||
date={selectedDate}
|
date={selectedDate}
|
||||||
user={props.user}
|
user={props.user}
|
||||||
/>
|
/>
|
||||||
|
@ -238,6 +240,7 @@ export const getServerSideProps: GetServerSideProps = async (context: GetServerS
|
||||||
"periodStartDate",
|
"periodStartDate",
|
||||||
"periodEndDate",
|
"periodEndDate",
|
||||||
"periodCountCalendarDays",
|
"periodCountCalendarDays",
|
||||||
|
"minimumBookingNotice",
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,7 @@ model EventType {
|
||||||
periodDays Int?
|
periodDays Int?
|
||||||
periodCountCalendarDays Boolean?
|
periodCountCalendarDays Boolean?
|
||||||
requiresConfirmation Boolean @default(false)
|
requiresConfirmation Boolean @default(false)
|
||||||
|
minimumBookingNotice Int @default(120)
|
||||||
}
|
}
|
||||||
|
|
||||||
model Credential {
|
model Credential {
|
||||||
|
|
Loading…
Reference in a new issue