[VDU-6] feat(implementação): implementando endpoint para buscar usuario por ID
This commit is contained in:
parent
e33bb452cf
commit
ef8c499f37
1 changed files with 27 additions and 0 deletions
|
|
@ -0,0 +1,27 @@
|
||||||
|
'use client';
|
||||||
|
|
||||||
|
import { useState } from 'react';
|
||||||
|
import { UserInterface } from '../../interfaces/User/UserInterface';
|
||||||
|
import { UserIndexByIDService } from '../../services/User/UserIndexByIDService';
|
||||||
|
import { useResponse } from '@/shared/components/response/ResponseContext';
|
||||||
|
|
||||||
|
export const useUserIndexByIdHook = () => {
|
||||||
|
const { setResponse } = useResponse();
|
||||||
|
|
||||||
|
const [user, setUser] = useState<UserInterface | null>(null);
|
||||||
|
|
||||||
|
const fetchUserById = async (userId: number) => {
|
||||||
|
try {
|
||||||
|
const response = await UserIndexByIDService(userId);
|
||||||
|
|
||||||
|
setUser(response.data);
|
||||||
|
setResponse(response);
|
||||||
|
} catch (error) {
|
||||||
|
// O withClientErrorHandler já deve tratar o erro e formatar a 'response',
|
||||||
|
// mas um catch local pode ser útil para lógicas adicionais se necessário.
|
||||||
|
console.error("Erro ao buscar usuário por ID:", error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return { user, fetchUserById };
|
||||||
|
};
|
||||||
Loading…
Add table
Reference in a new issue