@@ -42,8 +42,12 @@ export default function Page2() {
4242 const newInputs = [ ...inputs ] ;
4343 newInputs [ index ] = { id : userId , displayName : userData . data || userId } ; // Store both id and display name
4444 setInputs ( newInputs ) ;
45- } catch ( error ) {
46- console . error ( `Error fetching user ${ userId } :` , error ) ;
45+ } catch ( error : unknown ) {
46+ let errorMessage = 'μ μ μλ μ€λ₯κ° λ°μνμ΅λλ€.' ;
47+ if ( error instanceof Error ) {
48+ errorMessage = error . message ;
49+ }
50+ console . error ( `Error fetching user ${ userId } :` , errorMessage ) ;
4751 const newInputs = [ ...inputs ] ;
4852 newInputs [ index ] = { id : userId , displayName : userId } ; // Fallback to just ID if fetch fails
4953 setInputs ( newInputs ) ;
@@ -90,10 +94,51 @@ export default function Page2() {
9094 } , 3000 ) ;
9195 } ;
9296
93- const handleSolveProblem = ( ) => {
94- console . log ( 'Inputs:' , inputs . map ( input => input . id ) ) ;
95- // You can add logic here to process the inputs before navigating
96- router . push ( '/page3' ) ;
97+ const handleSolveProblem = async ( ) => {
98+ // Step 1: Check if all inputs are filled
99+ const allInputsFilled = inputs . every ( input => input . id !== '' ) ;
100+ if ( ! allInputsFilled ) {
101+ alert ( 'λͺ¨λ νμ IDλ₯Ό μ±μμ£ΌμΈμ.' ) ;
102+ return ;
103+ }
104+
105+ // Step 2: Construct the JSON body
106+ const myId = id ; // id from useFormStore()
107+ const memberIds = inputs . slice ( 1 ) . map ( input => input . id ) ; // Exclude the first input (my_id)
108+
109+ const requestBody = {
110+ my_id : myId ,
111+ member_ids : memberIds ,
112+ } ;
113+
114+ console . log ( 'Request Body:' , requestBody ) ;
115+
116+ // Step 3: Make the POST request
117+ try {
118+ const response = await fetch ( '/api/v1/teams/create' , {
119+ method : 'POST' ,
120+ headers : {
121+ 'Content-Type' : 'application/json' ,
122+ } ,
123+ body : JSON . stringify ( requestBody ) ,
124+ } ) ;
125+
126+ if ( ! response . ok ) {
127+ const errorData = await response . json ( ) ;
128+ throw new Error ( `HTTP error! status: ${ response . status } , message: ${ errorData . detail || response . statusText } ` ) ;
129+ }
130+
131+ const responseData = await response . json ( ) ;
132+ console . log ( 'Team creation successful:' , responseData ) ;
133+ router . push ( '/page3' ) ; // Navigate to page3 on success
134+ } catch ( error : unknown ) {
135+ console . error ( 'Error creating team:' , error ) ;
136+ let errorMessage = 'μ μ μλ μ€λ₯κ° λ°μνμ΅λλ€.' ;
137+ if ( error instanceof Error ) {
138+ errorMessage = error . message ;
139+ }
140+ alert ( `ν μμ±μ μ€ν¨νμ΅λλ€: ${ errorMessage } ` ) ;
141+ }
97142 } ;
98143
99144 return (
0 commit comments