@@ -8,6 +8,15 @@ import { useFormStore } from '../../store/formStore';
88import { authenticatedFetch } from '../../lib/api' ;
99import { useNavigationStore } from '../../store/navigationStore' ;
1010
11+ interface TeamMember {
12+ id : number ;
13+ user_id : number ;
14+ name : string ;
15+ email : string ;
16+ github_url ?: string ;
17+ linkedin_url ?: string ;
18+ }
19+
1120const questions = [
1221 { category : '1' , keyword : '관심사' , problem : '사용자의 관심사를 맞춰주세요. 예: 기술, 예술, 환경 등' } ,
1322 { category : '2' , keyword : '취미' , problem : '사용자의 취미를 맞춰주세요. 예: 등산, 독서, 요리 등' } ,
@@ -35,6 +44,30 @@ export default function Page3() {
3544
3645 const initializeChallenge = async ( ) => {
3746 if ( ! question && id && teamId ) {
47+ // Fetch team members to get their names
48+ let members : TeamMember [ ] = [ ] ;
49+ try {
50+ const teamResponse = await authenticatedFetch ( '/api/v1/teams/me' , {
51+ method : 'GET' ,
52+ headers : { 'Content-Type' : 'application/json' } ,
53+ } ) ;
54+ if ( teamResponse . ok ) {
55+ const teamData = await teamResponse . json ( ) ;
56+ if ( teamData && teamData . members ) {
57+ members = teamData . members ;
58+ }
59+ } else {
60+ console . error ( 'Failed to fetch team data' ) ;
61+ }
62+ } catch ( error ) {
63+ console . error ( 'Error fetching team members:' , error ) ;
64+ }
65+
66+ const findMemberName = ( userId : number ) : string => {
67+ const member = members . find ( ( m ) => m . user_id === userId ) ;
68+ return member ? member . name : String ( userId ) ; // Fallback to user_id as string
69+ } ;
70+
3871 // 1. Try to restore challenge from localStorage
3972 const savedChallengeJSON = localStorage . getItem ( CHALLENGE_DATA_KEY ) ;
4073 if ( savedChallengeJSON ) {
@@ -44,7 +77,8 @@ export default function Page3() {
4477 if ( savedChallenge . category && savedChallenge . assigned_challenge_id ) {
4578 const questionInfo = questions . find ( ( q ) => q . category === String ( savedChallenge . category ) ) ;
4679 if ( questionInfo ) {
47- setQuestion ( questionInfo . problem ) ;
80+ const memberName = findMemberName ( savedChallenge . user_id ) ;
81+ setQuestion ( [ memberName , questionInfo . problem ] . join ( ' ' ) ) ;
4882 setChallengeId ( savedChallenge . assigned_challenge_id ) ;
4983 return ; // Challenge successfully restored
5084 }
@@ -61,7 +95,7 @@ export default function Page3() {
6195 const assignResponse = await authenticatedFetch ( '/api/v1/challenges/assign' , {
6296 method : 'POST' ,
6397 headers : { 'Content-Type' : 'application/json' } ,
64- body : JSON . stringify ( { team_id : teamId , my_id : id , members_ids : memberIds } ) ,
98+ body : JSON . stringify ( { team_id : teamId , my_id : id , members_ids : memberIds . filter ( ( memberId ) => memberId !== Number ( id ) ) } ) ,
6599 } ) ;
66100
67101 if ( ! assignResponse . ok ) {
@@ -76,6 +110,7 @@ export default function Page3() {
76110 const dataToSave = {
77111 category : String ( newChallengeData . my_assigned . category ) ,
78112 assigned_challenge_id : newChallengeData . my_assigned . assigned_challenge_id ,
113+ user_id : newChallengeData . my_assigned . user_id ,
79114 } ;
80115
81116 // Save to localStorage for future restoration
@@ -85,7 +120,8 @@ export default function Page3() {
85120 // Set state from the new challenge data
86121 const questionInfo = questions . find ( ( q ) => q . category === dataToSave . category ) ;
87122 if ( questionInfo ) {
88- setQuestion ( questionInfo . problem ) ;
123+ const memberName = findMemberName ( dataToSave . user_id ) ;
124+ setQuestion ( [ memberName , questionInfo . problem ] . join ( ' ' ) ) ;
89125 setChallengeId ( dataToSave . assigned_challenge_id ) ;
90126 }
91127 } else {
0 commit comments