// @flow import React from 'react'; import { Component, Text, Button, View, TextInput } from 'reactxp'; import { Layout, Container, Header } from './Layout'; import styles from './SupportStyles'; import Img from './Img'; 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' | 'CONFIRM_NO_EMAIL' | '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 = (email: string) => { this.setState({ email: email }); } onChangeDescription = (description: string) => { this.setState({ message: description }); } 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 = () => { if (this.state.sendState === 'INITIAL' && this.state.email.length === 0) { this.setState({ sendState: 'CONFIRM_NO_EMAIL', }); } else { this._sendProblemReport(); } } _sendProblemReport() { 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 { sendState } = this.state; const header = Report a problem { (sendState === 'INITIAL' || sendState === 'CONFIRM_NO_EMAIL') && { '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 anonymised before being sent over an encrypted channel.' } } ; const content = this._renderContent(); return (