fix: contact form

This commit is contained in:
s
2025-12-13 17:53:11 +01:00
parent 6537e3aee1
commit 8434c781d6

View File

@@ -37,10 +37,28 @@ const Contact: React.FC<PageProps<DataProps>> = ({ data, location }) => {
const [name, setName] = useState<string>()
const [email, setEmail] = useState<string>()
const [emailError, setEmailError] = useState<boolean>(false)
const [subject, setSubject] = useState<string>()
const [message, setMessage] = useState<string>()
const [notification, setNotification] = useState<string>()
const handleEmailChange = (e: React.ChangeEvent<HTMLInputElement>) => {
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<PageProps<DataProps>> = ({ 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)}
/>
<div id="emailHelp" className="form-text">