@@ -4,8 +4,12 @@ import { useRouter } from 'next/navigation';
44import { Button } from '@/components/ui/button' ;
55import React , { useEffect , useState } from 'react' ;
66import Image from 'next/image' ;
7+ import { authenticatedFetch } from '../../lib/api' ;
8+ import { useFormStore } from '../../store/formStore' ;
79
810export default function Page4 ( ) {
11+ const { id } = useFormStore ( ) ;
12+
913 const [ result , setResult ] = useState < string > ( '' ) ;
1014 const [ clickCount , setClickCount ] = useState < number > ( 0 ) ;
1115 const [ lastClickTime , setLastClickTime ] = useState < number > ( 0 ) ;
@@ -20,7 +24,7 @@ export default function Page4() {
2024 router . push ( '/page2' ) ;
2125 } ;
2226
23- const handleSuccessClick = ( ) => {
27+ const handleSuccessClick = async ( ) => {
2428 const currentTime = new Date ( ) . getTime ( ) ;
2529 if ( currentTime - lastClickTime < 2000 ) { // 2 seconds window
2630 setClickCount ( prevCount => prevCount + 1 ) ;
@@ -30,9 +34,23 @@ export default function Page4() {
3034 setLastClickTime ( currentTime ) ;
3135
3236 if ( clickCount + 1 >= 5 ) { // Check if this click makes it 5
33- alert ( "수령 완료!" ) ;
3437 setClickCount ( 0 ) ; // Reset after alert
3538 setLastClickTime ( 0 ) ; // Reset time as well
39+
40+ const response = await authenticatedFetch ( '/api/v1/challenges/redeem' , {
41+ method : 'POST' ,
42+ headers : {
43+ 'Content-Type' : 'application/json' ,
44+ } ,
45+ body : JSON . stringify ( { user_id : id } ) ,
46+ } ) ;
47+
48+ if ( ! response . ok ) {
49+ throw new Error ( `HTTP error! status: ${ response . status } ` ) ;
50+ }
51+
52+ alert ( "수령 완료!" ) ;
53+
3654 }
3755 } ;
3856
0 commit comments