mirror of
https://github.com/Paris-est-Ludique/intranet.git
synced 2025-06-08 08:34:20 +02:00
Add sending meeting email to postulants
This commit is contained in:
parent
18c6f75511
commit
1c439b1206
@ -162,7 +162,12 @@ const RegisterForm = ({ dispatch }: Props): JSX.Element => {
|
||||
if (sending) {
|
||||
setSending(false)
|
||||
}
|
||||
sendSuccess = <span className={styles.success}>Formulaire envoyé !</span>
|
||||
sendSuccess = (
|
||||
<span className={styles.success}>
|
||||
Formulaire envoyé !<br />
|
||||
Tu as reçu un email de confirmation, peut-être dans tes spams.
|
||||
</span>
|
||||
)
|
||||
} else if (postulantError && _.isEmpty(postulant)) {
|
||||
if (sending) {
|
||||
setSending(false)
|
||||
@ -178,7 +183,7 @@ const RegisterForm = ({ dispatch }: Props): JSX.Element => {
|
||||
<span className={styles.sending}>
|
||||
Envoi en cours...
|
||||
<br />
|
||||
En cas de problème, écrire à contact@parisestludique.fr
|
||||
En cas de problème, écrire à benevoles@parisestludique.fr
|
||||
</span>
|
||||
)
|
||||
}
|
||||
@ -457,6 +462,7 @@ const RegisterForm = ({ dispatch }: Props): JSX.Element => {
|
||||
Ces rencontres ont lieu à 19h dans un bar/resto calme à Châtelet, le{" "}
|
||||
<a
|
||||
href="https://goo.gl/maps/N5NYWDF66vNQDFMh8"
|
||||
key="sfmMap"
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
>
|
||||
@ -465,6 +471,7 @@ const RegisterForm = ({ dispatch }: Props): JSX.Element => {
|
||||
, ou à une soirée festive à 2 pas du lieu du festival, aux{" "}
|
||||
<a
|
||||
href="https://www.captainturtle.fr/aperos-petanque-paris/"
|
||||
key="petanque"
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
>
|
||||
|
@ -37,6 +37,7 @@ export const miscMeetingDateListGet = expressAccessor.get(async (list) =>
|
||||
id: misc.id,
|
||||
meetingId: misc.meetingId,
|
||||
meetingTitle: misc.meetingTitle,
|
||||
meetingUrl: misc.meetingUrl,
|
||||
} as MiscMeetingDate)
|
||||
)
|
||||
)
|
||||
|
@ -1,7 +1,10 @@
|
||||
import _ from "lodash"
|
||||
import sgMail from "@sendgrid/mail"
|
||||
import ExpressAccessors from "./expressAccessors"
|
||||
import { Postulant, PostulantWithoutId, translationPostulant } from "../../services/postulants"
|
||||
import { canonicalEmail, canonicalMobile, trim, validMobile } from "../../utils/standardization"
|
||||
import { getSheet } from "./accessors"
|
||||
import { Misc, MiscWithoutId, translationMisc } from "../../services/miscs"
|
||||
|
||||
const expressAccessor = new ExpressAccessors<PostulantWithoutId, Postulant>(
|
||||
"Postulants",
|
||||
@ -36,6 +39,8 @@ export const postulantAdd = expressAccessor.add(async (list, body) => {
|
||||
comment: trim(params.comment),
|
||||
})
|
||||
|
||||
await sendMeetingEmail(newPostulant.email, newPostulant.firstname, newPostulant.firstMeeting)
|
||||
|
||||
return {
|
||||
toDatabase: newPostulant,
|
||||
toCaller: {},
|
||||
@ -48,3 +53,57 @@ function getByEmail<T extends { email: string }>(list: T[], rawEmail: string): T
|
||||
const volunteer = list.find((v) => canonicalEmail(v.email) === email)
|
||||
return volunteer
|
||||
}
|
||||
|
||||
async function sendMeetingEmail(
|
||||
email: string,
|
||||
firstname: string,
|
||||
firstMeeting: string
|
||||
): Promise<void> {
|
||||
const miscSheet = await getSheet<MiscWithoutId, Misc>("Miscs", new Misc(), translationMisc)
|
||||
const apiKey = process.env.SENDGRID_API_KEY || ""
|
||||
|
||||
if (firstMeeting === "") {
|
||||
if (__DEV__ || apiKey === "") {
|
||||
console.error(`Fake sending meeting email to ${email}`)
|
||||
} else {
|
||||
sgMail.setApiKey(apiKey)
|
||||
const msg = {
|
||||
to: email,
|
||||
from: "contact@parisestludique.fr",
|
||||
subject: "Première rencontre Paris est Ludique",
|
||||
text: `Salut ${firstname},\n\nNous allons te contacter prochainement pour trouver ensemble un moyen de se rencontrer.\n\nÀ bientôt :)\nPierre`,
|
||||
html: `Salut ${firstname},<br /><br />Nous allons te contacter prochainement pour trouver ensemble un moyen de se rencontrer.<br /><br />À bientôt :)<br />Pierre`,
|
||||
}
|
||||
await sgMail.send(msg)
|
||||
}
|
||||
return
|
||||
}
|
||||
// else
|
||||
|
||||
const miscList = await miscSheet.getList()
|
||||
if (!miscList) {
|
||||
throw Error("Unable to load miscList")
|
||||
}
|
||||
|
||||
const meetingLine = miscList.find((misc) => misc.meetingId === firstMeeting)
|
||||
if (!meetingLine) {
|
||||
throw Error(`Unable to find meeting ${firstMeeting}`)
|
||||
}
|
||||
const { meetingTitle, meetingUrl } = meetingLine
|
||||
|
||||
if (__DEV__ || apiKey === "") {
|
||||
console.error(
|
||||
`Fake sending meeting email to ${email} for ${meetingTitle} and url ${meetingUrl}`
|
||||
)
|
||||
} else {
|
||||
sgMail.setApiKey(apiKey)
|
||||
const msg = {
|
||||
to: email,
|
||||
from: "contact@parisestludique.fr",
|
||||
subject: "Première rencontre Paris est Ludique",
|
||||
text: `Salut ${firstname},\n\nNous t'attendons bien le ${meetingTitle} (${meetingUrl}) avec d'autres nouveaux comme toi et quelques bénévoles expérimentés pour parler du festival, du bénévolat, et surtout faire connaissance !\nSi tu as un empêchement, il nous serait vraiment utile de le savoir pour éviter de faire se déplacer l'un d'eux inutilement. Tu peux nous en prévenir en répondant à cet email.\n\nVivement qu'on se rencontre :)\nÀ bientôt,\nPierre`,
|
||||
html: `Salut ${firstname},<br /><br />Nous t'attendons bien le <a target="_blank" href="${meetingUrl}">${meetingTitle}</a> avec d'autres nouveaux comme toi et quelques bénévoles expérimentés pour parler du festival, du bénévolat, et surtout faire connaissance !<br />Si tu as un empêchement, il nous serait vraiment utile de le savoir pour éviter de faire se déplacer l'un d'eux inutilement. Tu peux nous en prévenir en répondant à cet email.<br /><br />Vivement qu'on se rencontre :)<br />À bientôt,<br />Pierre`,
|
||||
}
|
||||
await sgMail.send(msg)
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,8 @@ export class Misc {
|
||||
|
||||
meetingTitle = ""
|
||||
|
||||
meetingUrl = ""
|
||||
|
||||
discordInvitation = ""
|
||||
}
|
||||
|
||||
@ -13,6 +15,7 @@ export const translationMisc: { [k in keyof Misc]: string } = {
|
||||
id: "id",
|
||||
meetingId: "rencontreId",
|
||||
meetingTitle: "rencontreTitre",
|
||||
meetingUrl: "rencontreUrl",
|
||||
discordInvitation: "invitationDiscord",
|
||||
}
|
||||
|
||||
@ -24,6 +27,7 @@ export interface MiscMeetingDate {
|
||||
id: Misc["id"]
|
||||
meetingId: Misc["meetingId"]
|
||||
meetingTitle: Misc["meetingTitle"]
|
||||
meetingUrl: Misc["meetingUrl"]
|
||||
}
|
||||
|
||||
export interface MiscDiscordInvitation {
|
||||
|
Loading…
x
Reference in New Issue
Block a user