aboutsummaryrefslogtreecommitdiff
path: root/src/containers/Home/ReviewForm.tsx
diff options
context:
space:
mode:
authoreug-vs <eug-vs@keemail.me>2020-08-10 11:19:53 +0300
committereug-vs <eug-vs@keemail.me>2020-08-10 11:19:53 +0300
commitf97989967ee0b88a8c64f226a4b28a79eeef5fd2 (patch)
tree9311246c260705c3c89fded54fb0bb688c98beec /src/containers/Home/ReviewForm.tsx
parentcab8de5c6b246e1aa1376fa2b8666f09b44b6469 (diff)
downloadwhich-ui-f97989967ee0b88a8c64f226a4b28a79eeef5fd2.tar.gz
refactor: remove "Page" from container names
Diffstat (limited to 'src/containers/Home/ReviewForm.tsx')
-rw-r--r--src/containers/Home/ReviewForm.tsx74
1 files changed, 74 insertions, 0 deletions
diff --git a/src/containers/Home/ReviewForm.tsx b/src/containers/Home/ReviewForm.tsx
new file mode 100644
index 0000000..b626ce2
--- /dev/null
+++ b/src/containers/Home/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;