Skip to content

Commit

Permalink
Merge pull request #110 from SocialGouv/feat-envoie-ressources
Browse files Browse the repository at this point in the history
feat(ressources): redirection ressources
  • Loading branch information
alebret authored Dec 22, 2022
2 parents fa48203 + 31ad6ee commit 95e495e
Show file tree
Hide file tree
Showing 13 changed files with 201 additions and 9 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ NEXT_PUBLIC_MATOMO_URL = "https://matomo.fabrique.social.gouv.fr/"
NEXT_PUBLIC_MATOMO_ENABLED = false
NEXT_PUBLIC_PASTEK_CHAT_ID = 2
NEXT_PUBLIC_TEST_NUMBER_ENABLED = true
NEXT_PUBLIC_LANDING_PAGE_BLUES_RESOURCES = "https://1000jours-blues-preprod.dev.fabrique.social.gouv.fr/ressources"
1 change: 1 addition & 0 deletions .github/workflows/preproduction.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ jobs:
NEXT_PUBLIC_API_URL=https://backoffice-1000jours-preprod.dev.fabrique.social.gouv.fr
NEXT_PUBLIC_PASTEK_CHAT_ID=2
NEXT_PUBLIC_TEST_NUMBER_ENABLED=true
NEXT_PUBLIC_LANDING_PAGE_BLUES_RESOURCES=https://1000jours-blues-preprod.dev.fabrique.social.gouv.fr/ressources
deploy:
name: Deploy application
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
NEXT_PUBLIC_API_URL=https://backoffice-les1000jours.fabrique.social.gouv.fr
NEXT_PUBLIC_PASTEK_CHAT_ID=1
NEXT_PUBLIC_TEST_NUMBER_ENABLED=false
NEXT_PUBLIC_LANDING_PAGE_BLUES_RESOURCES=https://1000jours-blues.fabrique.social.gouv.fr/ressources
deploy:
name: Deploy application
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ jobs:
NEXT_PUBLIC_API_URL=https://backoffice-1000jours-preprod.dev.fabrique.social.gouv.fr
NEXT_PUBLIC_PASTEK_CHAT_ID=2
NEXT_PUBLIC_TEST_NUMBER_ENABLED=true
NEXT_PUBLIC_LANDING_PAGE_BLUES_RESOURCES=https://1000jours-blues-preprod.dev.fabrique.social.gouv.fr/ressources
deploy:
name: Deploy review branch
Expand Down
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ ENV NEXT_PUBLIC_TEST_NUMBER_ENABLED=$NEXT_PUBLIC_TEST_NUMBER_ENABLED
ARG NEXT_PUBLIC_PASTEK_CHAT_ID
ENV NEXT_PUBLIC_PASTEK_CHAT_ID=$NEXT_PUBLIC_PASTEK_CHAT_ID

ARG NEXT_PUBLIC_LANDING_PAGE_BLUES_RESOURCES
ENV NEXT_PUBLIC_LANDING_PAGE_BLUES_RESOURCES=$NEXT_PUBLIC_LANDING_PAGE_BLUES_RESOURCES

RUN yarn --production --frozen-lockfile --prefer-offline && yarn cache clean
RUN yarn build

Expand Down
49 changes: 49 additions & 0 deletions __tests__/components/ab-testing/give-access-to-resources.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { fireEvent, render, screen } from "@testing-library/react"
import { GiveAccessToResources } from "../../../src/components/ab-testing/resources/GiveAccessToResources"
import { STORAGE_TEST_ABC } from "../../../src/constants/constants"
import * as AbTestingUtils from "../../../src/utils/ab-testing/ab-testing.utils"

