diff --git a/src/api/users/useGetUsersMe.ts b/src/api/users/useGetUsersMe.ts new file mode 100644 index 00000000..b6940fd0 --- /dev/null +++ b/src/api/users/useGetUsersMe.ts @@ -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(); + + const { request } = useApi("get", "users/me"); + + const refineResponse = (response: any) => { + const user = response.data; + setUserInfo(user); + }; + + useEffect(() => request(refineResponse), []); + + return { userInfo }; +}; diff --git a/src/component/mypage/MyRentInfo/MyRent.tsx b/src/component/mypage/MyRentInfo/MyRent.tsx index 0cce2589..bd3960a9 100644 --- a/src/component/mypage/MyRentInfo/MyRent.tsx +++ b/src/component/mypage/MyRentInfo/MyRent.tsx @@ -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"; @@ -8,7 +8,7 @@ import { userIdAtom } from "~/atom/userAtom" const MyRent = () => { const userId = useRecoilValue(userIdAtom); - const { userInfo } = useGetUsersSearchId({ userId }); + const { userInfo } = useGetUsersMe(); return ( <> diff --git a/src/component/mypage/MyReservation.tsx b/src/component/mypage/MyReservation.tsx index 31d488f0..737a669c 100644 --- a/src/component/mypage/MyReservation.tsx +++ b/src/component/mypage/MyReservation.tsx @@ -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"; @@ -7,7 +7,7 @@ import { userIdAtom } from "~/atom/userAtom" const MyReservation = () => { const userId = useRecoilValue(userIdAtom); - const { userInfo } = useGetUsersSearchId({ userId }); + const { userInfo } = useGetUsersMe(); return ( <> diff --git a/src/component/mypage/Mypage.tsx b/src/component/mypage/Mypage.tsx index ee778265..6c12d4c3 100644 --- a/src/component/mypage/Mypage.tsx +++ b/src/component/mypage/Mypage.tsx @@ -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"; @@ -26,7 +26,7 @@ const Mypage = () => { myReview: , }; const userId = useRecoilValue(userIdAtom); - const { userInfo } = useGetUsersSearchId({ userId }); + const { userInfo } = useGetUsersMe(); const [deviceMode, setDeviceMode] = useState("desktop"); const convertRoleToStr = (roleInt: number) => {