import React from 'react'; import PropTypes from 'prop-types'; import { Input, Button, Modal, NgIf } from './'; import { prompt } from '../helpers/'; export class ModalPrompt extends React.Component { constructor(props){ super(props); this.state = { appear: false }; } componentDidMount(){ prompt.subscribe((text, okCallback, cancelCallback, type) => { console.log("REQUEST FOR PROMPT"); this.setState({ appear: true, error: null, type: type || 'text', text: text || '', fns: {ok: okCallback, cancel: cancelCallback} }); }); } onCancel(){ this.setState({appear: false}); this.state.fns.cancelCallback(); } onSubmit(e){ e && e.preventDefault && e.preventDefault(); this.state.fns.okCallback(this.state.value) .then(() => this.setState({appear: false})) .catch((message) => this.setState({error: message})); } render() { return (

{this.state.text}

this.setState({value: e.target.value})} />
{this.state.error} 
); } }