11import { useState , useEffect } from 'react' ;
2- import { useNavigate } from 'react-router-dom' ;
2+ import { useNavigate , useParams } from 'react-router-dom' ;
33import { ArrowLeft } from 'lucide-react' ;
44import { Bookmark } from 'lucide-react' ;
55import { GlobalButton } from '@/global/ui/GlobalButton' ;
66
7+ import { getMentorById } from '../api/MentorViewApi' ;
8+ import { MentorData } from '@/user/types' ;
9+ import { reverseJobCategoryMapping , reverseDetailedJobMapping } from '@/user/components/Mapping' ;
10+ import { reverseMentoringFieldMapping , reverseDayMapping } from '@/user/components/Mapping' ;
11+
712import MentorInfoProfile from '../../user/components/profileInfo/MentorInfoProfile' ;
813import MentorInfoBio from '../../user/components/profileInfo/MentorInfoBio' ;
914import MentorInfoFieldsHashtags from '../../user/components/profileInfo/MentorInfoFieldsHashtags' ;
@@ -12,50 +17,40 @@ import MentorInfoMessage from '../../user/components/profileInfo/MentorInfoMessa
1217import MentorInfoPortfolio from '../../user/components/profileInfo/MentorInfoPortfolio' ;
1318
1419const MentorInfoView = ( ) => {
20+ const { mentorId } = useParams < { mentorId : string } > ( ) ;
1521 const navigate = useNavigate ( ) ;
1622 const [ isBookmarked , setIsBookmarked ] = useState ( false ) ;
23+ const [ mentorData , setMentorData ] = useState < MentorData | null > ( null ) ;
1724
18- // 테스트용 멘티 데이터 && localStorage에서 데이터 불러오기 (api 연결시 제거)
19- const [ mentorData , setMentorData ] = useState ( ( ) => {
20- const savedData = localStorage . getItem ( "mentorData" ) ;
21- return savedData ? JSON . parse ( savedData ) : {
22- nickname : "바이" ,
23- 24- education : {
25- schoolName : "경북대학교" ,
26- major : "컴퓨터공학" ,
27- } ,
28- organization : {
29- name : "OO주식회사" ,
30- role : "브랜드 마케팅/카피라이팅" ,
31- experience : 6 ,
32- } ,
33- count : 716 ,
34- image : {
35- fileName : "" ,
36- filePath : "" ,
37- } ,
38- introduction : {
39- summary : "브랜드 마케팅에 대한 모든 것을 알려드립니다." ,
40- bio : "안녕하세요!\n저는 OO대학교 경영학과를 졸업하고 현재 XXXX에 다니고 있는 ‘바이’입니다." ,
41- } ,
42- availableDays : [ "월" , "목" ] ,
43- timezone : {
44- startTime : { period : "오전" , hour : "10" , minute : "00" } ,
45- endTime : { period : "오후" , hour : "18" , minute : "00" } ,
46- } ,
47- mentoringField : [ "취업 준비" , "커리어 고민" ] ,
48- hashtags : [ "마케팅" , "브랜드마케팅" , "이직" , "취준" , "진로고민상담" , "면접노하우" ] ,
49- message : "안녕하세요, 멘티 여러분!\n브랜드 마케팅 경험을 바탕으로 여러분의 성장을 지원하고 싶습니다." ,
50- portfolio : [
51- {
52- url : "https://example.com/portfolio1.pdf" ,
53- description : "브랜드 마케팅 포트폴리오.pdf" ,
54- size : 25 ,
55- } ,
56- ] ,
25+ useEffect ( ( ) => {
26+ const fetchData = async ( ) => {
27+ try {
28+ if ( ! mentorId || isNaN ( Number ( mentorId ) ) ) return ;
29+ const data = await getMentorById ( Number ( mentorId ) ) ;
30+
31+ // 매핑
32+ const localizedData : MentorData = {
33+ ...data ,
34+ mentoringField : data . mentoringField . map ( ( f ) => reverseMentoringFieldMapping [ f ] || f ) ,
35+ timezone : {
36+ ...data . timezone ,
37+ days : data . timezone . days . map ( ( d ) => reverseDayMapping [ d ] || d ) ,
38+ } ,
39+ organization : {
40+ ...data . organization ,
41+ jobCategory : reverseJobCategoryMapping [ data . organization . jobCategory ] || data . organization . jobCategory ,
42+ detailedJob : reverseDetailedJobMapping [ data . organization . detailedJob ] || data . organization . detailedJob ,
43+ } ,
44+ } ;
45+
46+ setMentorData ( localizedData ) ;
47+ } catch ( err ) {
48+ console . error ( "멘토 상세 불러오기 실패:" , err ) ;
49+ }
5750 } ;
58- } ) ;
51+
52+ fetchData ( ) ;
53+ } , [ mentorId ] ) ;
5954
6055 useEffect ( ( ) => {
6156 const storedBookmark = localStorage . getItem ( "isBookmarked" ) ;
@@ -68,6 +63,8 @@ const MentorInfoView = () => {
6863 localStorage . setItem ( "isBookmarked" , newBookmarkState . toString ( ) ) ;
6964 } ;
7065
66+ if ( ! mentorData ) return < div className = "p-4" > Loading...</ div > ;
67+
7168 return (
7269 < div className = "h-screen flex flex-col relative overflow-hidden" >
7370
@@ -98,7 +95,8 @@ const MentorInfoView = () => {
9895 < MentorInfoProfile
9996 nickname = { mentorData . nickname }
10097 name = { mentorData . organization . name }
101- role = { mentorData . organization . role }
98+ jobCategory = { mentorData . organization . jobCategory }
99+ detailedJob = { mentorData . organization . detailedJob }
102100 experience = { mentorData . organization . experience }
103101 count = { mentorData . count }
104102 image = { mentorData ?. image ?. filePath || "/assets/ringusprofile.png" }
@@ -109,13 +107,13 @@ const MentorInfoView = () => {
109107
110108 { /* 자기소개 */ }
111109 < MentorInfoBio
112- summary = { mentorData . introduction . summary }
113- bio = { mentorData . introduction . bio }
110+ title = { mentorData . introduction . title }
111+ content = { mentorData . introduction . content }
114112 />
115113
116114 { /* 선호 시간대 */ }
117115 < MentorInfoTime
118- availableDays = { mentorData . availableDays }
116+ days = { mentorData . timezone . days }
119117 startTime = { mentorData . timezone . startTime }
120118 endTime = { mentorData . timezone . endTime }
121119 />
0 commit comments