From 1deca816bd18eb6fba0563633f02873bcc54c9a9 Mon Sep 17 00:00:00 2001 From: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com> Date: Tue, 13 Sep 2022 02:11:59 +0530 Subject: [PATCH] Feat/team owner booking (#3999) * WIP: testing queries * feat: add badge * fix: get only id * refactor: get bookings query * WIP: display attendees added * fix: add type --- .../components/booking/BookingListItem.tsx | 113 ++++++++++++++++-- packages/trpc/server/routers/viewer.tsx | 15 +++ 2 files changed, 120 insertions(+), 8 deletions(-) diff --git a/apps/web/components/booking/BookingListItem.tsx b/apps/web/components/booking/BookingListItem.tsx index 414a97b115..49b1c2035d 100644 --- a/apps/web/components/booking/BookingListItem.tsx +++ b/apps/web/components/booking/BookingListItem.tsx @@ -327,8 +327,14 @@ function BookingListItem(booking: BookingItemProps) { "max-w-56 truncate text-sm font-medium leading-6 text-neutral-900 md:max-w-max", isCancelled ? "line-through" : "" )}> - {booking.eventType?.team && {booking.eventType.team.name}: } {booking.title} + + {booking.eventType?.team && {booking.eventType.team.name}} + + {!!booking?.eventType?.price && !booking.paid && ( + Pending payment + )} + {isPending && {t("unconfirmed")}} {booking.description && (
)} - {booking.attendees.length !== 0 && ( - e.stopPropagation()}> - {booking.attendees[0].email} - + )} {isCancelled && booking.rescheduled && (
@@ -373,4 +377,97 @@ function BookingListItem(booking: BookingItemProps) { ); } +interface UserProps { + id: number; + name: string | null; + email: string; +} + +const FirstAttendee = ({ + user, + currentEmail, +}: { + user: UserProps; + currentEmail: string | null | undefined; +}) => { + return user.email === currentEmail ? ( +
You
+ ) : ( + e.stopPropagation()}> + {user.name} + + ); +}; + +const Attendee: React.FC<{ email: string; children: React.ReactNode }> = ({ email, children }) => { + return ( + e.stopPropagation()}> + {children} + + ); +}; + +interface AttendeeProps { + name: string; + email: string; +} + +const DisplayAttendees = ({ + attendees, + user, + currentEmail, +}: { + attendees: AttendeeProps[]; + user: UserProps | null; + currentEmail: string | null | undefined; +}) => { + if (attendees.length === 1) { + return ( +
+ {user && } +  and  + {attendees[0].name} +
+ ); + } else if (attendees.length === 2) { + return ( +
+ {user && } + + {attendees[0].name} +
 and 
+ {attendees[1].name} +
+ ); + } else { + return ( +
+ {user && } + + {attendees[0].name} +  &  + ( +

{attendee.name}

+ ))}> +
{attendees.length - 1} more
+
+
+ ); + } +}; + +const Tag = ({ children, className = "" }: React.PropsWithChildren<{ className?: string }>) => { + return ( + + {children} + + ); +}; + export default BookingListItem; diff --git a/packages/trpc/server/routers/viewer.tsx b/packages/trpc/server/routers/viewer.tsx index 5c39f9fe6c..de5be4a382 100644 --- a/packages/trpc/server/routers/viewer.tsx +++ b/packages/trpc/server/routers/viewer.tsx @@ -510,6 +510,7 @@ const loggedInViewerRouter = createProtectedRouter() }; const passedBookingsFilter = bookingListingFilters[bookingListingByStatus]; const orderBy = bookingListingOrderby[bookingListingByStatus]; + const bookingsQuery = await prisma.booking.findMany({ where: { OR: [ @@ -523,6 +524,18 @@ const loggedInViewerRouter = createProtectedRouter() }, }, }, + { + eventType: { + team: { + members: { + some: { + userId: user.id, + role: "OWNER", + }, + }, + }, + }, + }, ], AND: [passedBookingsFilter], }, @@ -550,6 +563,8 @@ const loggedInViewerRouter = createProtectedRouter() user: { select: { id: true, + name: true, + email: true, }, }, rescheduled: true,