2024-01-13 14:53:47 +00:00
|
|
|
import {FC, useState} from "react";
|
|
|
|
|
import {useLocation, useNavigate} from "react-router-dom";
|
2024-01-14 08:52:21 +00:00
|
|
|
import './VerifyMail.css';
|
2024-01-14 08:59:26 +00:00
|
|
|
import {Helmet} from "react-helmet";
|
2024-01-13 14:53:47 +00:00
|
|
|
|
|
|
|
|
interface VerificationData {
|
|
|
|
|
eMail: string;
|
|
|
|
|
code: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const VerifyMail: FC = () => {
|
|
|
|
|
const navigate = useNavigate()
|
|
|
|
|
const location = useLocation();
|
|
|
|
|
const [code, setCode] = useState('000000');
|
|
|
|
|
|
|
|
|
|
if (location.state === null || location.state.email === undefined) {
|
|
|
|
|
return (
|
|
|
|
|
<div className="container">
|
|
|
|
|
<p>Are you in the right place? It doesn't look like you have an email to verify!</p>
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
const email = location.state.email;
|
|
|
|
|
|
|
|
|
|
function setFormData(data: DynamicFormData) {
|
|
|
|
|
console.log("Setting form data")
|
|
|
|
|
navigate('/thank-you', {
|
|
|
|
|
state: {
|
|
|
|
|
formData: data
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type DynamicFormData = {
|
|
|
|
|
[key: string]: string;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const handleCodeSubmit = async () => {
|
|
|
|
|
const verificationData: VerificationData = {
|
|
|
|
|
code: code,
|
|
|
|
|
eMail: email
|
|
|
|
|
}
|
|
|
|
|
console.log(verificationData);
|
2024-08-04 22:49:33 +00:00
|
|
|
fetch('https://forms-backend.alttd.com/api/verify_email/form', {
|
2024-01-13 14:53:47 +00:00
|
|
|
method: 'POST',
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
},
|
|
|
|
|
body: JSON.stringify(verificationData)
|
|
|
|
|
})
|
|
|
|
|
.then(response => {
|
|
|
|
|
if (!response.ok) {
|
|
|
|
|
//TODO fix error and make message here?
|
2024-04-28 15:59:17 +00:00
|
|
|
console.log(response)
|
2024-01-13 14:53:47 +00:00
|
|
|
throw new Error('Invalid code');
|
|
|
|
|
}
|
|
|
|
|
//TODO check if its json if not its just text we need to handle and put in a p tag
|
|
|
|
|
return response.json()
|
|
|
|
|
})
|
|
|
|
|
.then((data: DynamicFormData) => {
|
2024-04-28 15:59:17 +00:00
|
|
|
console.log(data);
|
2024-01-13 14:53:47 +00:00
|
|
|
setFormData(data);
|
|
|
|
|
})
|
|
|
|
|
.catch(error => {
|
|
|
|
|
console.error('Received an unexpected error: ' + error);
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="container">
|
2024-01-14 08:59:26 +00:00
|
|
|
<Helmet>
|
|
|
|
|
<title>Email validation</title>
|
|
|
|
|
</Helmet>
|
2024-01-14 08:52:21 +00:00
|
|
|
<header>Email validation</header>
|
|
|
|
|
<div className="content">
|
|
|
|
|
<p>Hi, you just completed a form and need to verify your email ({email}).</p>
|
|
|
|
|
<p>Please check your email for a verification code and enter it below:</p>
|
|
|
|
|
<input
|
|
|
|
|
type="text"
|
|
|
|
|
value={code}
|
|
|
|
|
onChange={(e) => {
|
|
|
|
|
if (/^\d{0,6}$/.test(e.target.value)) {
|
|
|
|
|
setCode(e.target.value);
|
|
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
pattern="\d{6}"
|
|
|
|
|
maxLength={6}
|
|
|
|
|
className="verification-code-input"
|
|
|
|
|
/>
|
|
|
|
|
<button onClick={handleCodeSubmit} className="submit-button">Submit Code</button>
|
|
|
|
|
</div>
|
2024-01-13 14:53:47 +00:00
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default VerifyMail
|