aboutsummaryrefslogtreecommitdiff
path: root/src/containers/HomePage/ReviewForm.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/containers/HomePage/ReviewForm.tsx')
-rw-r--r--src/containers/HomePage/ReviewForm.tsx74
1 files changed, 74 insertions, 0 deletions
diff --git a/src/containers/HomePage/ReviewForm.tsx b/src/containers/HomePage/ReviewForm.tsx
new file mode 100644
index 0000000..b626ce2
--- /dev/null
+++ b/src/containers/HomePage/ReviewForm.tsx
@@ -0,0 +1,74 @@
+import React, { useState } from 'react';
+import { useHistory } from 'react-router-dom';
+import { makeStyles } from '@material-ui/core/styles';
+import { TextField, Button } from '@material-ui/core';
+import { Rating } from '@material-ui/lab';
+import { useSnackbar } from 'notistack';
+
+import { post } from '../../requests';
+
+const version = 'v1.0.0';
+
+const useStyles = makeStyles(theme => ({
+ root: {
+ display: 'flex',
+ flexDirection: 'column'
+ },
+ textField: {
+ margin: theme.spacing(2, 0)
+ }
+}));
+
+const ReviewForm: React.FC = () => {
+ const [contents, setContents] = useState<string>('');
+ const [score, setScore] = useState<number>(0);
+ const classes = useStyles();
+ const history = useHistory();
+ const { enqueueSnackbar } = useSnackbar();
+
+ const handleSubmit = (): void => {
+ if (score) {
+ post('/feedback', { contents, score, version }).then(() => {
+ enqueueSnackbar('Your feedback has been submitted!', {
+ variant: 'success'
+ });
+ history.push('/feed');
+ });
+ }
+ };
+
+ const handleChange = (event: React.ChangeEvent<HTMLInputElement>): void => {
+ setContents(event.target?.value || '');
+ };
+
+ const handleChangeRating = (event: React.ChangeEvent<Record<string, unknown>>, newScore: number | null): void => {
+ setScore(newScore || 0);
+ };
+
+ return (
+ <div className={classes.root}>
+ <Rating value={score} onChange={handleChangeRating} size="large" />
+ <TextField
+ value={contents}
+ onChange={handleChange}
+ label="Feedback"
+ variant="outlined"
+ className={classes.textField}
+ rows={4}
+ multiline
+ />
+ <div>
+ <Button
+ variant="contained"
+ color="primary"
+ size="large"
+ onClick={handleSubmit}
+ >
+ submit
+ </Button>
+ </div>
+ </div>
+ );
+};
+
+export default ReviewForm;