Skip to content

Commit 6af4fc7

Browse files
authored
Merge pull request #213 from Pseudo-Lab/feat/getcloser-frontend-redeem
Feat/getcloser frontend redeem
2 parents e513f91 + a2d806f commit 6af4fc7

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

getcloser/frontend/src/app/page2/page.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
'use client';
22

3-
import { authenticatedFetch } from '../../lib/api';
3+
import Cookies from 'js-cookie';
44
import React, { useState, useEffect, useRef, useCallback } from 'react';
55
import Link from 'next/link';
66
import { useRouter } from 'next/navigation';
77
import { Button } from '@/components/ui/button';
88
import { Input } from '@/components/ui/input';
99
import { Label } from '@/components/ui/label';
10-
import { useFormStore } from '../../store/formStore';
1110
import Modal from '@/components/Modal';
12-
import Cookies from 'js-cookie';
11+
import { authenticatedFetch } from '../../lib/api';
12+
import { useFormStore } from '../../store/formStore';
1313

1414
export default function Page2() {
1515
const { id, setTeamId, setMemberIds } = useFormStore();

getcloser/frontend/src/app/page3/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import { useRouter } from 'next/navigation';
55
import { Button } from '@/components/ui/button';
66
import { Label } from '@/components/ui/label';
77
import { Textarea } from '@/components/ui/textarea';
8+
import React, { useEffect } from 'react';
89
import { useFormStore } from '../../store/formStore';
910
import { authenticatedFetch } from '../../lib/api';
10-
import React, { useEffect } from 'react'; // Import useEffect
1111

1212
export default function Page3() {
1313
const { question, answer, setAnswer, id, teamId, memberIds } = useFormStore(); // Destructure new state

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)