From c50c38657e23de012699781f07a51dd7e4199b77 Mon Sep 17 00:00:00 2001
From: eug-vs <eug-vs@keemail.me>
Date: Sun, 5 Jul 2020 12:18:55 +0300
Subject: feat: implement feedback feature

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

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

diff --git a/src/pages/HomePage/ReviewForm.tsx b/src/pages/HomePage/ReviewForm.tsx
new file mode 100644
index 0000000..58a61b4
--- /dev/null
+++ b/src/pages/HomePage/ReviewForm.tsx
@@ -0,0 +1,75 @@
+import React, { useState, useRef } from 'react';
+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';
+import { useAuth } from '../../hooks/useAuth';
+import { useNavigate } from '../../hooks/useNavigate';
+
+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 { navigate } = useNavigate();
+  const { enqueueSnackbar } = useSnackbar();
+
+  const handleSubmit = (): void => {
+    if (contents && score) {
+      post('/feedback', { contents, score, version }).then(() => {
+        enqueueSnackbar('Your feedback has been submitted!', {
+          variant: 'success'
+        });
+        navigate('feed');
+      });
+    }
+  };
+
+  const handleChange = (event: any): void => {
+    setContents(event.target?.value || '');
+  };
+
+  const handleChangeRating = (event: any, newScore: any): void => {
+    setScore(newScore);
+  };
+
+  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


From 202f2ab4209a836e51a57081e5f78e255973c6f1 Mon Sep 17 00:00:00 2001
From: eug-vs <eug-vs@keemail.me>
Date: Sun, 5 Jul 2020 12:22:38 +0300
Subject: style: fix eslint errors

---
 src/pages/HomePage/ReviewForm.tsx | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

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

diff --git a/src/pages/HomePage/ReviewForm.tsx b/src/pages/HomePage/ReviewForm.tsx
index 58a61b4..7ad0880 100644
--- a/src/pages/HomePage/ReviewForm.tsx
+++ b/src/pages/HomePage/ReviewForm.tsx
@@ -1,11 +1,10 @@
-import React, { useState, useRef } from 'react';
+import React, { useState } from 'react';
 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';
-import { useAuth } from '../../hooks/useAuth';
 import { useNavigate } from '../../hooks/useNavigate';
 
 const version = 'v1.0.0';
@@ -38,17 +37,17 @@ const ReviewForm: React.FC = () => {
     }
   };
 
-  const handleChange = (event: any): void => {
+  const handleChange = (event: React.ChangeEvent<HTMLInputElement>): void => {
     setContents(event.target?.value || '');
   };
 
-  const handleChangeRating = (event: any, newScore: any): void => {
-    setScore(newScore);
+  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"/>
+      <Rating value={score} onChange={handleChangeRating} size="large" />
       <TextField
         value={contents}
         onChange={handleChange}
-- 
cgit v1.2.3

