From f6568f7a6c3f2c30222ff44675ffb3cf279fffaf Mon Sep 17 00:00:00 2001 From: mbarry-ippon Date: Wed, 22 Mar 2023 12:34:12 +0100 Subject: [PATCH 01/23] feat: refacto des tags sur matomo --- .../ab-testing/measuring-intentions.test.js | 735 ------------------ .../utils/ab-testing/ab-testing.utils.test.js | 8 +- __tests__/utils/contact.utils.test.js | 55 +- pages/ab-testing/demographic-data-survey.js | 10 +- pages/contact/contact-form.js | 12 +- pages/contact/to-be-contacted.js | 18 +- pages/index.js | 13 +- pages/results.js | 42 +- pages/survey/before-survey.js | 12 +- pages/survey/epds-survey.js | 14 +- .../intentions/AskForDetailsQuestion.js | 127 --- .../intentions/BeCloseToRealityQuestion.js | 101 --- .../ab-testing/intentions/FormToSendMail.js | 150 ---- .../intentions/MeasuringIntentions.js | 97 --- .../intentions/TextAreaToSendDetails.js | 89 --- .../resources/GiveAccessToResources.js | 11 +- src/components/results/ContactMamanBlues.js | 12 +- src/components/results/Intentions.js | 12 +- src/components/results/RecruitParents.js | 12 +- src/utils/ab-testing/ab-testing.utils.js | 12 +- .../ab-testing/demographic-data.utils.js | 8 - .../ab-testing/measuring-intentions.utils.js | 7 - src/utils/contact.utils.js | 30 +- src/utils/pdf.utils.js | 1 - src/utils/tracker.utils.js | 78 +- 25 files changed, 154 insertions(+), 1512 deletions(-) delete mode 100644 __tests__/components/ab-testing/measuring-intentions.test.js delete mode 100644 src/components/ab-testing/intentions/AskForDetailsQuestion.js delete mode 100644 src/components/ab-testing/intentions/BeCloseToRealityQuestion.js delete mode 100644 src/components/ab-testing/intentions/FormToSendMail.js delete mode 100644 src/components/ab-testing/intentions/MeasuringIntentions.js delete mode 100644 src/components/ab-testing/intentions/TextAreaToSendDetails.js diff --git a/__tests__/components/ab-testing/measuring-intentions.test.js b/__tests__/components/ab-testing/measuring-intentions.test.js deleted file mode 100644 index f7f70c76..00000000 --- a/__tests__/components/ab-testing/measuring-intentions.test.js +++ /dev/null @@ -1,735 +0,0 @@ -import { fireEvent, render, screen } from "@testing-library/react" -import "@testing-library/jest-dom" -import { - SCORE_LEVEL_BAD, - SCORE_LEVEL_GOOD, -} from "../../../src/utils/score-level.utils" -import { - contacterAToutMoment, - demandeDeDetails, - estLePlusAdapte, - nePasSavoir, - seRapprocheDeLaRealite, -} from "../../../src/utils/ab-testing/measuring-intentions.utils" -import { displayComponentsByTest } from "../../../src/components/ab-testing/intentions/MeasuringIntentions" -import * as ContactMamanBlues from "../../../src/components/results/ContactMamanBlues" - -describe("UI de MeasuringIntentions", () => { - const findLabelEstLePlusAdapte = (value) => - estLePlusAdapte.reponses.find((item) => item.value === value).label - const findLabelDemandeDeDetailsLvl3 = (value) => - demandeDeDetails.lvl3.reponses.find((item) => item.value === value).label - - const mockSetState = jest.fn() - jest.mock("react", () => ({ - useState: (initial) => [initial, mockSetState], - })) - - // Bloc Elise - const mamanBluesBlocToBeInTheDocument = () => { - expect( - screen.getByRole("img", { - name: "Portrait d'Elise : présidente de l'association Maman Blues", - }) - ).toBeInTheDocument() - expect( - screen.getByRole("button", { name: ContactMamanBlues.buttonLabel }) - ).toBeInTheDocument() - } - - const mamanBluesBlocNotToBeInTheDocument = () => { - expect(screen.queryByRole("img", { name: "Portrait d'Elise" })).toBeNull() - } - - const onClickMaybeButton = async (maybeButton) => { - // Action - fireEvent.click(maybeButton) - - // Affichage du bouton - expect(maybeButton).not.toBeInTheDocument() - expect( - await screen.queryByText("Je ne suis pas sûr(e)") - ).not.toBeInTheDocument() - } - - const onClickNoButton = async (noButton) => { - // Action - fireEvent.click(noButton) - - // Phrase spécifique - expect(noButton).not.toBeInTheDocument() - expect(await screen.queryByText("Non")).not.toBeInTheDocument() - } - - describe("Reponse EPDS : Je vais bien", () => { - test("Test A => aucun retour", async () => { - expect( - displayComponentsByTest({ testId: "A", scoreLevel: SCORE_LEVEL_GOOD }) - ).toBeNull() - - expect(screen.queryByRole("button", { name: "Retour" })).toBeNull() - }) - - describe("Test B", () => { - let yesButton, noButton, maybeButton - - beforeEach(() => { - render( - displayComponentsByTest({ - testId: "B", - scoreLevel: SCORE_LEVEL_GOOD, - showBackButton: false, - setShowBackButton: mockSetState, - }) - ) - - yesButton = screen.getByRole("button", { name: "Oui" }) - noButton = screen.getByRole("button", { name: "Non" }) - maybeButton = screen.getByRole("button", { - name: "Je ne suis pas sûr(e)", - }) - - // Buttons - expect(yesButton).toBeInTheDocument() - expect(noButton).toBeInTheDocument() - expect(maybeButton).toBeInTheDocument() - expect( - screen.queryByRole("button", { name: "Retour" }) - ).not.toBeInTheDocument() - }) - - test("Réponse : Oui => affichage du portrait", async () => { - // Action - fireEvent.click(yesButton) - - // Phrase spécifique - expect(yesButton).not.toBeInTheDocument() - expect(await screen.queryByText("Oui")).not.toBeInTheDocument() - expect( - await screen.findByText( - "Vous allez bien, n'hésitez pas à revenir plus tard et vous questionner régulièrement. Sachez qu'Elise peut répondre à vos questions si vous en avez besoin." - ) - ).toBeVisible() - - // Bloc Elise - mamanBluesBlocToBeInTheDocument() - }) - - test("Réponse : Je ne suis pas sûr(e) => affichage du portrait", async () => { - onClickMaybeButton(maybeButton) - expect(await screen.findByText(nePasSavoir)).toBeVisible() - - // Bloc Elise - mamanBluesBlocToBeInTheDocument() - }) - - describe("Réponse : Non", () => { - test("Affichage de la nouvelle question", async () => { - onClickNoButton(noButton) - - expect(await screen.findByText(seRapprocheDeLaRealite)).toBeVisible() - expect( - await screen.getByRole("button", { - name: "Malgré le résultat, je n'ai pas l'impression d'aller bien", - }) - ).toBeInTheDocument() - expect( - await screen.getByRole("button", { - name: "Autre chose : nous le dire", - }) - ).toBeInTheDocument() - - // Bloc Elise - mamanBluesBlocNotToBeInTheDocument() - }) - - test("Réponse : je ne vais pas bien => affichage du portrait", async () => { - // Action - fireEvent.click(noButton) - - // Nouvelle question - const badButton = screen.getByRole("button", { - name: "Malgré le résultat, je n'ai pas l'impression d'aller bien", - }) - const otherButton = screen.getByRole("button", { - name: "Autre chose : nous le dire", - }) - expect(badButton).toBeInTheDocument() - expect(otherButton).toBeInTheDocument() - - // Action - fireEvent.click(badButton) - - // Phrase spécifique - expect(badButton).not.toBeInTheDocument() - expect( - await screen.findByText( - "Malgré le résultat, je n'ai pas l'impression d'aller bien" - ) - ).toBeVisible() - expect( - await screen.findByText( - "Nous vous conseillons de vous entretenir avec Elise. Elle saura vous apporter conseil." - ) - ).toBeVisible() - - // Bloc Elise - mamanBluesBlocToBeInTheDocument() - }) - - test("Réponse : autre chose => affichage textarea", async () => { - // Action - fireEvent.click(noButton) - - // Nouvelle question - const badButton = screen.getByRole("button", { - name: "Malgré le résultat, je n'ai pas l'impression d'aller bien", - }) - const otherButton = screen.getByRole("button", { - name: "Autre chose : nous le dire", - }) - expect(badButton).toBeInTheDocument() - expect(otherButton).toBeInTheDocument() - - // Action - fireEvent.click(otherButton) - - // Phrase spécifique - expect(otherButton).not.toBeInTheDocument() - expect( - await screen.findByText("Autre chose : nous le dire") - ).toBeVisible() - expect( - await screen.findByText( - "Expliquez-nous pourquoi vous êtes venu.es passer le test." - ) - ).toBeVisible() - expect( - screen.getByRole("textbox", { - name: "textValueOther", - }) - ).toBeInTheDocument() - - // Bloc Elise - mamanBluesBlocNotToBeInTheDocument() - }) - }) - }) - - describe("Test C", () => { - let yesButton, noButton, maybeButton - - beforeEach(() => { - render( - displayComponentsByTest({ - testId: "C", - scoreLevel: SCORE_LEVEL_GOOD, - showBackButton: false, - setShowBackButton: mockSetState, - }) - ) - - yesButton = screen.getByRole("button", { name: "Oui" }) - noButton = screen.getByRole("button", { name: "Non" }) - maybeButton = screen.getByRole("button", { - name: "Je ne suis pas sûr(e)", - }) - - // Buttons - expect(yesButton).toBeInTheDocument() - expect(noButton).toBeInTheDocument() - expect(maybeButton).toBeInTheDocument() - expect( - screen.queryByRole("button", { name: "Retour" }) - ).not.toBeInTheDocument() - }) - - afterEach(() => { - mamanBluesBlocNotToBeInTheDocument() - }) - - test("Réponse : Oui => affichage du portrait", async () => { - // Action - fireEvent.click(yesButton) - - // Phrase spécifique - expect( - await screen.findByText( - "Vous allez bien, n'hésitez pas à revenir plus tard et vous questionner régulièrement. Sachez qu'Elise peut répondre à vos questions si vous en avez besoin." - ) - ).toBeVisible() - }) - - test("Réponse : Je ne suis pas sûr(e) => affichage du portrait", async () => { - // Action - fireEvent.click(maybeButton) - - // Phrase spécifique - expect(await screen.findByText(nePasSavoir)).toBeVisible() - }) - - describe("Réponse : Non", () => { - test("Affichage de la nouvelle question", async () => { - // Action - fireEvent.click(noButton) - - // Phrase spécifique - expect(await screen.findByText(seRapprocheDeLaRealite)).toBeVisible() - expect( - await screen.getByRole("button", { - name: "Malgré le résultat, je n'ai pas l'impression d'aller bien", - }) - ).toBeInTheDocument() - expect( - await screen.getByRole("button", { - name: "Autre chose : nous le dire", - }) - ).toBeInTheDocument() - }) - - test("Réponse : je ne vais pas bien => affichage du portrait", async () => { - // Action - fireEvent.click(noButton) - - // Nouvelle question - const badButton = screen.getByRole("button", { - name: "Malgré le résultat, je n'ai pas l'impression d'aller bien", - }) - const otherButton = screen.getByRole("button", { - name: "Autre chose : nous le dire", - }) - expect(badButton).toBeInTheDocument() - expect(otherButton).toBeInTheDocument() - - // Action - fireEvent.click(badButton) - - // Phrase spécifique - expect( - await screen.findByText( - "Nous vous conseillons de vous entretenir avec Elise. Elle saura vous apporter conseil." - ) - ).toBeVisible() - }) - - test("Réponse : autre chose => affichage textarea", async () => { - // Action - fireEvent.click(noButton) - - // Nouvelle question - const badButton = screen.getByRole("button", { - name: "Malgré le résultat, je n'ai pas l'impression d'aller bien", - }) - const otherButton = screen.getByRole("button", { - name: "Autre chose : nous le dire", - }) - expect(badButton).toBeInTheDocument() - expect(otherButton).toBeInTheDocument() - - // Action - fireEvent.click(otherButton) - - // Phrase spécifique - expect( - await screen.findByText( - "Expliquez-nous pourquoi vous êtes venu.es passer le test." - ) - ).toBeVisible() - expect( - screen.getByRole("textbox", { - name: "textValueOther", - }) - ).toBeInTheDocument() - }) - }) - }) - }) - - describe("Reponse EPDS : Je ne vais pas bien", () => { - test("Test A => affichage portrait", async () => { - expect( - displayComponentsByTest({ testId: "A", scoreLevel: SCORE_LEVEL_BAD }) - ).toBeNull() - - expect(screen.queryByRole("button", { name: "Retour" })).toBeNull() - // On ne peut pas vérifier si le bloc de contact est présent car il est hors du bloc généré par `displayComponentsByTest` - }) - - describe("Test B", () => { - let yesButton, noButton, maybeButton - - beforeEach(() => { - render( - displayComponentsByTest({ - testId: "B", - scoreLevel: SCORE_LEVEL_BAD, - showBackButton: false, - setShowBackButton: mockSetState, - }) - ) - - yesButton = screen.getByRole("button", { name: "Oui" }) - noButton = screen.getByRole("button", { name: "Non" }) - maybeButton = screen.getByRole("button", { - name: "Je ne suis pas sûr(e)", - }) - - // Buttons - expect(yesButton).toBeInTheDocument() - expect(noButton).toBeInTheDocument() - expect(maybeButton).toBeInTheDocument() - expect( - screen.queryByRole("button", { name: "Retour" }) - ).not.toBeInTheDocument() - }) - - describe("Réponse : Oui", () => { - test("Affichage de la nouvelle question + réponses", async () => { - // Action - fireEvent.click(yesButton) - - // Phrase spécifique - expect(yesButton).not.toBeInTheDocument() - expect(await screen.queryByText("Oui")).not.toBeInTheDocument() - - expect( - await screen.findByText("Prenez une des actions suivantes.") - ).toBeVisible() - - // Nouveaux boutons - expect( - await screen.getByRole("button", { - name: findLabelEstLePlusAdapte("quiJoindre"), - }) - ).toBeInTheDocument() - expect( - await screen.getByRole("button", { - name: findLabelEstLePlusAdapte("quoiFaire"), - }) - ).toBeInTheDocument() - expect( - await screen.getByRole("button", { - name: findLabelEstLePlusAdapte("seTourner"), - }) - ).toBeInTheDocument() - expect( - await screen.getByRole("button", { - name: findLabelEstLePlusAdapte("aucune"), - }) - ).toBeInTheDocument() - - // Bloc Elise - mamanBluesBlocNotToBeInTheDocument() - }) - - describe("Réponses spécifiques", () => { - let quiJoindre, quoiFaire, seTourner, aucune - - beforeEach(() => { - // Action - fireEvent.click(yesButton) - - quiJoindre = screen.getByRole("button", { - name: findLabelEstLePlusAdapte("quiJoindre"), - }) - quoiFaire = screen.getByRole("button", { - name: findLabelEstLePlusAdapte("quoiFaire"), - }) - seTourner = screen.getByRole("button", { - name: findLabelEstLePlusAdapte("seTourner"), - }) - aucune = screen.getByRole("button", { - name: findLabelEstLePlusAdapte("aucune"), - }) - }) - - afterEach(() => { - // Bloc Elise - mamanBluesBlocToBeInTheDocument() - }) - - test("Réponse : Je sais qui joindre => formulaire", async () => { - // Action - fireEvent.click(quiJoindre) - - // Phrases spécifiques - expect( - await screen.findByText(findLabelEstLePlusAdapte("quiJoindre")) - ).toBeVisible() - expect(await screen.findByText(contacterAToutMoment)).toBeVisible() - - // Formaulaire - expect( - await screen.findByText( - "Recevez votre résultat au questionnaire par mail pour le partager à votre professionnel de santé :" - ) - ).toBeVisible() - expect( - screen.getByRole("form", { - name: "formToSendMail", - }) - ).toBeInTheDocument() - expect(await screen.findByText("Votre mail * :")).toBeVisible() - }) - - test("Réponse : Je sais quoi faire => formulaire", async () => { - // Action - fireEvent.click(quoiFaire) - - // Phrases spécifiques - expect( - await screen.findByText(findLabelEstLePlusAdapte("quoiFaire")) - ).toBeVisible() - expect(await screen.findByText(contacterAToutMoment)).toBeVisible() - - // Formaulaire - expect( - await screen.queryByText( - "Recevez votre résultat au questionnaire par mail pour le partager à votre professionnel de santé :" - ) - ).toBeNull() - expect( - screen.getByRole("form", { - name: "formToSendMail", - }) - ).toBeInTheDocument() - expect( - await screen.findByText("L'email de votre proche * :") - ).toBeVisible() - }) - - test("Réponse : Je ne sais pas vers qui me tourner => texte", async () => { - // Action - fireEvent.click(seTourner) - - expect( - await screen.findByText(findLabelEstLePlusAdapte("seTourner")) - ).toBeVisible() - }) - - test("Réponse : Aucune des trois : je vous explique => textarea", async () => { - // Action - fireEvent.click(aucune) - - // Phrases spécifiques - expect( - await screen.findByText(findLabelEstLePlusAdapte("aucune")) - ).toBeVisible() - expect( - await screen.findByText(estLePlusAdapte.commentaires.aucune) - ).toBeVisible() - expect(await screen.findByText(contacterAToutMoment)).toBeVisible() - - // Text Area - expect( - screen.getByRole("textbox", { - name: "textValueOther", - }) - ).toBeInTheDocument() - }) - }) - }) - - test("Réponse : Je ne suis pas sûr(e) => affichage du portrait", async () => { - onClickMaybeButton(maybeButton) - expect(await screen.findByText(nePasSavoir)).toBeVisible() - - // Bloc Elise - mamanBluesBlocToBeInTheDocument() - }) - - describe("Réponse : Non", () => { - test("Affichage de la nouvelle question & réponses", async () => { - onClickNoButton(noButton) - expect(await screen.findByText(seRapprocheDeLaRealite)).toBeVisible() - - // Nouveaux boutons - expect( - await screen.getByRole("button", { - name: findLabelDemandeDeDetailsLvl3("bien"), - }) - ).toBeInTheDocument() - expect( - await screen.getByRole("button", { - name: "J'ai fait le test par curiosité", - }) - ).toBeInTheDocument() - expect( - await screen.getByRole("button", { - name: "Je suis professionnel de santé", - }) - ).toBeInTheDocument() - }) - - describe("Réponses spécifiques", () => { - let bien, curiosite, proSante - - beforeEach(() => { - // Action - fireEvent.click(noButton) - - bien = screen.getByRole("button", { - name: findLabelDemandeDeDetailsLvl3("bien"), - }) - curiosite = screen.getByRole("button", { - name: "J'ai fait le test par curiosité", - }) - proSante = screen.getByRole("button", { - name: "Je suis professionnel de santé", - }) - }) - - test("Réponse : Malgré le résultat, je l'impression que tout va bien => texte", async () => { - // Action - fireEvent.click(bien) - - expect( - await screen.findByText(findLabelDemandeDeDetailsLvl3("bien")) - ).toBeVisible() - - // Bloc Elise - mamanBluesBlocToBeInTheDocument() - }) - - test("Réponse : J'ai fait le test par curiosité => texte", async () => { - // Action - fireEvent.click(curiosite) - - expect( - await screen.findByText("J'ai fait le test par curiosité") - ).toBeVisible() - - // Bloc Elise - mamanBluesBlocToBeInTheDocument() - }) - - test("Réponse : Je suis professionnel de santé => texte", async () => { - // Action - fireEvent.click(proSante) - - expect( - await screen.findByText("Je suis professionnel de santé") - ).toBeVisible() - - // Bloc Elise - mamanBluesBlocNotToBeInTheDocument() - }) - }) - }) - }) - - describe("Test C", () => { - let yesButton, noButton, maybeButton - - beforeEach(() => { - render( - displayComponentsByTest({ - testId: "C", - scoreLevel: SCORE_LEVEL_BAD, - showBackButton: false, - setShowBackButton: mockSetState, - }) - ) - - yesButton = screen.getByRole("button", { name: "Oui" }) - noButton = screen.getByRole("button", { name: "Non" }) - maybeButton = screen.getByRole("button", { - name: "Je ne suis pas sûr(e)", - }) - - // Buttons - expect(yesButton).toBeInTheDocument() - expect(noButton).toBeInTheDocument() - expect(maybeButton).toBeInTheDocument() - expect( - screen.queryByRole("button", { name: "Retour" }) - ).not.toBeInTheDocument() - }) - - afterEach(() => { - mamanBluesBlocNotToBeInTheDocument() - }) - - describe("Réponse : Oui", () => { - let quiJoindre, quoiFaire, seTourner, aucune - - beforeEach(() => { - // Action - fireEvent.click(yesButton) - - quiJoindre = screen.getByRole("button", { - name: findLabelEstLePlusAdapte("quiJoindre"), - }) - quoiFaire = screen.getByRole("button", { - name: findLabelEstLePlusAdapte("quoiFaire"), - }) - seTourner = screen.getByRole("button", { - name: findLabelEstLePlusAdapte("seTourner"), - }) - aucune = screen.getByRole("button", { - name: findLabelEstLePlusAdapte("aucune"), - }) - }) - - test("Réponse : Je sais qui joindre => formulaire", async () => { - // Action - fireEvent.click(quiJoindre) - }) - - test("Réponse : Je sais quoi faire => formulaire", async () => { - // Action - fireEvent.click(quoiFaire) - }) - - test("Réponse : Je ne sais pas vers qui me tourner => texte", async () => { - // Action - fireEvent.click(seTourner) - }) - - test("Réponse : Aucune des trois : je vous explique => textarea", async () => { - // Action - fireEvent.click(aucune) - }) - }) - - test("Réponse : Je ne suis pas sûr(e)", async () => { - // Action - fireEvent.click(maybeButton) - }) - - describe("Réponse : Non", () => { - let bien, curiosite, proSante - - beforeEach(() => { - // Action - fireEvent.click(noButton) - - bien = screen.getByRole("button", { - name: findLabelDemandeDeDetailsLvl3("bien"), - }) - curiosite = screen.getByRole("button", { - name: "J'ai fait le test par curiosité", - }) - proSante = screen.getByRole("button", { - name: "Je suis professionnel de santé", - }) - }) - - test("Réponse : Malgré le résultat, je l'impression que tout va bien => texte", async () => { - // Action - fireEvent.click(bien) - }) - - test("Réponse : J'ai fait le test par curiosité => texte", async () => { - // Action - fireEvent.click(curiosite) - }) - - test("Réponse : Je suis professionnel de santé => texte", async () => { - // Action - fireEvent.click(proSante) - }) - }) - }) - }) -}) diff --git a/__tests__/utils/ab-testing/ab-testing.utils.test.js b/__tests__/utils/ab-testing/ab-testing.utils.test.js index 986f45ac..0705d5ec 100644 --- a/__tests__/utils/ab-testing/ab-testing.utils.test.js +++ b/__tests__/utils/ab-testing/ab-testing.utils.test.js @@ -24,15 +24,11 @@ describe("Utils", () => { trackerSpy = jest.spyOn(TrackerUtils, "track") }) - test("Should return tracker with CATEG.test, course name and label", () => { + test("Should return tracker with label", () => { localStorage.setItem(STORAGE_TEST_ABC, "A") AbTestingUtils.trackerForAbTesting("my label") - expect(trackerSpy).toHaveBeenCalledWith( - TrackerUtils.CATEG.test, - `${TrackerUtils.ACTION.parcours}A`, - "my label" - ) + expect(trackerSpy).toHaveBeenCalledWith("Test_A", "my label") }) }) }) diff --git a/__tests__/utils/contact.utils.test.js b/__tests__/utils/contact.utils.test.js index 4ab24a41..9cc5c682 100644 --- a/__tests__/utils/contact.utils.test.js +++ b/__tests__/utils/contact.utils.test.js @@ -8,7 +8,7 @@ describe("Contact Utils", () => { localStorage.setItem(STORAGE_SOURCE, "1000-premiers-jours") const source = localStorage.getItem(STORAGE_SOURCE) beforeEach(() => { - trackerSpy = jest.spyOn(TrackerUtils, "track") + trackerSpy = jest.spyOn(TrackerUtils, "trackerForContact") }) afterEach(() => { @@ -16,30 +16,45 @@ describe("Contact Utils", () => { }) test("Should send tracker with email confirmation", () => { - ContactUtils.sendTrackerContactConfirmed(RequestContact.type.email) + TrackerUtils.trackerForContact() + ContactUtils.sendTrackerContactConfirmed( + RequestContact.type.email, + "Confirmation" + ) expect(trackerSpy).toHaveBeenCalledWith( - TrackerUtils.CATEG.contact, - TrackerUtils.ACTION.contact_confirm_sent, - `${TrackerUtils.CONTACT_SENT.mail} - ${source}` + `${TrackerUtils.CONTACT_SENT.mail}` ) }) test("Should send tracker with sms confirmation", () => { - ContactUtils.sendTrackerContactConfirmed(RequestContact.type.sms) + ContactUtils.sendTrackerContactConfirmed( + RequestContact.type.sms, + "Confirmation" + ) expect(trackerSpy).toHaveBeenCalledWith( - TrackerUtils.CATEG.contact, - TrackerUtils.ACTION.contact_confirm_sent, - `${TrackerUtils.CONTACT_SENT.sms} - ${source}` + `${TrackerUtils.CONTACT_SENT.sms}` ) }) test("Should send tracker with chat opening", () => { - ContactUtils.sendTrackerContactConfirmed(RequestContact.type.chat) + ContactUtils.sendTrackerContactConfirmed( + RequestContact.type.chat, + "Ouverture" + ) + expect(trackerSpy).toHaveBeenCalled() + expect(trackerSpy).toHaveBeenCalledWith( + `${TrackerUtils.CONTACT_SENT.chat}` + ) + }) + + test("Should send tracker with rdv confirmation", () => { + ContactUtils.sendTrackerContactConfirmed( + RequestContact.type.rendezvous, + "Confirmation" + ) expect(trackerSpy).toHaveBeenCalled() expect(trackerSpy).toHaveBeenCalledWith( - TrackerUtils.CATEG.contact, - TrackerUtils.ACTION.contact_confirm_sent, - `${TrackerUtils.CONTACT_SENT.chat} - ${source}` + `${TrackerUtils.CONTACT_SENT.rendezvous}` ) }) }) @@ -80,6 +95,20 @@ describe("Contact Utils", () => { expect(ContactUtils.isMamanBluesAvailableHours()).toBeFalsy() }) + test("Should return false with 12h55", () => { + const date = new Date("2023-02-13 12:55:05") + jest.useFakeTimers().setSystemTime(date) + + expect(ContactUtils.isMamanBluesAvailableHours()).toBeFalsy() + }) + + test("Should return true with 13h01", () => { + const date = new Date("2023-02-13 13:01:05") + jest.useFakeTimers().setSystemTime(date) + + expect(ContactUtils.isMamanBluesAvailableHours()).toBeTruthy() + }) + test("Should return false with 18h00", () => { const date = new Date("2023-02-13 18:00:05") jest.useFakeTimers().setSystemTime(date) diff --git a/pages/ab-testing/demographic-data-survey.js b/pages/ab-testing/demographic-data-survey.js index 31c5fd79..644d48e9 100644 --- a/pages/ab-testing/demographic-data-survey.js +++ b/pages/ab-testing/demographic-data-survey.js @@ -23,6 +23,7 @@ import { updateRadioButtonSelectedInList, } from "../../src/utils/main.utils" import * as StorageUtils from "../../src/utils/storage.utils" +import * as TrackerUtils from "../../src/utils/tracker.utils" import * as DemographicDataUtils from "../../src/utils/ab-testing/demographic-data.utils" import { JobSelector } from "../../src/components/JobSelector" import { DepartmentCodeSelector } from "../../src/components/DepartmentCodeSelector" @@ -205,12 +206,9 @@ export default function DemographicDataSurvey() { cspLibelle: jobValue.libelle, }, }) - - const trackerLabel = demographicData?.isAfterEpds - ? demographicData?.buttonLabelInInfoDemographicSurvey - : "Envoyer" - DemographicDataUtils.trackerForDemographie( - `Questionnaire démographique - ${trackerLabel}` + TrackerUtils.track( + TrackerUtils.CATEG.demography, + TrackerUtils.ACTION.end_demo ) } diff --git a/pages/contact/contact-form.js b/pages/contact/contact-form.js index 26c2802b..b8903c75 100644 --- a/pages/contact/contact-form.js +++ b/pages/contact/contact-form.js @@ -164,16 +164,10 @@ export default function ContactForm() { } const sendTrackerContactType = (typeContact) => { - TrackerUtils.genericTracker( - TrackerUtils.CATEG.contact, - TrackerUtils.NAME.contact_confirm_sent - ) if (typeContact) { - TrackerUtils.track( - TrackerUtils.CATEG.contact, - TrackerUtils.ACTION.contact_confirm_sent, - `${ContactUtils.trackerContactName(typeContact)} - ${websiteSource}` - ) + TrackerUtils.trackerForContact(TrackerUtils.ACTION.confirmation) + TrackerUtils.trackerForContact(ContactUtils.trackerContactName(typeContact)) + AbTestingUtils.trackerForAbTesting(TrackerUtils.ACTION.confirmation) AbTestingUtils.trackerForAbTesting(ContactUtils.trackerContactName(typeContact)) } } diff --git a/pages/contact/to-be-contacted.js b/pages/contact/to-be-contacted.js index f39d3587..8c7a7a09 100644 --- a/pages/contact/to-be-contacted.js +++ b/pages/contact/to-be-contacted.js @@ -99,7 +99,6 @@ export default function ToBeContacted() { const openWhatsapp = async () => { ContactUtils.saveContactRequest(RequestContact.type.chat, sendContactQuery) - ContactUtils.sendTrackerContactConfirmed(RequestContact.type.chat) window.open(URL_CHAT_WHATSAPP, "_blank") } @@ -121,17 +120,12 @@ export default function ToBeContacted() { } const onValidate = async (_event) => { - const source = StorageUtils.getInLocalStorage(STORAGE_SOURCE) - TrackerUtils.genericTracker( - TrackerUtils.CATEG.contact, - TrackerUtils.NAME.contact_type - ) - TrackerUtils.track( - TrackerUtils.CATEG.contact, - TrackerUtils.ACTION.contact_type, - `${itemValueType} - ${source}` - ) - AbTestingUtils.trackerForAbTesting(itemValueType) + if (itemValueType) { + TrackerUtils.trackerForContact(`Choix effectué`) + TrackerUtils.trackerForContact(`Choix ${itemValueType}`) + AbTestingUtils.trackerForAbTesting(`Choix effectué`) + AbTestingUtils.trackerForAbTesting(`Choix ${itemValueType}`) + } if (itemValueType == RequestContact.type.chat) activateChat() else goToContactForm() diff --git a/pages/index.js b/pages/index.js index 90c44c3f..63c31cfd 100644 --- a/pages/index.js +++ b/pages/index.js @@ -10,7 +10,7 @@ import { } from "../src/constants/constants" import { useRouter } from "next/router" import { gql, useLazyQuery } from "@apollo/client" -import { client, GET_TEMOIGNAGES_CHIFFRES } from "../apollo-client" +import { client } from "../apollo-client" import { convertArrayLabelsToObject, readSourceInUrl, @@ -54,17 +54,8 @@ export default function Home() { }, [localeSelected]) const startSurvey = () => { - TrackerUtils.genericTracker( - TrackerUtils.CATEG.home, - TrackerUtils.NAME.start - ) - TrackerUtils.track( - TrackerUtils.CATEG.home, - TrackerUtils.EVENT_CLICK, - `Commencer le test - ${source}` - ) - localStorage.setItem(STORAGE_SOURCE, source) + TrackerUtils.track(TrackerUtils.CATEG.home, TrackerUtils.ACTION.start) localStorage.setItem(STORAGE_TEST_ABC, AbTestingUtils.generateRandomTest()) goToBeforeSurvey() } diff --git a/pages/results.js b/pages/results.js index ef45c5eb..f7ba7fce 100644 --- a/pages/results.js +++ b/pages/results.js @@ -23,7 +23,7 @@ import { Intentions } from "../src/components/results/Intentions" import { DownloadApp } from "../src/components/results/DownloadApp" import { RecruitParents } from "../src/components/results/RecruitParents" import { GiveAccessToResources } from "../src/components/ab-testing/resources/GiveAccessToResources" -import * as AbTestingUtils from "../src/utils/ab-testing/ab-testing.utils" + export default function Results() { const SCORE_TO_SHOW_CONTACT_BLOC = 9 const OPINION_GOUV_URL = @@ -71,13 +71,9 @@ export default function Results() { target="_blank" rel="noreferrer" href={OPINION_GOUV_URL} - onClick={() => - TrackerUtils.track( - TrackerUtils.CATEG.results, - TrackerUtils.EVENT_CLICK, - "Je donne mon avis" - ) - } + onClick={() => { + TrackerUtils.trackerForIntentions(TrackerUtils.ACTION.opinion) + }} > { - let colorsByLevel - switch (scoreLevel) { - case 1: - colorsByLevel = "good-mood" - break - case 2: - colorsByLevel = "moderatelygood-mood" - break - case 3: - colorsByLevel = "bad-mood" - break - default: - break + const seuilScore = () => { + let seuil + if (scoreValue < 9) { + seuil = "score < 9" + } else if (scoreValue >= 9 && scoreValue < 11) { + seuil = "9 >= score < 11" + } else if (scoreValue >= 11) { + seuil = "score >= 11" } - return colorsByLevel + return seuil } useEffect(() => { - if (levelMacaronText(scoreLevelForMood)) { - AbTestingUtils.trackerForAbTesting( - `Macaron Elise - ${levelMacaronText(scoreLevelForMood)} - ${source}` - ) + if (seuilScore()) { + TrackerUtils.trackerForResults(seuilScore()) } }, []) diff --git a/pages/survey/before-survey.js b/pages/survey/before-survey.js index ee32a1a0..9032bd03 100644 --- a/pages/survey/before-survey.js +++ b/pages/survey/before-survey.js @@ -7,6 +7,7 @@ import { WidgetHeader } from "../../src/components/WidgetHeader" import { STORAGE_SOURCE } from "../../src/constants/constants" import * as DemographicDataUtils from "../../src/utils/ab-testing/demographic-data.utils" import * as StorageUtils from "../../src/utils/storage.utils" +import * as TrackerUtils from "../../src/utils/tracker.utils" export default function BeforeSurvey() { const router = useRouter() @@ -32,25 +33,22 @@ export default function BeforeSurvey() { }, []) const goToEpdsSurvey = async () => { - DemographicDataUtils.trackerForDemographie( - `Informations avant EPDS - Commencer le questionnaire - ${source}` - ) - router.push({ pathname: "/survey/epds-survey", }) } const goToNextPage = async () => { + TrackerUtils.track( + TrackerUtils.CATEG.introduction, + TrackerUtils.ACTION.end_intro + ) source === "1000-premiers-jours" ? await goToEpdsSurvey() : await goToDemographicSurvey() } const goToDemographicSurvey = async () => { - DemographicDataUtils.trackerForDemographie( - `Informations avant EPDS - ${demographicData?.buttonLabelInBeforeSurvey} - ${source}` - ) DemographicDataUtils.goToDemographicSurvey(router) } diff --git a/pages/survey/epds-survey.js b/pages/survey/epds-survey.js index 0e18f273..e1d0f0f1 100644 --- a/pages/survey/epds-survey.js +++ b/pages/survey/epds-survey.js @@ -186,6 +186,9 @@ export default function EpdsSurvey() { const onNextQuestion = () => { ref.current.next() setActualIndex(actualIndex + 1) + if (actualIndex + 1 === 1) { + TrackerUtils.trackerForSurvey(TrackerUtils.ACTION.start_survey) + } } const PreviousAndNextButton = ({ showPrevious, showNext }) => { @@ -222,16 +225,7 @@ export default function EpdsSurvey() { onClick={() => { setSendScore(true) setLoading(true) - - TrackerUtils.genericTracker( - TrackerUtils.CATEG.survey, - TrackerUtils.NAME.end - ) - TrackerUtils.track( - TrackerUtils.CATEG.survey, - TrackerUtils.EVENT_CLICK, - `Terminer - ${source}` - ) + TrackerUtils.trackerForSurvey(TrackerUtils.ACTION.end_survey) }} disabled={!isEnabledNextButton || isLoading} > diff --git a/src/components/ab-testing/intentions/AskForDetailsQuestion.js b/src/components/ab-testing/intentions/AskForDetailsQuestion.js deleted file mode 100644 index a5251924..00000000 --- a/src/components/ab-testing/intentions/AskForDetailsQuestion.js +++ /dev/null @@ -1,127 +0,0 @@ -import { useEffect, useState } from "react" -import { ToggleButton, ToggleButtonGroup } from "react-bootstrap" -import { - trackerForIntentions, - saveIsIntentionVersQuiSeTourner, -} from "../../../utils/ab-testing/measuring-intentions.utils" -import { convertStringWithfirstPartInBold } from "../../../utils/main.utils" -import { - SCORE_LEVEL_BAD, - SCORE_LEVEL_MEDIUM, -} from "../../../utils/score-level.utils" -import { ContactMamanBlues } from "../../results/ContactMamanBlues" -import { FormToSendMail } from "./FormToSendMail" -import { TextAreaToSendDetails } from "./TextAreaToSendDetails" - -const DETAILS_TYPE = { - TEXTE: "text", - TEXT_AREA: "text_area", - FORM: "form", -} - -export const AskForDetailsQuestion = ({ - scoreLevel, - displayMamanBlues = true, - data, -}) => { - const [askForDetails, setAskForDetails] = useState("") - const [displayMore, setDisplayMore] = useState() - const [displayItemSelected, setDisplayItemSelected] = useState(false) - - useEffect(() => { - switch (getDetailsTypeByValue(askForDetails.value)) { - case DETAILS_TYPE.TEXTE: - itemSelected(askForDetails.label) - saveIsIntentionVersQuiSeTourner(askForDetails.label) - - setDisplayMore( -
-
{askForDetails.label}
- {data.commentaires[askForDetails.value]} - {displayMamanBlues && askForDetails.value !== "proSante" && ( - - )} -
- ) - break - case DETAILS_TYPE.TEXT_AREA: - itemSelected(askForDetails.label) - - setDisplayMore( -
-
{askForDetails.label}
- {data.commentaires[askForDetails.value]} - -
- ) - break - case DETAILS_TYPE.FORM: - itemSelected(askForDetails.label) - - setDisplayMore( -
-
{askForDetails.label}
- -
- ) - break - } - }, [askForDetails]) - - const itemSelected = (label) => { - trackerForIntentions(scoreLevel, label) - setDisplayItemSelected(true) - } - - const getDetailsTypeByValue = (value) => { - switch (value) { - case "mal": - case "seTourner": - case "bien": - case "curiosite": - case "proSante": - return DETAILS_TYPE.TEXTE - case "autre": - case "aucune": - return DETAILS_TYPE.TEXT_AREA - case "quiJoindre": - case "quoiFaire": - return DETAILS_TYPE.FORM - } - } - - return ( -
- {!displayItemSelected && - convertStringWithfirstPartInBold("?", data.question)} - {!displayItemSelected && ( -
- - {data.reponses.map((item, index) => ( - setAskForDetails(item)} - > - {item.label} - - ))} - -
- )} - {displayMore} -
- ) -} diff --git a/src/components/ab-testing/intentions/BeCloseToRealityQuestion.js b/src/components/ab-testing/intentions/BeCloseToRealityQuestion.js deleted file mode 100644 index aaf0c229..00000000 --- a/src/components/ab-testing/intentions/BeCloseToRealityQuestion.js +++ /dev/null @@ -1,101 +0,0 @@ -import { useEffect, useState } from "react" -import { ToggleButton, ToggleButtonGroup } from "react-bootstrap" -import { - demandeDeDetailsByScoreLevel, - estLePlusAdapte, - estProcheDeLaRealite, - estProcheDeLaRealiteCommentaireByScoreLevel, - trackerForIntentions, -} from "../../../utils/ab-testing/measuring-intentions.utils" -import { - SCORE_LEVEL_BAD, - SCORE_LEVEL_GOOD, - SCORE_LEVEL_MEDIUM, -} from "../../../utils/score-level.utils" -import { ContactMamanBlues } from "../../results/ContactMamanBlues" -import { AskForDetailsQuestion } from "./AskForDetailsQuestion" - -export const BeCloseToRealityQuestion = ({ - scoreLevel, - displayMamanBlues = true, - setShowBackButton, -}) => { - const [beCloseToReality, setBeCloseToReality] = useState("") - const [displayMore, setDisplayMore] = useState() - const [displayItemSelected, setDisplayItemSelected] = useState(false) - - useEffect(() => { - if ( - (scoreLevel === SCORE_LEVEL_GOOD && beCloseToReality.value === "oui") || - beCloseToReality.value === "peutetre" - ) { - itemSelected(beCloseToReality.label) - - // Questionnaire terminé - setDisplayMore( -
- { - estProcheDeLaRealiteCommentaireByScoreLevel(scoreLevel)[ - beCloseToReality.value - ] - } - {displayMamanBlues && } -
- ) - } - if ( - beCloseToReality.value === "non" || - (scoreLevel === SCORE_LEVEL_MEDIUM && beCloseToReality.value === "oui") || - (scoreLevel === SCORE_LEVEL_BAD && beCloseToReality.value === "oui") - ) { - let data - if (beCloseToReality.value === "oui") data = estLePlusAdapte - if (beCloseToReality.value === "non") - data = demandeDeDetailsByScoreLevel(scoreLevel) - - itemSelected(beCloseToReality.label) - - // Réponses multiples - setDisplayMore( -
- -
- ) - } - }, [beCloseToReality]) - - const itemSelected = (label) => { - trackerForIntentions(scoreLevel, label) - setDisplayItemSelected(true) - setShowBackButton(true) - } - - return ( -
- {!displayItemSelected && {estProcheDeLaRealite.question}} - {!displayItemSelected && ( -
- - {estProcheDeLaRealite.reponses.map((item, index) => ( - setBeCloseToReality(item)} - > - {item.label} - - ))} - -
- )} - - {displayMore} -
- ) -} diff --git a/src/components/ab-testing/intentions/FormToSendMail.js b/src/components/ab-testing/intentions/FormToSendMail.js deleted file mode 100644 index 40b90c13..00000000 --- a/src/components/ab-testing/intentions/FormToSendMail.js +++ /dev/null @@ -1,150 +0,0 @@ -import { gql, useMutation } from "@apollo/client" -import { - EPDS_SEND_MAIL_ENTOURAGE, - EPDS_SEND_MAIL_HIMSELF, -} from "@socialgouv/nos1000jours-lib" -import { useEffect, useState } from "react" -import { client } from "../../../../apollo-client" -import { - PATTERN_EMAIL, - STORAGE_RESULTS_BOARD, -} from "../../../constants/constants" -import { Form } from "../../../constants/specificLabels" -import { - convertDateToString, - getColorIconAndTextByMood, - jsonParse, - LoaderFoButton, -} from "../../../utils/main.utils" -import { - contacterAToutMoment, - trackerForIntentions, -} from "../../../utils/ab-testing/measuring-intentions.utils" -import { ContactMamanBlues } from "../../results/ContactMamanBlues" -import * as StorageUtils from "../../../utils/storage.utils" - -/** - * @param {number} scoreLevel Niveau du score (1, 2, 3) obtenu lors du passage de l'EPDS - * @param {boolean} displayMamanBlues Afficher ou non le bloc de contact Maman Blues - * @param {boolean} forHimself Si `true`, le mail est envoyé à la personne qui remplit le formulaire, si `false`, c'est envoyé à un proche - * @returns Le formulaire pour envoyer le mail contenant les résultats du test EPDS - */ -export const FormToSendMail = ({ - scoreLevel, - displayMamanBlues = true, - forHimself, -}) => { - const [isEmailValid, setEmailValid] = useState() - const [isNameValid, setNameValid] = useState() - - const [canSend, setCanSend] = useState(false) - const [isLoading, setLoading] = useState(false) - const [queryShareResponses, setQueryShareResponses] = useState() - - const resultsBoard = jsonParse( - StorageUtils.getInLocalStorage(STORAGE_RESULTS_BOARD) - ) - const queryForPartage = forHimself - ? EPDS_SEND_MAIL_HIMSELF - : EPDS_SEND_MAIL_ENTOURAGE - - useEffect(() => { - setCanSend(isEmailValid && isNameValid) - }, [isEmailValid, isNameValid]) - - const [sendEmailReponseQuery] = useMutation(gql(queryForPartage), { - client: client, - onCompleted: () => { - setQueryShareResponses("Le mail a été envoyé") - setLoading(false) - }, - onError: (err) => { - console.warn(err) - setQueryShareResponses(err.toString()) - setLoading(false) - }, - }) - - const sendForm = async (event) => { - event.preventDefault() - setLoading(true) - - if (canSend) { - const inputs = event.target - const dateAsString = convertDateToString(new Date(), "/") - - trackerForIntentions( - scoreLevel, - `Envoi des réponses EPDS ${forHimself ? "à soi-même" : "à son entourage" - }` - ) - - await sendEmailReponseQuery({ - variables: { - detail_questions: resultsBoard.map((data) => data.question), - detail_reponses: resultsBoard.map((data) => data.response), - email: inputs.inputEmail.value, - prenom: inputs.inputName.value, - date: dateAsString, - mood_level: getColorIconAndTextByMood(scoreLevel).moodText, - }, - }) - } - } - - /* eslint-disable prettier/prettier */ - return ( -
-
- {forHimself && - "Recevez votre résultat au questionnaire par mail pour le partager à votre professionnel de santé :"} -
-
-
- - setNameValid(e.target.validity.valid)} - required - /> -
-
- - setEmailValid(e.target.validity.valid)} - required - /> -
-

