Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.
TypeScript i18nextnext-authnextjspostgresqlprismareact-emailt3-stacktailwindcsstrpcturborepotypescriptzod
♻️ Refactor email templates to self-contained docs-style i18n (RAL-1217) (#2479)
Luke Vella2c62026e7f74
diff --git a/packages/emails/locales/en/emails.json b/packages/emails/locales/en/emails.jsonindex a1f0c54a3..309c6f521 100644--- a/packages/emails/locales/en/emails.json+++ b/packages/emails/locales/en/emails.json@@ -1,13 +1,4 @@{- "abandoned_checkout_button": "Upgrade to Rallly Pro",- "abandoned_checkout_content": "I noticed you were checking out <b>Rallly Pro</b> earlier. I wanted to reach out to see if you had any questions or needed help with anything.",- "abandoned_checkout_name": "Hey {name},",- "abandoned_checkout_noname": "Hey there,",- "abandoned_checkout_offer": "To help you get started, you can get <b>{discount}% off</b> your first year. Just use the code below when you check out:",- "abandoned_checkout_preview": "Exclusive offer: Get {discount}% off your first year of Rallly Pro!",- "abandoned_checkout_signoff": "Best regards,",- "abandoned_checkout_subject": "Get {discount}% off your first year of Rallly Pro",- "abandoned_checkout_support": "If you have any questions about Rallly Pro or need help with anything at all, just reply to this email. I'm here to help!","changeEmail_codeValid": "This code is valid for 15 minutes","changeEmail_content2": "You're receiving this email because a request was made to change the email address of an account on <domain />. If this wasn't you contact <a>{supportEmail}</a>.","changeEmail_heading": "Verify your new email address",@@ -27,6 +18,7 @@"finalizeHost_heading": "Final date booked!","finalizeHost_preview": "Final date booked! We've notified participants and sent them calendar invites.","finalizeHost_subject": "Date booked for {title}",+ "finalizeParticipant_button": "View Event","finalizeParticipant_content": "<b>{hostName}</b> has booked <b>{title}</b> for the following date:","finalizeParticipant_content2": "Please find attached a calendar invite for this event.","finalizeParticipant_heading": "Final date booked!",@@ -34,6 +26,7 @@"finalizeParticipant_subject": "Date booked for {title}","license_key_activationSteps": "Follow these <a>instructions</a> to activate your license on your Rallly Self-Hosted instance.","license_key_content": "Your purchase has been confirmed and your license key has been generated.",+ "license_key_heading": "License confirmation","license_key_licenseKey": "License Key","license_key_nextStepsHeading": "Next Steps","license_key_plan": "Plan",diff --git a/packages/emails/package.json b/packages/emails/package.jsonindex 263caf700..5287d7453 100644--- a/packages/emails/package.json+++ b/packages/emails/package.json@@ -3,7 +3,7 @@"version": "0.0.0","private": true,"scripts": {- "dev": "email dev --dir ./src/previews",+ "dev": "email dev --dir ./src/templates","type-check": "tsc --pretty --noEmit","i18n:scan": "i18next-cli extract"},diff --git a/packages/emails/src/chrome.ts b/packages/emails/src/chrome.tsnew file mode 100644index 000000000..40b854479--- /dev/null+++ b/packages/emails/src/chrome.ts@@ -0,0 +1,17 @@+import { absoluteUrl } from "@rallly/utils/absolute-url";++import type { EmailBranding, EmailChrome } from "./types";++/**+ * Resolves the caller's branding plus deployment env constants (base URL,+ * domain, support email) into the `chrome` an email template renders with.+ */+export function resolveChrome(branding: EmailBranding): EmailChrome {+ const url = absoluteUrl();+ return {+ ...branding,+ baseUrl: url,+ domain: url.replace(/(^\w+:|^)\/\//, ""),+ supportEmail: process.env.SUPPORT_EMAIL ?? "",+ };+}diff --git a/packages/emails/src/components/email-context.tsx b/packages/emails/src/components/email-context.tsxdeleted file mode 100644index 5c8f69a33..000000000--- a/packages/emails/src/components/email-context.tsx+++ /dev/null@@ -1,24 +0,0 @@-import { i18nDefaultConfig, i18nInstance } from "../i18n";-import type { EmailContext } from "../types";--i18nInstance.init({- ...i18nDefaultConfig,- initAsync: true,-});--export const previewEmailContext: EmailContext = {- logoUrl: "https://d39ixtfgglw55o.cloudfront.net/images/rallly-logo-mark.png",- baseUrl: "https://rallly.co",- domain: "rallly.co",- supportEmail: "[email protected]",- i18n: i18nInstance,- t: i18nInstance.getFixedT("en"),- appName: "Rallly",- primaryColor: "#4f46e5",- hideAttribution: false,- i18nProps: {- i18n: i18nInstance,- t: i18nInstance.getFixedT("en"),- ns: "emails",- },-};diff --git a/packages/emails/src/components/email-layout.tsx b/packages/emails/src/components/email-layout.tsxdeleted file mode 100644index 5f8b93691..000000000--- a/packages/emails/src/components/email-layout.tsx+++ /dev/null@@ -1,78 +0,0 @@-import {- Body,- Container,- Head,- Html,- Img,- Preview,- Section,-} from "@react-email/components";-import { Trans } from "react-i18next/TransWithoutContext";--import type { EmailContext } from "../types";-import { darkTextColor, fontFamily, Link, Text } from "./styled-components";--export interface EmailLayoutProps {- preview: string;- ctx: EmailContext;- poweredBy?: boolean;-}--const containerStyles = {- maxWidth: "480px",- margin: "0 auto",- background: "white",- fontFamily,- padding: "32px 8px",- color: darkTextColor,-};--export const EmailLayout = ({- preview,- children,- ctx,- poweredBy = true,-}: React.PropsWithChildren<EmailLayoutProps>) => {- const { logoUrl } = ctx;- const shouldShowPoweredBy = poweredBy && !ctx.hideAttribution;- return (- <Html>- <Head />- <Preview>{preview}</Preview>- <Body style={{ backgroundColor: "#FFFFFF" }}>- <Container style={containerStyles}>- <Img- src={logoUrl}- height="42"- style={{- marginBottom: 32,- borderRadius: 6,- }}- alt={ctx.appName}- />- {children}- {shouldShowPoweredBy ? (- <Section>- <Text light={true}>- <Trans- {...ctx.i18nProps}- i18nKey="common_poweredBy"- defaults="Powered by <a>{domain}</a>"- values={{ domain: "rallly.co" }}- components={{- a: (- <Link- color={ctx.primaryColor}- href="https://rallly.co?utm_source=email&utm_medium=transactional"- />- ),- }}- />- </Text>- </Section>- ) : null}- </Container>- </Body>- </Html>- );-};diff --git a/packages/emails/src/components/notification-email.tsx b/packages/emails/src/components/notification-email.tsxdeleted file mode 100644index 17bc808a9..000000000--- a/packages/emails/src/components/notification-email.tsx+++ /dev/null@@ -1,59 +0,0 @@-import { Section } from "@react-email/components";-import { Trans } from "react-i18next/TransWithoutContext";--import type { EmailContext } from "../types";-import { EmailLayout } from "./email-layout";-import { Button, Link, Text } from "./styled-components";--export interface NotificationBaseProps {- title: string;- pollUrl: string;- disableNotificationsUrl: string;- ctx: EmailContext;-}--export interface NotificationEmailProps extends NotificationBaseProps {- preview: string;-}--export const NotificationEmail = ({- pollUrl,- disableNotificationsUrl,- preview,- children,- ctx,-}: React.PropsWithChildren<NotificationEmailProps>) => {- const { domain } = ctx;- return (- <EmailLayout ctx={ctx} preview={preview}>- {children}- <Section style={{ marginTop: 32, marginBottom: 32 }}>- <Button href={pollUrl} color={ctx.primaryColor}>- {ctx.t("common_viewOn", {- ns: "emails",- defaultValue: "View on {domain}",- domain,- })}- </Button>- </Section>- <Text light={true}>- <Trans- {...ctx.i18nProps}- i18nKey="common_disableNotifications"- defaults="You can <a>manage your notification settings</a> to stop receiving these emails."- components={{- a: (- <Link- color={ctx.primaryColor}- className="whitespace-nowrap"- href={disableNotificationsUrl}- />- ),- }}- />- </Text>- </EmailLayout>- );-};--export default NotificationEmail;diff --git a/packages/emails/src/components/powered-by.tsx b/packages/emails/src/components/powered-by.tsxnew file mode 100644index 000000000..f6a8dc120--- /dev/null+++ b/packages/emails/src/components/powered-by.tsx@@ -0,0 +1,40 @@+import { Trans } from "react-i18next/TransWithoutContext";++import { createEmailI18n } from "../i18n";+import type { EmailChrome } from "../types";+import { Link, Text } from "./styled-components";++export async function PoweredBy({+ chrome,+ locale = "en",+}: {+ chrome: EmailChrome;+ locale?: string;+}) {+ if (chrome.hideAttribution) {+ return null;+ }++ const { t, i18n } = await createEmailI18n(locale);++ return (+ <Text small light={true}>+ <Trans+ t={t}+ i18n={i18n}+ ns="emails"+ i18nKey="common_poweredBy"+ defaults="Powered by <a>{domain}</a>"+ values={{ domain: "Rallly" }}+ components={{+ a: (+ <Link+ color={chrome.primaryColor}+ href="https://rallly.co?utm_source=email&utm_medium=transactional"+ />+ ),+ }}+ />+ </Text>+ );+}diff --git a/packages/emails/src/components/preview-chrome.ts b/packages/emails/src/components/preview-chrome.tsnew file mode 100644index 000000000..f5045ffbc--- /dev/null+++ b/packages/emails/src/components/preview-chrome.ts@@ -0,0 +1,15 @@+import type { EmailChrome } from "../types";++/**+ * Sample branding/env used by the react-email preview server (`pnpm dev`).+ * Real sends build `chrome` from the caller's branding + env via `resolveChrome`.+ */+export const previewChrome: EmailChrome = {+ logoUrl: "https://d39ixtfgglw55o.cloudfront.net/images/rallly-logo-mark.png",+ baseUrl: "https://rallly.co",+ domain: "rallly.co",+ supportEmail: "[email protected]",+ appName: "Rallly",+ primaryColor: "#4f46e5",+ hideAttribution: false,+};diff --git a/packages/emails/src/components/styled-components.tsx b/packages/emails/src/components/styled-components.tsxindex 344c07976..67e5c6435 100644--- a/packages/emails/src/components/styled-components.tsx+++ b/packages/emails/src/components/styled-components.tsx@@ -4,14 +4,16 @@ import type {TextProps,} from "@react-email/components";import {+ Body as UnstyledBody,Button as UnstyledButton,+ Container as UnstyledContainer,Heading as UnstyledHeading,Link as UnstyledLink,Section as UnstyledSection,Text as UnstyledText,} from "@react-email/components";-import type { EmailContext } from "../types";+import type { EmailChrome } from "../types";export const lightTextColor = "#4B5563";export const darkTextColor = "#1F2937";@@ -36,11 +38,10 @@ export const Text = ();};-export const Domain = ({ ctx }: { ctx: EmailContext }) => {- const { baseUrl, domain } = ctx;+export const Domain = ({ chrome }: { chrome: EmailChrome }) => {return (- <Link color={ctx.primaryColor} href={baseUrl}>- {domain}+ <Link color={chrome.primaryColor} href={chrome.baseUrl}>+ {chrome.domain}</Link>);};@@ -57,12 +58,11 @@ export const Button = (borderRadius: "6px",padding: "14px",fontFamily,+ minWidth: "200px",boxSizing: "border-box",- display: "block",- width: "100%",- maxWidth: "100%",textAlign: "center",- fontSize: "14px",+ margin: "0 auto",+ fontSize: "16px",fontWeight: "bold",color: "white",}}@@ -74,14 +74,18 @@ export const Link = (props: LinkProps & { color?: string }) => {return (<UnstyledLink{...props}- style={{ color: props.color ?? "#4F46E5", fontFamily, ...props.style }}+ style={{+ color: props.color ?? "#4F46E5",+ fontFamily,+ ...props.style,+ }}/>);};const fontSize = {h1: "20px",- h2: "18px",+ h2: "16px",h3: "16px",h4: "16px",h5: "14px",@@ -99,6 +103,7 @@ export const Heading = (as={as}style={{fontSize: fontSize[as],+ fontWeight: "bold",...props.style,}}/>@@ -194,3 +199,31 @@ export const trackingWide = {export const fontFamily ="'Inter UI', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Helvetica Neue', sans-serif";++export const Body = (props: React.ComponentProps<typeof UnstyledBody>) => {+ return (+ <UnstyledBody+ {...props}+ style={{ backgroundColor: "#FFFFFF", ...props.style }}+ />+ );+};++export const Container = (+ props: React.ComponentProps<typeof UnstyledContainer>,+) => {+ return (+ <UnstyledContainer+ {...props}+ style={{+ maxWidth: "480px",+ margin: "0 auto",+ background: "white",+ fontFamily,+ padding: "32px 8px",+ color: darkTextColor,+ ...props.style,+ }}+ />+ );+};diff --git a/packages/emails/src/create-email-template.tsx b/packages/emails/src/create-email-template.tsxdeleted file mode 100644index e93a0f7c1..000000000--- a/packages/emails/src/create-email-template.tsx+++ /dev/null@@ -1,62 +0,0 @@-import { absoluteUrl } from "@rallly/utils/absolute-url";--import { createEmailI18n } from "./i18n";-import type { EmailAttachments, IcalEvent } from "./send";-import { sendEmail } from "./send";-import type { EmailBranding, EmailContext } from "./types";--type From = { name: string; address: string };--type TemplateProps<C> = C extends (props: infer P) => React.ReactNode- ? Omit<P, "ctx">- : never;--type SendArgs<C> = {- to: string;- locale?: string;- branding: EmailBranding;- props: TemplateProps<C>;- from?: From;- attachments?: EmailAttachments;- icalEvent?: IcalEvent;-};--/**- * Defines a sendable email from a template component + subject. Returns a single- * `send` function: the caller passes `branding` (instance or space) and `props`,- * and the package resolves env constants, assembles i18n, renders, and dispatches.- * No awareness of react-email/nodemailer/i18n leaks to callers.- */-export function createEmailTemplate<- C extends (props: never) => React.ReactNode,->(definition: {- component: C;- subject: (props: TemplateProps<C>, ctx: EmailContext) => string;-}) {- return async function send(args: SendArgs<C>) {- const url = absoluteUrl();- const { i18n, t } = await createEmailI18n(args.locale ?? "en");- const ctx: EmailContext = {- ...args.branding,- baseUrl: url,- domain: url.replace(/(^\w+:|^)\/\//, ""),- supportEmail: process.env.SUPPORT_EMAIL ?? "",- i18n,- t,- i18nProps: { i18n, t, ns: "emails" },- };-- return sendEmail({- to: args.to,- component: definition.component as unknown as (- props: TemplateProps<C> & { ctx: EmailContext },- ) => React.ReactNode,- props: args.props,- ctx,- subject: definition.subject(args.props, ctx),- from: args.from,- attachments: args.attachments,- icalEvent: args.icalEvent,- });- };-}diff --git a/packages/emails/src/i18n.ts b/packages/emails/src/i18n.tsindex a3d40eae2..ee2866218 100644--- a/packages/emails/src/i18n.ts+++ b/packages/emails/src/i18n.ts@@ -4,18 +4,6 @@ import ICU from "i18next-icu";import resourcesToBackend from "i18next-resources-to-backend";import { initReactI18next } from "react-i18next/initReactI18next";-const i18nInstance = createInstance();--i18nInstance- .use(initReactI18next)- .use(ICU)- .use(- resourcesToBackend(- (language: string, namespace: string) =>- import(`../locales/${language}/${namespace}.json`),- ),- );-const i18nDefaultConfig: InitOptions = {lng: "en",fallbackLng: "en",@@ -24,18 +12,28 @@ const i18nDefaultConfig: InitOptions = {defaultNS: "emails",} as const;-export type I18nInstance = typeof i18nInstance;-/**- * Initialises the email i18n instance for `locale` and returns the instance- * plus a locale-pinned `t`. `getFixedT(locale)` is concurrency-safe even though- * the instance is shared — it captures the locale regardless of the instance's- * current `language`. (Whether to swap the shared singleton for a per-send- * `createInstance()` is tracked in RAL-1219.)+ * Builds a fresh, locale-bound i18n instance for a single email render and+ * returns it with a locale-pinned `t`. Each email calls this with its `locale`+ * prop and localizes with `t(...)`; pass `t` + `i18n` to `<Trans>` (from+ * react-i18next/TransWithoutContext) for the few strings with inline markup.+ *+ * A fresh per-render instance (not a shared singleton) keeps `i18n.language`+ * correct under a concurrent fan-out, and TransWithoutContext keeps it free of+ * React context, which Next disallows in the server components that send email.*/export async function createEmailI18n(locale: string) {- await i18nInstance.init({ ...i18nDefaultConfig, lng: locale });- return { i18n: i18nInstance, t: i18nInstance.getFixedT(locale) };-}+ const i18n = createInstance();+ await i18n+ .use(ICU)+ .use(+ resourcesToBackend(+ (language: string, namespace: string) =>+ import(`../locales/${language}/${namespace}.json`),+ ),+ )+ .use(initReactI18next)+ .init({ ...i18nDefaultConfig, lng: locale });-export { i18nDefaultConfig, i18nInstance };+ return { i18n, t: i18n.getFixedT(locale, "emails") };+}diff --git a/packages/emails/src/previews/abandoned-checkout.tsx b/packages/emails/src/previews/abandoned-checkout.tsxdeleted file mode 100644index bc4315c6b..000000000--- a/packages/emails/src/previews/abandoned-checkout.tsx+++ /dev/null@@ -1,14 +0,0 @@-import { previewEmailContext } from "../components/email-context";-import { AbandonedCheckoutEmail } from "../templates/abandoned-checkout";--export default function AbandonedCheckoutEmailPreview() {- return (- <AbandonedCheckoutEmail- ctx={previewEmailContext}- discount={20}- couponCode="GETPRO1Y20"- recoveryUrl="https://example.com"- name="John Doe"- />- );-}diff --git a/packages/emails/src/previews/change-email.tsx b/packages/emails/src/previews/change-email.tsxdeleted file mode 100644index b47c68d7d..000000000--- a/packages/emails/src/previews/change-email.tsx+++ /dev/null@@ -1,6 +0,0 @@-import { previewEmailContext } from "../components/email-context";-import { ChangeEmailEmail } from "../templates/change-email";--export default function ChangeEmailEmailPreview() {- return <ChangeEmailEmail code="123456" ctx={previewEmailContext} />;-}diff --git a/packages/emails/src/previews/event-canceled.tsx b/packages/emails/src/previews/event-canceled.tsxdeleted file mode 100644index f6650fd9d..000000000--- a/packages/emails/src/previews/event-canceled.tsx+++ /dev/null@@ -1,16 +0,0 @@-import { previewEmailContext } from "../components/email-context";-import { EventCanceledEmail } from "../templates/event-canceled";--export default function EventCanceledPreview() {- return (- <EventCanceledEmail- title="Untitled Poll"- hostName="Host"- day="12"- dow="Fri"- date="Friday, 12th June 2020"- time="6:00 PM to 11:00 PM BST"- ctx={previewEmailContext}- />- );-}diff --git a/packages/emails/src/previews/finalized-host.tsx b/packages/emails/src/previews/finalized-host.tsxdeleted file mode 100644index b4d436fe4..000000000--- a/packages/emails/src/previews/finalized-host.tsx+++ /dev/null@@ -1,19 +0,0 @@-import { previewEmailContext } from "../components/email-context";-import { FinalizeHostEmail } from "../templates/finalized-host";--export default function FinalizedHostPreview() {- return (- <FinalizeHostEmail- name="John Doe"- location="Zoom"- attendees={["[email protected]", "[email protected]"]}- title="Untitled Poll"- pollUrl="https://rallly.co"- day="12"- dow="Fri"- date="Friday, 12th June 2020"- time="6:00 PM to 11:00 PM BST"- ctx={previewEmailContext}- />- );-}diff --git a/packages/emails/src/previews/finalized-participant.tsx b/packages/emails/src/previews/finalized-participant.tsxdeleted file mode 100644index 96e930878..000000000--- a/packages/emails/src/previews/finalized-participant.tsx+++ /dev/null@@ -1,17 +0,0 @@-import { previewEmailContext } from "../components/email-context";-import { FinalizeParticipantEmail } from "../templates/finalized-participant";--export default function FinalizedParticipantPreview() {- return (- <FinalizeParticipantEmail- title="Untitled Poll"- hostName="Host"- pollUrl="https://rallly.co"- day="12"- dow="Fri"- date="Friday, 12th June 2020"- time="6:00 PM to 11:00 PM BST"- ctx={previewEmailContext}- />- );-}diff --git a/packages/emails/src/previews/license-key.tsx b/packages/emails/src/previews/license-key.tsxdeleted file mode 100644index d865e0cd0..000000000--- a/packages/emails/src/previews/license-key.tsx+++ /dev/null@@ -1,13 +0,0 @@-import { previewEmailContext } from "../components/email-context";-import { LicenseKeyEmail } from "../templates/license-key";--export default function LicenseKeyPreview() {- return (- <LicenseKeyEmail- licenseKey="RLYV4-ABCD-1234-ABCD-1234-XXXX"- tier="PLUS"- seats={5}- ctx={previewEmailContext}- />- );-}diff --git a/packages/emails/src/previews/new-comment.tsx b/packages/emails/src/previews/new-comment.tsxdeleted file mode 100644index 75b99b986..000000000--- a/packages/emails/src/previews/new-comment.tsx+++ /dev/null@@ -1,16 +0,0 @@-import { previewEmailContext } from "../components/email-context";-import { NewCommentEmail } from "../templates/new-comment";--function NewCommentEmailPreview() {- return (- <NewCommentEmail- title="Untitled Poll"- authorName="Someone"- pollUrl="https://rallly.co"- disableNotificationsUrl="https://rallly.co"- ctx={previewEmailContext}- />- );-}--export default NewCommentEmailPreview;diff --git a/packages/emails/src/previews/new-participant-confirmation.tsx b/packages/emails/src/previews/new-participant-confirmation.tsxdeleted file mode 100644index 7da58a59f..000000000--- a/packages/emails/src/previews/new-participant-confirmation.tsx+++ /dev/null@@ -1,12 +0,0 @@-import { previewEmailContext } from "../components/email-context";-import { NewParticipantConfirmationEmail } from "../templates/new-participant-confirmation";--export default function NewParticipantConfirmationPreview() {- return (- <NewParticipantConfirmationEmail- title="Untitled Poll"- editSubmissionUrl="https://rallly.co"- ctx={previewEmailContext}- />- );-}diff --git a/packages/emails/src/previews/new-participant.tsx b/packages/emails/src/previews/new-participant.tsxdeleted file mode 100644index c5c246b87..000000000--- a/packages/emails/src/previews/new-participant.tsx+++ /dev/null@@ -1,14 +0,0 @@-import { previewEmailContext } from "../components/email-context";-import { NewParticipantEmail } from "../templates/new-participant";--export default function NewParticipantPreview() {- return (- <NewParticipantEmail- participantName="John Doe"- title="Untitled Poll"- pollUrl="https://rallly.co"- disableNotificationsUrl="https://rallly.co"- ctx={previewEmailContext}- />- );-}diff --git a/packages/emails/src/previews/new-poll.tsx b/packages/emails/src/previews/new-poll.tsxdeleted file mode 100644index 0f7656675..000000000--- a/packages/emails/src/previews/new-poll.tsx+++ /dev/null@@ -1,14 +0,0 @@-import { previewEmailContext } from "../components/email-context";-import { NewPollEmail } from "../templates/new-poll";--export default function NewPollPreview() {- return (- <NewPollEmail- title="Untitled Poll"- name="John Doe"- adminLink="https://rallly.co"- participantLink="https://rallly.co/invite/abc123"- ctx={previewEmailContext}- />- );-}diff --git a/packages/emails/src/previews/register.tsx b/packages/emails/src/previews/register.tsxdeleted file mode 100644index 258584ccf..000000000--- a/packages/emails/src/previews/register.tsx+++ /dev/null@@ -1,6 +0,0 @@-import { previewEmailContext } from "../components/email-context";-import { RegisterEmail } from "../templates/register";--export default function RegisterEmailPreview() {- return <RegisterEmail code="123456" ctx={previewEmailContext} />;-}diff --git a/packages/emails/src/previews/space-invite.tsx b/packages/emails/src/previews/space-invite.tsxdeleted file mode 100644index fd67bc817..000000000--- a/packages/emails/src/previews/space-invite.tsx+++ /dev/null@@ -1,14 +0,0 @@-import { previewEmailContext } from "../components/email-context";-import { SpaceInviteEmail } from "../templates/space-invite";--export default function SpaceInvitePreview() {- return (- <SpaceInviteEmail- spaceName="Marketing Team"- inviterName="John Smith"- spaceRole="member"- inviteUrl="https://rallly.co/invite/abc123"- ctx={previewEmailContext}- />- );-}diff --git a/packages/emails/src/previews/static/logo.png b/packages/emails/src/previews/static/logo.pngdeleted file mode 100644index 905aad7be..000000000Binary files a/packages/emails/src/previews/static/logo.png and /dev/null differdiff --git a/packages/emails/src/send.tsx b/packages/emails/src/send.tsxindex ae27c1042..8ece0213d 100644--- a/packages/emails/src/send.tsx+++ b/packages/emails/src/send.tsx@@ -3,7 +3,7 @@ import { render } from "@react-email/render";import type Mail from "nodemailer/lib/mailer";import { getTransport } from "./transport";-import type { EmailContext } from "./types";+import type { EmailBranding } from "./types";const logger = createLogger("emails");@@ -11,6 +11,17 @@ export type EmailAttachments = Mail.Options["attachments"];export type IcalEvent = Mail.Options["icalEvent"];type From = { name: string; address: string };+/** Args every `sendXEmail(...)` accepts. `props` are the template's own fields. */+export type SendArgs<P> = {+ to: string;+ locale?: string;+ branding: EmailBranding;+ props: Omit<P, "locale" | "chrome">;+ from?: From;+ attachments?: EmailAttachments;+ icalEvent?: IcalEvent;+};+function resolveFrom(from?: From): From {return (from ?? {@@ -61,27 +72,20 @@ async function dispatch(options: DispatchOptions) {}/**- * Internal: render a template component to html + plain text and dispatch.- * Used by `createEmailTemplate` — not part of the public API.+ * Renders a ready-built React element to html + plain text and dispatches.+ * Each template's `sendXEmail` builds its element (and subject) then calls this.*/-export async function sendEmail<P extends object>(options: {+export async function sendRenderedEmail(options: {to: string;- component: (props: P & { ctx: EmailContext }) => React.ReactNode;- props: P;- ctx: EmailContext;+ element: React.ReactNode;subject: string;from?: From;attachments?: EmailAttachments;icalEvent?: IcalEvent;}) {- const Component = options.component as unknown as (- props: P & { ctx: EmailContext },- ) => React.ReactNode;- const element = <Component {...options.props} ctx={options.ctx} />;-const [html, text] = await Promise.all([- render(element),- render(element, { plainText: true }),+ render(options.element),+ render(options.element, { plainText: true }),]);await dispatch({diff --git a/packages/emails/src/templates/abandoned-checkout.tsx b/packages/emails/src/templates/abandoned-checkout.tsxdeleted file mode 100644index f402644c6..000000000--- a/packages/emails/src/templates/abandoned-checkout.tsx+++ /dev/null@@ -1,129 +0,0 @@-import { Section } from "@react-email/components";-import { Trans } from "react-i18next/TransWithoutContext";--import { EmailLayout } from "../components/email-layout";-import { Button, Card, Signature, Text } from "../components/styled-components";-import type { EmailContext } from "../types";--interface AbandonedCheckoutEmailProps {- recoveryUrl: string;- discount: number;- couponCode: string;- name?: string;- ctx: EmailContext;-}--export const AbandonedCheckoutEmail = ({- recoveryUrl,- discount,- couponCode,- name,- ctx,-}: AbandonedCheckoutEmailProps) => {- return (- <EmailLayout- ctx={ctx}- poweredBy={false}- preview={ctx.t("abandoned_checkout_preview", {- defaultValue:- "Exclusive offer: Get {discount}% off your first year of Rallly Pro!",- discount,- ns: "emails",- })}- >- {name ? (- <Text>- <Trans- {...ctx.i18nProps}- i18nKey="abandoned_checkout_name"- defaults="Hey {name},"- values={{ name }}- />- </Text>- ) : (- <Text>- <Trans- {...ctx.i18nProps}- i18nKey="abandoned_checkout_noname"- defaults="Hey there,"- />- </Text>- )}- <Text>- <Trans- {...ctx.i18nProps}- i18nKey="abandoned_checkout_content"- defaults="I noticed you were exploring <b>Rallly Pro</b> and wanted to personally reach out. I'd love to hear what features caught your interest and answer any questions you might have."- components={{- b: <b />,- }}- />- </Text>- <Text>- <Trans- {...ctx.i18nProps}- i18nKey="abandoned_checkout_offer"- defaults="To help you get started, I'd like to offer you <b>{discount}% off your first year</b> with Rallly Pro. Simply use this code during checkout:"- values={{- discount,- }}- components={{- b: <b />,- }}- />- </Text>- <Section style={{ marginTop: 16, marginBottom: 16 }}>- <Card>- <Text- style={{- textAlign: "center",- fontFamily: "monospace",- fontWeight: "bold",- }}- >- {couponCode}- </Text>- </Card>- <Button href={recoveryUrl} id="recoveryUrl" color={ctx.primaryColor}>- <Trans- {...ctx.i18nProps}- i18nKey="abandoned_checkout_button"- defaults="Upgrade to Rallly Pro"- />- </Button>- </Section>- <Section>- <Text>- <Trans- {...ctx.i18nProps}- i18nKey="abandoned_checkout_support"- defaults="Have questions or need assistance? Just reply to this email."- />- </Text>- </Section>- <Section>- <Text>- <Trans- {...ctx.i18nProps}- i18nKey="abandoned_checkout_signoff"- defaults="Best regards,"- />- </Text>- </Section>- <Signature />- </EmailLayout>- );-};--AbandonedCheckoutEmail.getSubject = (- props: AbandonedCheckoutEmailProps,- ctx: EmailContext,-) => {- return `🎉 ${ctx.t("abandoned_checkout_subject", {- defaultValue: "Get {discount}% off your first year of Rallly Pro",- discount: props.discount,- ns: "emails",- })}`;-};--export default AbandonedCheckoutEmail;diff --git a/packages/emails/src/templates/change-email.tsx b/packages/emails/src/templates/change-email.tsxindex eddc22586..9edcd3c1f 100644--- a/packages/emails/src/templates/change-email.tsx+++ b/packages/emails/src/templates/change-email.tsx@@ -1,93 +1,136 @@-import { Section } from "@react-email/components";+import { Head, Hr, Html, Img, Preview } from "@react-email/components";import { Trans } from "react-i18next/TransWithoutContext";-import { EmailLayout } from "../components/email-layout";+import { resolveChrome } from "../chrome";+import { PoweredBy } from "../components/powered-by";+import { previewChrome } from "../components/preview-chrome";import {- Card,- Domain,+ Body,+ Container,Heading,Link,Text,trackingWide,} from "../components/styled-components";-import { createEmailTemplate } from "../create-email-template";-import type { EmailContext } from "../types";+import { createEmailI18n } from "../i18n";+import type { SendArgs } from "../send";+import { sendRenderedEmail } from "../send";+import type { EmailChrome } from "../types";-interface ChangeEmailEmailProps {+type ChangeEmailEmailProps = {+ locale?: string;+ chrome: EmailChrome;code: string;- ctx: EmailContext;-}+};-export const ChangeEmailEmail = ({ code, ctx }: ChangeEmailEmailProps) => {+async function ChangeEmailEmail({+ code,+ locale = "en",+ chrome,+}: ChangeEmailEmailProps) {+ const { t, i18n } = await createEmailI18n(locale);return (- <EmailLayout- ctx={ctx}- preview={ctx.t("changeEmail_preview", {- ns: "emails",- defaultValue: "Your 6-digit code is: {code}",- code,- })}- >- <Heading>- {ctx.t("changeEmail_heading", {- defaultValue: "Verify your new email address",- ns: "emails",- })}- </Heading>- <Text>- {ctx.t("changeEmail_text", {- defaultValue:- "Please use the following 6-digit verification code to confirm your new email address",- ns: "emails",+ <Html>+ <Head />+ <Preview>+ {t("changeEmail_preview", {+ defaultValue: "Your 6-digit code is: {code}",+ code,})}- </Text>- <Card style={{ textAlign: "center" }}>- <Text- style={{- ...trackingWide,- textAlign: "center",- fontSize: "32px",- fontWeight: "bold",- }}- id="code"- >- {code}- </Text>- <Text style={{ textAlign: "center" }} light={true}>- {ctx.t("changeEmail_codeValid", {- defaultValue: "This code is valid for 15 minutes",- ns: "emails",- })}- </Text>- </Card>- <Section>- <Text light={true}>- <Trans- {...ctx.i18nProps}- i18nKey="changeEmail_content2"- defaults="You're receiving this email because a request was made to change the email address of an account on <domain />. If this wasn't you contact <a>{supportEmail}</a>."- values={{ supportEmail: ctx.supportEmail }}- components={{- domain: <Domain ctx={ctx} />,- a: (- <Link- color={ctx.primaryColor}- href={`mailto:${ctx.supportEmail}`}- />- ),- }}+ </Preview>+ <Body>+ <Container>+ <Img+ src={chrome.logoUrl}+ height="42"+ style={{ marginBottom: 32, borderRadius: 6 }}+ alt={chrome.appName}/>- </Text>- </Section>- </EmailLayout>+ <Heading>+ {t("changeEmail_heading", {+ defaultValue: "Verify your new email address",+ })}+ </Heading>+ <Text>+ {t("changeEmail_text", {+ defaultValue:+ "Please use the following 6-digit verification code to confirm your new email address",+ })}+ </Text>+ <Text+ style={{+ ...trackingWide,+ fontSize: "32px",+ fontWeight: "bold",+ }}+ id="code"+ >+ {code}+ </Text>+ <Text light={true}>+ {t("changeEmail_codeValid", {+ defaultValue: "This code is valid for 15 minutes",+ })}+ </Text>+ <Hr />+ <Text small light={true}>+ <Trans+ t={t}+ i18n={i18n}+ ns="emails"+ i18nKey="changeEmail_content2"+ defaults="You're receiving this email because a request was made to change the email address of an account on <domain />. If this wasn't you contact <a>{supportEmail}</a>."+ values={{ supportEmail: chrome.supportEmail }}+ components={{+ domain: (+ <Link color={chrome.primaryColor} href={chrome.baseUrl}>+ {chrome.domain}+ </Link>+ ),+ a: (+ <Link+ color={chrome.primaryColor}+ href={`mailto:${chrome.supportEmail}`}+ />+ ),+ }}+ />+ </Text>+ <PoweredBy chrome={chrome} locale={locale} />+ </Container>+ </Body>+ </Html>);-};+}++ChangeEmailEmail.PreviewProps = {+ code: "123456",+ locale: "en",+ chrome: previewChrome,+} as ChangeEmailEmailProps;-export const sendChangeEmailEmail = createEmailTemplate({- component: ChangeEmailEmail,- subject: (_props, ctx) =>- ctx.t("changeEmail_subject", {+export default ChangeEmailEmail;++export async function sendChangeEmailEmail({+ to,+ locale = "en",+ branding,+ props,+ ...rest+}: SendArgs<ChangeEmailEmailProps>) {+ const { t } = await createEmailI18n(locale);+ await sendRenderedEmail({+ to,+ subject: t("changeEmail_subject", {defaultValue: "Verify your new email address",- ns: "emails",}),-});+ element: (+ <ChangeEmailEmail+ {...props}+ locale={locale}+ chrome={resolveChrome(branding)}+ />+ ),+ ...rest,+ });+}diff --git a/packages/emails/src/templates/event-canceled.tsx b/packages/emails/src/templates/event-canceled.tsxindex 4fd74fb87..308c9c532 100644--- a/packages/emails/src/templates/event-canceled.tsx+++ b/packages/emails/src/templates/event-canceled.tsx@@ -1,105 +1,166 @@-import { Column, Row, Section } from "@react-email/components";+import {+ Column,+ Head,+ Hr,+ Html,+ Img,+ Preview,+ Row,+ Section,+} from "@react-email/components";import { Trans } from "react-i18next/TransWithoutContext";-import { EmailLayout } from "../components/email-layout";-import { borderColor, Heading, Text } from "../components/styled-components";-import { createEmailTemplate } from "../create-email-template";-import type { EmailContext } from "../types";+import { resolveChrome } from "../chrome";+import { PoweredBy } from "../components/powered-by";+import { previewChrome } from "../components/preview-chrome";+import {+ Body,+ borderColor,+ Container,+ Heading,+ Text,+} from "../components/styled-components";+import { createEmailI18n } from "../i18n";+import type { SendArgs } from "../send";+import { sendRenderedEmail } from "../send";+import type { EmailChrome } from "../types";-export interface EventCanceledEmailProps {+export type EventCanceledEmailProps = {+ locale?: string;+ chrome: EmailChrome;title: string;hostName: string;day: string;dow: string;date: string;time: string;- ctx: EmailContext;-}+};-const EventCanceledEmail = ({+async function EventCanceledEmail({title,hostName,day,dow,date,time,- ctx,-}: EventCanceledEmailProps) => {+ locale = "en",+ chrome,+}: EventCanceledEmailProps) {+ const { t, i18n } = await createEmailI18n(locale);return (- <EmailLayout- ctx={ctx}- preview={ctx.t("eventCanceledPreview", {- defaultValue: "Event canceled",- ns: "emails",- })}- >- <Heading>- {ctx.t("eventCanceledHeading", {+ <Html>+ <Head />+ <Preview>+ {t("eventCanceledPreview", {defaultValue: "Event canceled",- ns: "emails",})}- </Heading>- <Text>- <Trans- {...ctx.i18nProps}- i18nKey="eventCanceledContent"- defaults="<b>{hostName}</b> has canceled <b>{title}</b> that was scheduled for:"- values={{ hostName, title }}- components={{- b: <strong />,- }}- />- </Text>- <Section data-testid="date-section">- <Row>- <Column style={{ width: 48 }}>- <Section- style={{- borderRadius: 5,- margin: 0,- width: 48,- height: 48,- textAlign: "center",- border: `1px solid ${borderColor}`,+ </Preview>+ <Body>+ <Container>+ <Img+ src={chrome.logoUrl}+ height="42"+ style={{ marginBottom: 32, borderRadius: 6 }}+ alt={chrome.appName}+ />+ <Heading>+ {t("eventCanceledHeading", {+ defaultValue: "Event canceled",+ })}+ </Heading>+ <Text>+ <Trans+ t={t}+ i18n={i18n}+ ns="emails"+ i18nKey="eventCanceledContent"+ defaults="<b>{hostName}</b> has canceled <b>{title}</b> that was scheduled for:"+ values={{ hostName, title }}+ components={{+ b: <strong />,}}- >- <Text- style={{ margin: "0 0 4px 0", fontSize: 10, lineHeight: 1 }}- >- {dow}- </Text>- <Text- style={{- fontSize: 20,- lineHeight: 1,- fontWeight: "bold",- margin: 0,- }}- >- {day}- </Text>- </Section>- </Column>- <Column style={{ paddingLeft: 16 }} align="left">- <Text style={{ margin: 0, fontWeight: "bold" }}>{date}</Text>- <Text light={true} style={{ margin: 0 }}>- {time}- </Text>- </Column>- </Row>- </Section>- </EmailLayout>+ />+ </Text>+ <Section data-testid="date-section">+ <Row>+ <Column style={{ width: 48 }}>+ <Section+ style={{+ borderRadius: 5,+ margin: 0,+ width: 48,+ height: 48,+ textAlign: "center",+ border: `1px solid ${borderColor}`,+ }}+ >+ <Text+ style={{ margin: "0 0 4px 0", fontSize: 10, lineHeight: 1 }}+ >+ {dow}+ </Text>+ <Text+ style={{+ fontSize: 20,+ lineHeight: 1,+ fontWeight: "bold",+ margin: 0,+ }}+ >+ {day}+ </Text>+ </Section>+ </Column>+ <Column style={{ paddingLeft: 16 }} align="left">+ <Text style={{ margin: 0, fontWeight: "bold" }}>{date}</Text>+ <Text light={true} style={{ margin: 0 }}>+ {time}+ </Text>+ </Column>+ </Row>+ </Section>+ <Hr style={{ margin: "16px 0" }} />+ <PoweredBy chrome={chrome} locale={locale} />+ </Container>+ </Body>+ </Html>);-};+}++EventCanceledEmail.PreviewProps = {+ title: "Untitled Poll",+ hostName: "Host",+ day: "12",+ dow: "Fri",+ date: "Friday, 12th June 2020",+ time: "6:00 PM to 11:00 PM BST",+ locale: "en",+ chrome: previewChrome,+} as EventCanceledEmailProps;-export { EventCanceledEmail };+export default EventCanceledEmail;-export const sendEventCanceledEmail = createEmailTemplate({- component: EventCanceledEmail,- subject: (props, ctx) =>- ctx.t("eventCanceledSubject", {+export async function sendEventCanceledEmail({+ to,+ locale = "en",+ branding,+ props,+ ...rest+}: SendArgs<EventCanceledEmailProps>) {+ const { t } = await createEmailI18n(locale);+ await sendRenderedEmail({+ to,+ subject: t("eventCanceledSubject", {defaultValue: "Canceled: {title}",title: props.title,- ns: "emails",}),-});+ element: (+ <EventCanceledEmail+ {...props}+ locale={locale}+ chrome={resolveChrome(branding)}+ />+ ),+ ...rest,+ });+}diff --git a/packages/emails/src/templates/finalized-host.tsx b/packages/emails/src/templates/finalized-host.tsxindex 538348f72..fa8d0d8bb 100644--- a/packages/emails/src/templates/finalized-host.tsx+++ b/packages/emails/src/templates/finalized-host.tsx@@ -1,17 +1,34 @@-import { Column, Row, Section } from "@react-email/components";+import {+ Column,+ Head,+ Hr,+ Html,+ Img,+ Preview,+ Row,+ Section,+} from "@react-email/components";import { Trans } from "react-i18next/TransWithoutContext";-import { EmailLayout } from "../components/email-layout";+import { resolveChrome } from "../chrome";+import { PoweredBy } from "../components/powered-by";+import { previewChrome } from "../components/preview-chrome";import {+ Body,Button,borderColor,+ Container,Heading,Text,} from "../components/styled-components";-import { createEmailTemplate } from "../create-email-template";-import type { EmailContext } from "../types";+import { createEmailI18n } from "../i18n";+import type { SendArgs } from "../send";+import { sendRenderedEmail } from "../send";+import type { EmailChrome } from "../types";-export interface FinalizeHostEmailProps {+type FinalizeHostEmailProps = {+ locale?: string;+ chrome: EmailChrome;date: string;day: string;dow: string;@@ -21,110 +38,145 @@ export interface FinalizeHostEmailProps {location: string | null;pollUrl: string;attendees: string[];- ctx: EmailContext;-}+};-const FinalizeHostEmail = ({+async function FinalizeHostEmail({title,pollUrl,day,dow,date,time,- ctx,-}: FinalizeHostEmailProps) => {+ locale = "en",+ chrome,+}: FinalizeHostEmailProps) {+ const { t, i18n } = await createEmailI18n(locale);return (- <EmailLayout- ctx={ctx}- preview={ctx.t("finalizeHost_preview", {- ns: "emails",- defaultValue:- "Final date booked! We've notified participants and sent them calendar invites.",- title,- })}- >- <Heading>- {ctx.t("finalizeHost_heading", {- defaultValue: "Final date booked!",- ns: "emails",- })}- </Heading>- <Text>- <Trans- {...ctx.i18nProps}- i18nKey="finalizeHost_content"- values={{ title }}- components={{- b: <strong />,- }}- defaults="<b>{title}</b> has been booked for:"- />- </Text>- <Section>- <Row>- <Column style={{ width: 48 }}>- <Section- style={{- borderRadius: 5,- margin: 0,- width: 48,- height: 48,- textAlign: "center",- border: `1px solid ${borderColor}`,- }}- >- <Text- style={{ margin: "0 0 4px 0", fontSize: 10, lineHeight: 1 }}- >- {dow}- </Text>- <Text- style={{- fontSize: 20,- lineHeight: 1,- fontWeight: "bold",- margin: 0,- }}- >- {day}- </Text>- </Section>- </Column>- <Column style={{ paddingLeft: 16 }} align="left">- <Text style={{ margin: 0, fontWeight: "bold" }}>{date}</Text>- <Text light={true} style={{ margin: 0 }}>- {time}- </Text>- </Column>- </Row>- </Section>- <Text>- {ctx.t("finalizeHost_content2", {+ <Html>+ <Head />+ <Preview>+ {t("finalizeHost_preview", {defaultValue:- "We've notified participants and sent them calendar invites.",- ns: "emails",+ "Final date booked! We've notified participants and sent them calendar invites.",+ title,})}- </Text>- <Section style={{ marginTop: 32 }}>- <Button href={pollUrl} color={ctx.primaryColor}>- {ctx.t("finalizeHost_button", {- defaultValue: "View Event",- ns: "emails",- })}- </Button>- </Section>- </EmailLayout>+ </Preview>+ <Body>+ <Container>+ <Img+ src={chrome.logoUrl}+ height="42"+ style={{ marginBottom: 32, borderRadius: 6 }}+ alt={chrome.appName}+ />+ <Heading>+ {t("finalizeHost_heading", { defaultValue: "Final date booked!" })}+ </Heading>+ <Text>+ <Trans+ t={t}+ i18n={i18n}+ ns="emails"+ i18nKey="finalizeHost_content"+ values={{ title }}+ components={{+ b: <strong />,+ }}+ defaults="<b>{title}</b> has been booked for:"+ />+ </Text>+ <Section>+ <Row>+ <Column style={{ width: 48 }}>+ <Section+ style={{+ borderRadius: 5,+ margin: 0,+ width: 48,+ height: 48,+ textAlign: "center",+ border: `1px solid ${borderColor}`,+ }}+ >+ <Text+ style={{ margin: "0 0 4px 0", fontSize: 10, lineHeight: 1 }}+ >+ {dow}+ </Text>+ <Text+ style={{+ fontSize: 20,+ lineHeight: 1,+ fontWeight: "bold",+ margin: 0,+ }}+ >+ {day}+ </Text>+ </Section>+ </Column>+ <Column style={{ paddingLeft: 16 }} align="left">+ <Text style={{ margin: 0, fontWeight: "bold" }}>{date}</Text>+ <Text light={true} style={{ margin: 0 }}>+ {time}+ </Text>+ </Column>+ </Row>+ </Section>+ <Text>+ {t("finalizeHost_content2", {+ defaultValue:+ "We've notified participants and sent them calendar invites.",+ })}+ </Text>+ <Button href={pollUrl} color={chrome.primaryColor}>+ {t("finalizeHost_button", { defaultValue: "View Event" })}+ </Button>+ <Hr style={{ margin: "16px 0" }} />+ <PoweredBy chrome={chrome} locale={locale} />+ </Container>+ </Body>+ </Html>);-};+}-export { FinalizeHostEmail };+FinalizeHostEmail.PreviewProps = {+ name: "John Doe",+ location: "Zoom",+ attendees: ["[email protected]", "[email protected]"],+ title: "Untitled Poll",+ pollUrl: "https://rallly.co",+ day: "12",+ dow: "Fri",+ date: "Friday, 12th June 2020",+ time: "6:00 PM to 11:00 PM BST",+ locale: "en",+ chrome: previewChrome,+} as FinalizeHostEmailProps;-export const sendFinalizeHostEmail = createEmailTemplate({- component: FinalizeHostEmail,- subject: (props, ctx) =>- ctx.t("finalizeHost_subject", {+export default FinalizeHostEmail;++export async function sendFinalizeHostEmail({+ to,+ locale = "en",+ branding,+ props,+ ...rest+}: SendArgs<FinalizeHostEmailProps>) {+ const { t } = await createEmailI18n(locale);+ await sendRenderedEmail({+ to,+ subject: t("finalizeHost_subject", {defaultValue: "Date booked for {title}",title: props.title,- ns: "emails",}),-});+ element: (+ <FinalizeHostEmail+ {...props}+ locale={locale}+ chrome={resolveChrome(branding)}+ />+ ),+ ...rest,+ });+}diff --git a/packages/emails/src/templates/finalized-participant.tsx b/packages/emails/src/templates/finalized-participant.tsxindex aca25a04d..a89f30e56 100644--- a/packages/emails/src/templates/finalized-participant.tsx+++ b/packages/emails/src/templates/finalized-participant.tsx@@ -1,17 +1,34 @@-import { Column, Row, Section } from "@react-email/components";+import {+ Column,+ Head,+ Hr,+ Html,+ Img,+ Preview,+ Row,+ Section,+} from "@react-email/components";import { Trans } from "react-i18next/TransWithoutContext";-import { EmailLayout } from "../components/email-layout";+import { resolveChrome } from "../chrome";+import { PoweredBy } from "../components/powered-by";+import { previewChrome } from "../components/preview-chrome";import {+ Body,Button,borderColor,+ Container,Heading,Text,} from "../components/styled-components";-import { createEmailTemplate } from "../create-email-template";-import type { EmailContext } from "../types";+import { createEmailI18n } from "../i18n";+import type { SendArgs } from "../send";+import { sendRenderedEmail } from "../send";+import type { EmailChrome } from "../types";-export interface FinalizeParticipantEmailProps {+type FinalizeParticipantEmailProps = {+ locale?: string;+ chrome: EmailChrome;date: string;day: string;dow: string;@@ -19,10 +36,9 @@ export interface FinalizeParticipantEmailProps {title: string;hostName: string;pollUrl: string;- ctx: EmailContext;-}+};-const FinalizeParticipantEmail = ({+async function FinalizeParticipantEmail({title,hostName,pollUrl,@@ -30,98 +46,140 @@ const FinalizeParticipantEmail = ({dow,date,time,- ctx,-}: FinalizeParticipantEmailProps) => {+ locale = "en",+ chrome,+}: FinalizeParticipantEmailProps) {+ const { t, i18n } = await createEmailI18n(locale);return (- <EmailLayout- ctx={ctx}- preview={ctx.t("finalizeParticipant_preview", {- defaultValue: "Final date booked!",- ns: "emails",- })}- >- <Heading>- {ctx.t("finalizeParticipant_heading", {+ <Html>+ <Head />+ <Preview>+ {t("finalizeParticipant_preview", {defaultValue: "Final date booked!",- ns: "emails",- })}- </Heading>- <Text>- <Trans- {...ctx.i18nProps}- i18nKey="finalizeParticipant_content"- defaults="<b>{hostName}</b> has booked <b>{title}</b> for the following date:"- values={{ hostName, title }}- components={{- b: <strong />,- }}- />- </Text>- <Section data-testid="date-section">- <Row>- <Column style={{ width: 48 }}>- <Section- style={{- borderRadius: 5,- margin: 0,- width: 48,- height: 48,- textAlign: "center",- border: `1px solid ${borderColor}`,- }}- >- <Text- style={{ margin: "0 0 4px 0", fontSize: 10, lineHeight: 1 }}- >- {dow}- </Text>- <Text- style={{- fontSize: 20,- lineHeight: 1,- fontWeight: "bold",- margin: 0,- }}- >- {day}- </Text>- </Section>- </Column>- <Column style={{ paddingLeft: 16 }} align="left">- <Text style={{ margin: 0, fontWeight: "bold" }}>{date}</Text>- <Text light={true} style={{ margin: 0 }}>- {time}- </Text>- </Column>- </Row>- </Section>- <Text>- {ctx.t("finalizeParticipant_content2", {- defaultValue:- "Please find attached a calendar invite for this event.",})}- </Text>- <Section style={{ marginTop: 32 }}>- <Button href={pollUrl} color={ctx.primaryColor}>- <Trans- {...ctx.i18nProps}- i18nKey="finalizeHost_button"- defaults="View Event"+ </Preview>+ <Body>+ <Container>+ <Img+ src={chrome.logoUrl}+ height="42"+ style={{ marginBottom: 32, borderRadius: 6 }}+ alt={chrome.appName}/>- </Button>- </Section>- </EmailLayout>+ <Heading>+ {t("finalizeParticipant_heading", {+ defaultValue: "Final date booked!",+ })}+ </Heading>+ <Text>+ <Trans+ t={t}+ i18n={i18n}+ ns="emails"+ i18nKey="finalizeParticipant_content"+ defaults="<b>{hostName}</b> has booked <b>{title}</b> for the following date:"+ values={{ hostName, title }}+ components={{+ b: <strong />,+ }}+ />+ </Text>+ <Section data-testid="date-section">+ <Row>+ <Column style={{ width: 48 }}>+ <Section+ style={{+ borderRadius: 5,+ margin: 0,+ width: 48,+ height: 48,+ textAlign: "center",+ border: `1px solid ${borderColor}`,+ }}+ >+ <Text+ style={{ margin: "0 0 4px 0", fontSize: 10, lineHeight: 1 }}+ >+ {dow}+ </Text>+ <Text+ style={{+ fontSize: 20,+ lineHeight: 1,+ fontWeight: "bold",+ margin: 0,+ }}+ >+ {day}+ </Text>+ </Section>+ </Column>+ <Column style={{ paddingLeft: 16 }} align="left">+ <Text style={{ margin: 0, fontWeight: "bold" }}>{date}</Text>+ <Text light={true} style={{ margin: 0 }}>+ {time}+ </Text>+ </Column>+ </Row>+ </Section>+ <Text>+ {t("finalizeParticipant_content2", {+ defaultValue:+ "Please find attached a calendar invite for this event.",+ })}+ </Text>+ <Button href={pollUrl} color={chrome.primaryColor}>+ <Trans+ t={t}+ i18n={i18n}+ ns="emails"+ i18nKey="finalizeParticipant_button"+ defaults="View Event"+ />+ </Button>+ <Hr style={{ margin: "16px 0" }} />+ <PoweredBy chrome={chrome} locale={locale} />+ </Container>+ </Body>+ </Html>);-};+}-export { FinalizeParticipantEmail };+FinalizeParticipantEmail.PreviewProps = {+ title: "Untitled Poll",+ hostName: "Host",+ pollUrl: "https://rallly.co",+ day: "12",+ dow: "Fri",+ date: "Friday, 12th June 2020",+ time: "6:00 PM to 11:00 PM BST",+ locale: "en",+ chrome: previewChrome,+} as FinalizeParticipantEmailProps;-export const sendFinalizeParticipantEmail = createEmailTemplate({- component: FinalizeParticipantEmail,- subject: (props, ctx) =>- ctx.t("finalizeParticipant_subject", {+export default FinalizeParticipantEmail;++export async function sendFinalizeParticipantEmail({+ to,+ locale = "en",+ branding,+ props,+ ...rest+}: SendArgs<FinalizeParticipantEmailProps>) {+ const { t } = await createEmailI18n(locale);+ await sendRenderedEmail({+ to,+ subject: t("finalizeParticipant_subject", {defaultValue: "Date booked for {title}",title: props.title,- ns: "emails",}),-});+ element: (+ <FinalizeParticipantEmail+ {...props}+ locale={locale}+ chrome={resolveChrome(branding)}+ />+ ),+ ...rest,+ });+}diff --git a/packages/emails/src/templates/license-key.tsx b/packages/emails/src/templates/license-key.tsxindex 99b170827..b37bd17cc 100644--- a/packages/emails/src/templates/license-key.tsx+++ b/packages/emails/src/templates/license-key.tsx@@ -1,154 +1,226 @@+import { Head, Html, Img, Preview } from "@react-email/components";import { Trans } from "react-i18next/TransWithoutContext";-import { EmailLayout } from "../components/email-layout";-import { Heading, Link, Text } from "../components/styled-components";-import { createEmailTemplate } from "../create-email-template";-import type { EmailContext } from "../types";+import { resolveChrome } from "../chrome";+import { previewChrome } from "../components/preview-chrome";+import {+ Body,+ Container,+ Heading,+ Link,+ Text,+} from "../components/styled-components";+import { createEmailI18n } from "../i18n";+import type { SendArgs } from "../send";+import { sendRenderedEmail } from "../send";+import type { EmailChrome } from "../types";-interface LicenseKeyEmailProps {+type LicenseKeyEmailProps = {+ locale?: string;+ chrome: EmailChrome;licenseKey: string;tier: string;seats: number;- ctx: EmailContext;-}+};-export const LicenseKeyEmail = ({+async function LicenseKeyEmail({licenseKey,tier,seats,- ctx,-}: LicenseKeyEmailProps) => {+ locale = "en",+ chrome,+}: LicenseKeyEmailProps) {+ const { t, i18n } = await createEmailI18n(locale);return (- <EmailLayout- poweredBy={false}- ctx={ctx}- preview={ctx.t("license_key_preview", {- defaultValue: "Your license key has been generated.",- ns: "emails",- })}- >- <Text>- <Trans- {...ctx.i18nProps}- i18nKey="license_key_content"- defaults="Your purchase has been confirmed and your license key has been generated."- />- </Text>- <Heading as="h2">- <Trans- {...ctx.i18nProps}- i18nKey="license_key_yourKey"- defaults="License Details"- />- </Heading>- <table>- <tr>- <td style={{ paddingRight: "16px" }}>+ <Html>+ <Head />+ <Preview>+ {t("license_key_preview", {+ defaultValue: "Your license key has been generated.",+ })}+ </Preview>+ <Body>+ <Container>+ <Img+ src={chrome.logoUrl}+ height="42"+ style={{ marginBottom: 32, borderRadius: 6 }}+ alt={chrome.appName}+ />+ <Heading>+ {t("license_key_heading", {+ defaultValue: "License confirmation",+ })}+ </Heading>+ <Text>+ <Trans+ t={t}+ i18n={i18n}+ ns="emails"+ i18nKey="license_key_content"+ defaults="Your purchase has been confirmed and your license key has been generated."+ />+ </Text>+ <Heading as="h2">+ <Trans+ t={t}+ i18n={i18n}+ ns="emails"+ i18nKey="license_key_yourKey"+ defaults="License Details"+ />+ </Heading>+ <table>+ <tr>+ <td style={{ paddingRight: "16px" }}>+ <Trans+ t={t}+ i18n={i18n}+ ns="emails"+ i18nKey="license_key_plan"+ defaults="Plan"+ />+ </td>+ <td>{tier}</td>+ </tr>+ <tr>+ <td style={{ paddingRight: "16px" }}>+ <Trans+ t={t}+ i18n={i18n}+ ns="emails"+ i18nKey="license_key_seats"+ defaults="Seats"+ />+ </td>+ <td>{seats}</td>+ </tr>+ <tr>+ <td style={{ paddingRight: "16px" }}>+ <Trans+ t={t}+ i18n={i18n}+ ns="emails"+ i18nKey="license_key_licenseKey"+ defaults="License Key"+ />+ </td>+ <td+ style={{+ fontFamily: "monospace",+ fontSize: "16px",+ letterSpacing: "0.1em",+ }}+ >+ {licenseKey}+ </td>+ </tr>+ </table>+ <Heading as="h2">+ <Trans+ t={t}+ i18n={i18n}+ ns="emails"+ i18nKey="license_key_nextStepsHeading"+ defaults="Next Steps"+ />+ </Heading>+ <Text><Trans- {...ctx.i18nProps}- i18nKey="license_key_plan"- defaults="Plan"+ t={t}+ i18n={i18n}+ ns="emails"+ i18nKey="license_key_activationSteps"+ defaults={+ "Follow these <a>instructions</a> to activate your license on your Rallly Self-Hosted instance."+ }+ components={{+ a: (+ <Link+ color={chrome.primaryColor}+ className="text-link"+ href="https://support.rallly.co/self-hosting/licensing#activating-your-license"+ />+ ),+ }}/>- </td>- <td>{tier}</td>- </tr>- <tr>- <td style={{ paddingRight: "16px" }}>+ </Text>+ <Heading as="h2"><Trans- {...ctx.i18nProps}- i18nKey="license_key_seats"- defaults="Seats"+ t={t}+ i18n={i18n}+ ns="emails"+ i18nKey="license_key_questionsHeading"+ defaults="Questions?"/>- </td>- <td>{seats}</td>- </tr>- <tr>- <td style={{ paddingRight: "16px" }}>+ </Heading>+ <Text><Trans- {...ctx.i18nProps}- i18nKey="license_key_licenseKey"- defaults="License Key"+ t={t}+ i18n={i18n}+ ns="emails"+ i18nKey="license_key_support"+ defaults={+ "Reply to this email or contact us at <a>{supportEmail}</a> if you need help."+ }+ values={{ supportEmail: chrome.supportEmail }}+ components={{+ a: (+ <Link+ color={chrome.primaryColor}+ className="text-link"+ href={`mailto:${chrome.supportEmail}`}+ />+ ),+ }}/>- </td>- <td- style={{- fontFamily: "monospace",- fontSize: "16px",- letterSpacing: "0.1em",- }}- >- {licenseKey}- </td>- </tr>- </table>- <Heading as="h2">- <Trans- {...ctx.i18nProps}- i18nKey="license_key_nextStepsHeading"- defaults="Next Steps"- />- </Heading>- <Text>- <Trans- {...ctx.i18nProps}- i18nKey="license_key_activationSteps"- defaults={- "Follow these <a>instructions</a> to activate your license on your Rallly Self-Hosted instance."- }- components={{- a: (- <Link- color={ctx.primaryColor}- className="text-link"- href="https://support.rallly.co/self-hosting/licensing#activating-your-license"- />- ),- }}- />- </Text>- <Heading as="h2">- <Trans- {...ctx.i18nProps}- i18nKey="license_key_questionsHeading"- defaults="Questions?"- />- </Heading>- <Text>- <Trans- {...ctx.i18nProps}- i18nKey="license_key_support"- defaults={- "Reply to this email or contact us at <a>{supportEmail}</a> if you need help."- }- values={{ supportEmail: ctx.supportEmail }}- components={{- a: (- <Link- color={ctx.primaryColor}- className="text-link"- href="mailto:[email protected]"- />- ),- }}- />- </Text>- <Text>- <Trans- {...ctx.i18nProps}- i18nKey="license_key_signoff"- defaults="Thank you for choosing Rallly!"- />- </Text>- </EmailLayout>+ </Text>+ <Text>+ <Trans+ t={t}+ i18n={i18n}+ ns="emails"+ i18nKey="license_key_signoff"+ defaults="Thank you for choosing Rallly!"+ />+ </Text>+ </Container>+ </Body>+ </Html>);-};+}-export const sendLicenseKeyEmail = createEmailTemplate({- component: LicenseKeyEmail,- subject: (props, ctx) =>- ctx.t("license_key_subject", {+LicenseKeyEmail.PreviewProps = {+ licenseKey: "RLYV4-ABCD-1234-ABCD-1234-XXXX",+ tier: "PLUS",+ seats: 5,+ locale: "en",+ chrome: previewChrome,+} as LicenseKeyEmailProps;++export default LicenseKeyEmail;++export async function sendLicenseKeyEmail({+ to,+ locale = "en",+ branding,+ props,+ ...rest+}: SendArgs<LicenseKeyEmailProps>) {+ const { t } = await createEmailI18n(locale);+ await sendRenderedEmail({+ to,+ subject: t("license_key_subject", {defaultValue: "Your Rallly Self-Hosted {tier} License",- ns: "emails",tier: props.tier,}),-});+ element: (+ <LicenseKeyEmail+ {...props}+ locale={locale}+ chrome={resolveChrome(branding)}+ />+ ),+ ...rest,+ });+}diff --git a/packages/emails/src/templates/new-comment.tsx b/packages/emails/src/templates/new-comment.tsxindex a968ed88a..5dead7159 100644--- a/packages/emails/src/templates/new-comment.tsx+++ b/packages/emails/src/templates/new-comment.tsx@@ -1,66 +1,145 @@+import { Head, Hr, Html, Img, Preview } from "@react-email/components";import { Trans } from "react-i18next/TransWithoutContext";-import type { NotificationBaseProps } from "../components/notification-email";-import NotificationEmail from "../components/notification-email";-import { Heading, Text } from "../components/styled-components";-import { createEmailTemplate } from "../create-email-template";+import { resolveChrome } from "../chrome";+import { PoweredBy } from "../components/powered-by";+import { previewChrome } from "../components/preview-chrome";+import {+ Body,+ Button,+ Container,+ Heading,+ Link,+ Text,+} from "../components/styled-components";+import { createEmailI18n } from "../i18n";+import type { SendArgs } from "../send";+import { sendRenderedEmail } from "../send";+import type { EmailChrome } from "../types";-export interface NewCommentEmailProps extends NotificationBaseProps {+type NewCommentEmailProps = {+ locale?: string;+ chrome: EmailChrome;+ title: string;authorName: string;-}+ pollUrl: string;+ disableNotificationsUrl: string;+};-const NewCommentEmail = ({+async function NewCommentEmail({title,authorName,pollUrl,disableNotificationsUrl,- ctx,-}: NewCommentEmailProps) => {+ locale = "en",+ chrome,+}: NewCommentEmailProps) {+ const { t, i18n } = await createEmailI18n(locale);return (- <NotificationEmail- ctx={ctx}- title={title}- pollUrl={pollUrl}- disableNotificationsUrl={disableNotificationsUrl}- preview={ctx.t("newComment_preview", {- ns: "emails",- defaultValue: "Go to your poll to see what they said.",- })}- >- <Heading>- <Trans- {...ctx.i18nProps}- i18nKey="newComment_heading"- defaults="New Comment"- />- </Heading>- <Text>- <Trans- {...ctx.i18nProps}- i18nKey="newComment_content"- defaults="<b>{authorName}</b> has commented on <b>{title}</b>."- components={{- b: <strong />,- }}- values={{- authorName,- title,- }}- />- </Text>- </NotificationEmail>+ <Html>+ <Head />+ <Preview>+ {t("newComment_preview", {+ defaultValue: "Go to your poll to see what they said.",+ })}+ </Preview>+ <Body>+ <Container>+ <Img+ src={chrome.logoUrl}+ height="42"+ style={{ marginBottom: 32, borderRadius: 6 }}+ alt={chrome.appName}+ />+ <Heading>+ <Trans+ t={t}+ i18n={i18n}+ ns="emails"+ i18nKey="newComment_heading"+ defaults="New Comment"+ />+ </Heading>+ <Text>+ <Trans+ t={t}+ i18n={i18n}+ ns="emails"+ i18nKey="newComment_content"+ defaults="<b>{authorName}</b> has commented on <b>{title}</b>."+ components={{ b: <strong /> }}+ values={{ authorName, title }}+ />+ </Text>+ <Button href={pollUrl} color={chrome.primaryColor}>+ <Trans+ t={t}+ i18n={i18n}+ ns="emails"+ i18nKey="common_viewOn"+ defaults="View on {domain}"+ values={{ domain: chrome.domain }}+ />+ </Button>+ <Hr style={{ margin: "16px 0" }} />+ <Text small light={true}>+ <Trans+ t={t}+ i18n={i18n}+ ns="emails"+ i18nKey="common_disableNotifications"+ defaults="You can <a>manage your notification settings</a> to stop receiving these emails."+ components={{+ a: (+ <Link+ color={chrome.primaryColor}+ style={{ whiteSpace: "nowrap" }}+ href={disableNotificationsUrl}+ />+ ),+ }}+ />+ </Text>+ <PoweredBy chrome={chrome} locale={locale} />+ </Container>+ </Body>+ </Html>);-};+}++NewCommentEmail.PreviewProps = {+ title: "Untitled Poll",+ authorName: "Someone",+ pollUrl: "https://rallly.co",+ disableNotificationsUrl: "https://rallly.co",+ locale: "en",+ chrome: previewChrome,+} as NewCommentEmailProps;-export { NewCommentEmail };+export default NewCommentEmail;-export const sendNewCommentEmail = createEmailTemplate({- component: NewCommentEmail,- subject: (props, ctx) =>- ctx.t("newComment_subject", {- ns: "emails",+export async function sendNewCommentEmail({+ to,+ locale = "en",+ branding,+ props,+ ...rest+}: SendArgs<NewCommentEmailProps>) {+ const { t } = await createEmailI18n(locale);+ await sendRenderedEmail({+ to,+ subject: t("newComment_subject", {defaultValue: "{authorName} has commented on {title}",authorName: props.authorName,title: props.title,}),-});+ element: (+ <NewCommentEmail+ {...props}+ locale={locale}+ chrome={resolveChrome(branding)}+ />+ ),+ ...rest,+ });+}diff --git a/packages/emails/src/templates/new-participant-confirmation.tsx b/packages/emails/src/templates/new-participant-confirmation.tsxindex ccfd529f5..d1f7aa6c5 100644--- a/packages/emails/src/templates/new-participant-confirmation.tsx+++ b/packages/emails/src/templates/new-participant-confirmation.tsx@@ -1,96 +1,145 @@+import { Head, Hr, Html, Img, Preview } from "@react-email/components";import { Trans } from "react-i18next/TransWithoutContext";-import { EmailLayout } from "../components/email-layout";+import { resolveChrome } from "../chrome";+import { PoweredBy } from "../components/powered-by";+import { previewChrome } from "../components/preview-chrome";import {+ Body,Button,- Domain,+ Container,Heading,- Section,+ Link,Text,} from "../components/styled-components";-import { createEmailTemplate } from "../create-email-template";-import type { EmailContext } from "../types";+import { createEmailI18n } from "../i18n";+import type { SendArgs } from "../send";+import { sendRenderedEmail } from "../send";+import type { EmailChrome } from "../types";-interface NewParticipantConfirmationEmailProps {+type NewParticipantConfirmationEmailProps = {+ locale?: string;+ chrome: EmailChrome;title: string;editSubmissionUrl: string;- ctx: EmailContext;-}+};-const NewParticipantConfirmationEmail = ({+async function NewParticipantConfirmationEmail({title,editSubmissionUrl,- ctx,-}: NewParticipantConfirmationEmailProps) => {- const { domain } = ctx;+ locale = "en",+ chrome,+}: NewParticipantConfirmationEmailProps) {+ const { t, i18n } = await createEmailI18n(locale);return (- <EmailLayout- ctx={ctx}- preview={ctx.t("newParticipantConfirmation_preview", {- defaultValue: "To edit your response use the link below",- ns: "emails",- })}- >- <Heading>- {ctx.t("newParticipantConfirmation_heading", {- defaultValue: "Poll Response Confirmation",- ns: "emails",+ <Html>+ <Head />+ <Preview>+ {t("newParticipantConfirmation_preview", {+ defaultValue: "To edit your response use the link below",})}- </Heading>- <Text>- <Trans- {...ctx.i18nProps}- i18nKey="newParticipantConfirmation_content"- defaults="Your response to <b>{title}</b> has been submitted."- components={{- b: <strong />,- }}- values={{ title }}- />- </Text>- <Text>- <Trans- {...ctx.i18nProps}- i18nKey="newParticipantConfirmation_content2"- defaults="While the poll is still open you can change your response using the link below."- />- </Text>- <Section style={{ marginTop: 32 }}>- <Button- id="editSubmissionUrl"- href={editSubmissionUrl}- color={ctx.primaryColor}- >- <Trans- {...ctx.i18nProps}- i18nKey="newParticipantConfirmation_button"- defaults="Review response on {domain}"- values={{ domain }}+ </Preview>+ <Body>+ <Container>+ <Img+ src={chrome.logoUrl}+ height="42"+ style={{ marginBottom: 32, borderRadius: 6 }}+ alt={chrome.appName}/>- </Button>- </Section>- <Text light>- <Trans- {...ctx.i18nProps}- i18nKey="newParticipantConfirmation_footnote"- defaults="You are receiving this email because a response was submitted on <domain />. If this wasn't you, please ignore this email."- components={{- domain: <Domain ctx={ctx} />,- }}- />- </Text>- </EmailLayout>+ <Heading>+ {t("newParticipantConfirmation_heading", {+ defaultValue: "Poll Response Confirmation",+ })}+ </Heading>+ <Text>+ <Trans+ t={t}+ i18n={i18n}+ ns="emails"+ i18nKey="newParticipantConfirmation_content"+ defaults="Your response to <b>{title}</b> has been submitted."+ components={{ b: <strong /> }}+ values={{ title }}+ />+ </Text>+ <Text>+ <Trans+ t={t}+ i18n={i18n}+ ns="emails"+ i18nKey="newParticipantConfirmation_content2"+ defaults="While the poll is still open you can change your response using the link below."+ />+ </Text>+ <Button+ id="editSubmissionUrl"+ href={editSubmissionUrl}+ color={chrome.primaryColor}+ >+ <Trans+ t={t}+ i18n={i18n}+ ns="emails"+ i18nKey="newParticipantConfirmation_button"+ defaults="Review response on {domain}"+ values={{ domain: chrome.domain }}+ />+ </Button>+ <Hr style={{ margin: "16px 0" }} />+ <Text small light={true}>+ <Trans+ t={t}+ i18n={i18n}+ ns="emails"+ i18nKey="newParticipantConfirmation_footnote"+ defaults="You are receiving this email because a response was submitted on <domain />. If this wasn't you, please ignore this email."+ components={{+ domain: (+ <Link color={chrome.primaryColor} href={chrome.baseUrl}>+ {chrome.domain}+ </Link>+ ),+ }}+ />+ </Text>+ <PoweredBy chrome={chrome} locale={locale} />+ </Container>+ </Body>+ </Html>);-};+}++NewParticipantConfirmationEmail.PreviewProps = {+ title: "Untitled Poll",+ editSubmissionUrl: "https://rallly.co",+ locale: "en",+ chrome: previewChrome,+} as NewParticipantConfirmationEmailProps;-export { NewParticipantConfirmationEmail };+export default NewParticipantConfirmationEmail;-export const sendNewParticipantConfirmationEmail = createEmailTemplate({- component: NewParticipantConfirmationEmail,- subject: (props, ctx) =>- ctx.t("newParticipantConfirmation_subject", {+export async function sendNewParticipantConfirmationEmail({+ to,+ locale = "en",+ branding,+ props,+ ...rest+}: SendArgs<NewParticipantConfirmationEmailProps>) {+ const { t } = await createEmailI18n(locale);+ await sendRenderedEmail({+ to,+ subject: t("newParticipantConfirmation_subject", {defaultValue: "Thanks for responding to {title}",title: props.title,- ns: "emails",}),-});+ element: (+ <NewParticipantConfirmationEmail+ {...props}+ locale={locale}+ chrome={resolveChrome(branding)}+ />+ ),+ ...rest,+ });+}diff --git a/packages/emails/src/templates/new-participant.tsx b/packages/emails/src/templates/new-participant.tsxindex 7135cbb3f..34859edea 100644--- a/packages/emails/src/templates/new-participant.tsx+++ b/packages/emails/src/templates/new-participant.tsx@@ -1,69 +1,154 @@+import { Head, Hr, Html, Img, Preview } from "@react-email/components";import { Trans } from "react-i18next/TransWithoutContext";-import type { NotificationBaseProps } from "../components/notification-email";-import NotificationEmail from "../components/notification-email";-import { Heading, Text } from "../components/styled-components";-import { createEmailTemplate } from "../create-email-template";+import { resolveChrome } from "../chrome";+import { PoweredBy } from "../components/powered-by";+import { previewChrome } from "../components/preview-chrome";+import {+ Body,+ Button,+ Container,+ Heading,+ Link,+ Text,+} from "../components/styled-components";+import { createEmailI18n } from "../i18n";+import type { SendArgs } from "../send";+import { sendRenderedEmail } from "../send";+import type { EmailChrome } from "../types";-export interface NewParticipantEmailProps extends NotificationBaseProps {+type NewParticipantEmailProps = {+ locale?: string;+ chrome: EmailChrome;+ title: string;participantName: string;-}+ pollUrl: string;+ disableNotificationsUrl: string;+};-const NewParticipantEmail = ({+async function NewParticipantEmail({title,participantName,pollUrl,disableNotificationsUrl,- ctx,-}: NewParticipantEmailProps) => {+ locale = "en",+ chrome,+}: NewParticipantEmailProps) {+ const { t, i18n } = await createEmailI18n(locale);return (- <NotificationEmail- ctx={ctx}- title={title}- pollUrl={pollUrl}- disableNotificationsUrl={disableNotificationsUrl}- preview={ctx.t("newParticipant_preview", {- defaultValue: "Go to your poll to see the new response.",- ns: "emails",- })}- >- <Heading>- {ctx.t("newParticipant_heading", {- defaultValue: "New Response",- ns: "emails",+ <Html>+ <Head />+ <Preview>+ {t("newParticipant_preview", {+ defaultValue: "Go to your poll to see the new response.",})}- </Heading>- <Text>- <Trans- {...ctx.i18nProps}- i18nKey="newParticipant_content"- defaults="<b>{name}</b> has responded to <b>{title}</b>."- components={{- b: <strong />,- }}- values={{ name: participantName, title }}- />- </Text>- <Text>- <Trans- {...ctx.i18nProps}- i18nKey="newParticipant_content2"- defaults="Go to your poll to see the new response."- />- </Text>- </NotificationEmail>+ </Preview>+ <Body>+ <Container>+ <Img+ src={chrome.logoUrl}+ height="42"+ style={{ marginBottom: 32, borderRadius: 6 }}+ alt={chrome.appName}+ />+ <Heading>+ <Trans+ t={t}+ i18n={i18n}+ ns="emails"+ i18nKey="newParticipant_heading"+ defaults="New Response"+ />+ </Heading>+ <Text>+ <Trans+ t={t}+ i18n={i18n}+ ns="emails"+ i18nKey="newParticipant_content"+ defaults="<b>{name}</b> has responded to <b>{title}</b>."+ components={{ b: <strong /> }}+ values={{ name: participantName, title }}+ />+ </Text>+ <Text>+ <Trans+ t={t}+ i18n={i18n}+ ns="emails"+ i18nKey="newParticipant_content2"+ defaults="Go to your poll to see the new response."+ />+ </Text>+ <Button href={pollUrl} color={chrome.primaryColor}>+ <Trans+ t={t}+ i18n={i18n}+ ns="emails"+ i18nKey="common_viewOn"+ defaults="View on {domain}"+ values={{ domain: chrome.domain }}+ />+ </Button>+ <Hr style={{ margin: "16px 0" }} />+ <Text small light={true}>+ <Trans+ t={t}+ i18n={i18n}+ ns="emails"+ i18nKey="common_disableNotifications"+ defaults="You can <a>manage your notification settings</a> to stop receiving these emails."+ components={{+ a: (+ <Link+ color={chrome.primaryColor}+ style={{ whiteSpace: "nowrap" }}+ href={disableNotificationsUrl}+ />+ ),+ }}+ />+ </Text>+ <PoweredBy chrome={chrome} locale={locale} />+ </Container>+ </Body>+ </Html>);-};+}++NewParticipantEmail.PreviewProps = {+ participantName: "John Doe",+ title: "Untitled Poll",+ pollUrl: "https://rallly.co",+ disableNotificationsUrl: "https://rallly.co",+ locale: "en",+ chrome: previewChrome,+} as NewParticipantEmailProps;-export { NewParticipantEmail };+export default NewParticipantEmail;-export const sendNewParticipantEmail = createEmailTemplate({- component: NewParticipantEmail,- subject: (props, ctx) =>- ctx.t("newParticipant_subject", {+export async function sendNewParticipantEmail({+ to,+ locale = "en",+ branding,+ props,+ ...rest+}: SendArgs<NewParticipantEmailProps>) {+ const { t } = await createEmailI18n(locale);+ await sendRenderedEmail({+ to,+ subject: t("newParticipant_subject", {defaultValue: "{name} has responded to {title}",name: props.participantName,title: props.title,- ns: "emails",}),-});+ element: (+ <NewParticipantEmail+ {...props}+ locale={locale}+ chrome={resolveChrome(branding)}+ />+ ),+ ...rest,+ });+}diff --git a/packages/emails/src/templates/new-poll.tsx b/packages/emails/src/templates/new-poll.tsxindex a086679ba..ebf7eb0e4 100644--- a/packages/emails/src/templates/new-poll.tsx+++ b/packages/emails/src/templates/new-poll.tsx@@ -1,79 +1,124 @@+import { Head, Hr, Html, Img, Preview } from "@react-email/components";import { Trans } from "react-i18next/TransWithoutContext";-import { EmailLayout } from "../components/email-layout";+import { resolveChrome } from "../chrome";+import { PoweredBy } from "../components/powered-by";+import { previewChrome } from "../components/preview-chrome";import {+ Body,Button,- Card,+ Container,Heading,Link,Text,} from "../components/styled-components";-import { createEmailTemplate } from "../create-email-template";-import type { EmailContext } from "../types";+import { createEmailI18n } from "../i18n";+import type { SendArgs } from "../send";+import { sendRenderedEmail } from "../send";+import type { EmailChrome } from "../types";-export interface NewPollEmailProps {+export type NewPollEmailProps = {+ locale?: string;+ chrome: EmailChrome;title: string;name: string;adminLink: string;participantLink: string;- ctx: EmailContext;-}+};-export const NewPollEmail = ({+async function NewPollEmail({title,adminLink,participantLink,- ctx,-}: NewPollEmailProps) => {+ locale = "en",+ chrome,+}: NewPollEmailProps) {+ const { t, i18n } = await createEmailI18n(locale);return (- <EmailLayout- ctx={ctx}- preview={ctx.t("newPoll_preview", {- defaultValue:- "Share your participant link to start collecting responses.",- ns: "emails",- })}- >- <Heading>- {ctx.t("newPoll_heading", {- defaultValue: "New Poll Created",- ns: "emails",+ <Html>+ <Head />+ <Preview>+ {t("newPoll_preview", {+ defaultValue:+ "Share your participant link to start collecting responses.",})}- </Heading>- <Text>- <Trans- {...ctx.i18nProps}- i18nKey="newPoll_content"- values={{ title }}- components={{- b: <strong />,- }}- defaults="Your meeting poll titled <b>{title}</b> is ready! Share it using the link below:"- />- </Text>- <Card style={{ textAlign: "center" }}>- <Text style={{ textAlign: "center" }}>- <Link color={ctx.primaryColor} href={participantLink}>- {participantLink}- </Link>- </Text>- </Card>- <Button href={adminLink} color={ctx.primaryColor}>- {ctx.t("newPoll_button", {- defaultValue: "Manage Poll",- ns: "emails",- })}- </Button>- </EmailLayout>+ </Preview>+ <Body>+ <Container>+ <Img+ src={chrome.logoUrl}+ height="42"+ style={{ marginBottom: 32, borderRadius: 6 }}+ alt={chrome.appName}+ />+ <Heading>+ {t("newPoll_heading", {+ defaultValue: "New Poll Created",+ })}+ </Heading>+ <Text>+ <Trans+ t={t}+ i18n={i18n}+ ns="emails"+ i18nKey="newPoll_content"+ values={{ title }}+ components={{+ b: <strong />,+ }}+ defaults="Your meeting poll titled <b>{title}</b> is ready! Share it using the link below:"+ />+ </Text>+ <Text>+ <Link color={chrome.primaryColor} href={participantLink}>+ {participantLink}+ </Link>+ </Text>+ <Button href={adminLink} color={chrome.primaryColor}>+ {t("newPoll_button", {+ defaultValue: "Manage Poll",+ })}+ </Button>+ <Hr style={{ margin: "16px 0" }} />+ <PoweredBy chrome={chrome} locale={locale} />+ </Container>+ </Body>+ </Html>);-};+}++NewPollEmail.PreviewProps = {+ title: "Untitled Poll",+ name: "John Doe",+ adminLink: "https://rallly.co",+ participantLink: "https://rallly.co/invite/abc123",+ locale: "en",+ chrome: previewChrome,+} as NewPollEmailProps;-export const sendNewPollEmail = createEmailTemplate({- component: NewPollEmail,- subject: (props, ctx) =>- ctx.t("newPoll_subject", {+export default NewPollEmail;++export async function sendNewPollEmail({+ to,+ locale = "en",+ branding,+ props,+ ...rest+}: SendArgs<NewPollEmailProps>) {+ const { t } = await createEmailI18n(locale);+ await sendRenderedEmail({+ to,+ subject: t("newPoll_subject", {defaultValue: "Let's find a date for {title}!",title: props.title,- ns: "emails",}),-});+ element: (+ <NewPollEmail+ {...props}+ locale={locale}+ chrome={resolveChrome(branding)}+ />+ ),+ ...rest,+ });+}diff --git a/packages/emails/src/templates/register.tsx b/packages/emails/src/templates/register.tsxindex 2f74259ac..c653c279e 100644--- a/packages/emails/src/templates/register.tsx+++ b/packages/emails/src/templates/register.tsx@@ -1,93 +1,136 @@-import { Section } from "@react-email/components";+import { Head, Hr, Html, Img, Preview } from "@react-email/components";import { Trans } from "react-i18next/TransWithoutContext";-import { EmailLayout } from "../components/email-layout";+import { resolveChrome } from "../chrome";+import { PoweredBy } from "../components/powered-by";+import { previewChrome } from "../components/preview-chrome";import {- Card,- Domain,+ Body,+ Container,Heading,Link,Text,trackingWide,} from "../components/styled-components";-import { createEmailTemplate } from "../create-email-template";-import type { EmailContext } from "../types";+import { createEmailI18n } from "../i18n";+import type { SendArgs } from "../send";+import { sendRenderedEmail } from "../send";+import type { EmailChrome } from "../types";-interface RegisterEmailProps {+type RegisterEmailProps = {+ locale?: string;+ chrome: EmailChrome;code: string;- ctx: EmailContext;-}+};-export const RegisterEmail = ({ code, ctx }: RegisterEmailProps) => {+async function RegisterEmail({+ code,+ locale = "en",+ chrome,+}: RegisterEmailProps) {+ const { t, i18n } = await createEmailI18n(locale);return (- <EmailLayout- ctx={ctx}- preview={ctx.t("register_preview", {- ns: "emails",- defaultValue: "Your 6-digit code is: {code}",- code,- })}- >- <Heading>- {ctx.t("register_heading", {- defaultValue: "Verify your email address",- ns: "emails",- })}- </Heading>- <Text>- {ctx.t("register_text", {- defaultValue:- "Please use the following 6-digit verification code to verify your email",- ns: "emails",+ <Html>+ <Head />+ <Preview>+ {t("register_preview", {+ defaultValue: "Your 6-digit code is: {code}",+ code,})}- </Text>- <Card style={{ textAlign: "center" }}>- <Text- style={{- ...trackingWide,- textAlign: "center",- fontSize: "32px",- fontWeight: "bold",- }}- id="code"- >- {code}- </Text>- <Text style={{ textAlign: "center" }} light={true}>- {ctx.t("register_codeValid", {- defaultValue: "This code is valid for 15 minutes",- ns: "emails",- })}- </Text>- </Card>- <Section>- <Text light={true}>- <Trans- {...ctx.i18nProps}- i18nKey="login_content2"- defaults="You're receiving this email because a request was made to login to <domain />. If this wasn't you contact <a>{supportEmail}</a>."- values={{ supportEmail: ctx.supportEmail }}- components={{- domain: <Domain ctx={ctx} />,- a: (- <Link- color={ctx.primaryColor}- href={`mailto:${ctx.supportEmail}`}- />- ),- }}+ </Preview>+ <Body>+ <Container>+ <Img+ src={chrome.logoUrl}+ height="42"+ style={{ marginBottom: 32, borderRadius: 6 }}+ alt={chrome.appName}/>- </Text>- </Section>- </EmailLayout>+ <Heading>+ {t("register_heading", {+ defaultValue: "Verify your email address",+ })}+ </Heading>+ <Text>+ {t("register_text", {+ defaultValue:+ "Please use the following 6-digit verification code to verify your email",+ })}+ </Text>+ <Text+ style={{+ ...trackingWide,+ fontSize: "32px",+ fontWeight: "bold",+ }}+ id="code"+ >+ {code}+ </Text>+ <Text light={true}>+ {t("register_codeValid", {+ defaultValue: "This code is valid for 15 minutes",+ })}+ </Text>+ <Hr />+ <Text small light={true}>+ <Trans+ t={t}+ i18n={i18n}+ ns="emails"+ i18nKey="login_content2"+ defaults="You're receiving this email because a request was made to login to <domain />. If this wasn't you contact <a>{supportEmail}</a>."+ values={{ supportEmail: chrome.supportEmail }}+ components={{+ domain: (+ <Link color={chrome.primaryColor} href={chrome.baseUrl}>+ {chrome.domain}+ </Link>+ ),+ a: (+ <Link+ color={chrome.primaryColor}+ href={`mailto:${chrome.supportEmail}`}+ />+ ),+ }}+ />+ </Text>+ <PoweredBy chrome={chrome} locale={locale} />+ </Container>+ </Body>+ </Html>);-};+}++RegisterEmail.PreviewProps = {+ code: "123456",+ locale: "en",+ chrome: previewChrome,+} as RegisterEmailProps;-export const sendRegisterEmail = createEmailTemplate({- component: RegisterEmail,- subject: (_props, ctx) =>- ctx.t("register_subject", {+export default RegisterEmail;++export async function sendRegisterEmail({+ to,+ locale = "en",+ branding,+ props,+ ...rest+}: SendArgs<RegisterEmailProps>) {+ const { t } = await createEmailI18n(locale);+ await sendRenderedEmail({+ to,+ subject: t("register_subject", {defaultValue: "Please verify your email address",- ns: "emails",}),-});+ element: (+ <RegisterEmail+ {...props}+ locale={locale}+ chrome={resolveChrome(branding)}+ />+ ),+ ...rest,+ });+}diff --git a/packages/emails/src/templates/reset-password.tsx b/packages/emails/src/templates/reset-password.tsxindex 9e559511d..5af2c2217 100644--- a/packages/emails/src/templates/reset-password.tsx+++ b/packages/emails/src/templates/reset-password.tsx@@ -1,75 +1,124 @@-import { Section } from "@react-email/components";+import { Head, Hr, Html, Img, Preview } from "@react-email/components";import { Trans } from "react-i18next/TransWithoutContext";-import { EmailLayout } from "../components/email-layout";-import { Button, Heading, Link, Text } from "../components/styled-components";-import { createEmailTemplate } from "../create-email-template";-import type { EmailContext } from "../types";+import { resolveChrome } from "../chrome";+import { PoweredBy } from "../components/powered-by";+import { previewChrome } from "../components/preview-chrome";+import {+ Body,+ Button,+ Container,+ Heading,+ Link,+ Text,+} from "../components/styled-components";+import { createEmailI18n } from "../i18n";+import type { SendArgs } from "../send";+import { sendRenderedEmail } from "../send";+import type { EmailChrome } from "../types";-interface ResetPasswordEmailProps {+type ResetPasswordEmailProps = {+ locale?: string;+ chrome: EmailChrome;resetLink: string;- ctx: EmailContext;-}+};-export const ResetPasswordEmail = ({+async function ResetPasswordEmail({resetLink,- ctx,-}: ResetPasswordEmailProps) => {+ locale = "en",+ chrome,+}: ResetPasswordEmailProps) {+ const { t, i18n } = await createEmailI18n(locale);return (- <EmailLayout- ctx={ctx}- preview={ctx.t("resetPassword_preview", {- defaultValue: "Use this link to reset your password.",- ns: "emails",- })}- >- <Heading>- {ctx.t("resetPassword_heading", {- defaultValue: "Reset your password",- ns: "emails",+ <Html>+ <Head />+ <Preview>+ {t("resetPassword_preview", {+ defaultValue: "Use this link to reset your password.",})}- </Heading>- <Text>- {ctx.t("resetPassword_content", {- defaultValue:- "We received a request to reset your password. Click the button below to create a new password.",- ns: "emails",- })}- </Text>- <Section style={{ marginBottom: 32 }}>- <Button href={resetLink} id="resetLink" color={ctx.primaryColor}>- <Trans- {...ctx.i18nProps}- i18nKey="resetPassword_button"- defaults="Reset password"+ </Preview>+ <Body>+ <Container>+ <Img+ src={chrome.logoUrl}+ height="42"+ style={{ marginBottom: 32, borderRadius: 6 }}+ alt={chrome.appName}/>- </Button>- </Section>- <Text light>- <Trans- {...ctx.i18nProps}- i18nKey="resetPassword_content2"- defaults="If you didn't request a password reset, you can ignore this email. Your password will not change unless you create a new one. If this request is suspicious, contact <a>{supportEmail}</a>."- values={{ supportEmail: ctx.supportEmail }}- components={{- a: (- <Link- color={ctx.primaryColor}- href={`mailto:${ctx.supportEmail}`}- />- ),- }}- />- </Text>- </EmailLayout>+ <Heading>+ {t("resetPassword_heading", {+ defaultValue: "Reset your password",+ })}+ </Heading>+ <Text>+ {t("resetPassword_content", {+ defaultValue:+ "We received a request to reset your password. Click the button below to create a new password.",+ })}+ </Text>+ <Button href={resetLink} id="resetLink" color={chrome.primaryColor}>+ <Trans+ t={t}+ i18n={i18n}+ ns="emails"+ i18nKey="resetPassword_button"+ defaults="Reset password"+ />+ </Button>+ <Hr style={{ margin: "16px 0" }} />+ <Text small light>+ <Trans+ t={t}+ i18n={i18n}+ ns="emails"+ i18nKey="resetPassword_content2"+ defaults="If you didn't request a password reset, you can ignore this email. Your password will not change unless you create a new one. If this request is suspicious, contact <a>{supportEmail}</a>."+ values={{ supportEmail: chrome.supportEmail }}+ components={{+ a: (+ <Link+ color={chrome.primaryColor}+ href={`mailto:${chrome.supportEmail}`}+ />+ ),+ }}+ />+ </Text>+ <PoweredBy chrome={chrome} locale={locale} />+ </Container>+ </Body>+ </Html>);-};+}++ResetPasswordEmail.PreviewProps = {+ resetLink: "https://rallly.co",+ locale: "en",+ chrome: previewChrome,+} as ResetPasswordEmailProps;-export const sendResetPasswordEmail = createEmailTemplate({- component: ResetPasswordEmail,- subject: (_props, ctx) =>- ctx.t("resetPassword_subject", {+export default ResetPasswordEmail;++export async function sendResetPasswordEmail({+ to,+ locale = "en",+ branding,+ props,+ ...rest+}: SendArgs<ResetPasswordEmailProps>) {+ const { t } = await createEmailI18n(locale);+ await sendRenderedEmail({+ to,+ subject: t("resetPassword_subject", {defaultValue: "Reset your password",- ns: "emails",}),-});+ element: (+ <ResetPasswordEmail+ {...props}+ locale={locale}+ chrome={resolveChrome(branding)}+ />+ ),+ ...rest,+ });+}diff --git a/packages/emails/src/templates/space-invite.tsx b/packages/emails/src/templates/space-invite.tsxindex 7ac9b0e94..f16116636 100644--- a/packages/emails/src/templates/space-invite.tsx+++ b/packages/emails/src/templates/space-invite.tsx@@ -1,65 +1,116 @@-import { Section } from "@react-email/components";+import { Head, Hr, Html, Img, Preview } from "@react-email/components";import { Trans } from "react-i18next/TransWithoutContext";-import { EmailLayout } from "../components/email-layout";-import { Button, Heading, Text } from "../components/styled-components";-import { createEmailTemplate } from "../create-email-template";-import type { EmailContext } from "../types";+import { resolveChrome } from "../chrome";+import { PoweredBy } from "../components/powered-by";+import { previewChrome } from "../components/preview-chrome";+import {+ Body,+ Button,+ Container,+ Heading,+ Text,+} from "../components/styled-components";+import { createEmailI18n } from "../i18n";+import type { SendArgs } from "../send";+import { sendRenderedEmail } from "../send";+import type { EmailChrome } from "../types";-interface SpaceInviteEmailProps {+type SpaceInviteEmailProps = {+ locale?: string;+ chrome: EmailChrome;spaceName: string;inviterName: string;spaceRole: string;inviteUrl: string;- ctx: EmailContext;-}+};-export const SpaceInviteEmail = ({+async function SpaceInviteEmail({spaceName,inviterName,spaceRole: role,inviteUrl,- ctx,-}: SpaceInviteEmailProps) => (- <EmailLayout- ctx={ctx}- preview={ctx.t("spaceInvite_preview", {- defaultValue: "You've been invited to join {spaceName}",- spaceName,- ns: "emails",- })}- >- <Heading>- {ctx.t("spaceInvite_heading", {- defaultValue: "You're invited!",- ns: "emails",- })}- </Heading>- <Text>- <Trans- {...ctx.i18nProps}- i18nKey="spaceInvite_content"- defaults="{inviterName} has invited you to join the {spaceName} space as a {role}."- values={{ inviterName, spaceName, role }}- />- </Text>- <Section style={{ marginBottom: 16 }}>- <Button href={inviteUrl} id="inviteUrl" color={ctx.primaryColor}>- {ctx.t("spaceInvite_button", {- defaultValue: "Accept Invitation",- ns: "emails",+ locale = "en",+ chrome,+}: SpaceInviteEmailProps) {+ const { t, i18n } = await createEmailI18n(locale);+ return (+ <Html>+ <Head />+ <Preview>+ {t("spaceInvite_preview", {+ defaultValue: "You've been invited to join {spaceName}",+ spaceName,})}- </Button>- </Section>- </EmailLayout>-);+ </Preview>+ <Body>+ <Container>+ <Img+ src={chrome.logoUrl}+ height="42"+ style={{ marginBottom: 32, borderRadius: 6 }}+ alt={chrome.appName}+ />+ <Heading>+ {t("spaceInvite_heading", {+ defaultValue: "You're invited!",+ })}+ </Heading>+ <Text>+ <Trans+ t={t}+ i18n={i18n}+ ns="emails"+ i18nKey="spaceInvite_content"+ defaults="{inviterName} has invited you to join the {spaceName} space as a {role}."+ values={{ inviterName, spaceName, role }}+ />+ </Text>+ <Button href={inviteUrl} id="inviteUrl" color={chrome.primaryColor}>+ {t("spaceInvite_button", {+ defaultValue: "Accept Invitation",+ })}+ </Button>+ <Hr style={{ margin: "16px 0" }} />+ <PoweredBy chrome={chrome} locale={locale} />+ </Container>+ </Body>+ </Html>+ );+}++SpaceInviteEmail.PreviewProps = {+ spaceName: "Marketing Team",+ inviterName: "John Smith",+ spaceRole: "member",+ inviteUrl: "https://rallly.co/invite/abc123",+ locale: "en",+ chrome: previewChrome,+} as SpaceInviteEmailProps;-export const sendSpaceInviteEmail = createEmailTemplate({- component: SpaceInviteEmail,- subject: (props, ctx) =>- ctx.t("spaceInvite_subject", {+export default SpaceInviteEmail;++export async function sendSpaceInviteEmail({+ to,+ locale = "en",+ branding,+ props,+ ...rest+}: SendArgs<SpaceInviteEmailProps>) {+ const { t } = await createEmailI18n(locale);+ await sendRenderedEmail({+ to,+ subject: t("spaceInvite_subject", {defaultValue: "You're invited to join {spaceName}",spaceName: props.spaceName,- ns: "emails",}),-});+ element: (+ <SpaceInviteEmail+ {...props}+ locale={locale}+ chrome={resolveChrome(branding)}+ />+ ),+ ...rest,+ });+}diff --git a/packages/emails/src/types.ts b/packages/emails/src/types.tsindex 081bdd34e..48fe46e34 100644--- a/packages/emails/src/types.ts+++ b/packages/emails/src/types.ts@@ -1,12 +1,7 @@-import type { TFunction } from "i18next";--import type { I18nInstance } from "./i18n";-/*** The themeable part of an email — the only thing that varies between instance- * and space branding. Passed as a prop on every send; the caller decides which- * to use. (Deployment constants like base URL / support email are resolved by- * the package from env, not passed.)+ * and space branding. The caller passes branding to each `sendXEmail`; the+ * package resolves env constants and hands the template its `chrome` prop.*/export type EmailBranding = {primaryColor: string;@@ -16,19 +11,12 @@ export type EmailBranding = {};/**- * Internal per-render context handed to template components: branding + env- * constants + a locale-pinned i18n. Assembled inside the package.+ * Branding + deployment env constants handed to a template as its `chrome`+ * prop. Translation is handled separately by the render-bound `t`/`Trans` from+ * `createEmailI18n`, not carried here.*/-export type EmailContext = EmailBranding & {+export type EmailChrome = EmailBranding & {baseUrl: string;domain: string;supportEmail: string;- i18n: I18nInstance;- t: TFunction;- /**- * Spread into every `<Trans {...ctx.i18nProps} />` to bind it to the email- * instance, locale-pinned `t`, and the `emails` namespace — so a template- * can't accidentally resolve a key against the wrong namespace.- */- i18nProps: { i18n: I18nInstance; t: TFunction; ns: "emails" };};