mirror of
https://github.com/Paris-est-Ludique/intranet.git
synced 2025-06-09 17:14:21 +02:00
Add email and error message when duplicate email at registration
This commit is contained in:
parent
dc4fdda658
commit
ebefcb247c
@ -76,7 +76,19 @@ const RegisterForm = ({ dispatch }: Props): JSX.Element => {
|
||||
toastError("Cet email est invalid ><")
|
||||
return
|
||||
}
|
||||
if (firstname && lastname && email && mobile && !sending) {
|
||||
if (!firstname || !lastname || !email || !mobile || sending) {
|
||||
toast.warning("Il faut remplir les quelques infos sur toi ><", {
|
||||
position: "top-center",
|
||||
autoClose: 6000,
|
||||
hideProgressBar: true,
|
||||
closeOnClick: true,
|
||||
pauseOnHover: true,
|
||||
draggable: true,
|
||||
progress: undefined,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
if (potentialVolunteer) {
|
||||
dispatch(
|
||||
fetchPostulantAdd({
|
||||
@ -121,43 +133,48 @@ const RegisterForm = ({ dispatch }: Props): JSX.Element => {
|
||||
}
|
||||
|
||||
setSending(true)
|
||||
} else {
|
||||
toast.warning("Il faut remplir les queques infos sur toi ><", {
|
||||
position: "top-center",
|
||||
autoClose: 6000,
|
||||
hideProgressBar: true,
|
||||
closeOnClick: true,
|
||||
pauseOnHover: true,
|
||||
draggable: true,
|
||||
progress: undefined,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const { error, entities: postulant } = useSelector(
|
||||
const { error: postulantError, entities: postulant } = useSelector(
|
||||
(state: AppState) => state.postulantAdd,
|
||||
shallowEqual
|
||||
)
|
||||
|
||||
const { error: volunteerError, entities: volunteer } = useSelector(
|
||||
(state: AppState) => state.volunteerAdd,
|
||||
shallowEqual
|
||||
)
|
||||
|
||||
let sendSuccess
|
||||
if (!_.isEmpty(postulant)) {
|
||||
let sendError
|
||||
let sendingElement
|
||||
if (
|
||||
!postulantError &&
|
||||
!_.isEmpty(postulant) &&
|
||||
(potentialVolunteer || (!volunteerError && !_.isEmpty(volunteer)))
|
||||
) {
|
||||
if (sending) {
|
||||
setSending(false)
|
||||
}
|
||||
sendSuccess = <span className={styles.success}>Formulaire envoyé !</span>
|
||||
}
|
||||
|
||||
let sendError
|
||||
if (error && _.isEmpty(postulant)) {
|
||||
} else if (postulantError && _.isEmpty(postulant)) {
|
||||
if (sending) {
|
||||
setSending(false)
|
||||
}
|
||||
sendError = <span className={styles.error}>{error}</span>
|
||||
}
|
||||
|
||||
let sendingElement
|
||||
sendError = <span className={styles.error}>{postulantError}</span>
|
||||
} else if (volunteerError && _.isEmpty(volunteer)) {
|
||||
if (sending) {
|
||||
sendingElement = <span className={styles.sending}>Envoi en cours...</span>
|
||||
setSending(false)
|
||||
}
|
||||
sendError = <span className={styles.error}>{volunteerError}</span>
|
||||
} else if (sending) {
|
||||
sendingElement = (
|
||||
<span className={styles.sending}>
|
||||
Envoi en cours...
|
||||
<br />
|
||||
En cas de problème, écrire à contact@parisestludique.fr
|
||||
</span>
|
||||
)
|
||||
}
|
||||
|
||||
const intro = (
|
||||
|
@ -604,7 +604,7 @@ async function tryNTimes<T>(
|
||||
return await func()
|
||||
} catch (e: any) {
|
||||
console.error(e?.error || e?.message || e)
|
||||
console.error(`${repeatCount} attemps left every ${delayBetweenAttempts}`)
|
||||
console.error(`${repeatCount} attempts left every ${delayBetweenAttempts}`)
|
||||
await new Promise<void>((resolve) => {
|
||||
setTimeout(() => resolve(), delayBetweenAttempts)
|
||||
})
|
||||
|
@ -12,7 +12,6 @@ import {
|
||||
translationVolunteer,
|
||||
VolunteerDayWishes,
|
||||
VolunteerParticipationDetails,
|
||||
VolunteerPartialAddReturn,
|
||||
} from "../../services/volunteers"
|
||||
import { canonicalEmail, canonicalMobile, trim, validMobile } from "../../utils/standardization"
|
||||
import { getJwt } from "../secure"
|
||||
@ -31,7 +30,9 @@ export const volunteerPartialAdd = expressAccessor.add(async (list, body) => {
|
||||
const params = body[0]
|
||||
const volunteer = getByEmail(list, params.email)
|
||||
if (volunteer) {
|
||||
throw Error("Il y a déjà un bénévole avec cet email")
|
||||
throw Error(
|
||||
"Il y a déjà un bénévole avec cet email. Mieux vaut redemander un mot de passe si tu l'as oublié."
|
||||
)
|
||||
}
|
||||
if (!validMobile(params.mobile)) {
|
||||
throw Error("Numéro de téléphone invalide, contacter pierre.scelles@gmail.com")
|
||||
@ -54,14 +55,31 @@ export const volunteerPartialAdd = expressAccessor.add(async (list, body) => {
|
||||
password2: passwordHash,
|
||||
})
|
||||
|
||||
await sendSignUpEmail(newVolunteer.email, password)
|
||||
|
||||
return {
|
||||
toDatabase: newVolunteer,
|
||||
toCaller: {
|
||||
password,
|
||||
} as VolunteerPartialAddReturn,
|
||||
toCaller: {},
|
||||
}
|
||||
})
|
||||
|
||||
async function sendSignUpEmail(email: string, password: string): Promise<void> {
|
||||
const apiKey = process.env.SENDGRID_API_KEY || ""
|
||||
if (__DEV__ || apiKey === "") {
|
||||
console.error(`Fake sending signup email to ${email} with password ${password}`)
|
||||
} else {
|
||||
sgMail.setApiKey(apiKey)
|
||||
const msg = {
|
||||
to: email,
|
||||
from: "contact@parisestludique.fr",
|
||||
subject: "Accès au site des bénévoles de Paris est Ludique",
|
||||
text: `Ton inscription est bien enregistrée, l'aventure PeL peut commencer ! :)\nVoici ton mot de passe pour accéder au site des bénévoles où tu t'es inscrit.e : ${password}\nTu y trouveras notamment comment on communique entre bénévoles.\nBonne journée !\nPierre`,
|
||||
html: `Ton inscription est bien enregistrée, l'aventure PeL peut commencer ! :)<br />Voici ton mot de passe pour accéder au <a href="https://fo.parisestludique.fr/">site des bénévoles</a> : <strong>${password}</strong><br />Tu y trouveras notamment comment on communique entre bénévoles.<br />Bonne journée !<br />Pierre`,
|
||||
}
|
||||
await sgMail.send(msg)
|
||||
}
|
||||
}
|
||||
|
||||
export const volunteerLogin = expressAccessor.get<VolunteerLogin>(async (list, bodyArray) => {
|
||||
const [body] = bodyArray
|
||||
const volunteer = getByEmail(list, body.email)
|
||||
|
@ -30,6 +30,9 @@ export default class ServiceAccessors<
|
||||
...axiosConfig,
|
||||
params: { id },
|
||||
})
|
||||
if (data.error) {
|
||||
throw Error(data.error)
|
||||
}
|
||||
return { data }
|
||||
} catch (error) {
|
||||
return { error: error as Error }
|
||||
@ -51,6 +54,9 @@ export default class ServiceAccessors<
|
||||
`${config.API_URL}/${this.elementName}ListGet`,
|
||||
axiosConfig
|
||||
)
|
||||
if (data.error) {
|
||||
throw Error(data.error)
|
||||
}
|
||||
return { data }
|
||||
} catch (error) {
|
||||
return { error: error as Error }
|
||||
@ -100,6 +106,9 @@ export default class ServiceAccessors<
|
||||
volunteerWithoutId,
|
||||
axiosConfig
|
||||
)
|
||||
if (data.error) {
|
||||
throw Error(data.error)
|
||||
}
|
||||
return { data }
|
||||
} catch (error) {
|
||||
return { error: error as Error }
|
||||
@ -122,6 +131,9 @@ export default class ServiceAccessors<
|
||||
volunteer,
|
||||
axiosConfig
|
||||
)
|
||||
if (data.error) {
|
||||
throw Error(data.error)
|
||||
}
|
||||
return { data }
|
||||
} catch (error) {
|
||||
return { error: error as Error }
|
||||
@ -143,6 +155,9 @@ export default class ServiceAccessors<
|
||||
`${config.API_URL}/${this.elementName}CountGet`,
|
||||
axiosConfig
|
||||
)
|
||||
if (data.error) {
|
||||
throw Error(data.error)
|
||||
}
|
||||
return { data }
|
||||
} catch (error) {
|
||||
return { error: error as Error }
|
||||
|
@ -24,7 +24,7 @@ export class Volunteer implements VolunteerPartial {
|
||||
|
||||
dayWishesComment = ""
|
||||
|
||||
tshirtCount = ""
|
||||
tshirtCount = 0
|
||||
|
||||
tshirtSize = ""
|
||||
|
||||
@ -92,12 +92,6 @@ export class VolunteerPartial {
|
||||
mobile = ""
|
||||
}
|
||||
|
||||
export class VolunteerPartialAddReturn {
|
||||
id = 0
|
||||
|
||||
password = ""
|
||||
}
|
||||
|
||||
export const elementName = "Volunteer"
|
||||
|
||||
export const volunteerExample: Volunteer = {
|
||||
@ -113,7 +107,7 @@ export const volunteerExample: Volunteer = {
|
||||
discordId: "",
|
||||
dayWishes: [],
|
||||
dayWishesComment: "",
|
||||
tshirtCount: "1",
|
||||
tshirtCount: 1,
|
||||
tshirtSize: "Femme M",
|
||||
food: "Végétarien",
|
||||
teamWishes: [],
|
||||
|
@ -7,7 +7,7 @@ import { postulantAdd } from "../services/postulantsAccessors"
|
||||
const postulantAdapter = createEntityAdapter<Postulant>()
|
||||
|
||||
const postulantAddSlice = createSlice({
|
||||
name: "addPostulant",
|
||||
name: "postulantAdd",
|
||||
initialState: postulantAdapter.getInitialState({
|
||||
readyStatus: "idle",
|
||||
} as StateRequest),
|
||||
@ -17,7 +17,7 @@ const postulantAddSlice = createSlice({
|
||||
},
|
||||
getSuccess: (state, { payload }: PayloadAction<Postulant>) => {
|
||||
state.readyStatus = "success"
|
||||
postulantAdapter.addOne(state, payload)
|
||||
postulantAdapter.setOne(state, payload)
|
||||
},
|
||||
getFailure: (state, { payload }: PayloadAction<string>) => {
|
||||
state.readyStatus = "failure"
|
||||
|
@ -7,7 +7,7 @@ import { volunteerPartialAdd } from "../services/volunteersAccessors"
|
||||
const volunteerAdapter = createEntityAdapter<Volunteer>()
|
||||
|
||||
const volunteerPartialAddSlice = createSlice({
|
||||
name: "addVolunteer",
|
||||
name: "volunteerAdd",
|
||||
initialState: volunteerAdapter.getInitialState({
|
||||
readyStatus: "idle",
|
||||
} as StateRequest),
|
||||
@ -17,7 +17,7 @@ const volunteerPartialAddSlice = createSlice({
|
||||
},
|
||||
getSuccess: (state, { payload }: PayloadAction<Volunteer>) => {
|
||||
state.readyStatus = "success"
|
||||
volunteerAdapter.addOne(state, payload)
|
||||
volunteerAdapter.setOne(state, payload)
|
||||
},
|
||||
getFailure: (state, { payload }: PayloadAction<string>) => {
|
||||
state.readyStatus = "failure"
|
||||
|
@ -7,7 +7,7 @@ import { wishAdd } from "../services/wishesAccessors"
|
||||
const wishAdapter = createEntityAdapter<Wish>()
|
||||
|
||||
const wishAddSlice = createSlice({
|
||||
name: "addWish",
|
||||
name: "wishAdd",
|
||||
initialState: wishAdapter.getInitialState({
|
||||
readyStatus: "idle",
|
||||
} as StateRequest),
|
||||
|
@ -8,7 +8,7 @@ import { wishListGet } from "../services/wishesAccessors"
|
||||
const wishAdapter = createEntityAdapter<Wish>()
|
||||
|
||||
const wishList = createSlice({
|
||||
name: "getWishList",
|
||||
name: "wishList",
|
||||
initialState: wishAdapter.getInitialState({
|
||||
readyStatus: "idle",
|
||||
} as StateRequest),
|
||||
|
Loading…
x
Reference in New Issue
Block a user