From ebc4c303e43c5be020f15ddcf5f5d4ae5cfed25e Mon Sep 17 00:00:00 2001 From: enlineawork Date: Mon, 7 Sep 2026 14:15:23 -0300 Subject: [PATCH] F3.1 WEB: ampliar alta de usuarios e Inspector --- web-v2/src/pages/NewUserPage.tsx | 48 +++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 7 deletions(-) diff --git a/web-v2/src/pages/NewUserPage.tsx b/web-v2/src/pages/NewUserPage.tsx index 1ee775f..69a918a 100644 --- a/web-v2/src/pages/NewUserPage.tsx +++ b/web-v2/src/pages/NewUserPage.tsx @@ -1,10 +1,11 @@ -import { useEffect, useState } from 'react'; +import { useEffect, useMemo, useState } from 'react'; import type { FormEvent } from 'react'; import { Link, useNavigate } from 'react-router'; import { Alert, LoadingBlock, errorMessage } from '../components/Feedback'; import { Icon } from '../components/Icon'; -import { createUser, listRoles } from '../lib/api'; +import { listRoles } from '../lib/api'; import type { AdministrativeRole } from '../lib/api'; +import { createUserProfile } from '../lib/userProfileApi'; export function NewUserPage() { const navigate = useNavigate(); @@ -18,17 +19,30 @@ export function NewUserPage() { listRoles().then(setRoles).catch((requestError) => setError(errorMessage(requestError))).finally(() => setLoading(false)); }, []); + const inspectorSelected = useMemo( + () => roles.some((role) => role.code === 'inspector' && roleIds.includes(role.id)), + [roles, roleIds], + ); const toggleRole = (id: string) => setRoleIds((current) => current.includes(id) ? current.filter((value) => value !== id) : [...current, id]); const submit = async (event: FormEvent) => { event.preventDefault(); setError(''); - setSubmitting(true); const data = new FormData(event.currentTarget); + const email = String(data.get('email') ?? '').trim(); + if (inspectorSelected && !email) { + setError('El email es obligatorio para usuarios con rol Inspector porque allí recibirán la documentación de sus inspecciones.'); + return; + } + setSubmitting(true); try { - const created = await createUser({ + const created = await createUserProfile({ username: String(data.get('username')), - email: String(data.get('email') ?? '') || undefined, + email: email || null, + dni: String(data.get('dni') ?? '').trim() || null, + phone: String(data.get('phone') ?? '').trim() || null, + jobTitle: String(data.get('jobTitle') ?? '').trim() || null, + employeeNumber: String(data.get('employeeNumber') ?? '').trim() || null, firstName: String(data.get('firstName')), lastName: String(data.get('lastName')), password: String(data.get('password')), @@ -45,10 +59,30 @@ export function NewUserPage() { return
Usuarios/Nuevo usuario
-
NUEVO ACCESO

Crear usuario

La contraseña inicial puede obligarse a cambiar en el primer ingreso.

+
NUEVO ACCESO

Crear usuario

Además del acceso, registrá los datos personales que identifican al agente y permiten las comunicaciones oficiales.

{error && {error}} {loading ? :
-

Datos personales

+
+

Datos personales

Nombre y apellido identifican al agente. DNI, contacto y función quedan asociados a su historial operativo.

+
+ + + + + + +
+
+ +
+

Acceso y contacto

El email del Inspector se utiliza también como destinatario de la documentación al cerrar la inspección.

+
+ + +
+ {inspectorSelected &&

Inspector: este email recibirá copia de las Actas/Informe correspondientes al cierre de la inspección.

} +
+

Seguridad

Roles

{roles.map((role) => )}
Cancelar