aboutsummaryrefslogtreecommitdiffstats
path: root/src/features/publishDebugInfo/Component.js
diff options
context:
space:
mode:
authorLibravatar muhamedsalih-tw <104364298+muhamedsalih-tw@users.noreply.github.com>2022-10-25 12:51:28 +0530
committerLibravatar GitHub <noreply@github.com>2022-10-25 07:21:28 +0000
commitf79727a8632490f11c1423773fdd6adfb6337a7b (patch)
treea80943f4e4e571359c8104341a3957f6e763dce4 /src/features/publishDebugInfo/Component.js
parentadd balajiv113 as a contributor for code (#701) [skip ci] (diff)
downloadferdium-app-f79727a8632490f11c1423773fdd6adfb6337a7b.tar.gz
ferdium-app-f79727a8632490f11c1423773fdd6adfb6337a7b.tar.zst
ferdium-app-f79727a8632490f11c1423773fdd6adfb6337a7b.zip
Transform 'AuthLayoutContainer' component hierarchy to tsx (#699)
Co-authored-by: Muhamed <> Co-authored-by: Vijay A <vraravam@users.noreply.github.com>
Diffstat (limited to 'src/features/publishDebugInfo/Component.js')
-rw-r--r--src/features/publishDebugInfo/Component.js219
1 files changed, 0 insertions, 219 deletions
diff --git a/src/features/publishDebugInfo/Component.js b/src/features/publishDebugInfo/Component.js
deleted file mode 100644
index 27661d917..000000000
--- a/src/features/publishDebugInfo/Component.js
+++ /dev/null
@@ -1,219 +0,0 @@
1import { inject, observer } from 'mobx-react';
2import PropTypes from 'prop-types';
3import { Component } from 'react';
4import { defineMessages, injectIntl } from 'react-intl';
5import injectSheet from 'react-jss';
6import { state as ModalState } from './store';
7
8import { H1 } from '../../components/ui/headline';
9import { sendAuthRequest } from '../../api/utils/auth';
10import Button from '../../components/ui/button';
11import Input from '../../components/ui/input/index';
12import Modal from '../../components/ui/Modal';
13import { DEBUG_API } from '../../config';
14import AppStore from '../../stores/AppStore';
15import ServicesStore from '../../stores/ServicesStore';
16
17const debug = require('../../preload-safe-debug')(
18 'Ferdium:feature:publishDebugInfo',
19);
20
21const messages = defineMessages({
22 title: {
23 id: 'feature.publishDebugInfo.title',
24 defaultMessage: 'Publish debug information',
25 },
26 info: {
27 id: 'feature.publishDebugInfo.info',
28 defaultMessage:
29 "Publishing your debug information helps us find issues and errors in Ferdium. By publishing your debug information you accept Ferdium Debugger's privacy policy and terms of service",
30 },
31 error: {
32 id: 'feature.publishDebugInfo.error',
33 defaultMessage:
34 'There was an error while trying to publish the debug information. Please try again later or view the console for more information.',
35 },
36 privacy: {
37 id: 'feature.publishDebugInfo.privacy',
38 defaultMessage: 'Privacy policy',
39 },
40 terms: {
41 id: 'feature.publishDebugInfo.terms',
42 defaultMessage: 'Terms of service',
43 },
44 publish: {
45 id: 'feature.publishDebugInfo.publish',
46 defaultMessage: 'Accept and publish',
47 },
48 published: {
49 id: 'feature.publishDebugInfo.published',
50 defaultMessage: 'Your debug log was published and is now availible at',
51 },
52});
53
54const styles = theme => ({
55 modal: {
56 width: '80%',
57 maxWidth: 600,
58 background: theme.styleTypes.primary.contrast,
59 paddingTop: 30,
60 },
61 headline: {
62 fontSize: 20,
63 marginBottom: 20,
64 marginTop: -27,
65 },
66 info: {
67 paddingBottom: 20,
68 },
69 link: {
70 color: `${theme.styleTypes.primary.accent} !important`,
71 padding: 10,
72 cursor: 'pointer',
73 },
74 button: {
75 width: '100%',
76 marginTop: 10,
77 cursor: 'pointer',
78 },
79});
80
81class PublishDebugLogModal extends Component {
82 state = {
83 log: null,
84 error: false,
85 isSendingLog: false,
86 };
87
88 // Close this modal
89 close() {
90 ModalState.isModalVisible = false;
91 this.setState({
92 log: null,
93 error: false,
94 isSendingLog: false,
95 });
96 }
97
98 async publishDebugInfo() {
99 debug('debugInfo: starting publish');
100 this.setState({
101 isSendingLog: true,
102 });
103
104 const debugInfo = JSON.stringify(this.props.stores.app.debugInfo);
105
106 const request = await sendAuthRequest(
107 `${DEBUG_API}/create`,
108 {
109 method: 'POST',
110 body: JSON.stringify({
111 log: debugInfo,
112 }),
113 },
114 false,
115 );
116
117 debug(`debugInfo: publishing status: ${request.status}`);
118 if (request.status === 200) {
119 const response = await request.json();
120 if (response.id) {
121 this.setState({
122 log: response.id,
123 });
124 } else {
125 this.setState({
126 error: true,
127 });
128 }
129 } else {
130 this.setState({
131 error: true,
132 });
133 }
134
135 debug('debugInfo: finished publishing');
136 }
137
138 render() {
139 const { isModalVisible } = ModalState;
140
141 const { classes } = this.props;
142
143 const { log, error, isSendingLog } = this.state;
144
145 const { intl } = this.props;
146
147 return (
148 <Modal
149 isOpen={isModalVisible}
150 shouldCloseOnOverlayClick
151 className={`${classes.modal} publish-debug`}
152 close={() => this.close()}
153 >
154 <H1 className={classes.headline}>
155 {intl.formatMessage(messages.title)}
156 </H1>
157 {log && (
158 <>
159 <p className={classes.info}>
160 {intl.formatMessage(messages.published)}
161 </p>
162 <Input showLabel={false} value={`${DEBUG_API}/${log}`} readonly />
163 </>
164 )}
165
166 {error && (
167 <p className={classes.info}>{intl.formatMessage(messages.error)}</p>
168 )}
169
170 {!log && !error && (
171 <>
172 <p className={classes.info}>{intl.formatMessage(messages.info)}</p>
173
174 <a
175 href={`${DEBUG_API}/privacy.html`}
176 target="_blank"
177 className={classes.link}
178 rel="noreferrer"
179 >
180 {intl.formatMessage(messages.privacy)}
181 </a>
182 <a
183 href={`${DEBUG_API}/terms.html`}
184 target="_blank"
185 className={classes.link}
186 rel="noreferrer"
187 >
188 {intl.formatMessage(messages.terms)}
189 </a>
190
191 <Button
192 type="button"
193 label={intl.formatMessage(messages.publish)}
194 className={classes.button}
195 onClick={() => this.publishDebugInfo()}
196 disabled={isSendingLog}
197 />
198 </>
199 )}
200 </Modal>
201 );
202 }
203}
204
205PublishDebugLogModal.propTypes = {
206 stores: PropTypes.shape({
207 app: PropTypes.instanceOf(AppStore).isRequired,
208 }).isRequired,
209 actions: PropTypes.shape({
210 service: PropTypes.instanceOf(ServicesStore).isRequired,
211 }).isRequired,
212 classes: PropTypes.object.isRequired,
213};
214
215export default injectIntl(
216 injectSheet(styles, { injectTheme: true })(
217 inject('stores', 'actions')(observer(PublishDebugLogModal)),
218 ),
219);