aboutsummaryrefslogtreecommitdiff
path: root/src/client/util/ReportManager.tsx
blob: 128d58d88c69e81d93f4bf04fde2d2d2c0692894 (plain)
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 { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { action, computed, observable, runInAction } from 'mobx';
import { observer } from 'mobx-react';
import * as React from 'react';
import { ColorState, SketchPicker } from 'react-color';
import { Doc } from '../../fields/Doc';
import { Id } from '../../fields/FieldSymbols';
import { BoolCast, Cast, StrCast } from '../../fields/Types';
import { addStyleSheet, addStyleSheetRule, Utils } from '../../Utils';
import { GoogleAuthenticationManager } from '../apis/GoogleAuthenticationManager';
import { DocServer } from '../DocServer';
import { Networking } from '../Network';
import { MainViewModal } from '../views/MainViewModal';
import { FontIconBox } from '../views/nodes/button/FontIconBox';
import { DragManager } from './DragManager';
import { GroupManager } from './GroupManager';
import './SettingsManager.scss';
import { undoBatch } from './UndoManager';
import { Octokit } from "@octokit/core";
import { CheckBox } from '../views/search/CheckBox';
const higflyout = require('@hig/flyout');
export const { anchorPoints } = higflyout;
export const Flyout = higflyout.default;

@observer
export class ReportManager extends React.Component<{}> {
    public static Instance: ReportManager;
    @observable private isOpen = false;

    private octokit: Octokit;

    constructor(props: {}) {
        super(props);
        ReportManager.Instance = this;

        this.octokit = new Octokit({
            auth: 'auth key'
        });
    }

    public close = action(() => (this.isOpen = false));
    public open = action(() => (this.isOpen = true));

    private bugTitle = '';
    private bugDescription = '';
    private toGithub = false;

    private formatTitle = (title: string, userEmail: string) => `${title} - ${userEmail.replace('@brown.edu', '')}`; 

    public async reportBug() {
        if (this.toGithub) {
            const req = await this.octokit.request('POST /repos/{owner}/{repo}/issues', {
                owner: 'brown-dash',
                repo: 'Dash-Web',
                title: this.formatTitle(this.bugTitle, Doc.CurrentUserEmail),
                body: this.bugDescription,
                labels: [
                    'from-dash-app',
                ]
            });

            // 201 status means success
            if (req.status !== 201) {
                alert('Error creating issue on github.');
                // on error, don't close the modal
                return;
            }
        }
        else {
            // if not going to github issues, not sure what to do yet...
        }

        // if we're down here, then we're good to go.
        this.bugTitle = '';
        this.bugDescription = '';
        this.toGithub = false;
        this.close();
    }

    private get reportInterface() {

        return (
            <div className="settings-interface">
                <div className="close-button" onClick={this.close}>
                    <FontAwesomeIcon icon={'times'} color="black" size={'lg'} />
                </div>

                <div className="settings-content">
                    <h3 style={{ 'textDecoration': 'underline'}}>Report an Issue</h3>
                    <label>Please leave a title for the bug.</label><br />
                    <input type="text" placeholder='title' onChange={(e) => this.bugTitle = e.target.value} />
                    <br />
                    <label>Please leave a description for the bug and how it can be recreated.</label>
                    <textarea placeholder='description' onChange={(e) => this.bugDescription = e.target.value}/>
                    <br /><br />
                    <label>Send to github issues? </label>
                    <input type="checkbox" onChange={(e) => this.toGithub = e.target.checked} />
                    <br />
                    <button onClick={() => this.reportBug()}>Submit</button>
                </div>


            </div>
        );
    }

    render() {
        return (
            <MainViewModal
                contents={this.reportInterface}
                isDisplayed={this.isOpen}
                interactive={true}
                closeOnExternalClick={this.close}
                dialogueBoxStyle={{ width: '500px', height: '300px', background: Cast(Doc.SharingDoc().userColor, 'string', null) }}
            />
        );
    }
}