Skip to content

Commit

Permalink
✨(frontend) add crisp chatbot
Browse files Browse the repository at this point in the history
Add crisp chatbot to allow users for interaction.
Create a new crisp chatbot component for this and populate with user info.
  • Loading branch information
Arnaud Robin authored and lebaudantoine committed Sep 20, 2024
1 parent ac86a4e commit f6911f3
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/frontend/apps/impress/.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
NEXT_PUBLIC_API_ORIGIN=
NEXT_PUBLIC_Y_PROVIDER_URL=
NEXT_PUBLIC_MEDIA_URL=
NEXT_PUBLIC_THEME=dsfr
NEXT_PUBLIC_THEME=dsfr
NEXT_PUBLIC_CRISP_WEBSITE_ID=
1 change: 1 addition & 0 deletions src/frontend/apps/impress/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"@hocuspocus/provider": "2.13.5",
"@openfun/cunningham-react": "2.9.4",
"@tanstack/react-query": "5.56.2",
"crisp-sdk-web": "*",
"i18next": "23.15.1",
"idb": "8.0.0",
"lodash": "4.17.21",
Expand Down
26 changes: 26 additions & 0 deletions src/frontend/apps/impress/src/components/CrispChat.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Crisp } from 'crisp-sdk-web';
import { useEffect } from 'react';

import { useAuthStore } from '@/core/auth';

const CrispChat = () => {
const { userData } = useAuthStore();

useEffect(() => {
const CRISP_WEBSITE_ID = process.env.NEXT_PUBLIC_CRISP_WEBSITE_ID;
if (CRISP_WEBSITE_ID) {
Crisp.configure(CRISP_WEBSITE_ID);

// Identify user if available
if (userData) {
Crisp.user.setEmail(userData.email);
}
} else {
console.warn('Crisp Website ID is not set');
}
}, [userData]);

return null;
};

export default CrispChat;
8 changes: 8 additions & 0 deletions src/frontend/apps/impress/src/crisp-sdk-web.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
declare module 'crisp-sdk-web' {
export const Crisp: {
configure: (websiteId: string) => void;
user: {
setEmail: (email: string) => void;
};
};
}
10 changes: 9 additions & 1 deletion src/frontend/apps/impress/src/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { AppProps } from 'next/app';
import dynamic from 'next/dynamic';
import Head from 'next/head';
import { useTranslation } from 'react-i18next';

Expand All @@ -12,6 +13,10 @@ type AppPropsWithLayout = AppProps & {
Component: NextPageWithLayout;
};

const CrispChat = dynamic(() => import('../components/CrispChat'), {
ssr: false,
});

export default function App({ Component, pageProps }: AppPropsWithLayout) {
useSWRegister();
const getLayout = Component.getLayout ?? ((page) => page);
Expand All @@ -29,7 +34,10 @@ export default function App({ Component, pageProps }: AppPropsWithLayout) {
/>
<link rel="icon" href="/favicon.ico" sizes="any" />
</Head>
<AppProvider>{getLayout(<Component {...pageProps} />)}</AppProvider>
<AppProvider>
{getLayout(<Component {...pageProps} />)}
<CrispChat />
</AppProvider>
</>
);
}
1 change: 1 addition & 0 deletions src/frontend/apps/impress/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
},
"include": [
"src/custom-next.d.ts",
"src/crisp-sdk-web.d.ts",
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
Expand Down

0 comments on commit f6911f3

Please sign in to comment.