Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat/#151] 사용자 정보(이름, 이메일) 조회 API 연결 #155

Merged
merged 5 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion src/apis/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { BASE_URL } from '@constants';
export const instance = axios.create({
baseURL: BASE_URL,

withCredentials: false,
withCredentials: true,
});

export function get<T>(...args: Parameters<typeof instance.get>) {
Expand Down
Empty file removed src/apis/myPage/.keep
Empty file.
26 changes: 26 additions & 0 deletions src/apis/myPage/useFetchUser.ts
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

해당 api는 메인 홈 화면에서 사용자 이름 불러올 때도 사용할 수 있을 것 같아서!
메인 페이지에서 호출하는 부분도 추가해주면 더 더 좋을 것 같단 생각이 들었습니닷 ! 😍

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { useSuspenseQuery } from '@tanstack/react-query';

import { instance } from '@apis/instance';

import { END_POINT, queryKey } from '@constants';

import { ApiResponseType, UserResponse } from '@types';

const fetchUser = async (): Promise<UserResponse> => {
try {
const response = await instance.get<ApiResponseType<UserResponse>>(
END_POINT.FETCH_USER
);
return response.data.data;
} catch (error) {
console.log(error);
throw error;
}
};

export const useFetchUser = () => {
return useSuspenseQuery({
queryKey: [queryKey.USER],
queryFn: fetchUser,
});
};
1 change: 1 addition & 0 deletions src/constants/apis/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ export const END_POINT = {
FETCH_STORE_COORDINATE_LIST: (station: string) =>
`/api/v1/store/coordinate-list?station=${station}`,
KAKAO_LOGIN: '/api/v1/user/login',
FETCH_USER: '/api/v1/user',
} as const;
1 change: 1 addition & 0 deletions src/constants/apis/queryKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ export const queryKey = {
STORE_RANK: 'storeRank',
STORE_COORDINATE_LIST: 'storeCoordinateList',
KAKAO_LOGIN: 'kakaoLogin',
USER: 'user',
} as const;
17 changes: 8 additions & 9 deletions src/pages/myPage/page/Mypage/MyPage.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
import { useFetchUser } from '@apis/myPage/useFetchUser';

import { AuthModal, Modal, TextButton } from '@components';
import { WHIPEE_CONTACT_FORM } from '@constants';
import { useEasyNavigate, useModal } from '@hooks';
import { LetsGoButton, ProfileCard } from '@pages/myPage/components';
import { isLoggedIn } from '@utils';

import {
letsGoButtonWrapper,
loginButton,
profileCardStyle,
} from './MyPage.css';

const user = {
userId: 1,
userName: '쥬먐이',
userEmail: '[email protected]',
};

const MyPage = () => {
const isLogin = true; //추후 삭제 후 localStorage.getItem로 수정할 예정
const isLogin = isLoggedIn();

const { isModalOpen, openModal, closeModal } = useModal();

Expand All @@ -26,13 +23,15 @@ const MyPage = () => {
window.open(WHIPEE_CONTACT_FORM, '_blank');
};

const { data: userData } = useFetchUser();

return (
<>
<section className={profileCardStyle[isLogin ? 'login' : 'logout']}>
<ProfileCard
isLogin={isLogin}
userName={user.userName}
userEmail={user.userEmail}
userName={userData.userName}
userEmail={userData.userEmail}
/>
</section>

Expand Down
4 changes: 4 additions & 0 deletions src/types/apis/myPage/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface UserResponse {
userName: string;
userEmail: string;
}
Loading