diff --git a/apollo-client.js b/apollo-client.js index a3e96523..bb21b087 100644 --- a/apollo-client.js +++ b/apollo-client.js @@ -117,6 +117,10 @@ export const UPDATE_REPONSES_EPDS_ID_IN_INFORMATION_DEMOGRAPHIQUES = gql` } ` +/** + * Enregistre la demande de contact dans la collection "Demande de contacts" + * ENUM_DEMANDEDECONTACT_TYPE_DE_CONTACT { sms, email, chat } + */ export const SAVE_DEMANDE_DE_CONTACT = gql` mutation ( $typeDeContact: ENUM_DEMANDEDECONTACT_TYPE_DE_CONTACT @@ -140,6 +144,48 @@ export const SAVE_DEMANDE_DE_CONTACT = gql` } ` +/** + * Enregistre le contact dans la collection "Contacts" + * ENUM_CONTACTS_TYPE_DE_CONTACT { sms, email, chat } + * ENUM_CONTACTS_PERSONNE_ACCOMPAGNEE { orientee, aidee, echange_initial, non_accompagnee, nouveau } + */ +export const SAVE_CONTACT = gql` + mutation ( + $prenom: String + $nombreEnfants: Int + $naissanceDernierEnfant: Date + $departementCode: String + $departementLibelle: String + $datePriseContact: Date + $typeDeContact: ENUM_CONTACTS_TYPE_DE_CONTACT + $personneAccompagnee: ENUM_CONTACTS_PERSONNE_ACCOMPAGNEE + $commentaire: String + $widgetEpdsSource: ID + ) { + createContact( + input: { + data: { + prenom: $prenom + nombre_enfants: $nombreEnfants + date_naissance_dernier_enfant: $naissanceDernierEnfant + departement_code: $departementCode + departement_libelle: $departementLibelle + date_prise_contact: $datePriseContact + type_de_contact: $typeDeContact + personne_accompagnee: $personneAccompagnee + commentaire: $commentaire + widget_epds_source: $widgetEpdsSource + } + } + ) { + contact { + id + prenom + } + } + } +` + export const DEMANDE_RESSOURCES = gql` mutation ($email: String) { partageRessourcesParMail(email: $email) diff --git a/pages/ab-testing/demographic-data-survey.js b/pages/ab-testing/demographic-data-survey.js index 968f87a9..31c5fd79 100644 --- a/pages/ab-testing/demographic-data-survey.js +++ b/pages/ab-testing/demographic-data-survey.js @@ -7,6 +7,8 @@ import { ContentLayout } from "../../src/components/Layout" import { WidgetHeader } from "../../src/components/WidgetHeader" import { STORAGE_RESULTS_ID, + STORAGE_TEST_DEMOGRAPHIC_DPT_CODE, + STORAGE_TEST_DEMOGRAPHIC_DPT_LIBELLE, STORAGE_TEST_DEMOGRAPHIC_ID, } from "../../src/constants/constants" import { @@ -181,6 +183,12 @@ export default function DemographicDataSurvey() { const situations = situationItems?.filter((item) => item.isChecked) const entourage = entourageItems?.find((item) => item.isChecked) + localStorage.setItem(STORAGE_TEST_DEMOGRAPHIC_DPT_CODE, residenceValue.code) + localStorage.setItem( + STORAGE_TEST_DEMOGRAPHIC_DPT_LIBELLE, + residenceValue.nom + ) + setLoading(true) await sendInfosQuery({ diff --git a/pages/contact/contact-form.js b/pages/contact/contact-form.js index 74eb085d..28292b35 100644 --- a/pages/contact/contact-form.js +++ b/pages/contact/contact-form.js @@ -9,6 +9,8 @@ import { STORAGE_CONTACT_HOURS, STORAGE_CONTACT_TYPE, STORAGE_SOURCE, + STORAGE_TEST_DEMOGRAPHIC_DPT_CODE, + STORAGE_TEST_DEMOGRAPHIC_DPT_LIBELLE, } from "../../src/constants/constants" import { stringIsNotNullNorEmpty, @@ -19,7 +21,7 @@ import { import * as StorageUtils from "../../src/utils/storage.utils" import { DatePickerLastChild } from "../../src/components/contact/DatePickerLastChild" import { useMutation } from "@apollo/client" -import { client, EPDS_CONTACT_INFORMATION, SAVE_DEMANDE_DE_CONTACT } from "../../apollo-client" +import { client, EPDS_CONTACT_INFORMATION, SAVE_CONTACT, SAVE_DEMANDE_DE_CONTACT } from "../../apollo-client" import { useRouter } from "next/router" import { WidgetHeader } from "../../src/components/WidgetHeader" import { Form } from "../../src/constants/specificLabels" @@ -38,6 +40,8 @@ export default function ContactForm() { const contactType = StorageUtils.getInLocalStorage(STORAGE_CONTACT_TYPE) const contactHours = StorageUtils.getInLocalStorage(STORAGE_CONTACT_HOURS) const websiteSource = StorageUtils.getInLocalStorage(STORAGE_SOURCE) + const dptCode = StorageUtils.getInLocalStorage(STORAGE_TEST_DEMOGRAPHIC_DPT_CODE) + const dptLibelle = StorageUtils.getInLocalStorage(STORAGE_TEST_DEMOGRAPHIC_DPT_LIBELLE) const localeSelected = StorageUtils.getLocaleInLocalStorage() const requiredField =

{Form.required}

@@ -47,6 +51,7 @@ export default function ContactForm() { onCompleted: () => { ContactUtils.sendTrackerContactConfirmed(contactType) ContactUtils.saveContactRequest(contactType, sendContactQuery) + setLoading(false) goToConfirmation() }, @@ -63,6 +68,13 @@ export default function ContactForm() { }, }) + const [sendContactMamanBluesQuery] = useMutation(SAVE_CONTACT, { + client: client, + onError: (err) => { + console.error(err) + }, + }) + useEffect(() => { if (numberOfChildren == 0) setChildBirthDate("") setCanSend( @@ -76,17 +88,20 @@ export default function ContactForm() { ) }, [isEmailValid, isPhoneValid, numberOfChildren, childBirthDate]) - const sendContactRequest = async (inputs) => { - if (!canSend) return - - const name = `${inputs.inputName.value} [${websiteSource}]` - const phoneNumber = phoneNumberFormatting(inputs.inputPhone.value) - + const getChildBirthDateInString = () => { let dateAsString = null if (stringIsNotNullNorEmpty(childBirthDate)) { const date = new Date(childBirthDate) dateAsString = convertDateToString(date, "-") } + return dateAsString + } + + const sendContactRequest = async (inputs) => { + if (!canSend) return + + const name = `${inputs.inputName.value} [${websiteSource}]` + const phoneNumber = phoneNumberFormatting(inputs.inputPhone.value) setLoading(true) await sendEmailContactQuery({ @@ -95,16 +110,38 @@ export default function ContactForm() { email: inputs.inputEmail.value, telephone: phoneNumber, nombreEnfants: numberOfChildren, - naissanceDernierEnfant: dateAsString, + naissanceDernierEnfant: getChildBirthDateInString(), moyen: contactType, horaires: contactHours, }, }) } + const sendContactMamanBluesRequest = async (inputs) => { + if (!canSend) return + + const phoneNumber = phoneNumberFormatting(inputs.inputPhone.value) + + await sendContactMamanBluesQuery({ + variables: { + prenom: inputs.inputName.value, + nombreEnfants: numberOfChildren, + naissanceDernierEnfant: getChildBirthDateInString(), + mode: contactType, + departementCode: dptCode, + departementLibelle: dptLibelle, + datePriseContact: null, + personneAccompagnee: "nouveau", + commentaire: `Numéro de télephone : ${phoneNumber}`, + widgetEpdsSource: websiteSource, + }, + }) + } + const sendForm = async (event) => { event.preventDefault() sendContactRequest(event.target) + sendContactMamanBluesRequest(event.target) } const cancel = () => { diff --git a/src/constants/constants.js b/src/constants/constants.js index 9105ff66..e829ab10 100644 --- a/src/constants/constants.js +++ b/src/constants/constants.js @@ -5,6 +5,8 @@ export const STORAGE_SOURCE = "source" export const STORAGE_TEST_ABC = "testABC" export const STORAGE_TEST_VERS_QUI_SE_TOURNER = "testVersQuiSeTourner" export const STORAGE_TEST_DEMOGRAPHIC_ID = "testDemographicId" +export const STORAGE_TEST_DEMOGRAPHIC_DPT_CODE = "testDemographicDptCode" +export const STORAGE_TEST_DEMOGRAPHIC_DPT_LIBELLE = "testDemographicDptLibelle" export const STORAGE_SCORE = "score" export const STORAGE_SCORE_LEVEL_MACARON = "scoreLevelForMacaron"