@@ -5,17 +5,18 @@ import { PageHeader } from "../../components/common/system/header/PageHeader";
55import { useNavigate , useParams } from "react-router-dom" ;
66import { MyPage_Profile_Medal } from "../../components/common/contentcard/MyPage_Profile_Medal" ;
77import { getProfile } from "../../api/member/profile" ;
8- import { getOtherUserMedals } from "../../api/contest/member" ;
8+ import { getOtherUserMedals } from "../../api/contest/member" ;
99import type { ProfileResponseData } from "../../api/member/profile" ;
1010import { useState , useEffect } from "react" ;
11- // import { createDirectChat } from "../../api/chat/direct";
11+ import { createDirectChat } from "../../api/chat/direct" ;
1212export const MyPageProfile = ( ) => {
13-
1413 const { memberId } = useParams < { memberId : string } > ( ) ;
1514 const numericMemberId = memberId ? Number ( memberId ) : null ;
1615 const navigate = useNavigate ( ) ;
1716
18- const [ profileData , setProfileData ] = useState < ProfileResponseData | null > ( null ) ;
17+ const [ profileData , setProfileData ] = useState < ProfileResponseData | null > (
18+ null ,
19+ ) ;
1920 const [ medalData , setMedalData ] = useState ( {
2021 myMedalTotal : 0 ,
2122 goldCount : 0 ,
@@ -54,7 +55,6 @@ export const MyPageProfile = () => {
5455 silverCount : medals . silverCount ,
5556 bronzeCount : medals . bronzeCount ,
5657 } ) ;
57-
5858 } catch ( e : any ) {
5959 setError ( e . message || "데이터를 불러오는 중 오류가 발생했습니다." ) ;
6060 } finally {
@@ -64,8 +64,8 @@ export const MyPageProfile = () => {
6464
6565 fetchData ( ) ;
6666 } , [ numericMemberId ] ) ;
67-
68- // 급수
67+
68+ // 급수
6969 function convertLevel ( level : string ) : string {
7070 const levelMap : Record < string , string > = {
7171 EXPERT : "자강" ,
@@ -80,48 +80,47 @@ export const MyPageProfile = () => {
8080 } ;
8181 return level ? ( levelMap [ level . toUpperCase ( ) ] ?? "급수 없음" ) : "급수 없음" ;
8282 }
83- // const handleChatClick = async () => {
84- // if (!numericMemberId) return;
85-
86- // try {
87- // const res = await createDirectChat(numericMemberId);
88- // if (res.success && res.data?.chatRoomId) {
89- // navigate(`/chat/personal/${res.data.chatRoomId}`);
90- // } else {
91- // console.error("채팅방 생성 실패", res);
92- // }
93- // } catch (err: any) {
94- // console.error(err);
95- // }
96- // };
83+ const handleChatClick = async ( ) => {
84+ if ( ! numericMemberId ) return ;
9785
86+ try {
87+ const res = await createDirectChat ( numericMemberId ) ;
88+ if ( res . success && res . data ?. chatRoomId ) {
89+ navigate ( `/chat/personal/${ res . data . chatRoomId } ` ) ;
90+ } else {
91+ console . error ( "채팅방 생성 실패" , res ) ;
92+ }
93+ } catch ( err : any ) {
94+ console . error ( err ) ;
95+ }
96+ } ;
9897
9998 if ( loading ) return < div className = "text-center py-10" > 로딩 중...</ div > ;
100- if ( error ) return < div className = "text-center py-10 text-red-500" > 에러: { error } </ div > ;
99+ if ( error )
100+ return < div className = "text-center py-10 text-red-500" > 에러: { error } </ div > ;
101101
102102 return (
103103 < div className = "flex flex-col overflow-hidden w-full" >
104104 < PageHeader title = "프로필" />
105105 < Profile
106106 name = { profileData ?. memberName || "" }
107107 gender = { profileData ?. gender === "MALE" ? "MALE" : "FEMALE" }
108- level = { convertLevel ( profileData ?. level || "" ) }
108+ level = { convertLevel ( profileData ?. level || "" ) }
109109 birth = { profileData ?. birth || "" }
110110 profileImage = { profileData ?. profileImgUrl || "" }
111111 />
112112
113-
114113 < div className = "my-8 flex flex-col gap-4 w-full items-center" >
115114 < MyPage_Text
116115 textLabel = "모임"
117116 numberValue = { profileData ?. myGroupCount ?? 0 }
118- onClick = { ( ) =>
117+ onClick = { ( ) =>
119118 navigate ( `/mypage/mygroup?memberId=${ numericMemberId } ` )
120119 }
121120 // onClick={() => navigate("/mypage/profile/group")}
122121 />
123122
124- < MyPage_Profile_Medal
123+ < MyPage_Profile_Medal
125124 myMedalTotal = { medalData . myMedalTotal }
126125 goldCount = { medalData . goldCount }
127126 silverCount = { medalData . silverCount }
@@ -139,10 +138,7 @@ export const MyPageProfile = () => {
139138 />
140139 </ div >
141140
142- < Grad_GR400_L
143- label = "개인 채팅 보내기"
144- // onClick={handleChatClick}
145- />
141+ < Grad_GR400_L label = "개인 채팅 보내기" onClick = { handleChatClick } />
146142 </ div >
147143 ) ;
148144} ;
0 commit comments