File tree Expand file tree Collapse file tree 2 files changed +49
-10
lines changed
src/frontend/apps/impress/src Expand file tree Collapse file tree 2 files changed +49
-10
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import { PropsWithChildren, useEffect } from 'react';
33
44import { Box } from '@/components' ;
55import { useCunninghamTheme } from '@/cunningham' ;
6- import { PostHogProvider , configureCrispSession } from '@/services' ;
6+ import { CrispProvider , PostHogProvider } from '@/services' ;
77import { useSentryStore } from '@/stores/useSentryStore' ;
88
99import { useConfig } from './api/useConfig' ;
@@ -29,14 +29,6 @@ export const ConfigProvider = ({ children }: PropsWithChildren) => {
2929 setTheme ( conf . FRONTEND_THEME ) ;
3030 } , [ conf ?. FRONTEND_THEME , setTheme ] ) ;
3131
32- useEffect ( ( ) => {
33- if ( ! conf ?. CRISP_WEBSITE_ID ) {
34- return ;
35- }
36-
37- configureCrispSession ( conf . CRISP_WEBSITE_ID ) ;
38- } , [ conf ?. CRISP_WEBSITE_ID ] ) ;
39-
4032 if ( ! conf ) {
4133 return (
4234 < Box $height = "100vh" $width = "100vw" $align = "center" $justify = "center" >
@@ -45,5 +37,11 @@ export const ConfigProvider = ({ children }: PropsWithChildren) => {
4537 ) ;
4638 }
4739
48- return < PostHogProvider conf = { conf . POSTHOG_KEY } > { children } </ PostHogProvider > ;
40+ return (
41+ < PostHogProvider conf = { conf . POSTHOG_KEY } >
42+ < CrispProvider websiteId = { conf ?. CRISP_WEBSITE_ID } >
43+ { children }
44+ </ CrispProvider >
45+ </ PostHogProvider >
46+ ) ;
4947} ;
Original file line number Diff line number Diff line change 33 */
44
55import { Crisp } from 'crisp-sdk-web' ;
6+ import { PropsWithChildren , useEffect , useState } from 'react' ;
7+ import { createGlobalStyle } from 'styled-components' ;
68
79import { User } from '@/features/auth' ;
810
11+ const CrispStyle = createGlobalStyle `
12+ #crisp-chatbox a{
13+ zoom: 0.8;
14+ }
15+
16+ @media screen and (width <= 1024px) {
17+ .c__modals--opened #crisp-chatbox {
18+ display: none!important;
19+ }
20+ }
21+ ` ;
22+
923export const initializeCrispSession = ( user : User ) => {
1024 if ( ! Crisp . isCrispInjected ( ) ) {
1125 return ;
@@ -29,3 +43,30 @@ export const terminateCrispSession = () => {
2943 Crisp . setTokenId ( ) ;
3044 Crisp . session . reset ( ) ;
3145} ;
46+
47+ interface CrispProviderProps {
48+ websiteId ?: string ;
49+ }
50+
51+ export const CrispProvider = ( {
52+ children,
53+ websiteId,
54+ } : PropsWithChildren < CrispProviderProps > ) => {
55+ const [ isConfigured , setIsConfigured ] = useState ( false ) ;
56+
57+ useEffect ( ( ) => {
58+ if ( ! websiteId ) {
59+ return ;
60+ }
61+
62+ setIsConfigured ( true ) ;
63+ configureCrispSession ( websiteId ) ;
64+ } , [ websiteId ] ) ;
65+
66+ return (
67+ < >
68+ { isConfigured && < CrispStyle /> }
69+ { children }
70+ </ >
71+ ) ;
72+ } ;
You can’t perform that action at this time.
0 commit comments