Skip to content

Commit 8f4e330

Browse files
authored
Merge pull request #166 from BlackBond06/Feat/Add-a-help-feature
Feat/add a help feature
2 parents 6a9112f + b71c30f commit 8f4e330

11 files changed

Lines changed: 776 additions & 4 deletions

File tree

package-lock.json

Lines changed: 86 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"@testing-library/react": "^14.0.0",
1212
"@testing-library/user-event": "^14.4.3",
1313
"axios": "^1.4.0",
14+
"formik": "^2.4.3",
1415
"isbn-validate": "^1.0.3",
1516
"lodash": "^4.17.21",
1617
"material-ui-popup-state": "^5.0.9",
@@ -25,7 +26,8 @@
2526
"react-scripts": "5.0.1",
2627
"react-simple-star-rating": "^5.1.7",
2728
"styled-components": "^5.3.11",
28-
"web-vitals": "^3.3.2"
29+
"web-vitals": "^3.3.2",
30+
"yup": "^1.2.0"
2931
},
3032
"scripts": {
3133
"start": "react-scripts start",

src/App.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ import Register from './components/Register/Register';
88
import UserAuthenticated from './ProtectedRoute';
99
import ForgotPassword from './pages/ForgotPassword/ForgotPassword';
1010
import ResetPassword from './pages/ResetPassword/ResetPassword';
11+
import Support from './pages/Support/Support';
1112
import PrivacyPolicy from './pages/PrivacyPolicy/PrivacyPolicy';
12-
1313
export default function App() {
1414
return (
1515
<Router>
1616
<Routes>
1717
<Route element={<UserAuthenticated />}>
1818
<Route path='/' element={<Home />} />
19+
<Route path='/support' element={<Support />} />
1920
<Route path='/profile' element={<Profile />} />
2021
<Route path='/privacy-policy' element={<PrivacyPolicy />} />
2122
</Route>

src/components/Dropdown/Dropdown.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export default function Dropdown() {
118118
transformOrigin={{ horizontal: 'right', vertical: 'top' }}
119119
anchorOrigin={{ horizontal: 'right', vertical: 'bottom' }}
120120
>
121-
<MenuItem>
121+
<MenuItem onClick={() => navigate('/support')}>
122122
<HelpIcon fontSize='large' />
123123
&nbsp; Help
124124
</MenuItem>
Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
import { Box, Button, Grid, IconButton, Paper, TextField } from '@mui/material';
2+
import axios from 'axios';
3+
import { Formik, Field, Form, ErrorMessage } from 'formik';
4+
import * as Yup from 'yup';
5+
import CircularProgress from '@mui/material/CircularProgress';
6+
import Snackbar from '@mui/material/Snackbar';
7+
import CloseIcon from '@mui/icons-material/Close';
8+
import React, { useState } from 'react';
9+
const SupportForm = () => {
10+
const [loading, setLoading] = useState(false);
11+
const [showSnackBar, setShowSnackBar] = useState(false);
12+
const [showError, setShowError] = useState(false);
13+
const [supportError, setSupportError] = useState('');
14+
const initialValue = {
15+
name: '',
16+
email: '',
17+
description: '',
18+
};
19+
const validationSchema = Yup.object({
20+
name: Yup.string().required('Required'),
21+
email: Yup.string().email('E-mail is not valid').required('Required'),
22+
description: Yup.string().required('Required!'),
23+
});
24+
const handleSubmit = async (values, onSubmitProps) => {
25+
const { name, email, description } = values;
26+
try {
27+
setLoading(true);
28+
const response = await axios.post(
29+
'http://localhost:3001/api/support/newsupport',
30+
{
31+
name,
32+
email,
33+
description,
34+
}
35+
);
36+
if (response.status === 200) {
37+
setShowSnackBar(true);
38+
onSubmitProps.resetForm();
39+
}
40+
} catch (err) {
41+
const errorMsg = err.response.data.message;
42+
setSupportError(errorMsg);
43+
setShowError(true);
44+
}
45+
setLoading(false);
46+
};
47+
const closeSnackBar = () => {
48+
setShowSnackBar(false);
49+
setShowError(false);
50+
};
51+
const action = (
52+
<React.Fragment>
53+
<IconButton
54+
size='small'
55+
aria-label='close'
56+
color='inherit'
57+
onClick={closeSnackBar}
58+
autoHideDuration={4000}
59+
>
60+
<CloseIcon fontSize='small' />
61+
</IconButton>
62+
</React.Fragment>
63+
);
64+
65+
return (
66+
<>
67+
<Snackbar
68+
action={action}
69+
open={showSnackBar}
70+
autoHideDuration={3000}
71+
onClose={closeSnackBar}
72+
message='Support Query Successfully Submitted'
73+
/>
74+
<Snackbar
75+
action={action}
76+
open={showError}
77+
autoHideDuration={3000}
78+
onClose={closeSnackBar}
79+
message={supportError}
80+
/>
81+
<Grid container>
82+
<Grid item sm={3} xs={false}></Grid>
83+
<Grid item sm={6} xs={12}>
84+
<Paper>
85+
<Box m={5} p={3}>
86+
<Formik
87+
initialValues={initialValue}
88+
validationSchema={validationSchema}
89+
onSubmit={handleSubmit}
90+
>
91+
{({
92+
values,
93+
handleChange,
94+
handleBlur,
95+
touched,
96+
errors,
97+
}) => {
98+
const { name, email } = values;
99+
return (
100+
<Form>
101+
<TextField
102+
label='Name'
103+
name='name'
104+
fullWidth
105+
variant='outlined'
106+
margin='dense'
107+
value={name}
108+
onChange={handleChange}
109+
onBlur={handleBlur}
110+
helperText={
111+
<ErrorMessage name='name' />
112+
}
113+
error={
114+
errors.name && touched.name
115+
}
116+
required
117+
/>
118+
<TextField
119+
label='E-mail'
120+
name='email'
121+
fullWidth
122+
variant='outlined'
123+
margin='dense'
124+
value={email}
125+
onChange={handleChange}
126+
onBlur={handleBlur}
127+
helperText={
128+
<ErrorMessage name='email' />
129+
}
130+
error={
131+
errors.email &&
132+
touched.email
133+
}
134+
required
135+
/>
136+
<Field
137+
as={TextField}
138+
label='How can we help?'
139+
type='text'
140+
name='description'
141+
fullWidth
142+
multiline
143+
margin='dense'
144+
variant='outlined'
145+
InputProps={{
146+
inputComponent: 'textarea',
147+
rows: 10,
148+
}}
149+
helperText={
150+
<ErrorMessage name='description' />
151+
}
152+
error={
153+
errors.description &&
154+
touched.description
155+
}
156+
/>
157+
<Button
158+
variant='contained'
159+
type='submit'
160+
color='primary'
161+
fullWidth
162+
disabled={loading}
163+
>
164+
{loading && (
165+
<CircularProgress
166+
size={15}
167+
sx={{ mr: '10px' }}
168+
color='inherit'
169+
/>
170+
)}
171+
Submit
172+
</Button>
173+
</Form>
174+
);
175+
}}
176+
</Formik>
177+
</Box>
178+
</Paper>
179+
</Grid>
180+
<Grid item sm={3} xs={false}></Grid>
181+
</Grid>
182+
</>
183+
);
184+
};
185+
186+
export default SupportForm;

0 commit comments

Comments
 (0)