aboutsummaryrefslogtreecommitdiffstats
path: root/src/features/publishDebugInfo/Component.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/features/publishDebugInfo/Component.js')
-rw-r--r--src/features/publishDebugInfo/Component.js208
1 files changed, 208 insertions, 0 deletions
diff --git a/src/features/publishDebugInfo/Component.js b/src/features/publishDebugInfo/Component.js
new file mode 100644
index 000000000..1f1b0ed45
--- /dev/null
+++ b/src/features/publishDebugInfo/Component.js
@@ -0,0 +1,208 @@
1import { H1 } from '@meetfranz/ui';
2import { inject, observer } from 'mobx-react';
3import PropTypes from 'prop-types';
4import React, { Component } from 'react';
5import { defineMessages, intlShape } from 'react-intl';
6import injectSheet from 'react-jss';
7import { state as ModalState } from '.';
8import { sendAuthRequest } from '../../api/utils/auth';
9import Button from '../../components/ui/Button';
10import Input from '../../components/ui/Input';
11import Modal from '../../components/ui/Modal';
12import { DEBUG_API } from '../../config';
13import AppStore from '../../stores/AppStore';
14
15
16const messages = defineMessages({
17 title: {
18 id: 'feature.publishDebugInfo.title',
19 defaultMessage: '!!!Publish debug information',
20 },
21 info: {
22 id: 'feature.publishDebugInfo.info',
23 defaultMessage: '!!!Publishing your debug information helps us find issues and errors in Ferdi. By publishing your debug information you accept Ferdi Debugger\'s privacy policy and terms of service',
24 },
25 error: {
26 id: 'feature.publishDebugInfo.error',
27 defaultMessage: '!!!There was an error while trying to publish the debug information. Please try again later or view the console for more information.',
28 },
29 privacy: {
30 id: 'feature.publishDebugInfo.privacy',
31 defaultMessage: '!!!Privacy policy',
32 },
33 terms: {
34 id: 'feature.publishDebugInfo.terms',
35 defaultMessage: '!!!Terms of service',
36 },
37 publish: {
38 id: 'feature.publishDebugInfo.publish',
39 defaultMessage: '!!!Accept and publish',
40 },
41 published: {
42 id: 'feature.publishDebugInfo.published',
43 defaultMessage: '!!!Your debug log was published and is now availible at',
44 },
45});
46
47const styles = theme => ({
48 container: {
49 minWidth: '70vw',
50 },
51 info: {
52 paddingTop: 20,
53 paddingBottom: 20,
54 },
55 link: {
56 color: `${theme.styleTypes.primary.accent} !important`,
57 padding: 10,
58 cursor: 'pointer',
59 },
60 button: {
61 width: '100%',
62 marginTop: 10,
63 cursor: 'pointer',
64 },
65 url: {
66 marginTop: 20,
67 width: '100%',
68
69 '& div': {
70 fontFamily: 'SFMono-Regular,Consolas,Liberation Mono,Menlo,Courier,monospace',
71 },
72
73 '& input': {
74 width: '100%',
75 padding: 15,
76 borderRadius: 6,
77 border: `solid 1px ${theme.styleTypes.primary.accent}`,
78 },
79 },
80});
81
82export default @injectSheet(styles) @inject('stores', 'actions') @observer class PublishDebugLogModal extends Component {
83 static propTypes = {
84 classes: PropTypes.object.isRequired,
85 };
86
87 static contextTypes = {
88 intl: intlShape,
89 };
90
91 state = {
92 log: null,
93 error: false,
94 isSendingLog: false,
95 }
96
97 // Close this modal
98 close() {
99 ModalState.isModalVisible = false;
100 }
101
102 async publishDebugInfo() {
103 this.setState({
104 isSendingLog: true,
105 });
106
107 const debugInfo = JSON.stringify(this.props.stores.app.debugInfo);
108
109 const request = await sendAuthRequest(`${DEBUG_API}/create`, {
110 method: 'POST',
111 body: JSON.stringify({
112 log: debugInfo,
113 }),
114 }, false);
115 const response = await request.json();
116
117 if (response.id) {
118 this.setState({
119 log: response.id,
120 });
121 } else {
122 this.setState({
123 error: true,
124 });
125 }
126 }
127
128 render() {
129 const { isModalVisible } = ModalState;
130
131 const {
132 classes,
133 } = this.props;
134
135 const {
136 log,
137 error,
138 isSendingLog,
139 } = this.state;
140
141 const { intl } = this.context;
142
143 return (
144 <Modal
145 isOpen={isModalVisible}
146 shouldCloseOnOverlayClick
147 close={() => this.close()}
148 >
149 <div className={classes.container}>
150 <H1>
151 {intl.formatMessage(messages.title)}
152 </H1>
153 { log && (
154 <>
155 <p className={classes.info}>{intl.formatMessage(messages.published)}</p>
156 <Input
157 className={classes.url}
158 showLabel={false}
159 field={{
160 type: 'url',
161 value: `${DEBUG_API}/${log}`,
162 disabled: true,
163 }}
164 readonly
165 />
166 </>
167 )}
168
169 {error && (
170 <p className={classes.info}>{intl.formatMessage(messages.error)}</p>
171 )}
172
173 {!log && !error && (
174 <>
175 <p className={classes.info}>{intl.formatMessage(messages.info)}</p>
176
177 <a href={`${DEBUG_API}/privacy.html`} target="_blank" className={classes.link}>
178 {intl.formatMessage(messages.privacy)}
179 </a>
180 <a href={`${DEBUG_API}/terms.html`} target="_blank" className={classes.link}>
181 {intl.formatMessage(messages.terms)}
182 </a>
183
184 <Button
185 type="button"
186 label={intl.formatMessage(messages.publish)}
187 className={classes.button}
188 onClick={() => this.publishDebugInfo()}
189 disabled={isSendingLog}
190 />
191 </>
192 )}
193 </div>
194 </Modal>
195 );
196 }
197}
198
199PublishDebugLogModal.wrappedComponent.propTypes = {
200 stores: PropTypes.shape({
201 app: PropTypes.instanceOf(AppStore).isRequired,
202 }).isRequired,
203 actions: PropTypes.shape({
204 service: PropTypes.shape({
205 setActive: PropTypes.func.isRequired,
206 }).isRequired,
207 }).isRequired,
208};