Skip to content

Commit f8358f8

Browse files
authored
feat: 마이페이지 내 정보 조회 기능 구현 (mock api) (#39)
* feat: 마이페이지 내 정보 조회 기능 구현 * fix: merge conflict 해결
1 parent 0b47e49 commit f8358f8

File tree

4 files changed

+62
-11
lines changed

4 files changed

+62
-11
lines changed

src/apis/incomingLetters.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { client } from '@/apis/client';
1+
import client from './client';
22

33
export const fetchIncomingLettersApi = async (token: string) => {
44
try {

src/apis/myPage.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import client from './client';
2+
3+
export const fetchMyPageInfo = async () => {
4+
try {
5+
const response = await client.get('/api/members/me');
6+
if (!response) throw new Error('❌데이터를 불러오던 중 오류가 발생했습니다');
7+
return response.data;
8+
} catch (error) {
9+
console.error(error);
10+
}
11+
};

src/pages/MyPage/index.tsx

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
1-
import { useState } from 'react';
1+
import { useState, useEffect } from 'react';
22
import { Link } from 'react-router';
33

44
import ConfirmModal from '@/components/ConfirmModal';
5+
import useMyPageStore from '@/stores/myPageStore';
56

67
import { TEMPERATURE_RANGE } from './constants';
78

8-
const DUMMY_TEMP = 48.5;
9-
const DUMMY_ZIP_CODE = '235EA';
10-
119
const MyPage = () => {
10+
useEffect(() => {
11+
fetchMyPageInfo();
12+
}, []);
13+
14+
const { data, fetchMyPageInfo } = useMyPageStore();
1215
const [isOpenModal, setIsOpenModal] = useState(false);
1316

1417
const getDescriptionByTemperature = (temp: number) => {
1518
const range = TEMPERATURE_RANGE.find((range) => temp >= range.min && temp < range.max);
1619
return range?.description;
1720
};
1821

19-
const description = getDescriptionByTemperature(DUMMY_TEMP);
22+
const description = getDescriptionByTemperature(Number(data.temperature));
2023

2124
return (
2225
<>
@@ -32,7 +35,7 @@ const MyPage = () => {
3235
)}
3336
<main className="flex grow flex-col gap-12 px-5 pt-20 pb-6">
3437
<h1 className="h2-b mx-auto flex gap-1.5">
35-
{DUMMY_ZIP_CODE.split('').map((code, index) => (
38+
{data.zipCode.split('').map((code, index) => (
3639
<div
3740
key={index}
3841
className="flex h-13.5 w-10 items-center justify-center rounded-sm bg-white inset-shadow-[0_4px_4px_0] inset-shadow-black/10"
@@ -44,12 +47,12 @@ const MyPage = () => {
4447
<section>
4548
<h2 className="mb-2 flex justify-between">
4649
<p className="body-sb text-gray-60">{description}</p>
47-
<p className="body-sb text-accent-1">{DUMMY_TEMP}</p>
50+
<p className="body-sb text-accent-1">{data.temperature}</p>
4851
</h2>
4952
<div className="h-4 w-full rounded-full bg-white">
5053
<div
5154
className="h-full w-[calc(${degree}%)] rounded-full bg-[#FFB5AC]"
52-
style={{ width: `calc(${DUMMY_TEMP}%)` }}
55+
style={{ width: `calc(${data.temperature}%)` }}
5356
/>
5457
</div>
5558
</section>
@@ -69,8 +72,8 @@ const MyPage = () => {
6972
<div className="flex justify-between">
7073
<p className="body-sb text-gray-100">로그인 정보</p>
7174
<p className="body-r text-gray-60">
72-
<span className="mr-2">카카오</span>
73-
<span>[email protected]</span>
75+
<span className="mr-2">{data.social}</span>
76+
<span>{data.email}</span>
7477
</p>
7578
</div>
7679
<p className="body-sb text-gray-100">로그아웃</p>

src/stores/myPageStore.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { create } from 'zustand';
2+
3+
import { fetchMyPageInfo } from '@/apis/mypage';
4+
5+
interface MyPageDataStore {
6+
zipCode: string;
7+
temperature: string;
8+
social: string;
9+
email: string;
10+
}
11+
12+
interface MyPageStore {
13+
data: MyPageDataStore;
14+
message: string;
15+
setMyPageData: (newData: MyPageDataStore) => void;
16+
fetchMyPageInfo: () => void;
17+
}
18+
const useMyPageStore = create<MyPageStore>((set) => ({
19+
data: {
20+
zipCode: '',
21+
temperature: '',
22+
social: '',
23+
email: '',
24+
},
25+
message: '',
26+
setMyPageData: (newData) => set({ data: newData }),
27+
fetchMyPageInfo: async () => {
28+
try {
29+
const responseData = await fetchMyPageInfo();
30+
set({ data: responseData.data, message: responseData.message });
31+
} catch (error) {
32+
console.error('데이터를 불러오던 중 에러가 발생했습니다', error);
33+
}
34+
},
35+
}));
36+
37+
export default useMyPageStore;

0 commit comments

Comments
 (0)