// @flow import React, { Component } from 'react'; import { Layout, Container, Header } from './Layout'; import ExternalLinkSVG from '../assets/images/icon-extLink.svg'; import type { AccountReduxState } from '../redux/account/reducers'; export type SupportReport = { email: string, message: string, savedReport: ?string, }; export type SupportState = { email: string, message: string, savedReport: ?string, sendState: 'INITIAL' | 'LOADING' | 'SUCCESS' | 'FAILED', }; export type SupportProps = { account: AccountReduxState, onClose: () => void; onViewLog: (string) => void; onCollectLog: (Array) => Promise; onSend: (email: string, message: string, savedReport: string) => void; }; export default class Support extends Component { props: SupportProps; state: SupportState = { email: '', message: '', savedReport: null, sendState: 'INITIAL', } validate() { return this.state.message.trim().length > 0; } onChangeEmail = (e: Event) => { const input = e.target; if(!(input instanceof HTMLInputElement)) { throw new Error('input must be an instance of HTMLInputElement'); } this.setState({ email: input.value }); } onChangeDescription = (e: Event) => { const input = e.target; if(!(input instanceof HTMLTextAreaElement)) { throw new Error('input must be an instance of HTMLTextAreaElement'); } this.setState({ message: input.value }); } onViewLog = () => { this._getLog() .then((path) => { this.props.onViewLog(path); }); } _getLog() { const toRedact = []; if (this.props.account.accountToken) { toRedact.push(this.props.account.accountToken.toString()); } const { savedReport } = this.state; return savedReport ? Promise.resolve(savedReport) : this.props.onCollectLog(toRedact) .then( path => { return new Promise(resolve => this.setState({ savedReport: path }, () => resolve(path))); }); } onSend = () => { this.setState({ sendState: 'LOADING', }, () => { this._getLog() .then((path) => { return this.props.onSend(this.state.email, this.state.message, path); }) .then( () => { this.setState({ sendState: 'SUCCESS', }); }) .catch( () => { this.setState({ sendState: 'FAILED', }); }); }); } render() { const header =

Report a problem

{ this.state.sendState === 'INITIAL' &&
{ `To help you more effectively, your app's log file will be attached to this message. Your data will remain secure and private, as it is encrypted & anonymised before sending.` }
}
; const content = this._renderContent(); return (