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 ] setting 뷰 msw 연결 #248

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
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
4 changes: 3 additions & 1 deletion src/mocks/handlers.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { userProfileResolvers } from '@/mocks/modal/resolvers/settingModalResover';

import { homeResolvers } from './home/resolvers/homeResolvers';

export const handlers = [...homeResolvers];
export const handlers = [...homeResolvers, ...userProfileResolvers];
13 changes: 13 additions & 0 deletions src/mocks/modal/resolvers/settingModalResover.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { HttpResponse, http } from 'msw';

import { SETTING_MODAL_RES } from '@/mocks/modal/responses/settingModalResponses';

export const SETTING_MODAL_URL = {
GET_PROFILE_INFO: 'api/v2/profiles',
};

export const userProfileResolvers = [
http.get(SETTING_MODAL_URL.GET_PROFILE_INFO, async () => {
return HttpResponse.json(SETTING_MODAL_RES.GET_PROFILE_INFO);
}),
];
20 changes: 20 additions & 0 deletions src/mocks/modal/responses/settingModalResponses.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export const SETTING_MODAL_RES = {
GET_PROFILE_INFO: {
status: 200,
message: '요청이 성공했습니다.',
data: {
id: '3',
name: '유영재',
email: '[email protected]',
imageUrl: '{profile image Url}',
isPushEnabled: true,
},
},
};

export const SETTING_MODIFY_RES = {
PUT_PROFILE: {
status: 200,
message: '요청이 성공했습니다.',
},
};
8 changes: 8 additions & 0 deletions src/shared/apisV2/modal/axios/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import axios from 'axios';

import { SETTING_MODAL_URL } from '@/mocks/modal/resolvers/settingModalResover';

export const getUserProfile = async () => {
const { data } = await axios.get(SETTING_MODAL_URL.GET_PROFILE_INFO);
return data;
};
18 changes: 18 additions & 0 deletions src/shared/apisV2/modal/queries/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { useQuery } from '@tanstack/react-query';

import { getUserProfile } from '@/shared/apisV2/modal/axios';

export interface UserProfile {
id: string;
name: string;
email: string;
imageUrl: string;
isPushEnabled: boolean;
}

export const useGetUserProfile = () => {
return useQuery<UserProfile>({
queryKey: ['UserProfile'],
queryFn: () => getUserProfile(),
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ import MailIcon from '@/shared/assets/svgs/mail.svg?react';
import ButtonSettingSaved from '../ButtonSettingSaved/ButtonSettingSaved';

interface User {
name: string;
email: string;
id: string | undefined;
name: string | undefined;
email: string | undefined;
imageUrl: string | undefined;
isPushEnabled: boolean | undefined;
}

interface AccountContentProps {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,29 @@ import { useState } from 'react';
import SettingIcon from '@/shared/assets/svgs/setting.svg?react';
import UserIcon from '@/shared/assets/svgs/user_circle.svg?react';

import { useGetUserProfile } from '@/shared/apisV2/modal/queries';

import AccountContent from './AccountContent/AccountContent';
import Tabs from './Tabs/Tabs';
import WorkSpaceSettingContent from './WorkspaceSettingContent/WorkspaceSettingContent';

const ModalContentsSetting = () => {
const [activeTab, setActiveTab] = useState<string>('account');
const user = {
name: '홍길동',
email: '[email protected]',
const { data, isLoading, error } = useGetUserProfile();

if (isLoading) {
return <div>Loading...</div>;
}
if (error) {
return <div>Error loading user profile</div>;
}

const userProfiles = {
id: data?.id,
name: data?.name,
email: data?.email,
imageUrl: data?.imageUrl,
isPushEnabled: data?.isPushEnabled,
};

const personalWorkspaces = ['개인 프로젝트'];
Expand Down Expand Up @@ -42,7 +56,7 @@ const ModalContentsSetting = () => {

<div className="flex flex-col p-[4rem]">
{activeTab === 'account' ? (
<AccountContent user={user} />
<AccountContent user={userProfiles} />
) : (
<WorkSpaceSettingContent personalWorkspaces={personalWorkspaces} teamWorkspaces={teamWorkspaces} />
)}
Expand Down
Loading