From 0d6148aa6af42e6a79196adb71d376b8f43b4b58 Mon Sep 17 00:00:00 2001 From: Alessandro Magionami Date: Sat, 11 Jan 2025 17:17:03 +0100 Subject: [PATCH] feat(workspaces): update email --- .../services/workspaceJoinRequests.ts | 132 +++++++++--------- 1 file changed, 67 insertions(+), 65 deletions(-) diff --git a/packages/server/modules/workspaces/services/workspaceJoinRequests.ts b/packages/server/modules/workspaces/services/workspaceJoinRequests.ts index 4f94ccdf7..d4e49c340 100644 --- a/packages/server/modules/workspaces/services/workspaceJoinRequests.ts +++ b/packages/server/modules/workspaces/services/workspaceJoinRequests.ts @@ -22,22 +22,22 @@ export const dismissWorkspaceJoinRequestFactory = getWorkspace: GetWorkspace updateWorkspaceJoinRequestStatus: UpdateWorkspaceJoinRequestStatus }) => - async ({ userId, workspaceId }: { userId: string; workspaceId: string }) => { - const workspace = await getWorkspace({ workspaceId }) - if (!workspace) { - throw new WorkspaceNotFoundError() - } - await updateWorkspaceJoinRequestStatus({ - userId, - workspaceId, - status: 'dismissed' - }) - return true + async ({ userId, workspaceId }: { userId: string; workspaceId: string }) => { + const workspace = await getWorkspace({ workspaceId }) + if (!workspace) { + throw new WorkspaceNotFoundError() } + await updateWorkspaceJoinRequestStatus({ + userId, + workspaceId, + status: 'dismissed' + }) + return true + } type WorkspaceJoinRequestReceivedEmailArgs = { workspace: { id: string; name: string; slug: string } - requester: { name: string; email: string } + requester: { name: string } workspaceAdmin: { id: string; name: string } } @@ -50,7 +50,7 @@ const buildMjmlBody = ({ Hi ${workspaceAdmin.name}!

-The user ${requester.name} (${requester.email}) requested to join the workspace ${workspace.name}. You can approve or deny the request from the workspace's members settings. +${requester.name} is requesting to join your workspace ${workspace.name}.

@@ -70,7 +70,7 @@ const buildTextBody = ({ const bodyStart = ` Hi ${workspaceAdmin.name}! \r\n\r\n -The user ${requester.name} (${requester.email}) requested to join the workspace ${workspace.name}. You can approve or deny the request from the workspace's members settings. +${requester.name} is requesting to join your workspace ${workspace.name}. \r\n\r\n ` const bodyEnd = `Have questions or feedback? Please write us at hello@speckle.systems and we'd be more than happy to talk.` @@ -83,7 +83,7 @@ const buildEmailTemplateParams = (args: WorkspaceJoinRequestReceivedEmailArgs) = mjml: buildMjmlBody(args), text: buildTextBody(args), cta: { - title: 'A user requested to join your workspace', + title: 'Manage Members', url } } @@ -103,35 +103,37 @@ export const sendWorkspaceJoinRequestReceivedEmailFactory = getWorkspaceCollaborators: GetWorkspaceCollaborators getUserEmails: FindEmailsByUserId }) => - async (args: Omit) => { - const [serverInfo, workspaceAdmins] = await Promise.all([ - getServerInfo(), - getWorkspaceCollaborators({ - workspaceId: args.workspace.id, - limit: 100, - filter: { roles: [Roles.Workspace.Admin] } + async (args: Omit) => { + const { requester, workspace } = args + const [serverInfo, workspaceAdmins] = await Promise.all([ + getServerInfo(), + getWorkspaceCollaborators({ + workspaceId: workspace.id, + limit: 100, + filter: { roles: [Roles.Workspace.Admin] } + }) + ]) + const sendEmailParams = await Promise.all( + workspaceAdmins.map(async (admin) => { + const userEmails = await getUserEmails({ userId: admin.id }) + const emailTemplateParams = buildEmailTemplateParams({ + requester, + workspace, + workspaceAdmin: admin }) - ]) - const sendEmailParams = await Promise.all( - workspaceAdmins.map(async (admin) => { - const userEmails = await getUserEmails({ userId: admin.id }) - const emailTemplateParams = buildEmailTemplateParams({ - ...args, - workspaceAdmin: admin - }) - const { html, text } = await renderEmail(emailTemplateParams, serverInfo, null) - const subject = 'Workspace join request received' - const sendEmailParams = { - html, - text, - subject, - to: userEmails.map((e) => e.email) - } - return sendEmailParams - }) - ) - await Promise.all(sendEmailParams.map((params) => sendEmail(params))) - } + const { html, text } = await renderEmail(emailTemplateParams, serverInfo, null) + const subject = `${requester.name} wants to join your workspace` + const sendEmailParams = { + html, + text, + subject, + to: userEmails.map((e) => e.email) + } + return sendEmailParams + }) + ) + await Promise.all(sendEmailParams.map((params) => sendEmail(params))) + } export const requestToJoinWorkspaceFactory = ({ @@ -145,27 +147,27 @@ export const requestToJoinWorkspaceFactory = getUserById: GetUser getWorkspace: GetWorkspace }) => - async ({ userId, workspaceId }: { userId: string; workspaceId: string }) => { - await createWorkspaceJoinRequest({ - userId, - workspaceId, - status: 'pending' - }) + async ({ userId, workspaceId }: { userId: string; workspaceId: string }) => { + await createWorkspaceJoinRequest({ + userId, + workspaceId, + status: 'pending' + }) - const requester = await getUserById(userId) - if (!requester) { - throw new NotFoundError('User not found') - } - - const workspace = await getWorkspace({ workspaceId }) - if (!workspace) { - throw new NotFoundError('Workspace not found') - } - - await sendWorkspaceJoinRequestReceivedEmail({ - workspace, - requester - }) - - return true + const requester = await getUserById(userId) + if (!requester) { + throw new NotFoundError('User not found') } + + const workspace = await getWorkspace({ workspaceId }) + if (!workspace) { + throw new NotFoundError('Workspace not found') + } + + await sendWorkspaceJoinRequestReceivedEmail({ + workspace, + requester + }) + + return true + }