Skip to content

Commit 0f21d9b

Browse files
authored
Merge pull request #3223 from andrewbaldwin44/feature/feedback-form
Add Locust Feedback Form
2 parents aa0b1c9 + 8d1a398 commit 0f21d9b

File tree

3 files changed

+110
-0
lines changed

3 files changed

+110
-0
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import { useState } from 'react';
2+
import { Alert, Box, Button, TextField, Typography } from '@mui/material';
3+
4+
import Form from 'components/Form/Form';
5+
import Modal from 'components/Modal/Modal';
6+
import LoadingButton from 'components/SwarmForm/LoadingButton';
7+
8+
interface IFeedbackForm {
9+
email: string;
10+
message: string;
11+
}
12+
13+
const unexpectedErrorMessage =
14+
"We're sorry but something seems to have gone wrong. Please try again or reach out to us directly at support@locust.cloud";
15+
16+
export default function FeedbackForm() {
17+
const [open, setOpen] = useState(false);
18+
const [isLoading, setIsLoading] = useState(false);
19+
const [errorMessage, setErrorMessage] = useState<string>();
20+
const [success, setSuccess] = useState<boolean>();
21+
22+
const onSubmitFeedback = async (inputData: IFeedbackForm) => {
23+
setIsLoading(true);
24+
25+
try {
26+
const response = await fetch('http://localhost:8000/1/customer/send-feedback', {
27+
method: 'POST',
28+
body: JSON.stringify(inputData),
29+
headers: { 'Content-Type': 'application/json' },
30+
});
31+
32+
if (response.status >= 400) {
33+
setErrorMessage(unexpectedErrorMessage);
34+
} else {
35+
setSuccess(true);
36+
}
37+
} catch {
38+
setErrorMessage(unexpectedErrorMessage);
39+
}
40+
41+
setIsLoading(false);
42+
};
43+
44+
return (
45+
<>
46+
<Box sx={{ display: 'flex', justifyContent: 'flex-end' }}>
47+
<Button color='inherit' onClick={() => setOpen(true)} variant='text'>
48+
Feedback
49+
</Button>
50+
</Box>
51+
<Modal onClose={() => setOpen(false)} open={open}>
52+
{success ? (
53+
<Box
54+
sx={{
55+
display: 'flex',
56+
flexDirection: 'column',
57+
justifyContent: 'center',
58+
textAlign: 'center',
59+
height: 200,
60+
}}
61+
>
62+
<Typography component='h4' sx={{ mb: 2 }} variant='h4'>
63+
Thanks for reaching out!
64+
</Typography>
65+
<Typography component='h4' variant='h5'>
66+
Your feedback is very valuable to us as we work to improve Locust!
67+
</Typography>
68+
</Box>
69+
) : (
70+
<Form<IFeedbackForm> onSubmit={onSubmitFeedback}>
71+
<Box sx={{ display: 'flex', flexDirection: 'column', rowGap: 2, my: 2 }}>
72+
<TextField label='Email' name='email' required type='email' />
73+
<TextField label='Name' name='name' />
74+
<TextField label='Message' multiline name='message' required rows={3} />
75+
{!!errorMessage && <Alert severity='error'>{errorMessage}</Alert>}
76+
77+
<LoadingButton isLoading={isLoading} type='submit'>
78+
Submit
79+
</LoadingButton>
80+
</Box>
81+
</Form>
82+
)}
83+
</Modal>
84+
</>
85+
);
86+
}

locust/webui/src/components/Layout/Footer/Footer.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Container } from '@mui/material';
22

33
import About from 'components/Layout/Footer/About';
4+
import FeedbackForm from 'components/Layout/Footer/FeedbackForm';
45

56
export default function Footer() {
67
return (
@@ -14,6 +15,7 @@ export default function Footer() {
1415
}}
1516
>
1617
<About />
18+
<FeedbackForm />
1719
</Container>
1820
);
1921
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { Button, ButtonProps, CircularProgress } from '@mui/material';
2+
3+
interface ILoadingButton extends ButtonProps {
4+
isLoading?: boolean;
5+
children?: React.ReactNode;
6+
}
7+
8+
export default function LoadingButton({ isLoading, children, variant, ...props }: ILoadingButton) {
9+
return (
10+
<>
11+
<Button
12+
{...props}
13+
disabled={props.disabled || isLoading}
14+
size='large'
15+
sx={{ ...props.sx, textTransform: 'none' }}
16+
variant={variant || 'contained'}
17+
>
18+
{isLoading ? <CircularProgress size={25} sx={{ color: 'white' }} /> : children || 'Submit'}
19+
</Button>
20+
</>
21+
);
22+
}

0 commit comments

Comments
 (0)