Skip to content

Commit 17ad2fc

Browse files
committed
feat(getcloser): implement /challenges/redeem API calls
1 parent 854ff40 commit 17ad2fc

1 file changed

Lines changed: 20 additions & 2 deletions

File tree

  • getcloser/frontend/src/app/page4

โ€Žgetcloser/frontend/src/app/page4/page.tsxโ€Ž

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@ import { useRouter } from 'next/navigation';
44
import { Button } from '@/components/ui/button';
55
import React, { useEffect, useState } from 'react';
66
import Image from 'next/image';
7+
import { authenticatedFetch } from '../../lib/api';
8+
import { useFormStore } from '../../store/formStore';
79

810
export 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

Comments
ย (0)