Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: locale and time format in attendee email #8941

Merged
merged 4 commits into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 9 additions & 5 deletions packages/emails/src/components/WhenInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import dayjs from "@calcom/dayjs";
// TODO: Use browser locale, implement Intl in Dayjs maybe?
import "@calcom/dayjs/locales";
import { getEveryFreqFor } from "@calcom/lib/recurringStrings";
import { TimeFormat } from "@calcom/lib/timeFormat";
import type { TimeFormat } from "@calcom/lib/timeFormat";
import type { CalendarEvent, Person } from "@calcom/types/Calendar";
import type { RecurringEvent } from "@calcom/types/Calendar";

Expand All @@ -31,10 +31,14 @@ export function getRecurringWhen({
return "";
}

export function WhenInfo(props: { calEvent: CalendarEvent; timeZone: string; t: TFunction }) {
const { timeZone, t, calEvent: { recurringEvent } = {} } = props;
const timeFormat = props.calEvent.organizer.timeFormat || TimeFormat.TWELVE_HOUR;
const locale = props.calEvent.organizer.language.locale;
export function WhenInfo(props: {
calEvent: CalendarEvent;
timeZone: string;
t: TFunction;
locale: string;
timeFormat: TimeFormat;
}) {
const { timeZone, t, calEvent: { recurringEvent } = {}, locale, timeFormat } = props;

function getRecipientStart(format: string) {
return dayjs(props.calEvent.startTime).tz(timeZone).locale(locale).format(format);
Expand Down
8 changes: 7 additions & 1 deletion packages/emails/src/templates/AttendeeScheduledEmail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ export const AttendeeScheduledEmail = (
} & Partial<React.ComponentProps<typeof BaseScheduledEmail>>
) => {
return (
<BaseScheduledEmail timeZone={props.attendee.timeZone} t={props.attendee.language.translate} {...props} />
<BaseScheduledEmail
locale={props.attendee.language.locale}
timeZone={props.attendee.timeZone}
t={props.attendee.language.translate}
timeFormat={props.attendee?.timeFormat}
{...props}
/>
);
};
9 changes: 7 additions & 2 deletions packages/emails/src/templates/BaseScheduledEmail.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { TFunction } from "next-i18next";

import dayjs from "@calcom/dayjs";
import { TimeFormat } from "@calcom/lib/timeFormat";
import type { CalendarEvent, Person } from "@calcom/types/Calendar";

import {
Expand All @@ -21,9 +22,13 @@ export const BaseScheduledEmail = (
timeZone: string;
includeAppsStatus?: boolean;
t: TFunction;
locale: string;
timeFormat: TimeFormat | undefined;
} & Partial<React.ComponentProps<typeof BaseEmailHtml>>
) => {
const { t, timeZone } = props;
const { t, timeZone, locale, timeFormat: timeFormat_ } = props;

const timeFormat = timeFormat_ ?? TimeFormat.TWELVE_HOUR;

function getRecipientStart(format: string) {
return dayjs(props.calEvent.startTime).tz(timeZone).format(format);
Expand Down Expand Up @@ -73,7 +78,7 @@ export const BaseScheduledEmail = (
)}
<Info label={t("rejection_reason")} description={props.calEvent.rejectionReason} withSpacer />
<Info label={t("what")} description={props.calEvent.title} withSpacer />
<WhenInfo calEvent={props.calEvent} t={t} timeZone={timeZone} />
<WhenInfo timeFormat={timeFormat} calEvent={props.calEvent} t={t} timeZone={timeZone} locale={locale} />
<WhoInfo calEvent={props.calEvent} t={t} />
<LocationInfo calEvent={props.calEvent} t={t} />
<Info label={t("description")} description={props.calEvent.description} withSpacer formatted />
Expand Down
10 changes: 9 additions & 1 deletion packages/emails/src/templates/BrokenIntegrationEmail.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TFunction } from "next-i18next";
import type { TFunction } from "next-i18next";
import { Trans } from "react-i18next";

import { AppStoreLocationType } from "@calcom/app-store/locations";
Expand Down Expand Up @@ -56,6 +56,8 @@ export const BrokenIntegrationEmail = (
) => {
const { calEvent, type } = props;
const t = calEvent.organizer.language.translate;
const locale = calEvent.organizer.language.locale;
const timeFormat = calEvent.organizer?.timeFormat;

if (type === "video") {
let location = calEvent.location ? getEnumKeyByEnumValue(AppStoreLocationType, calEvent.location) : " ";
Expand All @@ -70,6 +72,8 @@ export const BrokenIntegrationEmail = (
<BaseScheduledEmail
timeZone={calEvent.organizer.timeZone}
t={t}
timeFormat={timeFormat}
locale={locale}
subject={t("broken_integration")}
title={t("problem_adding_video_link")}
subtitle={<BrokenVideoIntegration location={location} eventTypeId={calEvent.eventTypeId} t={t} />}
Expand All @@ -94,6 +98,8 @@ export const BrokenIntegrationEmail = (
<BaseScheduledEmail
timeZone={calEvent.organizer.timeZone}
t={t}
timeFormat={timeFormat}
locale={locale}
subject={t("broken_integration")}
title={t("problem_updating_calendar")}
subtitle={<BrokenCalendarIntegration calendar={calendar} eventTypeId={calEvent.eventTypeId} t={t} />}
Expand All @@ -107,6 +113,8 @@ export const BrokenIntegrationEmail = (
<BaseScheduledEmail
timeZone={calEvent.organizer.timeZone}
t={t}
timeFormat={timeFormat}
locale={locale}
subject={t("broken_integration")}
title={t("problem_updating_calendar")}
headerType="xCircle"
Expand Down
4 changes: 4 additions & 0 deletions packages/emails/src/templates/NoShowFeeChargedEmail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@ export const NoShowFeeChargedEmail = (
) => {
const { calEvent } = props;
const t = props.attendee.language.translate;
const locale = props.attendee.language.locale;
const timeFormat = props.attendee?.timeFormat;

if (!calEvent.paymentInfo?.amount) throw new Error("No payment info");

return (
<BaseScheduledEmail
locale={locale}
title={t("no_show_fee_charged_text_body")}
headerType="calendarCircle"
timeFormat={timeFormat}
subtitle={
<>
{t("no_show_fee_charged_subtitle", {
Expand Down
5 changes: 5 additions & 0 deletions packages/emails/src/templates/OrganizerScheduledEmail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,18 @@ export const OrganizerScheduledEmail = (
}

const t = props.teamMember?.language.translate || props.calEvent.organizer.language.translate;
const locale = props.teamMember?.language.locale || props.calEvent.organizer.language.locale;
const timeFormat = props.teamMember?.timeFormat || props.calEvent.organizer?.timeFormat;

return (
<BaseScheduledEmail
locale={locale}
timeZone={props.teamMember?.timeZone || props.calEvent.organizer.timeZone}
t={t}
subject={t(subject)}
title={t(title)}
includeAppsStatus
timeFormat={timeFormat}
subtitle={
<>
{props.attendeeCancelled
Expand Down