-
Notifications
You must be signed in to change notification settings - Fork 12
/
Feedback.jsx
107 lines (92 loc) · 2.8 KB
/
Feedback.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import React from 'react';
import alertifyjs from 'alertifyjs';
import ReactSuggestionBox from 'react-suggestion-box';
import { TextField } from '@mui/material';
import { ReportProblem as Icon } from '@mui/icons-material';
import Captcha from './Captcha';
import { isLoggedIn } from '../../common/utils';
import { WHITE } from '../../common/constants';
import APIService from '../../services/APIService';
const Feedback = props => {
const isAuth = isLoggedIn();
const [name, setName] = React.useState(undefined)
const [email, setEmail] = React.useState(undefined)
const [captcha, setCaptcha] = React.useState(undefined)
const getStartControls = () => {
if(isAuth)
return null;
return (
<div className='col-md-12 no-side-padding'>
<TextField
id='feedback-name'
style={{marginBottom: '10px', background: WHITE}}
required
label="Name"
variant="outlined"
fullWidth
onChange={event => setName(event.target.value)}
/>
<TextField
id='feedback-email'
style={{marginBottom: '10px', background: WHITE}}
label="Email"
variant="outlined"
fullWidth
onChange={event => setEmail(event.target.value)}
required
type='email'
/>
</div>
)
}
const getEndControls = () => {
if(isAuth)
return null;
return (
<div className='col-md-12 no-side-padding' style={{marginTop: '10px'}}>
<div style={{display: 'flex', justifyContent: 'center'}}>
<Captcha onChange={ value => setCaptcha(value) } />
</div>
</div>
);
}
const sendFeedback = data => APIService.feedback().post(data).then(() => alertifyjs.success('Successfully submit feedback!'));
const onSubmit = data => {
if(isAuth)
sendFeedback(data);
else {
if(!name) {
document.getElementById('feedback-name').reportValidity()
return
}
if(!email) {
document.getElementById('feedback-email').reportValidity()
return
}
sendFeedback({...data, name: name, email: email})
}
}
const triggerValidity = () => {
if(isAuth)
return true
const isNameValid = document.getElementById('feedback-name').reportValidity()
if(isNameValid)
return document.getElementById('feedback-email').reportValidity()
return isNameValid
}
const isSendDisabled = !isAuth && !captcha;
return (
<ReactSuggestionBox
startControls={getStartControls()}
endControls={getEndControls()}
onSubmit={onSubmit}
isSendDisabled={isSendDisabled}
beforeSendValidator={triggerValidity}
icon={<Icon />}
title='Provide Feedback/Suggestion'
buttonTooltipText='Feedback'
{...props}
/>
);
}
export default Feedback;