describe("UI de GiveAccessToResources", () => {
describe("TEST A/B/C/D", () => {
const mailBtnText = "Je souhaite recevoir les ressources par mail"
const linkBtnText = "Afficher les ressources disponibles"

test("Should return modal with email when test is A", async () => {
localStorage.setItem(STORAGE_TEST_ABC, AbTestingUtils.TEST.A)
render(<GiveAccessToResources />)

const button = screen.getByRole("button", { name: mailBtnText })
expect(button).toBeInTheDocument()

fireEvent.click(button)
expect(await screen.queryByText("Fermer")).toBeInTheDocument()
})

test("Should return modal with email when test is B", async () => {
localStorage.setItem(STORAGE_TEST_ABC, AbTestingUtils.TEST.B)
render(<GiveAccessToResources />)

const button = screen.getByRole("button", { name: mailBtnText })
expect(button).toBeInTheDocument()

fireEvent.click(button)
expect(await screen.queryByText("Fermer")).toBeInTheDocument()
})

test("Should return link when test is C", async () => {
localStorage.setItem(STORAGE_TEST_ABC, AbTestingUtils.TEST.C)
render(<GiveAccessToResources />)

const button = screen.getByRole("button", { name: linkBtnText })
expect(button).toBeInTheDocument()
})

test("Should return link when test is D", async () => {
localStorage.setItem(STORAGE_TEST_ABC, AbTestingUtils.TEST.D)
render(<GiveAccessToResources />)

const button = screen.getByRole("button", { name: linkBtnText })
expect(button).toBeInTheDocument()
})
})
})
6 changes: 6 additions & 0 deletions apollo-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,9 @@ export const SAVE_DEMANDE_DE_CONTACT = gql`
}
}
`

export const DEMANDE_RESSOURCES = gql`
mutation ($email: String) {
partageRessourcesParMail(email: $email)
}
`
1 change: 1 addition & 0 deletions pages/_app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import "bootstrap/dist/css/bootstrap.css"
import "../styles/index.scss"
import "@gouvfr/dsfr/dist/dsfr/dsfr.min.css"

import { init } from "@socialgouv/matomo-next"
import App from "next/app"
Expand Down
1 change: 0 additions & 1 deletion pages/api/staticDepartmentComData.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export default async function staticDepartmentComData(_req, res) {
jsonDirectory + "/departments-com.csv",
"utf8"
)
console.log(fileContents)

//Return the content of the data file in json format
res.status(200).json(fileContents)
Expand Down
3 changes: 2 additions & 1 deletion pages/results.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import * as MainUtils from "../src/utils/main.utils"
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"

export default function Results() {
const SCORE_TO_SHOW_CONTACT_BLOC = 9
Expand Down Expand Up @@ -99,7 +100,7 @@ export default function Results() {
)}

<DescriptionAndConclusion />

