Skip to content

Commit 15afb7c

Browse files
committed
Berry widget demo env
1 parent 6f693fd commit 15afb7c

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/pages/index.tsx

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState } from 'react';
1+
import React, { useEffect, useState } from 'react';
22
import Layout from '@theme/Layout';
33
import { Box, Button, Container, Grid, Stack, Tab, Tabs, Typography } from '@mui/material';
44
import { TabContext, TabPanel } from '@mui/lab';
@@ -12,6 +12,29 @@ import ErrorBoundary from '../components/ErrorBoundary'; // Import the ErrorBoun
1212
export const Home = () => {
1313
const [tab, setTab] = useState('0');
1414

15+
useEffect(() => {
16+
// Load the Berry widget script only if it hasn’t already been loaded
17+
if (!document.getElementById('berry-widget-script')) {
18+
const script = document.createElement('script');
19+
script.id = 'berry-widget-script';
20+
script.type = 'text/javascript';
21+
script.src = 'https://www.berryapp.io/js/berry-widget.min.js';
22+
document.head.appendChild(script);
23+
24+
script.onload = () => {
25+
const widgetJwt = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE3MjU5NDg5MTcsImV4cCI6MTc0MTYwODkxNywiYXVkIjoiV2lkZ2V0SW5pdGlhbGl6YXRpb24iLCJvcmdhbml6YXRpb25JZCI6NjN9.oJEGkGq1q3uFD66J916f_ZBrqQjPHP9orUOKFxInG38';
26+
window.Berry.init({
27+
token: widgetJwt,
28+
primaryColor: '#021b9a',
29+
position: { side: 'right', offsetX: 25, offsetY: 100 },
30+
isOpenByDefault: false,
31+
botUrlPath: 'nova',
32+
showNewChat: true,
33+
});
34+
};
35+
}
36+
}, []);
37+
1538
return (
1639
<ErrorBoundary>
1740
<Layout

0 commit comments

Comments
 (0)