fix: contact form
This commit is contained in:
@@ -37,10 +37,28 @@ const Contact: React.FC<PageProps<DataProps>> = ({ data, location }) => {
|
|||||||
|
|
||||||
const [name, setName] = useState<string>()
|
const [name, setName] = useState<string>()
|
||||||
const [email, setEmail] = useState<string>()
|
const [email, setEmail] = useState<string>()
|
||||||
|
const [emailError, setEmailError] = useState<boolean>(false)
|
||||||
const [subject, setSubject] = useState<string>()
|
const [subject, setSubject] = useState<string>()
|
||||||
const [message, setMessage] = useState<string>()
|
const [message, setMessage] = useState<string>()
|
||||||
const [notification, setNotification] = 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) =>
|
const getBorderStyle = (value: string | undefined) =>
|
||||||
value === undefined ? {} : value ? {} : { border: '1px solid red' }
|
value === undefined ? {} : value ? {} : { border: '1px solid red' }
|
||||||
|
|
||||||
@@ -66,6 +84,11 @@ const Contact: React.FC<PageProps<DataProps>> = ({ data, location }) => {
|
|||||||
onSubmit={async (evt) => {
|
onSubmit={async (evt) => {
|
||||||
evt.preventDefault()
|
evt.preventDefault()
|
||||||
|
|
||||||
|
// Prevent sending if emailError is set
|
||||||
|
if (emailError) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if (name && email && subject && message) {
|
if (name && email && subject && message) {
|
||||||
const res = await nostrController
|
const res = await nostrController
|
||||||
.sendDM(
|
.sendDM(
|
||||||
@@ -121,10 +144,7 @@ Message: ${message}`
|
|||||||
name="email"
|
name="email"
|
||||||
rules="required|email"
|
rules="required|email"
|
||||||
aria-describedby="emailHelp"
|
aria-describedby="emailHelp"
|
||||||
onChange={(evt) => {
|
onChange={handleEmailChange}
|
||||||
setEmail(evt.target.value)
|
|
||||||
setNotification(undefined)
|
|
||||||
}}
|
|
||||||
style={getBorderStyle(email)}
|
style={getBorderStyle(email)}
|
||||||
/>
|
/>
|
||||||
<div id="emailHelp" className="form-text">
|
<div id="emailHelp" className="form-text">
|
||||||
|
|||||||
Reference in New Issue
Block a user