{Form.required}

- - -
{queryShareResponses}
-
-
{contacterAToutMoment}
- {displayMamanBlues && } -
- ) -} diff --git a/src/components/ab-testing/intentions/MeasuringIntentions.js b/src/components/ab-testing/intentions/MeasuringIntentions.js deleted file mode 100644 index 74d46d52..00000000 --- a/src/components/ab-testing/intentions/MeasuringIntentions.js +++ /dev/null @@ -1,97 +0,0 @@ -import React, { useEffect, useState } from "react" -import { clearIntentionsData } from "../../../utils/ab-testing/measuring-intentions.utils" -import { BeCloseToRealityQuestion } from "./BeCloseToRealityQuestion" -import * as Icon from "react-bootstrap-icons" -import { TEST } from "../../../utils/ab-testing/ab-testing.utils" - -const TEST_NUMBER_ENABLED = process.env.NEXT_PUBLIC_TEST_NUMBER_ENABLED - -export const MeasuringIntentions = ({ scoreLevel, setTestStarted }) => { - // Test C visible par défaut si l'on utilise pas l'AB testing - const [test, setTest] = useState(TEST.C) - const [component, setComponent] = useState() - const [showBackButton, setShowBackButton] = useState(false) - - useEffect(() => { - clearIntentionsData() - if (test != undefined && component == undefined) { - updateComponent() - } - }, [test, component]) - - useEffect(() => { - setTestStarted(showBackButton) - - if (showBackButton) { - updateComponent() - } - }, [showBackButton]) - - const updateComponent = () => { - const content = displayComponentsByTest({ - testId: test, - scoreLevel: scoreLevel, - onReset, - showBackButton, - setShowBackButton, - }) - - setComponent(content) - } - - const onReset = () => { - setComponent(undefined) - setShowBackButton(false) - } - - const showTestNumber = () => - TEST_NUMBER_ENABLED === "true" ?
Test {test}
: null - - return
{component}
-} - -export const displayComponentsByTest = ({ - testId, - scoreLevel, - onReset, - showBackButton, - setShowBackButton, -}) => { - if (testId == TEST.B) { - const contentTestB = ( - - ) - return cardComponentAndRetryButton(contentTestB, onReset, showBackButton) - } - - if (testId == TEST.C) { - const contentTestC = ( - - ) - return cardComponentAndRetryButton(contentTestC, onReset, showBackButton) - } - - return null -} - -const cardComponentAndRetryButton = (content, onReset, showBackButton) => ( -
- {showBackButton && ( - - )} - {content} -
-) diff --git a/src/components/ab-testing/intentions/TextAreaToSendDetails.js b/src/components/ab-testing/intentions/TextAreaToSendDetails.js deleted file mode 100644 index 5cb62572..00000000 --- a/src/components/ab-testing/intentions/TextAreaToSendDetails.js +++ /dev/null @@ -1,89 +0,0 @@ -import { gql, useMutation } from "@apollo/client" -import { EPDS_SAVE_COMMENTS } from "@socialgouv/nos1000jours-lib" -import { useEffect, useState } from "react" -import { client } from "../../../../apollo-client" -import { STORAGE_SCORE } from "../../../constants/constants" -import { LoaderFoButton } from "../../../utils/main.utils" -import { - contacterAToutMoment, - trackerForIntentions, -} from "../../../utils/ab-testing/measuring-intentions.utils" -import { ContactMamanBlues } from "../../results/ContactMamanBlues" -import * as StorageUtils from "../../../utils/storage.utils" - -export const TextAreaToSendDetails = ({ - scoreLevel, - displayMamanBlues = true, -}) => { - const [textValue, setTextValue] = useState("") - const [sendDetails, setSendDetails] = useState(false) - const [isLoading, setLoading] = useState(false) - const [sendSuccessful, setSendSuccessful] = useState(false) - - const handleSendDetails = () => setSendDetails(true) - - const [sendCommentsQuery] = useMutation(gql(EPDS_SAVE_COMMENTS), { - client: client, - onCompleted: () => { - setLoading(false) - setSendSuccessful(true) - }, - onError: (err) => { - console.error(err) - setLoading(false) - }, - }) - - const sendCommentsRequest = async () => { - const score = parseInt(StorageUtils.getInLocalStorage(STORAGE_SCORE)) - - await sendCommentsQuery({ - variables: { - score: score, - commentaire: textValue, - }, - }) - } - - useEffect(() => { - if (sendDetails) { - setLoading(true) - sendCommentsRequest() - - trackerForIntentions(scoreLevel, "Envoi du commentaire") - } - }, [sendDetails]) - - return ( -
-