feat: track no-shows in bookings (#15307)

* added dropdown for no-shows in past bookings

* added layout

* nit

* todo comment: figure out how to close dropdown

* more todo comments

* Adds TRPC route among other WIP

* functional update

* fixes type err

* fix type err

* fix: styles

* strikethrough in email

* NITs

* removed stale comment

* add tests

* err comment

---------

Co-authored-by: Peer Richelsen <[email protected]>
Co-authored-by: Peer Richelsen <[email protected]>
Co-authored-by: sean-brydon <[email protected]>
Co-authored-by: sean-brydon <[email protected]>
This commit is contained in:
authored and GitHub committed 2024-06-04 15:18:11 +00:00
1 parent 765d601ff9
commit 3a4ebadbf3
10 files changed
+419 -33

No files matched your search

@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "Attendee" ADD COLUMN "noShow" BOOLEAN DEFAULT false;
+1
View File
@@ -512,6 +512,7 @@ model Attendee {
booking Booking? @relation(fields: [bookingId], references: [id], onDelete: Cascade)
bookingId Int?
bookingSeat BookingSeat?
noShow Boolean? @default(false)
@@index([email])
@@index([bookingId])
@@ -1,3 +1,4 @@
import logger from "@calcom/lib/logger";
import { prisma } from "@calcom/prisma";
import type { TNoShowInputSchema } from "./noShow.schema";
@@ -7,15 +8,57 @@ type NoShowOptions = {
};
export const noShowHandler = async ({ input }: NoShowOptions) => {
const { bookingUid } = input;
await prisma.booking.update({
where: {
uid: bookingUid,
},
data: {
noShowHost: true,
},
});
const { bookingUid, attendees } = input;
try {
const attendeeEmails = attendees?.map((attendee) => attendee.email) || [];
if (attendees && attendeeEmails.length > 0) {
const allAttendees = await prisma.attendee.findMany({
where: {
AND: [
{
booking: {
uid: bookingUid,
},
email: {
in: attendeeEmails,
},
},
],
},
select: {
id: true,
email: true,
},
});
const updatePromises = attendees.map((attendee) => {
const attendeeToUpdate = allAttendees.find((a) => a.email === attendee.email);
if (attendeeToUpdate) {
return prisma.attendee.update({
where: { id: attendeeToUpdate.id },
data: { noShow: attendee.noShow },
});
}
});
await Promise.all(updatePromises);
} else {
await prisma.booking.update({
where: {
uid: bookingUid,
},
data: {
noShowHost: true,
},
});
}
} catch (error) {
if (error instanceof Error) {
logger.error(error.message);
}
}
};
export default noShowHandler;
@@ -2,6 +2,14 @@ import { z } from "zod";
export const ZNoShowInputSchema = z.object({
bookingUid: z.string(),
attendees: z
.array(
z.object({
email: z.string(),
noShow: z.boolean(),
})
)
.optional(),
});
export type TNoShowInputSchema = z.infer<typeof ZNoShowInputSchema>;
@@ -52,7 +52,7 @@ DropdownMenuContent.displayName = "DropdownMenuContent";
type DropdownMenuLabelProps = ComponentProps<(typeof DropdownMenuPrimitive)["Label"]>;
export const DropdownMenuLabel = (props: DropdownMenuLabelProps) => (
<DropdownMenuPrimitive.Label {...props} className="text-subtle px-3 py-2" />
<DropdownMenuPrimitive.Label {...props} className={classNames("text-subtle px-3 py-2", props.className)} />
);
type DropdownMenuItemProps = ComponentProps<(typeof DropdownMenuPrimitive)["CheckboxItem"]>;
@@ -71,12 +71,34 @@ export const DropdownMenuGroup = DropdownMenuPrimitive.Group;
type DropdownMenuCheckboxItemProps = ComponentProps<(typeof DropdownMenuPrimitive)["CheckboxItem"]>;
export const DropdownMenuCheckboxItem = forwardRef<HTMLDivElement, DropdownMenuCheckboxItemProps>(
({ children, ...props }, forwardedRef) => {
({ children, checked, onCheckedChange, ...props }, forwardedRef) => {
return (
<DropdownMenuPrimitive.CheckboxItem {...props} ref={forwardedRef} className="">
{children}
<DropdownMenuPrimitive.ItemIndicator>
<Icon name="circle-check" />
<DropdownMenuPrimitive.CheckboxItem
{...props}
checked={checked}
onCheckedChange={onCheckedChange}
ref={forwardedRef}
className="hover:text-emphasis text-default hover:bg-subtle flex flex-1 items-center space-x-2 px-3 py-2 hover:outline-none hover:ring-0 disabled:cursor-not-allowed">
<div className="w-full">{children}</div>
{!checked && (
<input
aria-disabled={true}
aria-label={typeof children === "string" ? `Not active ${children}` : undefined}
aria-readonly
checked={false}
type="checkbox"
className="text-emphasis dark:text-muted focus:ring-emphasis border-default bg-default ml-auto h-4 w-4 rounded hover:cursor-pointer"
/>
)}
<DropdownMenuPrimitive.ItemIndicator asChild>
<input
aria-disabled={true}
aria-readonly
aria-label={typeof children === "string" ? `Active ${children}` : undefined}
checked={true}
type="checkbox"
className="text-emphasis dark:text-muted focus:ring-emphasis border-default bg-default h-4 w-4 rounded hover:cursor-pointer"
/>
</DropdownMenuPrimitive.ItemIndicator>
</DropdownMenuPrimitive.CheckboxItem>
);
@@ -113,6 +135,7 @@ type DropdownItemProps = {
} & ButtonOrLinkProps;
type ButtonOrLinkProps = ComponentProps<"button"> & ComponentProps<"a">;
export function ButtonOrLink({ href, ...props }: ButtonOrLinkProps) {
const isLink = typeof href !== "undefined";
const ButtonOrLink = isLink ? "a" : "button";