Add seats to event types (#2485)
* Add seatsPerTimeSlot to event type schema * Add seats per time slot to event type form * Book event and render seats * Pass booking uid for seats * Disable requires confirmation if seats are enabled * Fix type errors * Update submodules * Fix type errors * Fix type errors * Fix duplicate string * Fix duplicate string * Fix schema and migration file * Fix render seats * Fix bookinguid typos * Remove console.log * Fix type error * Fix mobile formatting * Update apps/web/lib/hooks/useSlots.ts Co-authored-by: Omar López <[email protected]> * Update apps/web/lib/hooks/useSlots.ts Co-authored-by: Omar López <[email protected]> * Added translation for seats available text Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> Co-authored-by: zomars <[email protected]> Co-authored-by: alannnc <[email protected]>
This commit is contained in:
22 files changed
+326
-16
No files matched your search
@@ -6,7 +6,7 @@ import { stringify } from "querystring";
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
import getSlots from "@lib/slots";
|
||||
import { TimeRange, WorkingHours } from "@lib/types/schedule";
|
||||
import { CurrentSeats, TimeRange, WorkingHours } from "@lib/types/schedule";
|
||||
|
||||
dayjs.extend(isBetween);
|
||||
dayjs.extend(utc);
|
||||
@@ -15,11 +15,14 @@ type AvailabilityUserResponse = {
|
||||
busy: TimeRange[];
|
||||
timeZone: string;
|
||||
workingHours: WorkingHours[];
|
||||
currentSeats?: CurrentSeats[];
|
||||
};
|
||||
|
||||
type Slot = {
|
||||
time: Dayjs;
|
||||
users?: string[];
|
||||
bookingUid?: string;
|
||||
attendees?: number;
|
||||
};
|
||||
|
||||
type UseSlotsProps = {
|
||||
@@ -40,10 +43,11 @@ type getFilteredTimesProps = {
|
||||
eventLength: number;
|
||||
beforeBufferTime: number;
|
||||
afterBufferTime: number;
|
||||
currentSeats?: CurrentSeats[];
|
||||
};
|
||||
|
||||
export const getFilteredTimes = (props: getFilteredTimesProps) => {
|
||||
const { times, busy, eventLength, beforeBufferTime, afterBufferTime } = props;
|
||||
const { times, busy, eventLength, beforeBufferTime, afterBufferTime, currentSeats } = props;
|
||||
const finalizationTime = times[times.length - 1]?.add(eventLength, "minutes");
|
||||
// Check for conflicts
|
||||
for (let i = times.length - 1; i >= 0; i -= 1) {
|
||||
@@ -56,6 +60,10 @@ export const getFilteredTimes = (props: getFilteredTimesProps) => {
|
||||
const slotStartTime = times[i];
|
||||
const slotEndTime = times[i].add(eventLength, "minutes");
|
||||
const slotStartTimeWithBeforeBuffer = times[i].subtract(beforeBufferTime, "minutes");
|
||||
// If the event has seats then see if there is already a booking (want to show full bookings as well)
|
||||
if (currentSeats?.some((booking) => booking.startTime === slotStartTime.toISOString())) {
|
||||
break;
|
||||
}
|
||||
busy.every((busyTime): boolean => {
|
||||
const startTime = dayjs(busyTime.start);
|
||||
const endTime = dayjs(busyTime.end);
|
||||
@@ -124,19 +132,21 @@ export const useSlots = (props: UseSlotsProps) => {
|
||||
|
||||
const handleAvailableSlots = async (res: Response) => {
|
||||
const responseBody: AvailabilityUserResponse = await res.json();
|
||||
const { workingHours, busy, currentSeats } = responseBody;
|
||||
const times = getSlots({
|
||||
frequency: slotInterval || eventLength,
|
||||
inviteeDate: date,
|
||||
workingHours: responseBody.workingHours,
|
||||
workingHours,
|
||||
minimumBookingNotice,
|
||||
eventLength,
|
||||
});
|
||||
const filterTimeProps = {
|
||||
times,
|
||||
busy: responseBody.busy,
|
||||
busy,
|
||||
eventLength,
|
||||
beforeBufferTime,
|
||||
afterBufferTime,
|
||||
currentSeats,
|
||||
};
|
||||
const filteredTimes = getFilteredTimes(filterTimeProps);
|
||||
// temporary
|
||||
@@ -144,6 +154,14 @@ export const useSlots = (props: UseSlotsProps) => {
|
||||
return filteredTimes.map((time) => ({
|
||||
time,
|
||||
users: [user],
|
||||
// Conditionally add the attendees and booking id to slots object if there is already a booking during that time
|
||||
...(currentSeats?.some((booking) => booking.startTime === time.toISOString()) && {
|
||||
attendees:
|
||||
currentSeats[currentSeats.findIndex((booking) => booking.startTime === time.toISOString())]._count
|
||||
.attendees,
|
||||
bookingUid:
|
||||
currentSeats[currentSeats.findIndex((booking) => booking.startTime === time.toISOString())].uid,
|
||||
}),
|
||||
}));
|
||||
};
|
||||
|
||||
|
||||
+10
-2
@@ -4,7 +4,7 @@ import isToday from "dayjs/plugin/isToday";
|
||||
import utc from "dayjs/plugin/utc";
|
||||
|
||||
import { getWorkingHours } from "./availability";
|
||||
import { WorkingHours } from "./types/schedule";
|
||||
import { WorkingHours, CurrentSeats } from "./types/schedule";
|
||||
|
||||
dayjs.extend(isToday);
|
||||
dayjs.extend(utc);
|
||||
@@ -16,6 +16,7 @@ export type GetSlots = {
|
||||
workingHours: WorkingHours[];
|
||||
minimumBookingNotice: number;
|
||||
eventLength: number;
|
||||
currentSeats?: CurrentSeats[];
|
||||
};
|
||||
export type WorkingHoursTimeFrame = { startTime: number; endTime: number };
|
||||
|
||||
@@ -42,7 +43,14 @@ const splitAvailableTime = (
|
||||
return result;
|
||||
};
|
||||
|
||||
const getSlots = ({ inviteeDate, frequency, minimumBookingNotice, workingHours, eventLength }: GetSlots) => {
|
||||
const getSlots = ({
|
||||
inviteeDate,
|
||||
frequency,
|
||||
minimumBookingNotice,
|
||||
workingHours,
|
||||
eventLength,
|
||||
currentSeats,
|
||||
}: GetSlots) => {
|
||||
// current date in invitee tz
|
||||
const startDate = dayjs().add(minimumBookingNotice, "minute");
|
||||
const startOfDay = dayjs.utc().startOf("day");
|
||||
|
||||
@@ -24,6 +24,7 @@ export type BookingCreateBody = {
|
||||
timeZone: string;
|
||||
user?: string | string[];
|
||||
language: string;
|
||||
bookingUid?: string;
|
||||
customInputs: { label: string; value: string | boolean }[];
|
||||
metadata: {
|
||||
[key: string]: string;
|
||||
|
||||
@@ -24,6 +24,7 @@ export type AdvancedOptions = {
|
||||
availability?: { openingHours: WorkingHours[]; dateOverrides: WorkingHours[] };
|
||||
customInputs?: EventTypeCustomInput[];
|
||||
timeZone?: string;
|
||||
seatsPerTimeSlot: number;
|
||||
destinationCalendar?: {
|
||||
userId?: number;
|
||||
eventTypeId?: number;
|
||||
|
||||
@@ -16,3 +16,11 @@ export type WorkingHours = {
|
||||
startTime: number;
|
||||
endTime: number;
|
||||
};
|
||||
|
||||
export type CurrentSeats = {
|
||||
uid: string;
|
||||
startTime: string;
|
||||
_count: {
|
||||
attendees: number;
|
||||
};
|
||||
};
|
||||
Reference in new issue
Block a user