import React, { Fragment } from 'react'; import PropTypes from 'prop-types'; import Grid from '@material-ui/core/Grid'; import emailjs from '../../utilities/emailjs.js' import { withStyles } from '@material-ui/core/styles'; import TextField from '@material-ui/core/TextField'; import CheckCircleIcon from '@material-ui/icons/CheckCircle'; import Snackbar from '@material-ui/core/Snackbar'; import IconButton from '@material-ui/core/IconButton'; import CloseIcon from '@material-ui/icons/Close'; import Button from '@material-ui/core/Button'; import { Typography } from '@material-ui/core'; /** * Styles that the different * Material UI components pull * in. Mostly used for spacing. */ const styles = theme => ({ container: { display: 'flex', flexWrap: 'wrap' }, textField: { marginLeft: theme.spacing.unit, marginRight: theme.spacing.unit, marginTop: theme.spacing.unit, flexBasis: 280, width: '90%' }, button: { marginLeft: theme.spacing.unit, marginRight: theme.spacing.unit, marginTop: theme.spacing.unit, }, close: { padding: theme.spacing.unit / 2, }, icon: { fontSize: 20, marginRight: theme.spacing.unit, }, message: { display: 'flex', alignItems: 'center', }, menu: { width: 200, }, paper: { position: 'absolute', width: theme.spacing.unit * 50, backgroundColor: theme.palette.background.paper, boxShadow: theme.shadows[5], padding: theme.spacing.unit * 4, } }); /** * The form component. */ class ContactForm extends React.Component { /** * State of form components. */ state = { name: "", email: "", comments: "", open: false }; /** * Handles state change in form * components. */ handleChange = name => event => { this.setState({ [name]: event.target.value, }); }; /** * Handles closing the toast. */ handleClose = (event, reason) => { if (reason === 'clickaway') { return; } this.setState({ open: false }); }; /** * Event listener for form. * When the form is submitted, * this function passes the * data along to EmailJS. */ handleSubmit = e => { e.preventDefault(); const templateParams = { from_name: this.state.name, from_email: this.state.email, message_html: this.state.comments }; emailjs.send('default_service', 'template_XaKOJGSf', templateParams); this.setState({ name: "", email: "", comments: "", open: true }); }; /** * The render method for this component. */ render() { const { classes } = this.props; /** * The actual form. */ return ( {
} Send us an email!
Message sent.} action={[ , ]} />
); } } ContactForm.propTypes = { classes: PropTypes.object.isRequired, }; export default withStyles(styles)(ContactForm);