feat: preference to show/hide available seats count in events (#11109)
Co-authored-by: Peer Richelsen <[email protected]>
This commit is contained in:
1 parent
7e2ad3cea9
commit
9c3cbee363
26 files changed
+117
-12
No files matched your search
@@ -262,6 +262,7 @@ export default class EventManager {
|
||||
select: {
|
||||
seatsPerTimeSlot: true,
|
||||
seatsShowAttendees: true,
|
||||
seatsShowAvailabilityCount: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -327,6 +327,7 @@ const BookerComponent = ({
|
||||
prefetchNextMonth={prefetchNextMonth}
|
||||
monthCount={monthCount}
|
||||
seatsPerTimeSlot={event.data?.seatsPerTimeSlot}
|
||||
showAvailableSeatsCount={event.data?.seatsShowAvailabilityCount}
|
||||
/>
|
||||
</BookerSection>
|
||||
</AnimatePresence>
|
||||
|
||||
@@ -19,6 +19,7 @@ type AvailableTimeSlotsProps = {
|
||||
prefetchNextMonth: boolean;
|
||||
monthCount: number | undefined;
|
||||
seatsPerTimeSlot?: number | null;
|
||||
showAvailableSeatsCount?: boolean | null;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -32,6 +33,7 @@ export const AvailableTimeSlots = ({
|
||||
extraDays,
|
||||
limitHeight,
|
||||
seatsPerTimeSlot,
|
||||
showAvailableSeatsCount,
|
||||
prefetchNextMonth,
|
||||
monthCount,
|
||||
}: AvailableTimeSlotsProps) => {
|
||||
@@ -60,6 +62,7 @@ export const AvailableTimeSlots = ({
|
||||
seatsPerTimeSlot,
|
||||
attendees,
|
||||
bookingUid,
|
||||
showAvailableSeatsCount,
|
||||
});
|
||||
|
||||
if (seatsPerTimeSlot && seatsPerTimeSlot - attendees > 1) {
|
||||
@@ -116,6 +119,7 @@ export const AvailableTimeSlots = ({
|
||||
date={dayjs(slots.date)}
|
||||
slots={slots.slots}
|
||||
seatsPerTimeSlot={seatsPerTimeSlot}
|
||||
showAvailableSeatsCount={showAvailableSeatsCount}
|
||||
availableMonth={
|
||||
dayjs(selectedDate).format("MM") !== dayjs(slots.date).format("MM")
|
||||
? dayjs(slots.date).format("MMM")
|
||||
|
||||
@@ -4,6 +4,7 @@ import { shallow } from "zustand/shallow";
|
||||
|
||||
import { useEmbedUiConfig, useIsEmbed } from "@calcom/embed-core/embed-iframe";
|
||||
import { EventDetails, EventMembers, EventMetaSkeleton, EventTitle } from "@calcom/features/bookings";
|
||||
import { SeatsAvailabilityText } from "@calcom/features/bookings/components/SeatsAvailabilityText";
|
||||
import { EventMetaBlock } from "@calcom/features/bookings/components/event-meta/Details";
|
||||
import { useTimePreferences } from "@calcom/features/bookings/lib";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
@@ -130,13 +131,12 @@ export const EventMeta = () => {
|
||||
<EventMetaBlock icon={User} className={`${colorClass}`}>
|
||||
<div className="text-bookinghighlight flex items-start text-sm">
|
||||
<p>
|
||||
{bookingSeatAttendeesQty ? eventTotalSeats - bookingSeatAttendeesQty : eventTotalSeats} /{" "}
|
||||
{eventTotalSeats}{" "}
|
||||
{t("seats_available", {
|
||||
count: bookingSeatAttendeesQty
|
||||
? eventTotalSeats - bookingSeatAttendeesQty
|
||||
: eventTotalSeats,
|
||||
})}
|
||||
<SeatsAvailabilityText
|
||||
showExact={!!seatedEventData.showAvailableSeatsCount}
|
||||
totalSeats={eventTotalSeats}
|
||||
bookedSeats={bookingSeatAttendeesQty || 0}
|
||||
variant="fraction"
|
||||
/>
|
||||
</p>
|
||||
</div>
|
||||
</EventMetaBlock>
|
||||
|
||||
@@ -33,6 +33,7 @@ type SeatedEventData = {
|
||||
seatsPerTimeSlot?: number | null;
|
||||
attendees?: number;
|
||||
bookingUid?: string;
|
||||
showAvailableSeatsCount?: boolean | null;
|
||||
};
|
||||
|
||||
export type BookerStore = {
|
||||
@@ -206,6 +207,7 @@ export const useBookerStore = create<BookerStore>((set, get) => ({
|
||||
seatsPerTimeSlot: undefined,
|
||||
attendees: undefined,
|
||||
bookingUid: undefined,
|
||||
showAvailableSeatsCount: true,
|
||||
},
|
||||
setSeatedEventData: (seatedEventData: SeatedEventData) => {
|
||||
set({ seatedEventData });
|
||||
|
||||
@@ -12,6 +12,7 @@ import { Button, SkeletonText } from "@calcom/ui";
|
||||
|
||||
import { useBookerStore } from "../Booker/store";
|
||||
import { useTimePreferences } from "../lib";
|
||||
import { SeatsAvailabilityText } from "./SeatsAvailabilityText";
|
||||
import { TimeFormatToggle } from "./TimeFormatToggle";
|
||||
|
||||
type AvailableTimesProps = {
|
||||
@@ -24,6 +25,7 @@ type AvailableTimesProps = {
|
||||
bookingUid?: string
|
||||
) => void;
|
||||
seatsPerTimeSlot?: number | null;
|
||||
showAvailableSeatsCount?: boolean | null;
|
||||
showTimeFormatToggle?: boolean;
|
||||
className?: string;
|
||||
availableMonth?: string | undefined;
|
||||
@@ -35,6 +37,7 @@ export const AvailableTimes = ({
|
||||
slots,
|
||||
onTimeSelect,
|
||||
seatsPerTimeSlot,
|
||||
showAvailableSeatsCount,
|
||||
showTimeFormatToggle = true,
|
||||
className,
|
||||
availableMonth,
|
||||
@@ -110,15 +113,16 @@ export const AvailableTimes = ({
|
||||
{dayjs.utc(slot.time).tz(timezone).format(timeFormat)}
|
||||
{bookingFull && <p className="text-sm">{t("booking_full")}</p>}
|
||||
{hasTimeSlots && !bookingFull && (
|
||||
<p className="flex items-center text-sm lowercase">
|
||||
<p className="flex items-center text-sm">
|
||||
<span
|
||||
className={classNames(colorClass, "mr-1 inline-block h-2 w-2 rounded-full")}
|
||||
aria-hidden
|
||||
/>
|
||||
{slot.attendees ? seatsPerTimeSlot - slot.attendees : seatsPerTimeSlot}{" "}
|
||||
{t("seats_available", {
|
||||
count: slot.attendees ? seatsPerTimeSlot - slot.attendees : seatsPerTimeSlot,
|
||||
})}
|
||||
<SeatsAvailabilityText
|
||||
showExact={!!showAvailableSeatsCount}
|
||||
totalSeats={seatsPerTimeSlot}
|
||||
bookedSeats={slot.attendees || 0}
|
||||
/>
|
||||
</p>
|
||||
)}
|
||||
</Button>
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
import { classNames } from "@calcom/lib";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
|
||||
type Props = {
|
||||
/**
|
||||
* Whether to show the exact number of seats available or not
|
||||
*
|
||||
* @default true
|
||||
*/
|
||||
showExact: boolean;
|
||||
/**
|
||||
* Shows available seats count as either whole number or fraction.
|
||||
*
|
||||
* Applies only when `showExact` is `true`
|
||||
*
|
||||
* @default "whole"
|
||||
*/
|
||||
variant?: "whole" | "fraction";
|
||||
/** Number of seats booked in the event */
|
||||
bookedSeats: number;
|
||||
/** Total number of seats in the event */
|
||||
totalSeats: number;
|
||||
};
|
||||
|
||||
export const SeatsAvailabilityText = ({
|
||||
showExact = true,
|
||||
bookedSeats,
|
||||
totalSeats,
|
||||
variant = "whole",
|
||||
}: Props) => {
|
||||
const { t } = useLocale();
|
||||
const availableSeats = totalSeats - bookedSeats;
|
||||
const isHalfFull = bookedSeats / totalSeats >= 0.5;
|
||||
const isNearlyFull = bookedSeats / totalSeats >= 0.83;
|
||||
|
||||
return (
|
||||
<span className={classNames(showExact && "lowercase")}>
|
||||
{showExact
|
||||
? `${availableSeats}${variant === "fraction" ? ` / ${totalSeats}` : ""} ${t("seats_available", {
|
||||
count: availableSeats,
|
||||
})}`
|
||||
: isNearlyFull
|
||||
? t("seats_nearly_full")
|
||||
: isHalfFull
|
||||
? t("seats_half_full")
|
||||
: t("seats_available", {
|
||||
count: availableSeats,
|
||||
})}
|
||||
</span>
|
||||
);
|
||||
};
|
||||
@@ -275,6 +275,7 @@ const getEventTypesFromDB = async (eventTypeId: number) => {
|
||||
seatsPerTimeSlot: true,
|
||||
recurringEvent: true,
|
||||
seatsShowAttendees: true,
|
||||
seatsShowAvailabilityCount: true,
|
||||
bookingLimits: true,
|
||||
durationLimits: true,
|
||||
parentId: true,
|
||||
@@ -1071,6 +1072,7 @@ async function handler(
|
||||
// if seats are not enabled we should default true
|
||||
seatsShowAttendees: eventType.seatsPerTimeSlot ? eventType.seatsShowAttendees : true,
|
||||
seatsPerTimeSlot: eventType.seatsPerTimeSlot,
|
||||
seatsShowAvailabilityCount: eventType.seatsPerTimeSlot ? eventType.seatsShowAvailabilityCount : true,
|
||||
schedulingType: eventType.schedulingType,
|
||||
};
|
||||
|
||||
|
||||
@@ -263,6 +263,7 @@ const EmailEmbed = ({ eventType, username }: { eventType?: EventType; username:
|
||||
}
|
||||
onTimeSelect={onTimeSelect}
|
||||
slots={slots}
|
||||
showAvailableSeatsCount={eventType.seatsShowAvailabilityCount}
|
||||
/>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
@@ -39,6 +39,7 @@ const publicEventSelect = Prisma.validator<Prisma.EventTypeSelect>()({
|
||||
price: true,
|
||||
currency: true,
|
||||
seatsPerTimeSlot: true,
|
||||
seatsShowAvailabilityCount: true,
|
||||
bookingFields: true,
|
||||
team: {
|
||||
select: {
|
||||
|
||||
@@ -79,6 +79,7 @@ const commons = {
|
||||
schedulingType: SchedulingType.COLLECTIVE,
|
||||
seatsPerTimeSlot: null,
|
||||
seatsShowAttendees: null,
|
||||
seatsShowAvailabilityCount: null,
|
||||
id: 0,
|
||||
hideCalendarNotes: false,
|
||||
recurringEvent: null,
|
||||
|
||||
@@ -174,6 +174,7 @@ export default async function getEventTypeById({
|
||||
destinationCalendar: true,
|
||||
seatsPerTimeSlot: true,
|
||||
seatsShowAttendees: true,
|
||||
seatsShowAvailabilityCount: true,
|
||||
webhooks: {
|
||||
select: {
|
||||
id: true,
|
||||
|
||||
@@ -93,6 +93,7 @@ export const buildEventType = (eventType?: Partial<EventType>): EventType => {
|
||||
afterEventBuffer: 0,
|
||||
seatsPerTimeSlot: null,
|
||||
seatsShowAttendees: null,
|
||||
seatsShowAvailabilityCount: null,
|
||||
schedulingType: null,
|
||||
scheduleId: null,
|
||||
bookingLimits: null,
|
||||
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "EventType" ADD COLUMN "seatsShowAvailabilityCount" BOOLEAN DEFAULT true;
|
||||
@@ -98,6 +98,7 @@ model EventType {
|
||||
afterEventBuffer Int @default(0)
|
||||
seatsPerTimeSlot Int?
|
||||
seatsShowAttendees Boolean? @default(false)
|
||||
seatsShowAvailabilityCount Boolean? @default(true)
|
||||
schedulingType SchedulingType?
|
||||
schedule Schedule? @relation(fields: [scheduleId], references: [id])
|
||||
scheduleId Int?
|
||||
|
||||
@@ -575,6 +575,7 @@ export const allManagedEventTypeProps: { [k in keyof Omit<Prisma.EventTypeSelect
|
||||
successRedirectUrl: true,
|
||||
seatsPerTimeSlot: true,
|
||||
seatsShowAttendees: true,
|
||||
seatsShowAvailabilityCount: true,
|
||||
periodType: true,
|
||||
hashedLink: true,
|
||||
webhooks: true,
|
||||
|
||||
@@ -206,6 +206,7 @@ export const deleteCredentialHandler = async ({ ctx, input }: DeleteCredentialOp
|
||||
bookingFields: true,
|
||||
seatsPerTimeSlot: true,
|
||||
seatsShowAttendees: true,
|
||||
seatsShowAvailabilityCount: true,
|
||||
eventName: true,
|
||||
},
|
||||
},
|
||||
@@ -295,6 +296,7 @@ export const deleteCredentialHandler = async ({ ctx, input }: DeleteCredentialOp
|
||||
cancellationReason: "Payment method removed by organizer",
|
||||
seatsPerTimeSlot: booking.eventType?.seatsPerTimeSlot,
|
||||
seatsShowAttendees: booking.eventType?.seatsShowAttendees,
|
||||
seatsShowAvailabilityCount: booking.eventType?.seatsShowAvailabilityCount,
|
||||
},
|
||||
{
|
||||
eventName: booking?.eventType?.eventName,
|
||||
|
||||
@@ -191,6 +191,7 @@ async function getBookings({
|
||||
currency: true,
|
||||
metadata: true,
|
||||
seatsShowAttendees: true,
|
||||
seatsShowAvailabilityCount: true,
|
||||
team: {
|
||||
select: {
|
||||
id: true,
|
||||
|
||||
Vendored
+1
@@ -177,6 +177,7 @@ export interface CalendarEvent {
|
||||
eventTypeId?: number | null;
|
||||
appsStatus?: AppsStatus[];
|
||||
seatsShowAttendees?: boolean | null;
|
||||
seatsShowAvailabilityCount?: boolean | null;
|
||||
attendeeSeatId?: string;
|
||||
seatsPerTimeSlot?: number | null;
|
||||
schedulingType?: SchedulingType | null;
|
||||
|
||||
Reference in new issue
Block a user