Desktop register: validate email format client-side and disable submit to avoid 400
This commit is contained in:
parent
2c7c22d70b
commit
2a8fb4330c
1 changed files with 11 additions and 1 deletions
|
|
@ -207,6 +207,8 @@ function App() {
|
|||
const autoLaunchRef = useRef(false)
|
||||
const autoUpdateRef = useRef(false)
|
||||
const logoFallbackRef = useRef(false)
|
||||
const emailRegex = useRef(/^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/i)
|
||||
const isEmailValid = useMemo(() => emailRegex.current.test(collabEmail.trim()), [collabEmail])
|
||||
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
|
|
@ -449,6 +451,10 @@ function App() {
|
|||
setError("Informe o e-mail do colaborador vinculado a esta máquina.")
|
||||
return
|
||||
}
|
||||
if (!emailRegex.current.test(normalizedEmail)) {
|
||||
setError("Informe um e-mail válido (ex.: nome@empresa.com)")
|
||||
return
|
||||
}
|
||||
const normalizedName = collabName.trim()
|
||||
if (!normalizedName) {
|
||||
setError("Informe o nome completo do colaborador.")
|
||||
|
|
@ -837,10 +843,14 @@ function App() {
|
|||
</label>
|
||||
<input
|
||||
className="w-full rounded-lg border border-slate-300 px-3 py-2 text-sm"
|
||||
type="email"
|
||||
placeholder="colaborador@empresa.com"
|
||||
value={collabEmail}
|
||||
onChange={(e) => setCollabEmail(e.target.value)}
|
||||
/>
|
||||
{collabEmail && !isEmailValid ? (
|
||||
<p className="text-xs text-rose-600">Informe um e-mail válido (ex.: nome@empresa.com)</p>
|
||||
) : null}
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<label className="text-sm font-medium">
|
||||
|
|
@ -874,7 +884,7 @@ function App() {
|
|||
</div>
|
||||
) : null}
|
||||
<div className="mt-2 flex gap-2">
|
||||
<button disabled={busy || !validatedCompany} onClick={register} className="rounded-lg border border-black bg-black px-3 py-2 text-sm font-semibold text-white hover:bg-black/90 disabled:opacity-60">Registrar máquina</button>
|
||||
<button disabled={busy || !validatedCompany || !isEmailValid || !collabName.trim() || provisioningCode.trim().length < 32} onClick={register} className="rounded-lg border border-black bg-black px-3 py-2 text-sm font-semibold text-white hover:bg-black/90 disabled:opacity-60">Registrar máquina</button>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue