From 12803b0bafe239f3af437b5f0ce5f7598d511130 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment?= Date: Wed, 28 Feb 2024 14:56:32 +0100 Subject: [PATCH] fix: crisp env variable usage --- webapp/src/components/support/Crisp.ts | 48 ++++++++++++++------------ 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/webapp/src/components/support/Crisp.ts b/webapp/src/components/support/Crisp.ts index 8ec4d98d..33450dd4 100644 --- a/webapp/src/components/support/Crisp.ts +++ b/webapp/src/components/support/Crisp.ts @@ -9,33 +9,37 @@ type CrispProps = { onClose: () => void; } +const crispToken = process.env.NEXT_PUBLIC_CRISP_TOKEN as string + const CrispChat = (props: CrispProps) => { const { user, onClose } = props; useEffect(() => { - Crisp.configure(process.env.NEXT_PUBLIC_CRISP_TOKEN as string, { - autoload: false, - }); - Crisp.setTokenId(`cje-token-crisp-${user.id.toString()}`) - if (user.firstName && user.lastName) Crisp.user.setNickname(`${user.firstName} ${user.lastName}`) - if (user.userEmail) Crisp.user.setEmail(`${user.userEmail}`) - if (user.status_image) { - Crisp.session.setData({ - hasCjePass: user.status_image === 'approved' + if (crispToken) { + Crisp.configure(crispToken, { + autoload: false, + }); + Crisp.setTokenId(`cje-token-crisp-${user.id.toString()}`) + if (user.firstName && user.lastName) Crisp.user.setNickname(`${user.firstName} ${user.lastName}`) + if (user.userEmail) Crisp.user.setEmail(`${user.userEmail}`) + if (user.status_image) { + Crisp.session.setData({ + hasCjePass: user.status_image === 'approved' + }) + } + + // NEED DOMAIN NAME TO SET AVATAR => TODO LATER + // if (user.status_image === 'approved' && user.image && user.image.url) { + // Crisp.user.setAvatar(user.image.url) + // } + + Crisp.chat.open() + Crisp.chat.show() + Crisp.chat.onChatClosed(() => { + Crisp.chat.hide() + onClose() }) } - - // NEED DOMAIN NAME TO SET AVATAR => TODO LATER - // if (user.status_image === 'approved' && user.image && user.image.url) { - // Crisp.user.setAvatar(user.image.url) - // } - - Crisp.chat.open() - Crisp.chat.show() - Crisp.chat.onChatClosed(() => { - Crisp.chat.hide() - onClose() - }) - }, []) + }) return null }