Skip to content
Merged
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
2 changes: 1 addition & 1 deletion src/apis/incomingLetters.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { client } from '@/apis/client';
import client from './client';

export const fetchIncomingLettersApi = async (token: string) => {
try {
Expand Down
11 changes: 11 additions & 0 deletions src/apis/myPage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import client from './client';

export const fetchMyPageInfo = async () => {
try {
const response = await client.get('/api/members/me');
if (!response) throw new Error('❌데이터를 불러오던 중 오류가 발생했습니다');
return response.data;
} catch (error) {
console.error(error);
}
};
23 changes: 13 additions & 10 deletions src/pages/MyPage/index.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
import { useState } from 'react';
import { useState, useEffect } from 'react';
import { Link } from 'react-router';

import ConfirmModal from '@/components/ConfirmModal';
import useMyPageStore from '@/stores/myPageStore';

import { TEMPERATURE_RANGE } from './constants';

const DUMMY_TEMP = 48.5;
const DUMMY_ZIP_CODE = '235EA';

const MyPage = () => {
useEffect(() => {
fetchMyPageInfo();
}, []);

const { data, fetchMyPageInfo } = useMyPageStore();
const [isOpenModal, setIsOpenModal] = useState(false);

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

const description = getDescriptionByTemperature(DUMMY_TEMP);
const description = getDescriptionByTemperature(Number(data.temperature));

return (
<>
Expand All @@ -32,7 +35,7 @@ const MyPage = () => {
)}
<main className="flex grow flex-col gap-12 px-5 pt-20 pb-6">
<h1 className="h2-b mx-auto flex gap-1.5">
{DUMMY_ZIP_CODE.split('').map((code, index) => (
{data.zipCode.split('').map((code, index) => (
<div
key={index}
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"
Expand All @@ -44,12 +47,12 @@ const MyPage = () => {
<section>
<h2 className="mb-2 flex justify-between">
<p className="body-sb text-gray-60">{description}</p>
<p className="body-sb text-accent-1">{DUMMY_TEMP}도</p>
<p className="body-sb text-accent-1">{data.temperature}도</p>
</h2>
<div className="h-4 w-full rounded-full bg-white">
<div
className="h-full w-[calc(${degree}%)] rounded-full bg-[#FFB5AC]"
style={{ width: `calc(${DUMMY_TEMP}%)` }}
style={{ width: `calc(${data.temperature}%)` }}
/>
</div>
</section>
Expand All @@ -69,8 +72,8 @@ const MyPage = () => {
<div className="flex justify-between">
<p className="body-sb text-gray-100">로그인 정보</p>
<p className="body-r text-gray-60">
<span className="mr-2">카카오</span>
<span>[email protected]</span>
<span className="mr-2">{data.social}</span>
<span>{data.email}</span>
</p>
</div>
<p className="body-sb text-gray-100">로그아웃</p>
Expand Down
37 changes: 37 additions & 0 deletions src/stores/myPageStore.ts
Copy link
Collaborator

Choose a reason for hiding this comment

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

마이페이지 데이터가 전역으로 관리되어야 하는 이유가 있나용?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

다른 기능에서 사용할 것 같아서 전역으로 관리한 건데 이후에 이 페이지에서만 사용된다면 컴포넌트 단위에서 관리하도록 하겠습니다!

Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { create } from 'zustand';

import { fetchMyPageInfo } from '@/apis/mypage';

interface MyPageDataStore {
zipCode: string;
temperature: string;
social: string;
email: string;
}

interface MyPageStore {
data: MyPageDataStore;
message: string;
setMyPageData: (newData: MyPageDataStore) => void;
fetchMyPageInfo: () => void;
}
const useMyPageStore = create<MyPageStore>((set) => ({
data: {
zipCode: '',
temperature: '',
social: '',
email: '',
},
message: '',
setMyPageData: (newData) => set({ data: newData }),
fetchMyPageInfo: async () => {
try {
const responseData = await fetchMyPageInfo();
set({ data: responseData.data, message: responseData.message });
} catch (error) {
console.error('데이터를 불러오던 중 에러가 발생했습니다', error);
}
},
}));

export default useMyPageStore;