From 7ba15a22d1bd57e7c26ff2d5fccf5505aaf8619e Mon Sep 17 00:00:00 2001
From: eug-vs <eug-vs@keemail.me>
Date: Mon, 10 Aug 2020 00:28:39 +0300
Subject: refactor: move pages -> containers

---
 src/containers/HomePage/ReviewForm.tsx | 74 ++++++++++++++++++++++++++++++++++
 1 file changed, 74 insertions(+)
 create mode 100644 src/containers/HomePage/ReviewForm.tsx

(limited to 'src/containers/HomePage/ReviewForm.tsx')

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;
-- 
cgit v1.2.3

