@@ -9,6 +9,7 @@ import type { FlowToUser } from "../Models/FlujosPA";
99
1010export function usePrestamos ( ) {
1111 const { prestamos, Tickets, Logs} = useGraphServices ( )
12+ const { dispositivosById} = useDispositivos ( )
1213 const [ rows , setRows ] = React . useState < prestamos [ ] > ( [ ] ) ;
1314 const [ loading , setLoading ] = React . useState ( false ) ;
1415 const [ submitting , setSubmitting ] = React . useState ( false ) ;
@@ -20,19 +21,17 @@ export function usePrestamos() {
2021 const [ errors , setErrors ] = React . useState < prestamosErrors > ( { } ) ;
2122 const { account} = useAuth ( )
2223 const notifyFlow = new FlowClient ( "https://defaultcd48ecd97e154f4b97d9ec813ee42b.2c.environment.api.powerplatform.com:443/powerautomate/automations/direct/workflows/a21d66d127ff43d7a940369623f0b27d/triggers/manual/paths/invoke?api-version=1&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=0ptZLGTXbYtVNKdmIvLdYPhw1Wcqb869N3AOZUf2OH4" )
23-
24+
2425 const buildFilter = React . useCallback ( ( ) : GetAllOpts => {
2526 const filters : string [ ] = [ ] ;
2627
2728 if ( estado && estado !== "all" ) filters . push ( `fields/Estado eq '${ estado } '` ) ;
28- if ( search ) filters . push ( `startswith(fields/Title, '${ search } ')` ) ;
29-
3029
3130 return {
3231 filter : filters . join ( " and " ) ,
3332 orderby : "fields/Created asc" ,
3433 } ;
35- } , [ estado , search ] ) ;
34+ } , [ estado , ] ) ;
3635
3736 const validate = ( ) => {
3837 const e : prestamosErrors = { } ;
@@ -167,8 +166,29 @@ export function usePrestamos() {
167166 }
168167 }
169168
169+ const visibleRows = React . useMemo ( ( ) => {
170+ const q = search . trim ( ) . toLowerCase ( ) ;
171+ if ( ! q || q . length < 3 ) return rows ;
172+
173+ return rows . filter ( p => {
174+ const d = dispositivosById . get ( p . Id_dispositivo ) ;
175+
176+ return (
177+ p . Title ?. toLowerCase ( ) . includes ( q ) ||
178+ p . nombreSolicitante ?. toLowerCase ( ) . includes ( q ) ||
179+ ( d ?. Referencia ?? "" ) . toLowerCase ( ) . includes ( q ) ||
180+ ( d ?. Serial ?? "" ) . toLowerCase ( ) . includes ( q ) ||
181+ ( d ?. Title ) ?. toLowerCase ( ) . includes ( q )
182+ ) ;
183+ } ) ;
184+ } , [ rows , search , dispositivosById ] ) ;
185+
186+
187+ React . useEffect ( ( ) => { load ( ) ; } , [ load ] ) ;
188+
189+
170190 return {
171- rows, loading, error, load, reload, estado, setEstado, search, setSearch, handleSubmit, errors, submitting, setField, state, notify, finalizeLoan, notifyEstado
191+ visibleRows , rows, loading, error, load, reload, estado, setEstado, search, setSearch, handleSubmit, errors, submitting, setField, state, notify, finalizeLoan, notifyEstado
172192 } ;
173193}
174194
@@ -313,8 +333,17 @@ export function useDispositivos() {
313333 load ( ) ;
314334 } , [ load ] ) ;
315335
336+ React . useEffect ( ( ) => { load ( ) ; } , [ load ] ) ;
337+
338+
339+ const dispositivosById = React . useMemo ( ( ) => {
340+ const m = new Map < string , dispositivos > ( ) ;
341+ for ( const d of rows ) m . set ( d ?. Id ?? "" , d ) ;
342+ return m ;
343+ } , [ rows ] ) ;
344+
316345 return {
317- rows, loading, error, load, reload, estado, setEstado, search, setSearch, handleSubmit, errors, state, setState, submitting, setField, borrowDevice, deviceReturn, editDevice
346+ dispositivosById , rows, loading, error, load, reload, estado, setEstado, search, setSearch, handleSubmit, errors, state, setState, submitting, setField, borrowDevice, deviceReturn, editDevice
318347 } ;
319348}
320349
0 commit comments