From 2a8fb4330c128007c20207dbdc57d67258cbe0c1 Mon Sep 17 00:00:00 2001 From: Esdras Renan Date: Sun, 19 Oct 2025 02:25:12 -0300 Subject: [PATCH] Desktop register: validate email format client-side and disable submit to avoid 400 --- apps/desktop/src/main.tsx | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/apps/desktop/src/main.tsx b/apps/desktop/src/main.tsx index a4311e5..398fa4f 100644 --- a/apps/desktop/src/main.tsx +++ b/apps/desktop/src/main.tsx @@ -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() { setCollabEmail(e.target.value)} /> + {collabEmail && !isEmailValid ? ( +

Informe um e-mail válido (ex.: nome@empresa.com)

+ ) : null}
) : null}
- +
) : (