Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.
TypeScript i18nextnext-authnextjspostgresqlprismareact-emailt3-stacktailwindcsstrpcturborepotypescriptzod
Update all template imports (#414)
Luke Vella25d50a97684a
diff --git a/src/server/routers/polls.ts b/src/server/routers/polls.tsindex d34e341be..f985889d0 100644--- a/src/server/routers/polls.ts+++ b/src/server/routers/polls.ts@@ -2,6 +2,8 @@ import { TRPCError } from "@trpc/server";import { z } from "zod";import { prisma } from "~/prisma/db";+import newPollTemplate from "~/templates/new-poll";+import newVerfiedPollTemplate from "~/templates/new-poll-verified";import { absoluteUrl } from "../../utils/absolute-url";import { sendEmailTemplate } from "../../utils/api-utils";@@ -149,7 +151,7 @@ export const polls = createRouter()try {if (poll.verified) {await sendEmailTemplate({- templateName: "new-poll-verified",+ templateString: newVerfiedPollTemplate,to: input.user.email,subject: `Rallly: ${poll.title}`,templateVars: {@@ -167,7 +169,7 @@ export const polls = createRouter()const verifyEmailUrl = `${pollUrl}?code=${verificationCode}`;await sendEmailTemplate({- templateName: "new-poll",+ templateString: newPollTemplate,to: input.user.email,subject: `Rallly: ${poll.title} - Verify your email address`,templateVars: {diff --git a/src/server/routers/polls/verification.ts b/src/server/routers/polls/verification.tsindex e4bf3215e..a39bbd376 100644--- a/src/server/routers/polls/verification.ts+++ b/src/server/routers/polls/verification.ts@@ -2,6 +2,7 @@ import { TRPCError } from "@trpc/server";import { z } from "zod";import { prisma } from "~/prisma/db";+import newPollTemplate from "~/templates/new-poll";import { absoluteUrl } from "../../../utils/absolute-url";import { sendEmailTemplate } from "../../../utils/api-utils";@@ -83,7 +84,7 @@ export const verification = createRouter()const verifyEmailUrl = `${pollUrl}?code=${token}`;await sendEmailTemplate({- templateName: "new-poll",+ templateString: newPollTemplate,to: poll.user.email,subject: `Rallly: ${poll.title} - Verify your email address`,templateVars: {diff --git a/src/utils/api-utils.ts b/src/utils/api-utils.tsindex 87b7538f3..382623d2d 100644--- a/src/utils/api-utils.ts+++ b/src/utils/api-utils.ts@@ -1,8 +1,7 @@import * as Eta from "eta";-import { readFileSync } from "fs";-import path from "path";import { prisma } from "~/prisma/db";+import newCommentTemplate from "~/templates/new-comment";import { absoluteUrl } from "./absolute-url";import { sendEmail } from "./send-email";@@ -47,7 +46,7 @@ export const sendNotification = async (switch (action.type) {case "newParticipant":await sendEmailTemplate({- templateName: "new-participant",+ templateString: newCommentTemplate,to: poll.user.email,subject: `Rallly: ${poll.title} - New Participant`,templateVars: {@@ -63,7 +62,7 @@ export const sendNotification = async (break;case "newComment":await sendEmailTemplate({- templateName: "new-comment",+ templateString: newCommentTemplate,to: poll.user.email,subject: `Rallly: ${poll.title} - New Comment`,templateVars: {@@ -85,27 +84,19 @@ export const sendNotification = async (};interface SendEmailTemplateParams {- templateName?: string;- templateString?: string;+ templateString: string;to: string;subject: string;templateVars: Record<string, string | undefined>;}export const sendEmailTemplate = async ({- templateName,templateString,templateVars,to,subject,}: SendEmailTemplateParams) => {- const template =- templateString ??- readFileSync(- path.join(process.cwd(), "templates", `${templateName}.html`),- ).toString();-- const rendered = await Eta.render(template, templateVars);+ const rendered = await Eta.render(templateString, templateVars);if (rendered) {await sendEmail({@@ -114,6 +105,6 @@ export const sendEmailTemplate = async ({subject,});} else {- throw new Error(`Failed to render email template: ${templateName}`);+ throw new Error(`Failed to render email template`);}};diff --git a/templates/new-comment.html b/templates/new-comment.tssimilarity index 99%rename from templates/new-comment.htmlrename to templates/new-comment.tsindex e58757a76..b4c718c93 100644--- a/templates/new-comment.html+++ b/templates/new-comment.ts@@ -1,4 +1,4 @@-<!DOCTYPE html>+const template = `<!DOCTYPE html><html lang="en" xmlns:v="urn:schemas-microsoft-com:vml"><head><meta charset="utf-8">@@ -149,4 +149,6 @@</table></div></body>-</html>+</html>`;++export default template;diff --git a/templates/new-participant.html b/templates/new-participant.tssimilarity index 99%rename from templates/new-participant.htmlrename to templates/new-participant.tsindex a6a7959fa..b0f053999 100644--- a/templates/new-participant.html+++ b/templates/new-participant.ts@@ -1,4 +1,4 @@-<!DOCTYPE html>+const template = `<!DOCTYPE html><html lang="en" xmlns:v="urn:schemas-microsoft-com:vml"><head><meta charset="utf-8">@@ -149,4 +149,6 @@</table></div></body>-</html>+</html>`;++export default template;diff --git a/templates/new-poll-verified.html b/templates/new-poll-verified.tssimilarity index 99%rename from templates/new-poll-verified.htmlrename to templates/new-poll-verified.tsindex ce14ae63c..fcb41ffcb 100644--- a/templates/new-poll-verified.html+++ b/templates/new-poll-verified.ts@@ -1,4 +1,4 @@-<!DOCTYPE html>+const template = `<!DOCTYPE html><html lang="en" xmlns:v="urn:schemas-microsoft-com:vml"><head><meta charset="utf-8">@@ -146,4 +146,6 @@</table></div></body>-</html>+</html>`;++export default template;diff --git a/templates/new-poll.html b/templates/new-poll.tssimilarity index 99%rename from templates/new-poll.htmlrename to templates/new-poll.tsindex 1bf2e1669..8e25da159 100644--- a/templates/new-poll.html+++ b/templates/new-poll.ts@@ -1,4 +1,4 @@-<!DOCTYPE html>+const template = `<!DOCTYPE html><html lang="en" xmlns:v="urn:schemas-microsoft-com:vml"><head><meta charset="utf-8">@@ -156,4 +156,6 @@</table></div></body>-</html>+</html>`;++export default template;