-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBugReport.js
118 lines (106 loc) · 3.8 KB
/
BugReport.js
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
108
109
110
111
112
113
114
115
116
117
118
import * as React from 'react';
import { useState, useEffect } from "react";
import { makeStyles } from "@material-ui/core";
import {Stack, Typography} from "@mui/material";
import {Modal, TextField, Paper, Button, IconButton, Tooltip} from "@material-ui/core";
import { Octokit } from "@octokit/core";
import BugReportIcon from '@mui/icons-material/BugReport';
import CloseIcon from '@mui/icons-material/Close';
import SendIcon from '@mui/icons-material/Send';
import { auth } from './bugSubmitAuth';
const useStyles = makeStyles( {
inputField: {
width: '100%',
},
buttons: {
marginTop: "20px",
width: "100%",
justifyContent: "center",
alignContent: "center"
},
paper: {
position: 'absolute',
top: '50%',
left: '50%',
transform: 'translate(-50%, -50%)',
width: '50vw',
bgcolor: 'background.paper',
boxShadow: 24,
p: 4,
padding: '30px'
},
title: {
marginBottom: "10px",
width: "100%"
},
});
export default function BugReport(props) {
const classes = useStyles();
const [open, setOpen] = useState(false);
const [description, setDescription] = useState("");
const [disableSubmit, setDisableSubmit] = useState(true);
useEffect(() => {
const numberOfWords = description.split(" ").length;
setDisableSubmit(!(numberOfWords > 3) || description === '');
}, [description])
const handleOpen = () => setOpen(true);
const handleClose = () => setOpen(false);
function updateDescription(event) {
const input = event.target.value;
setDescription(input);
}
async function sendGitHub() {
const octokit = new Octokit({
auth: auth
})
await octokit.request('POST /repos/Project-Sustain/sustain-download-service/issues', {
owner: 'Project-Sustain',
repo: 'sustain-download-service',
title: `Bug Report: ${description.split(" ").slice(0, 3).join(" ")}...`,
body: description,
labels: [
'bug', 'userSubmitted'
]
})
}
return (
<div>
<Tooltip title='Bug Report'>
<IconButton variant="outlined" onClick={handleOpen}>
<BugReportIcon/>
</IconButton>
</Tooltip>
<Modal
open={open}
onClose={handleClose}
>
<Paper className={classes.paper}>
<div className={classes.title}>
<Typography variant="h6" component="h2" textAlign="center">
Submit a Bug Report
</Typography>
</div>
<TextField
className={classes.inputField}
multiline
rows={6}
label="Please describe the issue you are noticing..."
value={description}
variant="outlined"
onChange={(event) => updateDescription(event)}
/>
<Stack direction='row' spacing={2} className={classes.buttons}>
<Button disabled={disableSubmit} variant="outlined" onClick={() => {
sendGitHub().then(() => {
setDescription("");
handleClose();
props.setAlert(true);
});
}}><SendIcon/> Submit Bug</Button>
<Button variant="outlined" onClick={handleClose}><CloseIcon/></Button>
</Stack>
</Paper>
</Modal>
</div>
)
}