mirror of
https://github.com/CompassConnections/Compass.git
synced 2026-04-10 09:39:36 -04:00
Refactor email creation process: rename and update createShareEmails to createShareCompassEmails, add support for pagination with startIndex and n, and replace sendOutreachEmail with sendShareCompassEmail.
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
import {PrivateUser, User} from 'common/user'
|
||||
import {sleep} from 'common/util/time'
|
||||
import {sendOutreachEmail} from 'email/functions/helpers'
|
||||
import {sendShareCompassEmail} from 'email/functions/helpers'
|
||||
import {keyBy} from 'lodash'
|
||||
import {getAllPrivateUsers, getAllUsers, getUser} from 'shared/utils'
|
||||
|
||||
export const createEmails = async (
|
||||
sendEmail: (toUser: User, privateUser: PrivateUser) => Promise<any>,
|
||||
ids: string[],
|
||||
{ids, startIndex, n}: {ids: string[]; startIndex: number; n: number},
|
||||
) => {
|
||||
let users = []
|
||||
if (ids.length) {
|
||||
@@ -17,6 +17,15 @@ export const createEmails = async (
|
||||
} else {
|
||||
users = await getAllUsers()
|
||||
}
|
||||
|
||||
if (startIndex) {
|
||||
users = users.slice(startIndex)
|
||||
}
|
||||
|
||||
if (n) {
|
||||
users = users.slice(0, n)
|
||||
}
|
||||
|
||||
const _privateUsers = await getAllPrivateUsers()
|
||||
const privateUsers = keyBy(_privateUsers, 'id')
|
||||
|
||||
@@ -38,6 +47,6 @@ export const createEmails = async (
|
||||
}
|
||||
}
|
||||
|
||||
export const createShareEmails = async ({ids}: {ids: string[]}) => {
|
||||
return await createEmails(sendOutreachEmail, ids)
|
||||
export const createShareCompassEmails = async (options: any) => {
|
||||
return await createEmails(sendShareCompassEmail, options)
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import {render} from '@react-email/render'
|
||||
import {defaultLocale} from 'common/constants'
|
||||
import {debug} from 'common/logger'
|
||||
import {MatchesType} from 'common/profiles/bookmarked_searches'
|
||||
import {PrivateUser, User} from 'common/user'
|
||||
@@ -195,7 +196,7 @@ export const sendNewEndorsementEmail = async (
|
||||
})
|
||||
}
|
||||
|
||||
export const sendOutreachEmail = async (toUser: User, privateUser: PrivateUser) => {
|
||||
export const sendShareCompassEmail = async (toUser: User, privateUser: PrivateUser) => {
|
||||
const {sendToEmail, unsubscribeUrl} = getNotificationDestinationsForUser(
|
||||
privateUser,
|
||||
'platform_updates',
|
||||
@@ -208,7 +209,7 @@ export const sendOutreachEmail = async (toUser: User, privateUser: PrivateUser)
|
||||
|
||||
const locale = privateUser?.locale
|
||||
const t = createT(locale)
|
||||
console.log(`Sending email to ${privateUser.email} in ${locale}`)
|
||||
console.log(`Sending email to ${privateUser.email} in ${locale ?? defaultLocale} (${toUser.id})`)
|
||||
|
||||
const subject = t(
|
||||
'email.share.preview',
|
||||
|
||||
Reference in New Issue
Block a user