fix: cal video recording email (#12079)

* fix: cal video recording email

* fix: add check for recording

* chore: remove logs

* chore: change message

---------

Co-authored-by: Peer Richelsen <peeroke@gmail.com>
This commit is contained in:
Udit Takkar 2023-10-31 22:05:23 +05:30 committed by GitHub
parent 0be1387d0f
commit 4d49fb0636
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 80 additions and 23 deletions

View File

@ -141,17 +141,6 @@ function BookingListItem(booking: BookingItemProps) {
: []), : []),
]; ];
const showRecordingActions: ActionType[] = [
{
id: "view_recordings",
label: t("view_recordings"),
onClick: () => {
setViewRecordingsDialogIsOpen(true);
},
disabled: mutation.isLoading,
},
];
let bookedActions: ActionType[] = [ let bookedActions: ActionType[] = [
{ {
id: "cancel", id: "cancel",
@ -270,11 +259,21 @@ function BookingListItem(booking: BookingItemProps) {
const bookingLink = buildBookingLink(); const bookingLink = buildBookingLink();
const title = booking.title; const title = booking.title;
// To be used after we run query on legacy bookings
// const showRecordingsButtons = booking.isRecorded && isPast && isConfirmed;
const showRecordingsButtons = const showRecordingsButtons = !!(booking.isRecorded && isPast && isConfirmed);
(booking.location === "integrations:daily" || booking?.location?.trim() === "") && isPast && isConfirmed; const checkForRecordingsButton =
!showRecordingsButtons && (booking.location === "integrations:daily" || booking?.location?.trim() === "");
const showRecordingActions: ActionType[] = [
{
id: checkForRecordingsButton ? "check_for_recordings" : "view_recordings",
label: checkForRecordingsButton ? t("check_for_recordings") : t("view_recordings"),
onClick: () => {
setViewRecordingsDialogIsOpen(true);
},
disabled: mutation.isLoading,
},
];
return ( return (
<> <>
@ -299,7 +298,7 @@ function BookingListItem(booking: BookingItemProps) {
paymentCurrency={booking.payment[0].currency} paymentCurrency={booking.payment[0].currency}
/> />
)} )}
{showRecordingsButtons && ( {(showRecordingsButtons || checkForRecordingsButton) && (
<ViewRecordingsDialog <ViewRecordingsDialog
booking={booking} booking={booking}
isOpenDialog={viewRecordingsDialogIsOpen} isOpenDialog={viewRecordingsDialogIsOpen}
@ -469,7 +468,9 @@ function BookingListItem(booking: BookingItemProps) {
</> </>
) : null} ) : null}
{isPast && isPending && !isConfirmed ? <TableActions actions={bookedActions} /> : null} {isPast && isPending && !isConfirmed ? <TableActions actions={bookedActions} /> : null}
{showRecordingsButtons && <TableActions actions={showRecordingActions} />} {(showRecordingsButtons || checkForRecordingsButton) && (
<TableActions actions={showRecordingActions} />
)}
{isCancelled && booking.rescheduled && ( {isCancelled && booking.rescheduled && (
<div className="hidden h-full items-center md:flex"> <div className="hidden h-full items-center md:flex">
<RequestSentMessage /> <RequestSentMessage />

View File

@ -62,6 +62,46 @@ const triggerWebhook = async ({
await Promise.all(promises); await Promise.all(promises);
}; };
const checkIfUserIsPartOfTheSameTeam = async (
teamId: number | undefined | null,
userId: number,
userEmail: string | undefined | null
) => {
if (!teamId) return false;
const getUserQuery = () => {
if (!!userEmail) {
return {
OR: [
{
id: userId,
},
{
email: userEmail,
},
],
};
} else {
return {
id: userId,
};
}
};
const team = await prisma.team.findFirst({
where: {
id: teamId,
members: {
some: {
user: getUserQuery(),
},
},
},
});
return !!team;
};
async function handler(req: NextApiRequest, res: NextApiResponse) { async function handler(req: NextApiRequest, res: NextApiResponse) {
if (!process.env.SENDGRID_API_KEY || !process.env.SENDGRID_EMAIL) { if (!process.env.SENDGRID_API_KEY || !process.env.SENDGRID_EMAIL) {
return res.status(405).json({ message: "No SendGrid API key or email" }); return res.status(405).json({ message: "No SendGrid API key or email" });
@ -137,12 +177,22 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
const isUserAttendeeOrOrganiser = const isUserAttendeeOrOrganiser =
booking?.user?.id === session.user.id || booking?.user?.id === session.user.id ||
attendeesList.find((attendee) => attendee.id === session.user.id); attendeesList.find(
(attendee) => attendee.id === session.user.id || attendee.email === session.user.email
);
if (!isUserAttendeeOrOrganiser) { if (!isUserAttendeeOrOrganiser) {
return res.status(403).send({ const isUserMemberOfTheTeam = checkIfUserIsPartOfTheSameTeam(
message: "Unauthorised", booking?.eventType?.teamId,
}); session.user.id,
session.user.email
);
if (!isUserMemberOfTheTeam) {
return res.status(403).send({
message: "Unauthorised",
});
}
} }
await prisma.booking.update({ await prisma.booking.update({
@ -202,7 +252,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
return res.status(403).json({ message: "User does not have team plan to send out emails" }); return res.status(403).json({ message: "User does not have team plan to send out emails" });
} catch (err) { } catch (err) {
console.warn("something_went_wrong", err); console.warn("Error in /recorded-daily-video", err);
return res.status(500).json({ message: "something went wrong" }); return res.status(500).json({ message: "something went wrong" });
} }
} }

View File

@ -1296,6 +1296,7 @@
"select_calendars": "Select which calendars you want to check for conflicts to prevent double bookings.", "select_calendars": "Select which calendars you want to check for conflicts to prevent double bookings.",
"check_for_conflicts": "Check for conflicts", "check_for_conflicts": "Check for conflicts",
"view_recordings": "View recordings", "view_recordings": "View recordings",
"check_for_recordings":"Check for recordings",
"adding_events_to": "Adding events to", "adding_events_to": "Adding events to",
"follow_system_preferences": "Follow system preferences", "follow_system_preferences": "Follow system preferences",
"custom_brand_colors": "Custom brand colors", "custom_brand_colors": "Custom brand colors",

View File

@ -50,8 +50,13 @@ export default class OrganizerDailyVideoDownloadRecordingEmail extends BaseEmail
return this.getFormattedRecipientTime({ time: this.calEvent.endTime, format }); return this.getFormattedRecipientTime({ time: this.calEvent.endTime, format });
} }
protected getLocale(): string {
return this.calEvent.organizer.language.locale;
}
protected getFormattedDate() { protected getFormattedDate() {
const organizerTimeFormat = this.calEvent.organizer.timeFormat || TimeFormat.TWELVE_HOUR; const organizerTimeFormat = this.calEvent.organizer.timeFormat || TimeFormat.TWELVE_HOUR;
return `${this.getOrganizerStart(organizerTimeFormat)} - ${this.getOrganizerEnd( return `${this.getOrganizerStart(organizerTimeFormat)} - ${this.getOrganizerEnd(
organizerTimeFormat organizerTimeFormat
)}, ${this.t(this.getOrganizerStart("dddd").toLowerCase())}, ${this.t( )}, ${this.t(this.getOrganizerStart("dddd").toLowerCase())}, ${this.t(

View File

@ -174,7 +174,7 @@ export const ViewRecordingsDialog = (props: IViewRecordingsDialog) => {
return ( return (
<Dialog open={isOpenDialog} onOpenChange={setIsOpenDialog}> <Dialog open={isOpenDialog} onOpenChange={setIsOpenDialog}>
<DialogContent> <DialogContent enableOverflow>
<DialogHeader title={t("recordings_title")} subtitle={subtitle} /> <DialogHeader title={t("recordings_title")} subtitle={subtitle} />
{roomName ? ( {roomName ? (
<LicenseRequired> <LicenseRequired>