diff --git a/app/settings/api/queue/subscription-created.ts b/app/settings/api/queue/subscription-created.ts index 9e92ec8..d26ea97 100644 --- a/app/settings/api/queue/subscription-created.ts +++ b/app/settings/api/queue/subscription-created.ts @@ -9,6 +9,7 @@ import type { Metadata } from "integrations/paddle"; import { translateSubscriptionStatus } from "integrations/paddle"; import fetchMessagesQueue from "app/messages/api/queue/fetch-messages"; import fetchCallsQueue from "app/phone-calls/api/queue/fetch-calls"; +import { subscribeNotificationMailer } from "../../../../mailers/subscribe-notification-mailer"; const logger = appLogger.child({ queue: "subscription-created" }); @@ -33,8 +34,7 @@ export const subscriptionCreatedQueue = Queue("api/queue/subscription-c } const isReturningSubscriber = organization.subscriptions.length > 0; - const orgOwner = organization.memberships.find((membership) => membership.role === MembershipRole.OWNER); - const email = orgOwner!.user!.email; + const orgOwner = organization.memberships.find((membership) => membership.role === MembershipRole.OWNER)!.user!; await db.subscription.create({ data: { organizationId, @@ -80,7 +80,7 @@ export const subscriptionCreatedQueue = Queue("api/queue/subscription-c subject: "Welcome back to Shellphone", text: "Welcome back to Shellphone", html: "Welcome back to Shellphone", - recipients: [email], + recipients: [orgOwner.email], }).catch((error) => { logger.error(error); }); @@ -88,14 +88,7 @@ export const subscriptionCreatedQueue = Queue("api/queue/subscription-c return; } - sendEmail({ - subject: "Welcome to Shellphone", - text: `Welcome to Shellphone`, - html: `Welcome to Shellphone`, - recipients: [email], - }).catch((error) => { - logger.error(error); - }); + await (await subscribeNotificationMailer({ to: orgOwner.email, userName: orgOwner.fullName })).send(); }); export default subscriptionCreatedQueue; diff --git a/db/schema.prisma b/db/schema.prisma index 49a9458..37cc6ca 100644 --- a/db/schema.prisma +++ b/db/schema.prisma @@ -57,9 +57,9 @@ model Subscription { enum SubscriptionStatus { active - trialing + trialing // not used past_due - paused + paused // not used deleted } diff --git a/mailers/subscribe-notification-mailer.ts b/mailers/subscribe-notification-mailer.ts new file mode 100644 index 0000000..e822f14 --- /dev/null +++ b/mailers/subscribe-notification-mailer.ts @@ -0,0 +1,35 @@ +import previewEmail from "preview-email"; + +import { sendEmail } from "integrations/aws-ses"; +import { render } from "./renderer"; + +type ResetPasswordMailer = { + to: string; + userName: string; +}; + +export async function subscribeNotificationMailer({ to, userName }: ResetPasswordMailer) { + const origin = process.env.APP_ORIGIN || process.env.BLITZ_DEV_SERVER_ORIGIN; + const phoneSettingsUrl = `${origin}/settings/phone`; + const html = await render("subscribe-notification", { name: userName, phoneSettingsUrl }); + const msg = { + from: "mokhtar@shellphone.app", + to, + subject: "Your Shellphone subscription", + html, + }; + + return { + async send() { + if (process.env.NODE_ENV === "production") { + return sendEmail({ + recipients: [msg.to], + subject: msg.subject, + html: msg.html, + }); + } + + return previewEmail(msg); + }, + }; +} diff --git a/mailers/templates/forgot-password.html b/mailers/templates/forgot-password.html index c79b666..6f2415f 100644 --- a/mailers/templates/forgot-password.html +++ b/mailers/templates/forgot-password.html @@ -36,8 +36,9 @@ bodyClass: bg-gray-postmark-lighter href="{{ action_url }}" class="button button--green" target="_blank" - >Reset your password + Reset your password + diff --git a/mailers/templates/subscribe-notification.html b/mailers/templates/subscribe-notification.html new file mode 100644 index 0000000..6d471a0 --- /dev/null +++ b/mailers/templates/subscribe-notification.html @@ -0,0 +1,57 @@ +--- +bodyClass: bg-gray-postmark-lighter +--- + + + + + + + + + +