import React, { Component } from 'react'; import { ActivityIndicator, KeyboardAvoidingView, TouchableHighlight, TouchableWithoutFeedback, StyleSheet, TextInput, Keyboard, Text, View } from 'react-native'; import hosts from '../db/hosts' const validator = require("email-validator") import ScrollableContainer from '../components/scrollableContainer' import ClearText from '../components/text' import Heading from '../components/heading' import Button from '../components/button' import CheckBox from '../components/checkbox' import Modal from '../components/modal' export default class Contact extends Component { constructor() { super() this.state = { name: '', email: '', message: '', track: false, publish: false, sending: false, done: false, } this.setName = this.setName.bind(this) this.setEmail = this.setEmail.bind(this) this.setTrack = this.setTrack.bind(this) this.setPublish = this.setPublish.bind(this) this.setMessage = this.setMessage.bind(this) this.send = this.send.bind(this) this.reset = this.reset.bind(this) } setName(name) { this.setState({ name, error: false }) } setEmail(email) { this.setState({ email, error: false }) } setTrack(track) { this.setState({ track: ! track }) } setPublish(publish) { this.setState({ publish: ! publish }) } setMessage(message) { this.setState({ message: message }) } send() { var isValidEmail = validator.validate(this.state.email) if (! isValidEmail) { // return this.setState({ error: true }) this.setState({ sending: true, track: false }) } else { this.setState({ sending: true }) } // fetch('POST', hosts.feedback, { // 'Content-Type' : 'multipart/form-data', // }, [ // { name: 'name', data: this.state.name }, // { name: 'email', data: this.state.email }, // { name: 'message', data: this.state.message }, // { name: 'track', data: this.state.track }, // { name: 'publish', data: this.state.publish }, // { name: 'secret', data: 'iNr51NbvUDqbBzyray7gdZZjigDtlJj9' }, // ]).then(() => { // this.setState({ done: true }) // }).catch((e) => { // console.warn(e) // this.setState({ done: true }) // }) } reset() { this.setState({ name: '', email: '', message: '', track: false, publish: false, sending: false, done: false, }) } render() { return ( {this.props.content.body} {this.renderForm()} {this.renderComments()} {this.renderActivity()} ) } renderForm() { let error = this.state.error ? ( Please enter a valid email address ) : ( ) return ( {error}