From bfb7eed608d64ec62447fd1be57c1b2f4d7cc94a Mon Sep 17 00:00:00 2001 From: enlineawork Date: Thu, 10 Sep 2026 20:16:21 -0300 Subject: [PATCH 01/10] fix: use authenticated CSRF-aware request for inspection planning --- .../pages/InspectionVisitCreateF61Page.tsx | 35 ++++--------------- 1 file changed, 7 insertions(+), 28 deletions(-) diff --git a/web-v2/src/pages/InspectionVisitCreateF61Page.tsx b/web-v2/src/pages/InspectionVisitCreateF61Page.tsx index 0a2daa7..a3854f1 100644 --- a/web-v2/src/pages/InspectionVisitCreateF61Page.tsx +++ b/web-v2/src/pages/InspectionVisitCreateF61Page.tsx @@ -4,6 +4,7 @@ import { Link, useNavigate } from 'react-router'; import { Alert, LoadingBlock } from '../components/Feedback'; import { Icon } from '../components/Icon'; import { SearchableSelect } from '../components/SearchableSelect'; +import { apiRequest } from '../lib/api'; interface Option { id: string; @@ -23,28 +24,6 @@ interface CreatedInspection { code: string; } -async function requestJson(url: string, init?: RequestInit): Promise { - const response = await fetch(`/api/v3${url}`, { - credentials: 'same-origin', - ...init, - headers: { - Accept: 'application/json', - ...(init?.body ? { 'Content-Type': 'application/json' } : {}), - ...(init?.headers ?? {}), - }, - }); - const payload = await response.json().catch(() => ({})); - if (!response.ok) { - const message = typeof payload?.message === 'string' - ? payload.message - : typeof payload?.error?.message === 'string' - ? payload.error.message - : `No se pudo completar la operación (${response.status}).`; - throw new Error(message); - } - return payload as T; -} - function inspectorName(person: Inspector): string { return `${person.firstName} ${person.lastName}`.trim() || person.username; } @@ -76,8 +55,8 @@ export function InspectionVisitCreateF61Page() { useEffect(() => { setLoading(true); Promise.all([ - requestJson<{ data: Option[] }>('/inspection-visits/planning-context/departments'), - requestJson<{ data: Inspector[] }>('/inspection-visits/assignees'), + apiRequest<{ data: Option[] }>('/inspection-visits/planning-context/departments'), + apiRequest<{ data: Inspector[] }>('/inspection-visits/assignees'), ]).then(([departmentResponse, inspectorResponse]) => { setDepartments(departmentResponse.data); setInspectors(inspectorResponse.data); @@ -94,7 +73,7 @@ export function InspectionVisitCreateF61Page() { setYacimientos([]); setOperators([]); if (!departmentId) return; - requestJson<{ data: Option[] }>(`/inspection-visits/planning-context/departments/${departmentId}/areas`) + apiRequest<{ data: Option[] }>(`/inspection-visits/planning-context/departments/${departmentId}/areas`) .then((response) => setAreas(response.data)) .catch((cause) => setError(cause instanceof Error ? cause.message : String(cause))); }, [departmentId]); @@ -105,7 +84,7 @@ export function InspectionVisitCreateF61Page() { setYacimientos([]); setOperators([]); if (!areaId) return; - requestJson<{ data: Option[] }>(`/inspection-visits/planning-context/areas/${areaId}/yacimientos`) + apiRequest<{ data: Option[] }>(`/inspection-visits/planning-context/areas/${areaId}/yacimientos`) .then((response) => setYacimientos(response.data)) .catch((cause) => setError(cause instanceof Error ? cause.message : String(cause))); }, [areaId]); @@ -118,7 +97,7 @@ export function InspectionVisitCreateF61Page() { if (Number.isNaN(parsedStart.getTime())) return; const at = encodeURIComponent(parsedStart.toISOString()); setLoadingOperators(true); - requestJson<{ data: Option[] }>(`/inspection-visits/planning-context/areas/${areaId}/operators?at=${at}`) + apiRequest<{ data: Option[] }>(`/inspection-visits/planning-context/areas/${areaId}/operators?at=${at}`) .then((response) => { setOperators(response.data); if (response.data.length === 1 && response.data[0]) setOperatorId(response.data[0].id); @@ -142,7 +121,7 @@ export function InspectionVisitCreateF61Page() { setBusy(true); try { - const created = await requestJson('/inspection-visits', { + const created = await apiRequest('/inspection-visits', { method: 'POST', body: JSON.stringify({ operationalAreaId: areaId, From a407bf46c5a77bacc3f4c703bad8e37ca52a71b1 Mon Sep 17 00:00:00 2001 From: enlineawork Date: Thu, 10 Sep 2026 20:16:40 -0300 Subject: [PATCH 02/10] ux: remove duplicated global operational context bar --- web-v2/src/layout/AppLayout.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/web-v2/src/layout/AppLayout.tsx b/web-v2/src/layout/AppLayout.tsx index 120150e..898e860 100644 --- a/web-v2/src/layout/AppLayout.tsx +++ b/web-v2/src/layout/AppLayout.tsx @@ -3,7 +3,6 @@ import { NavLink, Outlet, useNavigate } from 'react-router'; import { useAuth } from '../auth/AuthContext'; import { APP_PHASE, APP_VERSION } from '../config/version'; import { Icon } from '../components/Icon'; -import { OperationalContextBar } from '../components/OperationalContextBar'; import type { IconName } from '../components/Icon'; interface NavItem { @@ -118,7 +117,6 @@ export function AppLayout() { DH Inspección v{APP_VERSION} -