diff --git a/src/assets/icons/phone.svg b/src/assets/icons/phone.svg new file mode 100644 index 00000000..4e79d051 --- /dev/null +++ b/src/assets/icons/phone.svg @@ -0,0 +1,4 @@ + diff --git a/src/pages/profile/Profile.tsx b/src/pages/profile/Profile.tsx index 134f0c1c..72624ea9 100644 --- a/src/pages/profile/Profile.tsx +++ b/src/pages/profile/Profile.tsx @@ -1,8 +1,172 @@ -import { Link } from 'react-router-dom'; +import { useState, useEffect, useContext, useCallback } from 'react'; +import { useNavigate } from 'react-router-dom'; +import { AuthContext } from '@/context/AuthContext'; +import RegisterLayout from '@/components/layout/RegisterLayout'; +import Footer from '@/components/layout/Footer'; +import Table from '@/components/common/table/Table'; +import Button from '@/components/common/Button'; +import Modal from '@/components/common/Modal'; +import { getUser } from '@/api/userApi'; +import { getUserApplications } from '@/api/applicationApi'; +import formatPhone from '@/utils/formatPhone'; +import phone from '@/assets/icons/phone.svg'; +import location from '@/assets/icons/location-red.svg'; + export default function Profile() { + const navigate = useNavigate(); + const { isLoggedIn } = useContext(AuthContext); + const [profileInfo, setProfileInfo] = useState({ + name: '', + phone: '', + address: '', + bio: '', + }); + const [hasInfo, setHasInfo] = useState(false); + const [hasApplications, setHasApplications] = useState(false); + const [modal, setModal] = useState({ + isOpen: false, + message: '', + }); + const [buttonSize, setButtonSize] = useState<'large' | 'medium'>('medium'); + const [isLoading, setIsLoading] = useState(true); + + useEffect(() => { + const handleResize = () => { + if (window.innerWidth >= 768) { + setButtonSize('large'); + } else { + setButtonSize('medium'); + } + }; + + handleResize(); + window.addEventListener('resize', handleResize); + + return () => window.removeEventListener('resize', handleResize); + }, []); + + useEffect(() => { + const userId = localStorage.getItem('userId'); + + if (!userId) { + setModal({ + isOpen: true, + message: '로그인이 필요합니다.', + }); + return; + } + + const fetchUserInfo = async () => { + try { + const userInfo = await getUser(userId); + setProfileInfo({ + name: userInfo.item.name ?? '', + phone: userInfo.item.phone ?? '', + address: userInfo.item.address ?? '', + bio: userInfo.item.bio ?? '', + }); + setHasInfo(!!userInfo.item.name); + const applications = await getUserApplications(userId); + setHasApplications(applications.count > 0); + } catch (error) { + setModal({ + isOpen: true, + message: (error as Error).message, + }); + } finally { + setIsLoading(false); + } + }; + fetchUserInfo(); + }, [isLoggedIn]); + + const handleModalConfirm = useCallback(() => { + if (modal.message.includes('로그인')) { + setModal({ isOpen: false, message: '' }); + navigate('/login'); + } else { + setModal({ isOpen: false, message: '' }); + } + }, [modal.message, navigate]); + return ( <> - 등록하기 + {isLoading ? ( +
+ {profileInfo.bio} +
+ )} +