Skip to content

Commit 5d3117b

Browse files
authored
Merge pull request #139 from prgrms-web-devcourse-final-project/134-feature/mypage-setting
[Feature] 마이페이지 CSS 수정, 데이터 바인딩
2 parents dc7bb76 + 7b9b41b commit 5d3117b

File tree

4 files changed

+61
-14
lines changed

4 files changed

+61
-14
lines changed

src/components/DogProfile/index.tsx

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as S from './styles'
2-
import { Typo13, Typo15, Typo20 } from '~components/Typo'
2+
import { Typo13, Typo14, Typo15, Typo20 } from '~components/Typo'
33
import { Separator } from '~components/Separator'
44
import Profile from '~components/Profile'
55
import { DogProfileType } from '~types/dogProfile'
@@ -18,22 +18,38 @@ const calculateAge = (birthDate?: Date): number => {
1818
}
1919
return age
2020
}
21-
export default function DogProfile({ name, gender, profileImg, birthDate, breed, comment }: DogProfileType) {
21+
export default function DogProfile({
22+
name,
23+
gender,
24+
profileImg,
25+
birthDate,
26+
breed,
27+
comment,
28+
isNeutered,
29+
weight,
30+
}: DogProfileType) {
2231
const age = calculateAge(stringToDate(birthDate!))
2332
return (
2433
<S.DogInfoArea>
2534
<S.DogInfoWrapper>
2635
<Profile $size={80} $src={profileImg || ''} />
2736
<S.DogDetailWrapper>
2837
<S.TypoWrapper>
29-
<Typo20 $weight='700'>{name}</Typo20>
38+
<S.TyopNameWrapper>
39+
<Typo20 $weight='700'>{name}</Typo20>
40+
</S.TyopNameWrapper>
3041
<Typo15 $weight='400'>{breed}</Typo15>
3142
<Separator $height={8} />
3243
<Typo15 $weight='400'>{age}</Typo15>
3344
<Separator $height={8} />
3445
<Typo15 $weight='400'>{gender === 'MALE' ? '남' : '여'}</Typo15>
3546
</S.TypoWrapper>
36-
</S.DogDetailWrapper>
47+
<S.DogDetailInfoWrapper>
48+
<Typo14 $weight='400'>중성화 {isNeutered === 'TRUE' ? 'O' : 'X'}</Typo14>
49+
<Separator $height={8} />
50+
<Typo14 $weight='400'>{weight} KG</Typo14>
51+
</S.DogDetailInfoWrapper>
52+
</S.DogDetailWrapper>
3753
</S.DogInfoWrapper>
3854

3955
<S.OneLineIntro>

src/components/DogProfile/styles.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,13 @@ export const TypoWrapper = styled.div<{ $gap?: number }>`
55
display: flex;
66
align-items: center;
77
gap: ${({ $gap = 4 }) => $gap}px;
8+
margin-bottom: 0.1rem;
9+
margin-top: 1rem;
10+
`
11+
export const TyopNameWrapper = styled.div`
12+
margin-right: 0.3rem;
13+
margin-bottom: 0.4rem;
814
`
9-
1015
export const DogInfoArea = styled(Box)`
1116
padding: 16px 20px;
1217
`
@@ -15,7 +20,12 @@ export const DogInfoWrapper = styled.div`
1520
align-items: center;
1621
gap: 12px;
1722
`
18-
23+
export const DogDetailInfoWrapper = styled.div`
24+
display: flex;
25+
gap: 0.3rem;
26+
align-items: center;
27+
margin-bottom: 1rem;
28+
`
1929
export const DogDetailWrapper = styled.div`
2030
display: flex;
2131
flex-direction: column;

src/pages/MyPage/index.tsx

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,44 @@
11
import { fetchMypage } from '~apis/myPage/fetchMypage'
2-
// import ProfileImage from 'assets/masterprofile.svg?react'
32
import { Helmet } from 'react-helmet-async'
43
import { IoSettingsOutline } from 'react-icons/io5'
5-
import { Typo13, Typo15, Typo24 } from '~components/Typo'
4+
import { Typo14, Typo15, Typo24 } from '~components/Typo'
65
import SettingModal from '~modals/SettingModal'
76
import { useModalStore } from '~stores/modalStore'
87
import * as S from './styles'
98
import CountSection from '~components/WalkCountArea'
109
import { useQuery } from '@tanstack/react-query'
1110
import DogProfile from '~components/DogProfile'
11+
import { FAMILY_ROLE } from '~constants/familyRole'
12+
import { useEffect, useState } from 'react'
1213

1314
export default function MyPage() {
1415
const { data } = useQuery({
1516
queryKey: ['myPage'],
1617
queryFn: fetchMypage,
1718
})
19+
const [ProfileImage, setProfileImage] = useState<React.ComponentType | null>(null)
1820

1921
const myPageData = data?.data // API 응답 구조에 맞춰 접근
2022
console.log(myPageData)
2123

24+
useEffect(() => {
25+
if (myPageData?.profileImg) {
26+
// profileImg에서 파일 번호를 추출
27+
const avatarNumber = myPageData.profileImg.match(/Avatar(\d+)/)?.[1]
28+
29+
if (avatarNumber) {
30+
import(`../../../src/assets/avatars/Avatar${avatarNumber}.svg?react`)
31+
.then(module => {
32+
setProfileImage(() => module.default)
33+
})
34+
.catch(err => console.error('Error loading SVG:', err))
35+
}
36+
}
37+
}, [myPageData?.profileImg])
38+
2239
const { pushModal } = useModalStore()
40+
const familyRole = Object.values(FAMILY_ROLE)
41+
console.log(familyRole)
2342

2443
const onSettingsClick = () => {
2544
pushModal(<SettingModal />)
@@ -43,16 +62,18 @@ export default function MyPage() {
4362
<S.ProfileSection>
4463
<S.ProfileArea>
4564
{/* <ProfileImage /> */}
46-
{myPageData?.profileImg}
65+
{ProfileImage && <ProfileImage />}
4766
</S.ProfileArea>
4867
<S.ProfileText>
4968
<Typo24 $weight='800'>{myPageData?.name}</Typo24>
5069
<Typo15 $weight='400' $color='font_2'>
5170
{myPageData?.address} 거주
5271
</Typo15>
5372
<S.TypoWrap>
54-
<Typo13 $weight='700'>{myPageData?.gender}</Typo13>
55-
<Typo13 $weight='700'>{myPageData?.familyRole}</Typo13>
73+
<Typo14 $weight='700'>{myPageData?.gender === 'FEMALE' ? '여자' : '남자'}</Typo14>
74+
<Typo14 $weight='700'>
75+
{myPageData?.familyRole ? FAMILY_ROLE[myPageData.familyRole as keyof typeof FAMILY_ROLE] : ''}
76+
</Typo14>
5677
</S.TypoWrap>
5778
</S.ProfileText>
5879
</S.ProfileSection>

src/pages/MyPage/styles.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export const SettingIcon = styled.div`
4848

4949
export const ProfileSection = styled.div`
5050
width: 100%;
51-
height: 17.8125rem;
51+
height: 19rem;
5252
flex-shrink: 0;
5353
background-color: ${({ theme }) => theme.colors.grayscale.gc_4};
5454
border-radius: 1rem;
@@ -57,8 +57,8 @@ export const ProfileSection = styled.div`
5757
`
5858

5959
export const ProfileArea = styled.div`
60-
width: 8.75rem;
61-
height: 8.75rem;
60+
width: 11rem;
61+
height: 10rem;
6262
flex-shrink: 0;
6363
margin: 1.5rem auto;
6464
display: flex;

0 commit comments

Comments
 (0)