/* This is the form component to register an email adress to your mailing list. This is just the frontend, and the email will be send to our backend API (/api/mailingList) */ import Image from "next/image"; import Mailing from "public/landing/mailing.svg"; import axios from "axios"; import { toast } from "react-toastify"; import { useState } from "react"; const MailingList = () => { const [mail, setMail] = useState(null); const [loading, setLoading] = useState(false); const [valid, setValid] = useState(true); const validateEmail = () => { // Regex patern for email validation let regex = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; if (regex.test(mail)) { // this is a valid email address subscribe(); setValid(true); } else { // invalid email. toast.error("Your email is invalid"); setValid(false); } }; const subscribe = () => { setLoading(true); axios .put("api/mailingList", { mail, }) .then((result) => { if (result.status === 200) { toast.success(result.data.message); setLoading(false); } }) .catch((err) => { console.log(err); setLoading(false); }); }; return (

Stay Tuned

{ setMail(e.target.value); }} type='email' placeholder='Your email' className={`input input-primary input-bordered ${ valid ? null : "input-error" }`}>
); }; export default MailingList;