Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/api/users/useGetUsersMe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { useEffect, useState } from "react";
import { useApi } from "../../hook/useApi";
import { User } from "../../type";

export const useGetUsersMe = () => {
const [userInfo, setUserInfo] = useState<User>();

const { request } = useApi("get", "users/me");

const refineResponse = (response: any) => {
const user = response.data;
setUserInfo(user);
};

useEffect(() => request(refineResponse), []);

return { userInfo };
};
4 changes: 2 additions & 2 deletions src/component/mypage/MyRentInfo/MyRent.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useGetUsersSearchId } from "~/api/users/useGetUsersSearchId";
import { useGetUsersMe } from "~/api/users/useGetUsersMe";
import RentHistory from "./RentHistory";
import RentedOrReservedBooks from "./RentedOrReservedBooks";
import InquireBoxTitle from "~/component/utils/InquireBoxTitle";
Expand All @@ -8,7 +8,7 @@ import { userIdAtom } from "~/atom/userAtom"

const MyRent = () => {
const userId = useRecoilValue(userIdAtom);
const { userInfo } = useGetUsersSearchId({ userId });
const { userInfo } = useGetUsersMe();

return (
<>
Expand Down
4 changes: 2 additions & 2 deletions src/component/mypage/MyReservation.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useGetUsersSearchId } from "~/api/users/useGetUsersSearchId";
import { useGetUsersMe } from "~/api/users/useGetUsersMe";
import RentedOrReservedBooks from "./MyRentInfo/RentedOrReservedBooks";
import InquireBoxTitle from "~/component/utils/InquireBoxTitle";
import Reserve from "~/asset/img/list-check-solid.svg";
Expand All @@ -7,7 +7,7 @@ import { userIdAtom } from "~/atom/userAtom"

const MyReservation = () => {
const userId = useRecoilValue(userIdAtom);
const { userInfo } = useGetUsersSearchId({ userId });
const { userInfo } = useGetUsersMe();

return (
<>
Expand Down
4 changes: 2 additions & 2 deletions src/component/mypage/Mypage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Link, useSearchParams } from "react-router-dom";
import { myPageTabList } from "../../constant/tablist";
import { useTabFocus } from "../../hook/useTabFocus";
import { useNewDialog } from "../../hook/useNewDialog";
import { useGetUsersSearchId } from "../../api/users/useGetUsersSearchId";
import { useGetUsersMe } from "../../api/users/useGetUsersMe";
import { lendingRestriction } from "../../util/date";
import MyRent from "./MyRentInfo/MyRent";
import MyReservation from "./MyReservation";
Expand All @@ -26,7 +26,7 @@ const Mypage = () => {
myReview: <MyReview />,
};
const userId = useRecoilValue(userIdAtom);
const { userInfo } = useGetUsersSearchId({ userId });
const { userInfo } = useGetUsersMe();
const [deviceMode, setDeviceMode] = useState("desktop");

const convertRoleToStr = (roleInt: number) => {
Expand Down