Skip to content

Commit 52f8918

Browse files
committed
Quiz page function and notify
1 parent 3ffb8ab commit 52f8918

4 files changed

Lines changed: 61 additions & 164 deletions

File tree

front-end/src/components/Chatbot.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
import axios from "axios"
1010
import { script } from './ChatbotScript'
1111
import { useNavigate } from "react-router-dom"
12+
import { startWindToast } from "@mariojgt/wind-notify/packages/index.js"
1213

1314
const API_URL = import.meta.env.VITE_API_URL
1415

@@ -125,6 +126,7 @@ function Chatbot() {
125126

126127
try {
127128
// const response = await axios.post(API_URL + '/api/Chatbot/send-message', payload)
129+
startWindToast("WARNING!", "Our AI service is currently down", 'warning', 3, 'top')
128130
// const chatContent = response.data.chatContent
129131
// const carDescriptions = response.data.carDescriptions
130132
// const citations = response.data.citations

front-end/src/pages/Quiz.jsx

Lines changed: 52 additions & 163 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
import React, { useState } from 'react'
22
import { useNavigate } from 'react-router-dom'
33
import axios from 'axios'
4+
import { startWindToast } from "@mariojgt/wind-notify/packages/index.js"
45

56
const API_URL = import.meta.env.VITE_API_URL
67

78
const Quiz = () => {
89
const navigate = useNavigate()
9-
10-
const [answers, setAnswers] = useState({})
11-
const [inputValue, setInputValue] = useState("")
12-
const [showModal, setShowModal] = useState(true)
10+
const [answers, setAnswers] = useState({
11+
q1: '',
12+
q2: '',
13+
q3: '',
14+
q4: '',
15+
q5: '',
16+
q6: '',
17+
q7: ''
18+
})
1319
const [recommendedCar, setRecommendedCar] = useState(undefined)
1420
const [showToast, setShowToast] = useState(undefined)
1521
const [currentQuestionIndex, setCurrentQuestionIndex] = useState(0)
@@ -38,33 +44,25 @@ const Quiz = () => {
3844
9: "feature",
3945
10: "situation description"
4046
}
41-
const toggleModal = () => {
42-
setShowModal(!showModal)
43-
}
47+
4448
const handleBack = () => {
4549
navigate(-1)
4650
}
4751

4852
const handleSubmit = async () => {
49-
setLoading(true)
50-
const finalAnswers = {
51-
...answers,
52-
[questionKeys[currentQuestionIndex]]: inputValue
53-
}
54-
55-
if (Object.values(finalAnswers).every(answer => answer === "")) {
53+
if (Object.values(answers).every(answer => answer === "")) {
5654
setShowToast({ key: 'error', value: 'Please provide at least 1 answer' })
5755
setTimeout(() => setShowToast(undefined), 3000)
5856
return
5957
}
6058

61-
setAnswers(finalAnswers)
62-
const flatAnswer = Object.entries(finalAnswers)
59+
const flatAnswer = Object.entries(answers)
6360
.filter(([_, value]) => value)
64-
.map(([key, value]) => `${key}: ${value}`)
65-
.join(", ")
66-
67-
await sendAIQuery(flatAnswer)
61+
.map(([_, value], index) => `${questions[index]} ${value}`)
62+
.join("; ")
63+
setLoading(true)
64+
// await sendAIQuery(flatAnswer)
65+
startWindToast("WARNING!", "Our AI service is currently down", 'warning', 3, 'top')
6866
setLoading(false)
6967
}
7068

@@ -103,22 +101,13 @@ const Quiz = () => {
103101
.map(([key, value]) => `${key}: ${value}`)
104102
.join(", ")
105103

106-
await sendAIQuery(flatAnswer + "but not previous vehicle")
104+
// await sendAIQuery(flatAnswer + "but not previous vehicle")
107105
setLoading(false)
108106
}
109107

110108
return (
111109
<div className='container mx-auto items-center space-y-2'>
112-
{showModal && (
113-
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black bg-opacity-50">
114-
<div className="bg-white text-gray-900 p-6 rounded-lg w-11/12 md:w-1/3 relative shadow-lg">
115-
<button onClick={toggleModal} className="absolute top-2 right-2 text-gray-600 text-2xl">&times;</button>
116-
<h2 className="text-xl font-bold mb-4 text-blue-900">Here to Help!</h2>
117-
<p>Answer a few simple questions, and I'll help you find the perfect car!</p>
118-
</div>
119-
</div>
120-
)}
121-
110+
122111
{loading && (
123112
<div className="fixed toast toast-center toast-middle z-50">
124113
<div className={`alert alert-info flex justify-center mx-auto w-fit`}>
@@ -134,141 +123,41 @@ const Quiz = () => {
134123
</div>
135124
</div>
136125
)}
137-
126+
138127
{/*Quiz section*/}
139128
<div className='flex justify-center items-center'>
140129
<div className="card bg-base-100 shadow-xl w-11/12 md:w-2/3 lg:w-1/2 border border-blue-900">
141130
<div className="card-body py-12 px-24">
142-
<h2 className="card-title text-center text-2xl font-bold text-blue-500 self-center shadow-sm">
131+
<h2 className="card-title text-center text-2xl font-bold text-blue-500 self-center">
143132
Car Quiz
144133
</h2>
145-
<div className="form-control">
146-
{/*First Question*/}
147-
<div>
148-
<label className="label">
149-
<span className="label-text text-base font-semibold">{questions[currentQuestionIndex]}</span>
150-
</label>
151-
<div className='flex items-center border rounded-full border-gray-200'>
152-
<span className="pl-4 text-gray-500"></span>
153-
<input
154-
type='text'
155-
value={inputValue}
156-
onChange={(e) => setInputValue(e.target.value)}
157-
className='input border-none w-full focus:outline-none [&::-webkit-inner-spin-button]:appearance-none h-fit'
158-
placeholder='40000'
159-
/>
160-
161-
</div>
162-
</div>
163-
{/*Second Question*/}
164-
<div>
165-
<label className="label">
166-
<span className="label-text text-base font-semibold">{questions[currentQuestionIndex+1]}</span>
167-
</label>
168-
<div className='flex items-center justify-center space-x-4 py-2'>
169-
<button
170-
onClick={() => setInputValue('new')}
171-
className={`btn btn-sm ${inputValue === 'new' ? 'bg-blue-500 text-white' : 'bg-gray-200 text-gray-800'} hover:bg-blue-400 transition duration-300 w-1/4`}
172-
>
173-
new
174-
</button>
175-
<button
176-
onClick={() => setInputValue('used')}
177-
className={`btn btn-sm ${inputValue === 'used' ? 'bg-blue-500 text-white' : 'bg-gray-200 text-gray-800'} hover:bg-blue-400 transition duration-300 w-1/4`}
178-
>
179-
used
180-
</button>
181-
</div>
182-
</div>
183-
{/*Third Question*/}
184-
<div>
185-
<label className="label">
186-
<span className="label-text text-base font-semibold">{questions[currentQuestionIndex+2]}</span>
187-
</label>
188-
<div className='flex items-center border rounded-full border-gray-200'>
189-
<span className="pl-4 text-gray-500"></span>
190-
<input
191-
type='text'
192-
value={inputValue}
193-
onChange={(e) => setInputValue(e.target.value)}
194-
className='input border-none w-full focus:outline-none [&::-webkit-inner-spin-button]:appearance-none h-fit'
195-
placeholder='I would like up to 7 people'
196-
/>
197-
198-
</div>
199-
</div>
200-
{/*Fourth Question*/}
201-
<div>
202-
<label className="label">
203-
<span className="label-text text-base font-semibold">{questions[currentQuestionIndex+3]}</span>
204-
</label>
205-
<div className='flex items-center border rounded-full border-gray-200'>
206-
<span className="pl-4 text-gray-500"></span>
207-
<input
208-
type='text'
209-
value={inputValue}
210-
onChange={(e) => setInputValue(e.target.value)}
211-
className='input border-none w-full focus:outline-none [&::-webkit-inner-spin-button]:appearance-none h-fit'
212-
placeholder='family vacations, school, and road trips'
213-
/>
214-
</div>
215-
</div>
216-
{/*Fifth Question*/}
217-
<div>
218-
<label className="label">
219-
<span className="label-text text-base font-semibold">{questions[currentQuestionIndex+4]}</span>
220-
</label>
221-
<div className='flex items-center border rounded-full border-gray-200'>
222-
<span className="pl-4 text-gray-500"></span>
223-
<input
224-
type='text'
225-
value={inputValue}
226-
onChange={(e) => setInputValue(e.target.value)}
227-
className='input border-none w-full focus:outline-none [&::-webkit-inner-spin-button]:appearance-none h-fit'
228-
placeholder='I want a sun roof and lots of seats'
229-
/>
230-
</div>
231-
</div>
232-
{/*Sixth Question*/}
233-
<div>
234-
<label className="label">
235-
<span className="label-text text-base font-semibold">{questions[currentQuestionIndex+5]}</span>
236-
</label>
237-
<div className='flex items-center border rounded-full border-gray-200'>
238-
<span className="pl-4 text-gray-500"></span>
239-
<input
240-
type='text'
241-
value={inputValue}
242-
onChange={(e) => setInputValue(e.target.value)}
243-
className='input border-none w-full focus:outline-none [&::-webkit-inner-spin-button]:appearance-none h-fit'
244-
placeholder='Avoid high maintenance and poor fuel economy'
245-
/>
246-
</div>
247-
</div>
248-
{/*Seventh Question*/}
249-
<div>
250-
<label className="label">
251-
<span className="label-text text-base font-semibold">{questions[currentQuestionIndex+6]}</span>
252-
</label>
253-
<div className='flex items-center border rounded-full border-gray-200'>
254-
<span className="pl-4 text-gray-500"></span>
255-
<input
256-
type='text'
257-
value={inputValue}
258-
onChange={(e) => setInputValue(e.target.value)}
259-
className='input border-none w-full focus:outline-none [&::-webkit-inner-spin-button]:appearance-none h-fit'
260-
placeholder='I want forward collision warning to alert me'
261-
/>
262-
</div>
263-
</div>
264-
<div className='flex justify-center items center'>
265-
<button
266-
onClick={() => handleSubmit()}
267-
className="mt-2 btn w-1/3 bg-gradient-to-tr from-green-600 via-green-400 to-green-600 text-white hover:from-green-500 hover:to-green-400 transition-transform transform hover:scale-105 shadow-lg">
268-
Finish
269-
</button>
270-
</div>
271-
</div>
134+
<div className="form-control">
135+
{questions.map((question, index) => {
136+
const key = Object.keys(answers)[index]
137+
return (
138+
<fieldset className="fieldset" key={index}>
139+
<legend className="fieldset-legend">{question}</legend>
140+
<label className="input">
141+
<input
142+
type='text'
143+
value={answers.key}
144+
onChange={(e) => setAnswers(prev => ({ ...prev, [key]: e.target.value }))}
145+
className='grow'
146+
/>
147+
<span className="badge badge-neutral badge-xs">Optional</span>
148+
</label>
149+
</fieldset>
150+
)
151+
})}
152+
153+
<div className='flex justify-center items center'>
154+
<button
155+
onClick={() => handleSubmit()}
156+
className="mt-2 btn w-1/3 bg-gradient-to-tr from-green-600 via-green-400 to-green-600 text-white hover:from-green-500 hover:to-green-400 transition-transform transform hover:scale-105 shadow-lg">
157+
Finish
158+
</button>
159+
</div>
160+
</div>
272161
</div>
273162
</div>
274163
</div>
@@ -297,8 +186,8 @@ const Quiz = () => {
297186
</div>
298187
</div>
299188
)}
300-
301-
<div className="flex justify-center text-center">
189+
190+
<div className="flex justify-center text-center">
302191
<button
303192
onClick={handleBack}
304193
className="mt-6 bg-gray-300 text-black py-3 px-6 rounded-lg hover:from-teal-500 hover:to-blue-500 shadow-md text-lg font-semibold transition-transform transform hover:scale-105"
@@ -307,7 +196,7 @@ const Quiz = () => {
307196
</button>
308197
</div>
309198

310-
199+
311200
</div>
312201
)
313202
}

front-end/src/pages/SearchPage/VehicleList.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useNavigate } from 'react-router-dom'
22
import { useDispatch, useSelector } from 'react-redux'
3-
import { useMemo, useState } from 'react'
3+
import { useMemo } from 'react'
44
import { isVehicleSustainable } from './FilterTool'
55
import sustainableIcon from 'src/assets/sustainableicon.png'
66

front-end/src/pages/WelcomePage.jsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import { useEffect } from 'react'
12
import { useNavigate } from 'react-router-dom'
23
import CarCarousel from '../components/Carousel'
4+
import { startWindToast } from "@mariojgt/wind-notify/packages/index.js"
35

46
const WelcomePage = () => {
57
const navigate = useNavigate();
@@ -8,6 +10,10 @@ const WelcomePage = () => {
810
navigate('/inter');
911
}
1012

13+
useEffect(() => {
14+
startWindToast("WARNING!", "Our AI service is currently down", 'warning', 10, 'middle');
15+
}, [])
16+
1117
return (
1218
<div className="flex flex-col justify-center items-center space-y-8">
1319
<div className="text-center lg:text-left lg:space-x-8 lg:p-8 flex flex-col lg:flex-row items-center justify-center">

0 commit comments

Comments
 (0)