diff --git a/client/src/views/email-verification/components/SignupForm.js b/client/src/views/email-verification/components/SignupForm.js new file mode 100644 index 000000000..ab2903565 --- /dev/null +++ b/client/src/views/email-verification/components/SignupForm.js @@ -0,0 +1,127 @@ +import React, { Component } from 'react' +import PropTypes from 'prop-types' +import { withStyles } from '@material-ui/core/styles' +import withWidth from '@material-ui/core/withWidth' +import { Mutation } from 'react-apollo' + +import Typography from '@material-ui/core/Typography' +import Grid from '@material-ui/core/Grid' +import Button from '@material-ui/core/Button' +import InputBase from '@material-ui/core/InputBase' + +import styles from './styles' + +import NEWSLETTER_SIGNUP from '../graphql/NewsletterSignup' + +import { isEmpty } from '../../../utils/js-helpers' + +export class SignupForm extends Component { + constructor (props) { + super(props) + + this.handleChange = this.handleChange.bind(this) + this.handleSubmit = this.handleSubmit.bind(this) + this.validate = this.validate.bind(this) + + this.state = { + email: '', + emailError: '' + } + } + + render () { + const { classes, width } = this.props + return ( + + {(NewsletterSignup, { loading, error, data }) => { + let successMessage = false + if (data.NewsletterSignup === 'SUCESS') { + successMessage = true + } + return ( + + Stay in touch! + Opt-in our mailing list to stay up to date with the Advanced Algos Project. +
+ + Thank you for your interest! We'll keep you informed + + + + + +
+
+ ) + }} +
+ ) + } + + validate (data) { + const errors = {} + switch (data.id) { + case 'email': + if (data.value === '') { + this.setState({ emailError: 'Please enter an email address' }) + } else { + this.setState({ emailError: '' }) + } + break + default: + } + return errors + } + + handleChange (e) { + let id = e.target.id + let value = e.target.value + let error = this.validate({ id, value }) + switch (id) { + case 'email': + if (!isEmpty(error)) this.setState({ emailError: error }) + this.setState({ emaail: value }) + break + default: + } + } + + async handleSubmit (e, NewsletterSignup, email) { + e.preventDefault() + const signupResponse = await NewsletterSignup({ variables: { email } }) + console.log('NewsletterSignup: ', signupResponse) + this.setState({ email: '' }) + } +} + +SignupForm.propTypes = { + classes: PropTypes.object, + width: PropTypes.string +} + +const SignupFormWithStyles = withStyles(styles)(SignupForm) + +export default withWidth()(SignupFormWithStyles) diff --git a/client/src/views/email-verification/components/SignupVerifyResponse.js b/client/src/views/email-verification/components/SignupVerifyResponse.js new file mode 100644 index 000000000..b7eef1e6b --- /dev/null +++ b/client/src/views/email-verification/components/SignupVerifyResponse.js @@ -0,0 +1,68 @@ +import React from 'react' +import PropTypes from 'prop-types' + +import { BannerTopBar } from '../../common' +import SignupForm from './SignupForm' + +export class SignupVerifyResponse extends React.Component { + componentDidMount () { + const { mutate } = this.props + mutate() + }; + + render () { + const { loading, error, data } = this.props + let BannerTitle = '' + let BannerText = '' + let displayForm = false + console.log('SignupVerifyResponse:', loading, error, data) + if (error) { + if (error.message === 'GraphQL error: Error: Token Expired. Please resubmit email address.') { + BannerText = [ + 'Newsletter Signup Error: Verification Token Expired', +
, + 'Please try signing up again! We apologize for the inconvenience,', +
, + 'but we highly value your seurity and privacy.' + ] + } else { + BannerText = ['Newsletter Signup Error: ',
, error.message] + } + } + if (loading && !error) { + BannerText = ['Processing newsletter sign-up...',
, 'Thank you for opting-in to recieve updates about the Advanced Algos project!'] + } + if (data !== undefined && data !== null) { + console.log(data) + return ( + + + {displayForm && } + + ) + } else { + return ( + + ) + } + } +} + +SignupVerifyResponse.propTypes = { + mutate: PropTypes.string, + loading: PropTypes.bool, + error: PropTypes.object, + data: PropTypes.object +} + +export default SignupVerifyResponse diff --git a/client/src/views/email-verification/components/styles.js b/client/src/views/email-verification/components/styles.js new file mode 100644 index 000000000..5c70b4544 --- /dev/null +++ b/client/src/views/email-verification/components/styles.js @@ -0,0 +1,65 @@ +import lightGreen from '@material-ui/core/colors/lightGreen' + +const styles = theme => ({ + textLight: { + color: theme.palette.primary.light + }, + textWhite: { + color: theme.palette.common.white + }, + textSuccess: { + color: lightGreen[400] + }, + copyright: { + paddingTop: theme.spacing.unit * 3 + }, + linkLight: { + color: theme.palette.secondary.main, + textDecoration: 'none' + }, + signupRight: { + marginTop: theme.spacing.unit * 2, + [theme.breakpoints.down('xs')]: { + textAlign: 'center' + } + }, + signupContainer: { + marginBottom: theme.spacing.unit * 2, + [theme.breakpoints.down('xs')]: { + textAlign: 'center' + } + }, + signupInput: { + borderRadius: 4, + backgroundColor: theme.palette.common.white, + border: '1px solid #ced4da', + fontSize: 16, + padding: '10px 12px', + transition: theme.transitions.create(['border-color', 'box-shadow']), + marginRight: theme.spacing.unit * 1 + }, + signupInputSubmit: { + boxShadow: 'none', + textTransform: 'none', + fontSize: 16, + lineHeight: '1.1875em', + color: theme.palette.common.white, + padding: '10px 12px', + backgroundColor: '#5bc0de', + borderColor: '#46b8da', + '&:hover': { + backgroundColor: '#31b0d5', + borderColor: '#269abc' + }, + '&:active': { + boxShadow: 'none', + backgroundColor: '#0062cc', + borderColor: '#005cbf' + }, + '&:focus': { + boxShadow: '0 0 0 0.2rem rgba(0,123,255,.5)' + } + } +}) + +export default styles diff --git a/client/src/views/email-verification/graphql/NewsletterSignup.js b/client/src/views/email-verification/graphql/NewsletterSignup.js new file mode 100644 index 000000000..314b47bf3 --- /dev/null +++ b/client/src/views/email-verification/graphql/NewsletterSignup.js @@ -0,0 +1,10 @@ +/* eslint-disable no-unused-vars */ +import gql from 'graphql-tag' + +const NEWSLETTER_SIGNUP = gql` + mutation NewsletterSignup($email: String!) { + master_NewsletterSignup(email: $email) + } +` + +export default NEWSLETTER_SIGNUP diff --git a/client/src/views/email-verification/index.js b/client/src/views/email-verification/index.js index 9c4df6a77..8e38064c6 100644 --- a/client/src/views/email-verification/index.js +++ b/client/src/views/email-verification/index.js @@ -4,12 +4,12 @@ import queryString from 'query-string' import { Mutation } from 'react-apollo' import { BannerTopBar } from '../common' +import SignupVerifyResponse from './components/SignupVerifyResponse' import NEWSLETTER_SIGNUP_VERIFY from './graphql/NewsletterSignupVerify' export const EmailSignupConfirm = ({ tokenParam }) => { let token - let BannerTitle = '' let BannerText = '' if (tokenParam !== '' && tokenParam !== null) { const values = queryString.parse(tokenParam) @@ -38,33 +38,14 @@ export const EmailSignupConfirm = ({ tokenParam }) => { variables={{ token: token }} > {(NewsletterSignupVerify, { loading, error, data }) => { - console.log(loading, error, data) - if (error) { - BannerText = ['Newsletter Signup Error: ',
, JSON.stringify(error)] - } - if (loading && !error) { - BannerText = ['Processing newsletter sign-up...',
, 'Thank you for opting-in to recieve updates about the Advanced Algos project!'] - } - if (data !== undefined && data !== null) { - console.log(data) - return ( - - ) - } else { - return ( - - ) - } + return ( + + ) } }