From 8434c781d67958c78afa040978edf5aa7c01681b Mon Sep 17 00:00:00 2001 From: s Date: Sat, 13 Dec 2025 17:53:11 +0100 Subject: [PATCH] fix: contact form --- src/pages/contact.tsx | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/pages/contact.tsx b/src/pages/contact.tsx index 7dede26..0a2139b 100644 --- a/src/pages/contact.tsx +++ b/src/pages/contact.tsx @@ -37,10 +37,28 @@ const Contact: React.FC> = ({ data, location }) => { const [name, setName] = useState() const [email, setEmail] = useState() + const [emailError, setEmailError] = useState(false) const [subject, setSubject] = useState() const [message, setMessage] = useState() const [notification, setNotification] = useState() + const handleEmailChange = (e: React.ChangeEvent) => { + const value = e.target.value + setEmail(value) + + if ( + value && + (value.toLowerCase().includes('@gmail.com') || + value.toLowerCase().includes('@googlemail.com')) + ) { + setEmailError(true) + setNotification('Gmail addresses are not allowed.') + } else { + setEmailError(false) + setNotification(undefined) + } + } + const getBorderStyle = (value: string | undefined) => value === undefined ? {} : value ? {} : { border: '1px solid red' } @@ -66,6 +84,11 @@ const Contact: React.FC> = ({ data, location }) => { onSubmit={async (evt) => { evt.preventDefault() + // Prevent sending if emailError is set + if (emailError) { + return + } + if (name && email && subject && message) { const res = await nostrController .sendDM( @@ -121,10 +144,7 @@ Message: ${message}` name="email" rules="required|email" aria-describedby="emailHelp" - onChange={(evt) => { - setEmail(evt.target.value) - setNotification(undefined) - }} + onChange={handleEmailChange} style={getBorderStyle(email)} />