<GiveAccessToResources />
{scoreLevelForMacaron == SCORE_LEVEL_MEDIUM ||
scoreLevelForMacaron == SCORE_LEVEL_BAD ? (
<Intentions moodLevel={scoreLevelForMood} />
Expand Down
129 changes: 129 additions & 0 deletions src/components/ab-testing/resources/GiveAccessToResources.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
import { Button } from "@dataesr/react-dsfr"
import { useEffect, useState } from "react"
import { Modal } from "react-bootstrap"
import { STORAGE_TEST_ABC } from "../../../constants/constants"
import * as StorageUtils from "../../../utils/storage.utils"
import * as AbTestingUtils from "../../../utils/ab-testing/ab-testing.utils"
import { client, DEMANDE_RESSOURCES } from "../../../../apollo-client"
import { useMutation } from "@apollo/client"
import { LoaderFoButton } from "../../../utils/main.utils"

export const GiveAccessToResources = () => {
const RESOURCES_URL = process.env.NEXT_PUBLIC_LANDING_PAGE_BLUES_RESOURCES
const test = StorageUtils.getInLocalStorage(STORAGE_TEST_ABC)

const [show, setShow] = useState(false)
const [isLoading, setLoading] = useState(false)
const [mailValue, setMailValue] = useState()

const openUrl = (url) => window.open(url, "_blank")
const handleChange = (event) => setMailValue(event.target.value)
const openModal = () => setShow(true)
const closeModal = () => setShow(false)

const shouldSendEmail = () =>
test === AbTestingUtils.TEST.A || test === AbTestingUtils.TEST.B

useEffect(() => {
shouldSendEmail()
? AbTestingUtils.trackerForAbTesting(
"Je souhaite recevoir les ressources par mail"
)
: AbTestingUtils.trackerForAbTesting(
"Afficher les ressources disponibles"
)
}, [])

const componentForRedirection = () => {
return (
<Button
className="fr-btn--secondary"
onClick={() => openUrl(RESOURCES_URL)}
>
Afficher les ressources disponibles
</Button>
)
}

const [sendResourcesQuery] = useMutation(DEMANDE_RESSOURCES, {
client: client,
onCompleted: () => {
setLoading(false)
closeModal()
},
onError: (err) => {
console.error(err)
setLoading(false)
},
})

const sendMail = async () => {
setLoading(false)
AbTestingUtils.trackerForAbTesting(
"Je souhaite recevoir les ressources par mail - Envoie du mail"
)

setLoading(true)
await sendResourcesQuery({
variables: {
email: mailValue,
},
})
}

const componentToSendMail = () => {
return (
<div>
<Button className="fr-btn--secondary" onClick={() => openModal()}>
Je souhaite recevoir les ressources par mail
</Button>

<Modal show={show} centered size="lg">
<Modal.Header className="fr-modal__header">
<button
className="fr-btn--close fr-btn"
aria-controls="fr-modal-2"
onClick={closeModal}
>
Fermer
</button>
</Modal.Header>

<Modal.Body>
<div className="fr-input-group">
<label className="fr-label" htmlFor="email-resources">
Recevez nos ressources orientées sur les difficultés maternelles
dans votre boite mail
<span className="fr-hint-text">
Format attendu : [email protected]
</span>
</label>
<input
className="fr-input"
name="email"
autoComplete="email"
id="email-resources"
type="email"
onChange={handleChange}
value={mailValue}
/>
</div>
</Modal.Body>

<Modal.Footer>
<Button onClick={() => sendMail()} disabled={isLoading}>
Envoyer
{isLoading ? <LoaderFoButton /> : null}
</Button>
</Modal.Footer>
</Modal>
</div>
)
}

return (
<div>
{shouldSendEmail() ? componentToSendMail() : componentForRedirection()}
</div>
)
}
8 changes: 4 additions & 4 deletions src/constants/specificLabels.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export const Labels = {
},
}

const descriptionLvl2 =
"Les changements importants liés à l’arrivée d’un bébé sont des facteurs de stress dont certains signes peuvent évoquer ceux de la dépression post partum. Vous exprimez des signes évocateurs de la dépression post partum, il est donc nécessaire d'échanger avec un professionnel de santé. Demandez de l'aide à Elise, ou consultez notre page des ressources."
export const EpdsResultsComments = {
level1: {
description:
Expand All @@ -17,13 +19,11 @@ export const EpdsResultsComments = {
"Nous vous invitons à vous questionner de nouveau dans les 14 jours.",
},
level2: {
description:
"Les changements importants liés à l’arrivée d’un bébé sont des facteurs de stress dont certains signes peuvent évoquer ceux de la dépression post partum. Vous exprimez des signes évocateurs de la dépression post partum, il est donc nécessaire d'échanger avec un professionnel de santé.",
description: descriptionLvl2,
conclusion: "",
},
level3: {
description:
"Les changements importants liés à l’arrivée d’un bébé sont des facteurs de stress dont certains signes peuvent évoquer ceux de la dépression post partum. Vous exprimez des signes évocateurs de la dépression post partum, il est donc nécessaire d'échanger avec un professionnel de santé.",
description: descriptionLvl2,
conclusion: "",
},
}
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1210,9 +1210,9 @@
integrity sha512-hPNtz+gHcc8m7ZPANxSOFMz4Ap+M9FHOudqoMR/+Kjl5FCOqwA6u/aoYnMJ8KqedS1k5XThFMp7jiktr53qXYw==

"@gouvfr/dsfr@^1.8.1":
version "1.8.1"
resolved "https://registry.yarnpkg.com/@gouvfr/dsfr/-/dsfr-1.8.1.tgz#2484eb8ad9a73b5f01c5f41f49146d1aa8a71b7b"
integrity sha512-XpVFdvhtalA5jSAhzzNaMd+/Hvf8Ef9jCdAZhuukEEMo2/cWvCgzz9tfbE+9QTJDIVP+EwJ7aCGWcXUSWkOHJg==
version "1.8.5"
resolved "https://registry.yarnpkg.com/@gouvfr/dsfr/-/dsfr-1.8.5.tgz#e99d095e99debcce0c41db18989637290d588b78"
integrity sha512-29L+THvWmYJXztPa0Os5TS9yD2WQbrH7VnCKxkyUXQZQ+6lsGebtz0GdCnLexOWDfCn1y53Mh7+/ihxI/z0Vjw==

"@graphql-typed-document-node/core@^3.0.0":
version "3.1.1"
Expand Down

0 comments on commit 95e495e

Please sign in to comment.