Skip to content

Commit

Permalink
Merge pull request #132 from SocialGouv/feat/envoi-contact-bo
Browse files Browse the repository at this point in the history
feat(contact): envoi de la demande au BO
  • Loading branch information
alebret authored Feb 16, 2023
2 parents f16f4ba + 57419b4 commit 77b827f
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 8 deletions.
46 changes: 46 additions & 0 deletions apollo-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions pages/ab-testing/demographic-data-survey.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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({
Expand Down
53 changes: 45 additions & 8 deletions pages/contact/contact-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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"
Expand All @@ -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 = <p className="required-field">{Form.required}</p>
Expand All @@ -47,6 +51,7 @@ export default function ContactForm() {
onCompleted: () => {
ContactUtils.sendTrackerContactConfirmed(contactType)
ContactUtils.saveContactRequest(contactType, sendContactQuery)

setLoading(false)
goToConfirmation()
},
Expand All @@ -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(
Expand All @@ -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({
Expand All @@ -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 = () => {
Expand Down
2 changes: 2 additions & 0 deletions src/constants/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 77b827f

Please sign in to comment.