From a569cbd0bc5fd2e40dfcecf554c3330ffd569ae9 Mon Sep 17 00:00:00 2001 From: Benjamin Guedj Date: Mon, 13 May 2024 09:29:59 +0200 Subject: [PATCH] feat: Add chat with whatsapp --- apollo-client.js | 3 + pages/contact/contact-confirmed.js | 2 + pages/contact/to-be-contacted.js | 94 ++++++++++++++++++++++----- src/components/contact/ContactForm.js | 11 +++- src/constants/constants.js | 3 + src/utils/contact.utils.js | 2 + src/utils/tracker.utils.js | 1 + 7 files changed, 99 insertions(+), 17 deletions(-) diff --git a/apollo-client.js b/apollo-client.js index 96c83a2a..e7618ede 100644 --- a/apollo-client.js +++ b/apollo-client.js @@ -36,6 +36,9 @@ export const GET_ACTIVATION_TILE_STATUS = gql` query activationTile { activationTile { activation_tile + rdv + sms + whatsapp } } ` diff --git a/pages/contact/contact-confirmed.js b/pages/contact/contact-confirmed.js index 580d5cc8..2a5eac32 100644 --- a/pages/contact/contact-confirmed.js +++ b/pages/contact/contact-confirmed.js @@ -61,6 +61,8 @@ export default function ContactConfirmed() { "Vous devriez recevoir un email de notre équipe dans les 48h. Pensez bien à vérifier dans vos spams."} {contactType === RequestContact.type.sms && "Vous devriez recevoir un SMS de notre équipe dans les 48h en fonction des disponibilités sélectionnées."} + {contactType === RequestContact.type.whatsapp && + "Vous devriez recevoir un message de notre équipe dans les 48h."} {contactType === RequestContact.type.rendezvous && "Vous serez contacté sur le numéro de téléphone que vous avez communiqué."}

diff --git a/pages/contact/to-be-contacted.js b/pages/contact/to-be-contacted.js index 6ce05f43..08a91b8b 100644 --- a/pages/contact/to-be-contacted.js +++ b/pages/contact/to-be-contacted.js @@ -27,6 +27,8 @@ import { ContactForm } from "../../src/components/contact/ContactForm" import * as StorageUtils from "../../src/utils/storage.utils" import * as TrackerUtils from "../../src/utils/tracker.utils" import * as ContactUtils from "../../src/utils/contact.utils" +import { useQuery } from "@apollo/client" +import { client, GET_ACTIVATION_TILE_STATUS } from "../../apollo-client" export default function ToBeContacted() { const router = useRouter() @@ -36,6 +38,7 @@ export default function ToBeContacted() { const [contactHours, setContactHours] = useState(defaultContactHours) const [itemValueType, setItemValueType] = useState() const [isSmsSelected, setSmsSelected] = useState(false) + const [isWhatsappSelected, setWhatsappSelected] = useState(false) const [isPhoneValid, setIsPhoneValide] = useState(false) const [websiteSource, setWebsiteSource] = useState(false) const [canSend, setCanSend] = useState(false) @@ -55,6 +58,8 @@ export default function ToBeContacted() { useEffect(() => { setSmsSelected(itemValueType == RequestContact.type.sms) + setWhatsappSelected(itemValueType == RequestContact.type.whatsapp) + console.log(itemValueType) }, [itemValueType]) const cancel = () => { @@ -74,9 +79,9 @@ export default function ToBeContacted() { }) } - const onClickSelector = () => { + const onClickSelector = (type) => { TrackerUtils.trackerForContact("Choix effectué") - TrackerUtils.trackerForContact("Choix sms") + TrackerUtils.trackerForContact("Choix " + type.id) } const sendTrackerContactType = (typeContact) => { @@ -92,6 +97,10 @@ export default function ToBeContacted() { if (itemValueType === RequestContact.type.sms) { sendTrackerContactType(itemValueType) goToContactValidation("/contact/contact-confirmed") + } + if (itemValueType === RequestContact.type.whatsapp) { + sendTrackerContactType(itemValueType) + goToContactValidation("/contact/contact-confirmed") } else if (itemValueType === RequestContact.type.rendezvous) { TrackerUtils.trackerForContact("Choix effectué") TrackerUtils.trackerForContact("Choix rendezvous") @@ -110,7 +119,7 @@ export default function ToBeContacted() { checked={itemValueType === type.id} onChange={(e) => { setItemValueType(e.currentTarget.value) - onClickSelector() + onClickSelector(type) }} > @@ -134,6 +143,16 @@ export default function ToBeContacted() { ) + const WhatsappComponent = () => ( +
+ + {defaultContactTypes.byWhatsapp.map((type) => ( + {CustomToggleButton(type)} + ))} + +
+ ) + const CalendlyComponent = () => { return ( <> @@ -146,14 +165,28 @@ export default function ToBeContacted() { ) } - const ButtonGroupType = () => ( - - - - - - - ) + const ButtonGroupType = (params) => { + const _activationTile = params.activationTile + if (_activationTile) { + return ( + + + {activationTile.rdv ? : null} + {activationTile.sms ? : null} + {activationTile.whatsapp ? : null} + + + ) + } + return ( + + + + + + + ) + } const buttonGroupHours = () => ( + if (error) return

Error

+ const activationTile = data.activationTile + return ( @@ -208,7 +249,7 @@ export default function ToBeContacted() { imageUrl="/img/image-wanda.png" />

Je préfére être contacté.e par :

- + {isSmsSelected ? ( <> @@ -225,7 +266,17 @@ export default function ToBeContacted() { /> ) : null} - {!isSmsSelected && ( + {isWhatsappSelected ? ( + <> + + + ) : null} + {!isSmsSelected && !isWhatsappSelected && ( {websiteSource !== OPEN_CONTACT_FROM_EMAIL && ( diff --git a/src/constants/constants.js b/src/constants/constants.js index e9474b25..31806f8d 100644 --- a/src/constants/constants.js +++ b/src/constants/constants.js @@ -27,10 +27,13 @@ export const OPEN_CONTACT_FROM_EMAIL = "fromEmail" export const PATTERN_EMAIL = "[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+.[a-zA-Z.]{2,15}" +export const URL_CHAT_WHATSAPP = "https://wa.me/message/ZMCTRIQWA7OKD1" + export const RequestContact = { type: { sms: "sms", rendezvous: "rendezvous", + whatsapp: "whatsapp", }, hours: { morning: "matin", diff --git a/src/utils/contact.utils.js b/src/utils/contact.utils.js index 568526c3..bf93a6ce 100644 --- a/src/utils/contact.utils.js +++ b/src/utils/contact.utils.js @@ -14,6 +14,8 @@ export const trackerContactName = (typeContact) => { switch (typeContact) { case RequestContact.type.sms: return TrackerUtils.CONTACT_SENT.sms + case RequestContact.type.whatsapp: + return TrackerUtils.CONTACT_SENT.whatsapp case RequestContact.type.rendezvous: return TrackerUtils.CONTACT_SENT.rendezvous } diff --git a/src/utils/tracker.utils.js b/src/utils/tracker.utils.js index c351797d..fcc27574 100644 --- a/src/utils/tracker.utils.js +++ b/src/utils/tracker.utils.js @@ -43,6 +43,7 @@ export const ACTION = { export const CONTACT_SENT = { sms: "Confirmation sms", + whatsapp: "Confirmation whatsapp", rendezvous: "Confirmation rendezvous", }