11import { useState , useEffect } from 'react' ;
22import { Link } from 'react-router' ;
33
4+ import { fetchMyPageInfo } from '@/apis/myPage' ;
45import { deleteUserInfo } from '@/apis/auth' ;
56import ConfirmModal from '@/components/ConfirmModal' ;
67import useAuthStore from '@/stores/authStore' ;
7- import useMyPageStore from '@/stores/myPageStore' ;
88
99import { TEMPERATURE_RANGE } from './constants' ;
1010import useToastStore from '@/stores/toastStore' ;
1111import ModalOverlay from '@/components/ModalOverlay' ;
1212
1313const MyPage = ( ) => {
14- useEffect ( ( ) => {
15- fetchMyPageInfo ( ) ;
16- } , [ ] ) ;
17-
18- const { data, fetchMyPageInfo } = useMyPageStore ( ) ;
14+ const [ myInfo , setMyInfo ] = useState < MyPage > ( ) ;
1915
2016 const [ isOpenModal , setIsOpenModal ] = useState ( false ) ;
2117 const [ isOpenWarningModal , setIsOpenWarningModal ] = useState ( false ) ;
2218
2319 const logout = useAuthStore ( ( state ) => state . logout ) ;
2420 const setToastActive = useToastStore ( ( state ) => state . setToastActive ) ;
2521
22+ useEffect ( ( ) => {
23+ const fetchData = async ( ) => {
24+ const data = await fetchMyPageInfo ( ) ;
25+ if ( data ) setMyInfo ( data ) ;
26+ } ;
27+ fetchData ( ) ;
28+ } , [ ] ) ;
29+
2630 const getDescriptionByTemperature = ( temp : number ) => {
2731 const range = TEMPERATURE_RANGE . find ( ( range ) => temp >= range . min && temp < range . max ) ;
2832 return range ?. description ;
2933 } ;
3034
31- const description = getDescriptionByTemperature ( Number ( data . temperature ) ) ;
32-
3335 const handleLeave = async ( ) => {
3436 try {
3537 const response = await deleteUserInfo ( ) ;
@@ -88,7 +90,7 @@ const MyPage = () => {
8890
8991 < main className = "flex grow flex-col gap-12 px-5 pt-20 pb-6" >
9092 < h1 className = "h2-b mx-auto flex gap-1.5" >
91- { data . zipCode . split ( '' ) . map ( ( code , index ) => (
93+ { myInfo ? .zipCode . split ( '' ) . map ( ( code , index ) => (
9294 < div
9395 key = { index }
9496 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"
@@ -99,13 +101,15 @@ const MyPage = () => {
99101 </ h1 >
100102 < section >
101103 < h2 className = "mb-2 flex justify-between" >
102- < p className = "body-sb text-gray-60 dark:text-white" > { description } </ p >
103- < p className = "body-sb text-accent-2" > { data . temperature } 도</ p >
104+ < p className = "body-sb text-gray-60 dark:text-white" >
105+ { getDescriptionByTemperature ( Number ( myInfo ?. temperature ) ) }
106+ </ p >
107+ < p className = "body-sb text-accent-2" > { myInfo ?. temperature } 도</ p >
104108 </ h2 >
105109 < div className = "h-4 w-full rounded-full bg-white" >
106110 < div
107111 className = "h-full w-[calc(${degree}%)] rounded-full bg-[#FFB5AC]"
108- style = { { width : `calc(${ data . temperature } %)` } }
112+ style = { { width : `calc(${ myInfo ? .temperature } %)` } }
109113 />
110114 </ div >
111115 </ section >
@@ -131,8 +135,8 @@ const MyPage = () => {
131135 < div className = "flex justify-between" >
132136 < p className = "body-sb text-gray-100 dark:text-white" > 로그인 정보</ p >
133137 < p className = "body-r text-gray-60 dark:text-white" >
134- < span className = "mr-2" > { data . social } </ span >
135- < span > { data . email } </ span >
138+ < span className = "mr-2" > { myInfo ? .social } </ span >
139+ < span > { myInfo ? .email } </ span >
136140 </ p >
137141 </ div >
138142 < div
@@ -143,7 +147,7 @@ const MyPage = () => {
143147 >
144148 < p className = "body-sb text-gray-100 dark:text-white" > 경고 횟수</ p >
145149 < p className = "body-r text-gray-60 dark:text-white" >
146- < span > { data . warningCount } 회</ span >
150+ < span > { myInfo ? .warningCount } 회</ span >
147151 </ p >
148152 </ div >
149153
0 commit comments