import React, { Component } from 'react';
import {
ActivityIndicator,
KeyboardAvoidingView,
Touchable,
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}
)
}
renderActivity() {
let activity;
if (! this.state.done) {
activity = (
Sending your message...
)
}
else {
activity = (
Thanks!
Your message has been delivered.
Thank you for your feedback.
)
}
return (
{activity}
)
}
renderComments() {
const comments = this.props.comments.map( (comment, i) => {
const date = comment[0].replace(/:\d\d$/,'')
return (
{comment[1]}
{date}
{comment[2]}
)
})
return (
{comments}
)
}
}
const styles = StyleSheet.create({
container: {
justifyContent: 'flex-start',
alignItems: 'center',
flex: 1,
},
body: {
justifyContent: 'flex-start',
alignItems: 'center',
},
innerContainer: {
justifyContent: 'flex-start',
alignItems: 'center',
},
bodyText: {
width: 400,
marginBottom: 20,
},
message: {
backgroundColor: 'rgb(0,0,0)',
borderRadius: 20,
padding: 20,
},
modal: {
backgroundColor: 'rgba(0,0,0,0.9)',
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
textInput: {
width: 350,
height: 40,
padding: 5,
fontSize: 15,
fontFamily: '"Futura-Medium", sans-serif',
backgroundColor: 'white',
borderColor: 'gray',
borderWidth: 1,
marginTop: 10,
marginLeft: 5,
marginBottom: 5,
marginRight: 5,
},
textArea: {
width: 350,
height: 200,
},
checkboxes: {
alignItems: 'flex-start',
marginLeft: 5,
},
checkboxContainerStyle: {
marginTop: 10,
},
checkboxLabelStyle: {
color: '#ddd',
fontFamily: '"Futura-Medium", sans-serif',
},
keyboardAvoidingViewInner: {
alignItems: 'center',
},
lastMessage: {
marginBottom: 10,
},
comments: {
marginTop: 20,
paddingBottom: 100,
width: 400,
},
comment: {
borderWidth: 1,
borderColor: 'rgb(128,128,128)',
padding: 10,
margin: 10,
},
commentRow: {
flexDirection: 'row',
},
commentName: {
flex: 1,
fontSize: 13,
textAlign: 'left',
},
commentDate: {
flex: 1,
fontSize: 13,
textAlign: 'right',
},
commentBody: {
marginTop: 10,
fontSize: 13,
borderTopWidth: 1,
borderTopColor: 'rgb(64,64,64)',
textAlign: 'left',
},
})