diff --git a/hooks/agenda/useFetchGet.ts b/hooks/agenda/useFetchGet.ts index e2f9a0517..9e8e13f9c 100644 --- a/hooks/agenda/useFetchGet.ts +++ b/hooks/agenda/useFetchGet.ts @@ -30,7 +30,7 @@ const useFetchGet = ({ url, isReady = true, params }: FetchGetProps) => { }, [url, isReady, params]); useEffect(() => { - if (url) { + if (url && isReady) { getData(); // 조건에 맞을 때만 getData 호출 } }, [url, isReady, JSON.stringify(params)]); diff --git a/hooks/useAxiosAgendaError.ts b/hooks/useAxiosAgendaError.ts index db5216a79..a2f21aabf 100644 --- a/hooks/useAxiosAgendaError.ts +++ b/hooks/useAxiosAgendaError.ts @@ -2,7 +2,7 @@ import { AxiosError, AxiosResponse } from 'axios'; import Cookies from 'js-cookie'; import { useEffect, useState } from 'react'; import { useSetRecoilState } from 'recoil'; -import { instanceInAgenda } from 'utils/axios'; +import { instanceInAgenda, instance } from 'utils/axios'; import { agendaErrorState } from 'utils/recoil/agendaError'; import { loginState } from 'utils/recoil/login'; @@ -17,7 +17,7 @@ export default function useAxiosAgendaError() { return; } try { - const res = await instanceInAgenda.post( + const res = await instance.post( `/pingpong/users/accesstoken?refreshToken=${refreshToken}` ); localStorage.setItem('42gg-token', res.data.accessToken); @@ -42,7 +42,7 @@ export default function useAxiosAgendaError() { if (!isRecalling) { setIsRecalling(true); try { - const res = await instanceInAgenda.post( + const res = await instance.post( `/pingpong/users/accesstoken?refreshToken=${refreshToken}` ); localStorage.setItem('42gg-token', res.data.accessToken); diff --git a/pages/agenda/profile/user.tsx b/pages/agenda/profile/user.tsx index 6ce58592f..c2fe22cdd 100644 --- a/pages/agenda/profile/user.tsx +++ b/pages/agenda/profile/user.tsx @@ -26,8 +26,6 @@ const AgendaProfile = () => { const [isIntraId, setIsIntraId] = useState(false); // 인트라 아이디가 42에 있는지 확인 const [isAgendaId, setIsAgendaId] = useState(false); // 인트라 아이디가 agenda에 있는지 확인 const [activeTab, setActiveTab] = useState('current'); // 현재 활성화된 탭 상태 관리 - const [agendaProfileData, setAgendaProfileData] = - useState(null); // agendaProfileData 상태 추가 /** API GET */ // GET: intraData (42 인트라 데이터 가져오기) @@ -36,7 +34,7 @@ const AgendaProfile = () => { isReady: Boolean(queryIntraId), }); // GET: agendaProfileData (GG 아젠다 유저 데이터 가져오기) - const { data: fetchedAgendaProfileData, getData: getAgendaProfileData } = + const { data: agendaProfileData, getData: getAgendaProfileData } = useFetchGet({ url: `/profile/${queryIntraId}`, isReady: isIntraId, @@ -80,20 +78,13 @@ const AgendaProfile = () => { // 2. intraData가 있으면 인트라 아이디가 42에 있다는 뜻이므로 isIntraId = true setIsIntraId(!!intraData); // 3. agendaProfileData가 있으면 아젠다에 등록된 사용자이므로 isAgendaId = true - setIsAgendaId(!!fetchedAgendaProfileData); - if (isAgendaId) { - setAgendaProfileData(fetchedAgendaProfileData); - } else { - setAgendaProfileData(null); // fetchedAgendaProfileData가 없을 때 초기화 - } + setIsAgendaId(!!agendaProfileData); }; - updateProfileStatus(); - }, [queryIntraId, intraData, fetchedAgendaProfileData]); - useEffect(() => { setIsIntraId(false); setIsAgendaId(false); - }, [queryIntraId]); + updateProfileStatus(); + }, [queryIntraId, intraData, agendaProfileData]); /** UI Rendering */ if (!queryIntraId || !myIntraId) {