import React, { useState } from 'react' import axios from 'axios' import { FormattedMessage, useIntl } from 'react-intl' import { ReCaptcha } from 'react-recaptcha-v3' import { useHistory } from "react-router-dom"; import Header from './Header'; import Footer from './Footer'; const css = require('../css/registration.css'); interface ErrorMessageDialogProps { message: string } const ErrorMessageDialog = (props: ErrorMessageDialogProps) => { let result; const message = props.message; if (message) { result =

{message}

} else { result = } return result; } type RegistrationBody = { email: string; firstName: string; lastName: string; password: string; recaptcha: string; } const RegistrationForm = () => { const [email, setEmail] = useState(""); const [lastName, setLastname] = useState("") const [firstname, setFirstname] = useState(""); const [password, setPassword] = useState(""); const [recaptcha, setRecaptcha] = useState(undefined); const [errorMsg, setErrorMsg] = useState(undefined); const history = useHistory(); const intl = useIntl(); const handleSubmit = async (event: React.FormEvent) => { event.preventDefault(); // @Todo: Movo to a type ... const payload = JSON.stringify( { email: email, firstName: firstname, lastName: lastName, password: password, recaptcha: recaptcha } ); await axios.post("http://localhost:8080/service/user", payload, { headers: { 'Content-Type': 'application/json' } } ).then(response => { // All was ok, let's sent to success page ... history.push("/c/user/registrationSuccess"); }).catch(error => { // Handle error ... const data = error.response; let errorMsg = intl.formatMessage({ id: "registration.unexpected", defaultMessage: "Unexpected error. Please, try latter." }) if (data != null) { let errorMsg = Object.values(data.fieldErrors)[0] as string; } setErrorMsg(errorMsg); }); } return (

handleSubmit(e)}> setEmail(e.target.value)} placeholder={intl.formatMessage({ id: "registration.email", defaultMessage: "Email" })} required={true} autoComplete="email" /> setFirstname(e.target.value)} placeholder={intl.formatMessage({ id: "registration.firstname", defaultMessage: "First Name" })} required={true} autoComplete="given-name" /> setLastname(e.target.value)} placeholder={intl.formatMessage({ id: "registration.lastname", defaultMessage: "Last Name" })} required={true} autoComplete="family-name" /> setPassword(e.target.value)} placeholder={intl.formatMessage({ id: "registration.password", defaultMessage: "Password" })} required={true} autoComplete="new-password" />

); } const RegistationFormPage = (props: any) => { return (
); } const RegistrationSuccessPage = (props: any) => { return (

); } export { RegistationFormPage, RegistrationSuccessPage };