Update frontend/src/App.tsx
Browse files- frontend/src/App.tsx +125 -125
frontend/src/App.tsx
CHANGED
@@ -1,126 +1,126 @@
|
|
1 |
-
import { useEffect } from "react";
|
2 |
-
import { useState } from "react";
|
3 |
-
import { ChainlitAPI, sessionState, useChatSession } from "@chainlit/react-client";
|
4 |
-
import { Playground } from "./components/playground";
|
5 |
-
import { useRecoilValue } from "recoil";
|
6 |
-
|
7 |
-
|
8 |
-
import Header from "@/components/header";
|
9 |
-
import Banner from "@/components/banner";
|
10 |
-
import AlertComponent from "@/components/alertComponent";
|
11 |
-
|
12 |
-
const CHAINLIT_SERVER = "
|
13 |
-
const userEnv = {};
|
14 |
-
|
15 |
-
const apiClient = new ChainlitAPI(CHAINLIT_SERVER);
|
16 |
-
|
17 |
-
interface Amounts {
|
18 |
-
[key: string]: number;
|
19 |
-
}
|
20 |
-
function App() {
|
21 |
-
const { connect } = useChatSession();
|
22 |
-
const session = useRecoilValue(sessionState);
|
23 |
-
|
24 |
-
useEffect(() => {
|
25 |
-
if (session?.socket.connected) {
|
26 |
-
return;
|
27 |
-
}
|
28 |
-
fetch(apiClient.buildEndpoint('/custom-auth'))
|
29 |
-
.then((res) => res.json())
|
30 |
-
.then((data) => {
|
31 |
-
connect({ client: apiClient, userEnv, accessToken: `Bearer: ${data.token}` });
|
32 |
-
});
|
33 |
-
}, [session, connect]);
|
34 |
-
|
35 |
-
// Initialize state to manage multiple amounts
|
36 |
-
const [amounts, setAmounts] = useState<Amounts>({});
|
37 |
-
|
38 |
-
// Function to update individual amount
|
39 |
-
const setAmount = (id: string, value: number) => {
|
40 |
-
setAmounts((prevAmounts) => ({
|
41 |
-
...prevAmounts,
|
42 |
-
[id]: value,
|
43 |
-
}));
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
};
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
return (
|
53 |
-
<>
|
54 |
-
|
55 |
-
|
56 |
-
<Header />
|
57 |
-
<Banner />
|
58 |
-
<div className="relative" style={{ marginTop: '40px' }}>
|
59 |
-
<div className="absolute left-20">
|
60 |
-
<div className="flex flex-col">
|
61 |
-
<header className="text-2xl font-bold leading-8 text-black pl-16">
|
62 |
-
<h1>Your Personalised Package:</h1>
|
63 |
-
</header>
|
64 |
-
<AlertComponent
|
65 |
-
logoUrl="https://cdn.builder.io/api/v1/image/assets/TEMP/be051a227710fa99e9efda725e8d0dc36c64fad96e941813d07d6250884eadb2?apiKey=b1f64df9aada44c6ba1728b031344f7b&"
|
66 |
-
alertText="PUBLIC & PRODUCT LIABILITY"
|
67 |
-
status="?"
|
68 |
-
amount={amounts['publicLiability'] || 0}
|
69 |
-
setAmount={(value) => setAmount('publicLiability', value)}
|
70 |
-
/>
|
71 |
-
<AlertComponent
|
72 |
-
logoUrl="https://cdn.builder.io/api/v1/image/assets/TEMP/fb7d406f3707aefeb694b288abea645b643e28df498e96faa3a88f8ae3b4f096?apiKey=b1f64df9aada44c6ba1728b031344f7b&"
|
73 |
-
alertText="FIRE AND ACCIDENTAL DAMAGE"
|
74 |
-
status="?"
|
75 |
-
amount={amounts['fireDamage'] || 0}
|
76 |
-
setAmount={(value) => setAmount('fireDamage', value)}
|
77 |
-
/>
|
78 |
-
<AlertComponent
|
79 |
-
logoUrl="https://cdn.builder.io/api/v1/image/assets/TEMP/af6837406a2497c1255b86413c1138e2c55b3fc5c643e05f560bafd57e9bd20b?apiKey=b1f64df9aada44c6ba1728b031344f7b&"
|
80 |
-
alertText="GLASS"
|
81 |
-
status="?"
|
82 |
-
amount={amounts['glass'] || 0}
|
83 |
-
setAmount={(value) => setAmount('glass', value)}
|
84 |
-
/>
|
85 |
-
<AlertComponent
|
86 |
-
logoUrl="https://cdn.builder.io/api/v1/image/assets/TEMP/a7ffd8559e286d4d85db00334a22a1a956d9835240ad8d97e82af98af62a149e?apiKey=b1f64df9aada44c6ba1728b031344f7b&"
|
87 |
-
alertText="PERSONAL EQUIPMENT"
|
88 |
-
status="?"
|
89 |
-
amount={amounts['personalEquipment'] || 0}
|
90 |
-
setAmount={(value) => setAmount('personalEquipment', value)}
|
91 |
-
/>
|
92 |
-
<AlertComponent
|
93 |
-
logoUrl="https://cdn.builder.io/api/v1/image/assets/TEMP/89dc158bec91bc71c7b35c5b9752238d239eb70b38f3256e62653dee21b33b55?apiKey=b1f64df9aada44c6ba1728b031344f7b&"
|
94 |
-
alertText="THEFT"
|
95 |
-
status="?"
|
96 |
-
amount={amounts['theft'] || 0}
|
97 |
-
setAmount={(value) => setAmount('theft', value)}
|
98 |
-
/>
|
99 |
-
</div>
|
100 |
-
|
101 |
-
<button className="justify-center items-center px-16 py-4 mt-3 ml-16 max-w-full text-base font-bold text-center text-lime-900 whitespace-nowrap rounded border border-solid border-[color:var(--Color-Functional-Primary--Dark,#558000)] w-[522px] max-md:px-5">
|
102 |
-
Go to quote
|
103 |
-
</button>
|
104 |
-
|
105 |
-
<button className="flex gap-2.5 justify-center px-5 py-2.5 mt-60 ml-16 text-base font-bold text-center text-lime-700 whitespace-nowrap bg-white rounded border border-solid border-[color:var(--Color-Functional-Primary--Dark,#558000)] max-md:mt-10 max-md:ml-2.5 items-center">
|
106 |
-
<img loading="lazy" src="https://cdn.builder.io/api/v1/image/assets/TEMP/91c9b9f5d1f2a509afd2c46fab93912852f90f3b085e3f35ce1e33c252fedf1b?apiKey=b1f64df9aada44c6ba1728b031344f7b&" alt="" className="w-4 aspect-square" />
|
107 |
-
Back to packages
|
108 |
-
</button>
|
109 |
-
|
110 |
-
|
111 |
-
</div>
|
112 |
-
</div>
|
113 |
-
|
114 |
-
|
115 |
-
<div className="playground-container">
|
116 |
-
<Playground />
|
117 |
-
</div>
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
</>
|
123 |
-
);
|
124 |
-
}
|
125 |
-
|
126 |
export default App;
|
|
|
1 |
+
import { useEffect } from "react";
|
2 |
+
import { useState } from "react";
|
3 |
+
import { ChainlitAPI, sessionState, useChatSession } from "@chainlit/react-client";
|
4 |
+
import { Playground } from "./components/playground";
|
5 |
+
import { useRecoilValue } from "recoil";
|
6 |
+
|
7 |
+
|
8 |
+
import Header from "@/components/header";
|
9 |
+
import Banner from "@/components/banner";
|
10 |
+
import AlertComponent from "@/components/alertComponent";
|
11 |
+
|
12 |
+
const CHAINLIT_SERVER = "/custom-auth";
|
13 |
+
const userEnv = {};
|
14 |
+
|
15 |
+
const apiClient = new ChainlitAPI(CHAINLIT_SERVER);
|
16 |
+
|
17 |
+
interface Amounts {
|
18 |
+
[key: string]: number;
|
19 |
+
}
|
20 |
+
function App() {
|
21 |
+
const { connect } = useChatSession();
|
22 |
+
const session = useRecoilValue(sessionState);
|
23 |
+
|
24 |
+
useEffect(() => {
|
25 |
+
if (session?.socket.connected) {
|
26 |
+
return;
|
27 |
+
}
|
28 |
+
fetch(apiClient.buildEndpoint('/custom-auth'))
|
29 |
+
.then((res) => res.json())
|
30 |
+
.then((data) => {
|
31 |
+
connect({ client: apiClient, userEnv, accessToken: `Bearer: ${data.token}` });
|
32 |
+
});
|
33 |
+
}, [session, connect]);
|
34 |
+
|
35 |
+
// Initialize state to manage multiple amounts
|
36 |
+
const [amounts, setAmounts] = useState<Amounts>({});
|
37 |
+
|
38 |
+
// Function to update individual amount
|
39 |
+
const setAmount = (id: string, value: number) => {
|
40 |
+
setAmounts((prevAmounts) => ({
|
41 |
+
...prevAmounts,
|
42 |
+
[id]: value,
|
43 |
+
}));
|
44 |
+
|
45 |
+
|
46 |
+
|
47 |
+
|
48 |
+
};
|
49 |
+
|
50 |
+
|
51 |
+
|
52 |
+
return (
|
53 |
+
<>
|
54 |
+
|
55 |
+
|
56 |
+
<Header />
|
57 |
+
<Banner />
|
58 |
+
<div className="relative" style={{ marginTop: '40px' }}>
|
59 |
+
<div className="absolute left-20">
|
60 |
+
<div className="flex flex-col">
|
61 |
+
<header className="text-2xl font-bold leading-8 text-black pl-16">
|
62 |
+
<h1>Your Personalised Package:</h1>
|
63 |
+
</header>
|
64 |
+
<AlertComponent
|
65 |
+
logoUrl="https://cdn.builder.io/api/v1/image/assets/TEMP/be051a227710fa99e9efda725e8d0dc36c64fad96e941813d07d6250884eadb2?apiKey=b1f64df9aada44c6ba1728b031344f7b&"
|
66 |
+
alertText="PUBLIC & PRODUCT LIABILITY"
|
67 |
+
status="?"
|
68 |
+
amount={amounts['publicLiability'] || 0}
|
69 |
+
setAmount={(value) => setAmount('publicLiability', value)}
|
70 |
+
/>
|
71 |
+
<AlertComponent
|
72 |
+
logoUrl="https://cdn.builder.io/api/v1/image/assets/TEMP/fb7d406f3707aefeb694b288abea645b643e28df498e96faa3a88f8ae3b4f096?apiKey=b1f64df9aada44c6ba1728b031344f7b&"
|
73 |
+
alertText="FIRE AND ACCIDENTAL DAMAGE"
|
74 |
+
status="?"
|
75 |
+
amount={amounts['fireDamage'] || 0}
|
76 |
+
setAmount={(value) => setAmount('fireDamage', value)}
|
77 |
+
/>
|
78 |
+
<AlertComponent
|
79 |
+
logoUrl="https://cdn.builder.io/api/v1/image/assets/TEMP/af6837406a2497c1255b86413c1138e2c55b3fc5c643e05f560bafd57e9bd20b?apiKey=b1f64df9aada44c6ba1728b031344f7b&"
|
80 |
+
alertText="GLASS"
|
81 |
+
status="?"
|
82 |
+
amount={amounts['glass'] || 0}
|
83 |
+
setAmount={(value) => setAmount('glass', value)}
|
84 |
+
/>
|
85 |
+
<AlertComponent
|
86 |
+
logoUrl="https://cdn.builder.io/api/v1/image/assets/TEMP/a7ffd8559e286d4d85db00334a22a1a956d9835240ad8d97e82af98af62a149e?apiKey=b1f64df9aada44c6ba1728b031344f7b&"
|
87 |
+
alertText="PERSONAL EQUIPMENT"
|
88 |
+
status="?"
|
89 |
+
amount={amounts['personalEquipment'] || 0}
|
90 |
+
setAmount={(value) => setAmount('personalEquipment', value)}
|
91 |
+
/>
|
92 |
+
<AlertComponent
|
93 |
+
logoUrl="https://cdn.builder.io/api/v1/image/assets/TEMP/89dc158bec91bc71c7b35c5b9752238d239eb70b38f3256e62653dee21b33b55?apiKey=b1f64df9aada44c6ba1728b031344f7b&"
|
94 |
+
alertText="THEFT"
|
95 |
+
status="?"
|
96 |
+
amount={amounts['theft'] || 0}
|
97 |
+
setAmount={(value) => setAmount('theft', value)}
|
98 |
+
/>
|
99 |
+
</div>
|
100 |
+
|
101 |
+
<button className="justify-center items-center px-16 py-4 mt-3 ml-16 max-w-full text-base font-bold text-center text-lime-900 whitespace-nowrap rounded border border-solid border-[color:var(--Color-Functional-Primary--Dark,#558000)] w-[522px] max-md:px-5">
|
102 |
+
Go to quote
|
103 |
+
</button>
|
104 |
+
|
105 |
+
<button className="flex gap-2.5 justify-center px-5 py-2.5 mt-60 ml-16 text-base font-bold text-center text-lime-700 whitespace-nowrap bg-white rounded border border-solid border-[color:var(--Color-Functional-Primary--Dark,#558000)] max-md:mt-10 max-md:ml-2.5 items-center">
|
106 |
+
<img loading="lazy" src="https://cdn.builder.io/api/v1/image/assets/TEMP/91c9b9f5d1f2a509afd2c46fab93912852f90f3b085e3f35ce1e33c252fedf1b?apiKey=b1f64df9aada44c6ba1728b031344f7b&" alt="" className="w-4 aspect-square" />
|
107 |
+
Back to packages
|
108 |
+
</button>
|
109 |
+
|
110 |
+
|
111 |
+
</div>
|
112 |
+
</div>
|
113 |
+
|
114 |
+
|
115 |
+
<div className="playground-container">
|
116 |
+
<Playground />
|
117 |
+
</div>
|
118 |
+
|
119 |
+
|
120 |
+
|
121 |
+
|
122 |
+
</>
|
123 |
+
);
|
124 |
+
}
|
125 |
+
|
126 |
export default App;
|