Skip to content

Commit

Permalink
Feat: fetchSettingUserInfo msw 연동
Browse files Browse the repository at this point in the history
  • Loading branch information
minseong0324 committed Mar 20, 2024
1 parent affcee9 commit ab9e61a
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/apis/settingUserInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ import { instance } from './axios';

export const fetchSettingUserInfo = async () => {
const response = await instance.get(`/users`);
return response.data.data;
console.log(response.data)
return response.data;
};
2 changes: 1 addition & 1 deletion src/hooks/useFetchSettingUserInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ export const useFetchSettingUserInfo = () => {
staleTime: 600000, // 10분
gcTime: 300000, // 5분
});
return data;
return { data };
}
8 changes: 8 additions & 0 deletions src/mocks/apis/getSettingUserInfo/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"success": true,
"data": {
"nickname": "나는 카페베리",
"provider": "구글 로그인 회원"
},
"error": null
}
8 changes: 8 additions & 0 deletions src/mocks/apis/getSettingUserInfo/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { rest } from 'msw';
import {data} from './data.json';

export const getSettingUserInfoHandler = [
rest.get(`/users`, (req, res, ctx) => {
return res(ctx.status(200), ctx.json(data));
}),
];
5 changes: 3 additions & 2 deletions src/mocks/handlers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { cafeInfoHandler } from './apis/cafeInfo';
import { cafesHandler } from './apis/cafes';
import { getSettingUserInfoHandler } from './apis/getSettingUserInfo';
import {likeHandler} from './apis/like';
import { patchNicknameHandler } from './apis/patchNickname';
import { putLikeHandler } from './apis/putLike';
Expand All @@ -12,5 +13,5 @@ export const handlers = [
...putLikeHandler,
...userInfoHandler,
...patchNicknameHandler,
];

...getSettingUserInfoHandler,
];
7 changes: 1 addition & 6 deletions src/pages/Setting/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,10 @@ import {useLoginStatus} from '@/hooks/useLoginStatus';
import { useFetchSettingUserInfo } from '@/hooks/useFetchSettingUserInfo';
import { useLogout } from '@/hooks/useLogout';

const data = { //TODO: 지워야 함. dummy
nickname: 'Cafevery',
provider: '카카오 로그인 회원',
};

export default function Setting() {
const {isLoggedIn} = useLoginStatus();
const {mutate} = useLogout();
//const { data } = useFetchSettingUserInfo(); //TODO: 주석 해제 해야함.
const { data } = useFetchSettingUserInfo();

const handleLogout = () => {
mutate();
Expand Down

0 comments on commit ab9e61a

Please sign in to comment.