small aditions
This commit is contained in:
parent
e50b99641c
commit
f9073af330
13
src/api/users.ts
Normal file
13
src/api/users.ts
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import axiosInstance from "./axiosInstance";
|
||||||
|
|
||||||
|
export const getAllUsers = async (page: number) => {
|
||||||
|
const res = await axiosInstance.get("/api/users", {
|
||||||
|
params: { page },
|
||||||
|
});
|
||||||
|
return res.data;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getUserById = async (id: number) => {
|
||||||
|
const res = await axiosInstance.get(`api/users/${id}`);
|
||||||
|
return res.data;
|
||||||
|
};
|
||||||
@ -9,6 +9,7 @@ export const useLogin = () => {
|
|||||||
|
|
||||||
onSuccess: (data) => {
|
onSuccess: (data) => {
|
||||||
localStorage.setItem("access_token", data.token);
|
localStorage.setItem("access_token", data.token);
|
||||||
|
toast.success("Logged In!");
|
||||||
},
|
},
|
||||||
|
|
||||||
onError: (err: any) => {
|
onError: (err: any) => {
|
||||||
|
|||||||
0
src/hooks/users/useUserById.ts
Normal file
0
src/hooks/users/useUserById.ts
Normal file
8
src/hooks/users/useUsers.ts
Normal file
8
src/hooks/users/useUsers.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import { useQuery } from "@tanstack/react-query";
|
||||||
|
import { getAllUsers } from "../../api/users";
|
||||||
|
|
||||||
|
export const useUsers = (page: number) =>
|
||||||
|
useQuery({
|
||||||
|
queryKey: ["users"],
|
||||||
|
queryFn: () => getAllUsers(page),
|
||||||
|
});
|
||||||
@ -16,6 +16,7 @@ const ProfilePage = () => {
|
|||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Container>
|
<Container>
|
||||||
<Box sx={{ padding: 4, maxWidth: 360 }}>
|
<Box sx={{ padding: 4, maxWidth: 360 }}>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user