import { Button, Input, Typography } from 'antd'; import signup from 'api/user/signup'; import ROUTES from 'constants/routes'; import history from 'lib/history'; import React, { useState } from 'react'; import { connect } from 'react-redux'; import { bindActionCreators } from 'redux'; import { ThunkDispatch } from 'redux-thunk'; import { GlobalTimeLoading, UserLoggedIn } from 'store/actions'; import AppActions from 'types/actions'; import { ButtonContainer, Container, FormWrapper, LogoImageContainer, Title, } from './styles'; const Signup = ({ globalLoading, loggedIn }: SignupProps): JSX.Element => { const [state, setState] = useState({ submitted: false }); const [formState, setFormState] = useState({ firstName: { value: '' }, companyName: { value: '' }, email: { value: '' }, password: { value: '', valid: true }, emailOptIn: { value: true }, }); const updateForm = ( name: string, target: EventTarget & HTMLInputElement, ): void => { if (name === 'firstName') { setFormState({ ...formState, firstName: { ...formState.firstName, value: target.value }, }); } else if (name === 'email') { setFormState({ ...formState, email: { ...formState.email, value: target.value }, }); } }; const handleSubmit = (e: React.FormEvent): void => { (async (): Promise => { try { e.preventDefault(); setState((state) => ({ ...state, submitted: true })); const payload = { first_name: formState.firstName, email: formState.email, }; const response = await signup({ email: JSON.stringify(payload), }); if (response.statusCode === 200) { loggedIn(); globalLoading(); history.push(ROUTES.APPLICATION); } else { // @TODO throw a error notification here } } catch (error) { console.error(error); // @TODO throw a error notification here } })(); }; return (
Create your account Monitor your applications. Find what is causing issues.
updateForm('email', e.target)} required id="signupEmail" />
updateForm('firstName', e.target)} required id="signupFirstName" />
); }; interface DispatchProps { globalLoading: () => void; loggedIn: () => void; } const mapDispatchToProps = ( dispatch: ThunkDispatch, ): DispatchProps => ({ globalLoading: bindActionCreators(GlobalTimeLoading, dispatch), loggedIn: bindActionCreators(UserLoggedIn, dispatch), }); type SignupProps = DispatchProps; export default connect(null, mapDispatchToProps)(Signup);