mirror of
https://github.com/lukevella/rallly.git
synced 2025-07-31 06:59:07 +02:00
♻️ Improve email abstraction (#863)
This commit is contained in:
parent
516a4114d0
commit
8cad515dc4
10 changed files with 751 additions and 152 deletions
|
@ -1,5 +1,4 @@
|
|||
import { prisma } from "@rallly/database";
|
||||
import { sendEmail } from "@rallly/emails";
|
||||
import { absoluteUrl } from "@rallly/utils";
|
||||
import { TRPCError } from "@trpc/server";
|
||||
import { z } from "zod";
|
||||
|
@ -78,6 +77,7 @@ export const auth = router({
|
|||
.mutation(
|
||||
async ({
|
||||
input,
|
||||
ctx,
|
||||
}): Promise<
|
||||
| { ok: true; token: string }
|
||||
| { ok: false; reason: "userAlreadyExists" | "emailNotAllowed" }
|
||||
|
@ -107,7 +107,7 @@ export const auth = router({
|
|||
code,
|
||||
});
|
||||
|
||||
await sendEmail("RegisterEmail", {
|
||||
await ctx.emailClient.sendTemplate("RegisterEmail", {
|
||||
to: input.email,
|
||||
subject: `${input.name}, please verify your email address`,
|
||||
props: {
|
||||
|
@ -168,6 +168,7 @@ export const auth = router({
|
|||
.mutation(
|
||||
async ({
|
||||
input,
|
||||
ctx,
|
||||
}): Promise<
|
||||
| { ok: true; token: string }
|
||||
| { ok: false; reason: "emailNotAllowed" | "userNotFound" }
|
||||
|
@ -193,7 +194,7 @@ export const auth = router({
|
|||
code,
|
||||
});
|
||||
|
||||
await sendEmail("LoginEmail", {
|
||||
await ctx.emailClient.sendTemplate("LoginEmail", {
|
||||
to: input.email,
|
||||
subject: `${code} is your 6-digit code`,
|
||||
props: {
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import { prisma } from "@rallly/database";
|
||||
import { sendEmail } from "@rallly/emails";
|
||||
import { absoluteUrl, shortUrl } from "@rallly/utils";
|
||||
import { TRPCError } from "@trpc/server";
|
||||
import dayjs from "dayjs";
|
||||
|
@ -133,7 +132,7 @@ export const polls = router({
|
|||
});
|
||||
|
||||
if (user) {
|
||||
await sendEmail("NewPollEmail", {
|
||||
await ctx.emailClient.sendTemplate("NewPollEmail", {
|
||||
to: user.email,
|
||||
subject: `Let's find a date for ${poll.title}`,
|
||||
props: {
|
||||
|
@ -678,7 +677,7 @@ export const polls = router({
|
|||
});
|
||||
}
|
||||
|
||||
const emailToHost = sendEmail("FinalizeHostEmail", {
|
||||
const emailToHost = ctx.emailClient.sendTemplate("FinalizeHostEmail", {
|
||||
subject: `Date booked for ${poll.title}`,
|
||||
to: poll.user.email,
|
||||
props: {
|
||||
|
@ -702,7 +701,7 @@ export const polls = router({
|
|||
});
|
||||
|
||||
const emailsToParticipants = participantsToEmail.map((p) => {
|
||||
return sendEmail("FinalizeParticipantEmail", {
|
||||
return ctx.emailClient.sendTemplate("FinalizeParticipantEmail", {
|
||||
subject: `Date booked for ${poll.title}`,
|
||||
to: p.email,
|
||||
props: {
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import { prisma } from "@rallly/database";
|
||||
import { sendEmail } from "@rallly/emails";
|
||||
import { absoluteUrl } from "@rallly/utils";
|
||||
import { z } from "zod";
|
||||
|
||||
|
@ -82,7 +81,7 @@ export const comments = router({
|
|||
{ ttl: 0 },
|
||||
);
|
||||
emailsToSend.push(
|
||||
sendEmail("NewCommentEmail", {
|
||||
ctx.emailClient.sendTemplate("NewCommentEmail", {
|
||||
to: email,
|
||||
subject: `${authorName} has commented on ${poll.title}`,
|
||||
props: {
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import { prisma } from "@rallly/database";
|
||||
import { sendEmail } from "@rallly/emails";
|
||||
import { absoluteUrl } from "@rallly/utils";
|
||||
import { TRPCError } from "@trpc/server";
|
||||
import { z } from "zod";
|
||||
|
@ -107,7 +106,7 @@ export const participants = router({
|
|||
);
|
||||
|
||||
emailsToSend.push(
|
||||
sendEmail("NewParticipantConfirmationEmail", {
|
||||
ctx.emailClient.sendTemplate("NewParticipantConfirmationEmail", {
|
||||
to: email,
|
||||
subject: `Thanks for responding to ${poll.title}`,
|
||||
props: {
|
||||
|
@ -144,7 +143,7 @@ export const participants = router({
|
|||
{ ttl: 0 },
|
||||
);
|
||||
emailsToSend.push(
|
||||
sendEmail("NewParticipantEmail", {
|
||||
ctx.emailClient.sendTemplate("NewParticipantEmail", {
|
||||
to: email,
|
||||
subject: `${participant.name} has responded to ${poll.title}`,
|
||||
props: {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue