import React, { useState, useEffect } from 'react'; import { FormattedMessage, useIntl } from 'react-intl'; import ReCAPTCHA from 'react-google-recaptcha'; import { useHistory } from 'react-router-dom'; import Client , { ErrorInfo} from '../../classes/client'; import FormContainer from '../layout/form-container'; import Header from '../layout/header'; import Footer from '../layout/footer'; import { FormControl, Typography } from '@material-ui/core'; import { useSelector } from 'react-redux'; import { useMutation } from 'react-query'; import { activeInstance } from '../../redux/clientSlice'; import Input from '../form/input'; import GlobalError from '../form/global-error'; import SubmitButton from '../form/submit-button'; export type Model = { email: string; lastname: string; firstname: string; password: string; recaptcha: string; } const defaultModel: Model = { email: '', lastname: '', firstname: '', password: '', recaptcha: '' }; const RegistrationForm = () => { const [model, setModel] = useState(defaultModel); const [error, setError] = useState(); const history = useHistory(); const intl = useIntl(); const Client: Client = useSelector(activeInstance); const mutation = useMutation( (model: Model) => Client.registerNewUser({ ...model }), { onSuccess: () => history.push("/c/registration-success"), onError: (error) => { setError(error); } } ); const handleOnSubmit = (event: React.FormEvent): void => { event.preventDefault(); mutation.mutate(model); }; const handleOnChange = (event: React.ChangeEvent): void => { event.preventDefault(); const name = event.target.name; const value = event.target.value; setModel({ ...model, [name as keyof Model]: value }); } return (
{ model.recaptcha = value; setModel(model) }} />
); } const RegistationPage = () => { useEffect(() => { document.title = 'Registration | WiseMapping'; }); return (
); } export default RegistationPage;