import React from 'react'; import { Helmet } from 'react-helmet'; import brand from 'ba-api/brand'; import PropTypes from 'prop-types'; import { withStyles } from '@material-ui/core/styles'; import { bindActionCreators } from 'redux'; import { connect } from 'react-redux'; import data from 'ba-api/emailData'; import { EmailHeader, EmailList, EmailSidebar, ComposeEmail, Notification } from 'ba-components'; import { fetchMailAction, openMailAction, filterAction, composeAction, discardAction, searchAction, sendAction, moveAction, deleteAction, toggleStaredAction, closeNotifAction } from 'ba-actions/EmailActions'; const styles = theme => ({ root: { flexGrow: 1, minHeight: 600, zIndex: 1, background: theme.palette.grey[50], overflow: 'hidden', display: 'flex', boxShadow: theme.shadows[2] } }); // validation functions const email = value => ( value && !/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i.test(value) ? 'Invalid email' : '' ); class Email extends React.Component { state = { to: '', subject: '', validMail: '', mobileOpen: false, }; componentDidMount() { this.props.fetchData(data); } handleChange = (event, name) => { if (name === 'to') { this.setState({ validMail: email(event.target.value) }); } this.setState({ [name]: event.target.value, }); }; handleReply = (mail) => { this.props.compose(); this.setState({ to: mail.get('name'), subject: 'Reply: ' + mail.get('subject'), }); } handleCompose = () => { this.props.compose(); this.setState({ to: ' ', subject: ' ', }); } handleDrawerToggle = () => { this.setState(state => ({ mobileOpen: !state.mobileOpen })); }; render() { const { classes, emailData, openMail, goto, currentPage, openFrm, discard, search, keyword, sendEmail, moveTo, remove, toggleStar, closeNotif, messageNotif } = this.props; const { to, subject, validMail, mobileOpen } = this.state; const title = brand.name + ' - Email'; const description = brand.desc; return (