From f79727a8632490f11c1423773fdd6adfb6337a7b Mon Sep 17 00:00:00 2001 From: muhamedsalih-tw <104364298+muhamedsalih-tw@users.noreply.github.com> Date: Tue, 25 Oct 2022 12:51:28 +0530 Subject: Transform 'AuthLayoutContainer' component hierarchy to tsx (#699) Co-authored-by: Muhamed <> Co-authored-by: Vijay A --- src/features/publishDebugInfo/Component.tsx | 208 ++++++++++++++++++++++++++++ 1 file changed, 208 insertions(+) create mode 100644 src/features/publishDebugInfo/Component.tsx (limited to 'src/features/publishDebugInfo/Component.tsx') diff --git a/src/features/publishDebugInfo/Component.tsx b/src/features/publishDebugInfo/Component.tsx new file mode 100644 index 000000000..e265902dd --- /dev/null +++ b/src/features/publishDebugInfo/Component.tsx @@ -0,0 +1,208 @@ +import { inject, observer } from 'mobx-react'; +import { Component, ReactElement } from 'react'; +import { defineMessages, injectIntl, WrappedComponentProps } from 'react-intl'; +import withStyles, { WithStylesProps } from 'react-jss'; +import { StoresProps } from '../../@types/ferdium-components.types'; +import { state as ModalState } from './store'; +import { H1 } from '../../components/ui/headline'; +import { sendAuthRequest } from '../../api/utils/auth'; +import Button from '../../components/ui/button'; +import Input from '../../components/ui/input/index'; +import Modal from '../../components/ui/Modal'; +import { DEBUG_API } from '../../config'; + +const debug = require('../../preload-safe-debug')( + 'Ferdium:feature:publishDebugInfo', +); + +const messages = defineMessages({ + title: { + id: 'feature.publishDebugInfo.title', + defaultMessage: 'Publish debug information', + }, + info: { + id: 'feature.publishDebugInfo.info', + defaultMessage: + "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", + }, + error: { + id: 'feature.publishDebugInfo.error', + defaultMessage: + 'There was an error while trying to publish the debug information. Please try again later or view the console for more information.', + }, + privacy: { + id: 'feature.publishDebugInfo.privacy', + defaultMessage: 'Privacy policy', + }, + terms: { + id: 'feature.publishDebugInfo.terms', + defaultMessage: 'Terms of service', + }, + publish: { + id: 'feature.publishDebugInfo.publish', + defaultMessage: 'Accept and publish', + }, + published: { + id: 'feature.publishDebugInfo.published', + defaultMessage: 'Your debug log was published and is now availible at', + }, +}); + +const styles = theme => ({ + modal: { + width: '80%', + maxWidth: 600, + background: theme.styleTypes.primary.contrast, + paddingTop: 30, + }, + headline: { + fontSize: 20, + marginBottom: 20, + marginTop: -27, + }, + info: { + paddingBottom: 20, + }, + link: { + color: `${theme.styleTypes.primary.accent} !important`, + padding: 10, + cursor: 'pointer', + }, + button: { + width: '100%', + marginTop: 10, + cursor: 'pointer', + }, +}); + +interface IProps + extends Partial, + WithStylesProps, + WrappedComponentProps {} + +interface IState { + log: null; + error: boolean; + isSendingLogs: boolean; +} + +@inject('stores', 'actions') +@observer +class PublishDebugLogModal extends Component { + constructor(props: IProps) { + super(props); + + this.state = { + log: null, + error: false, + isSendingLogs: false, + }; + } + + // Close this modal + close(): void { + ModalState.isModalVisible = false; + this.setState({ + log: null, + error: false, + isSendingLogs: false, + }); + } + + async publishDebugInfo(): Promise { + debug('debugInfo: starting publish'); + this.setState({ + isSendingLogs: true, + }); + + const debugInfo = JSON.stringify(this.props.stores?.app?.debugInfo); + + const request = await sendAuthRequest( + `${DEBUG_API}/create`, + { + method: 'POST', + body: JSON.stringify({ + log: debugInfo, + }), + }, + false, + ); + + debug(`debugInfo: publishing status: ${request.status}`); + if (request.status === 200) { + const response = await request.json(); + if (response.id) { + this.setState({ log: response.id }); + } else { + this.setState({ error: true }); + } + } else { + this.setState({ error: true }); + } + + debug('debugInfo: finished publishing'); + } + + render(): ReactElement { + const { isModalVisible } = ModalState; + const { classes, intl } = this.props; + const { log, error, isSendingLogs } = this.state; + + return ( + this.close()} + > +

+ {intl.formatMessage(messages.title)} +

+ {log && ( + <> +

+ {intl.formatMessage(messages.published)} +

+ {/* TODO - [TS DEBT] need to check if take readOnly and use it */} + + + )} + {error && ( +

{intl.formatMessage(messages.error)}

+ )} + {!log && !error && ( + <> +

{intl.formatMessage(messages.info)}

+ + {intl.formatMessage(messages.privacy)} + + + {intl.formatMessage(messages.terms)} + +