diff --git a/frontend/src/app/groups/[groupId]/join/ClientPage.tsx b/frontend/src/app/groups/[groupId]/join/ClientPage.tsx new file mode 100644 index 00000000..5ef10695 --- /dev/null +++ b/frontend/src/app/groups/[groupId]/join/ClientPage.tsx @@ -0,0 +1,88 @@ +'use client'; + +import { useState } from 'react'; +import { useRouter } from 'next/navigation'; +import { Button } from '@/components/ui/button'; + +interface Props { + groupId: string; +} + +export default function ClientPage({ groupId }: Props) { + const router = useRouter(); + const [context, setContext] = useState(''); + const [error, setError] = useState(null); + const [isSubmitting, setIsSubmitting] = useState(false); + + const handleSubmit = async (e: React.FormEvent) => { + e.preventDefault(); + setIsSubmitting(true); + setError(null); + + try { + const token = localStorage.getItem('accessToken'); + if (!token) { + setError('로그인이 필요합니다.'); + setIsSubmitting(false); + return; + } + + const response = await fetch(`http://localhost:8080/api/v1/groups/${groupId}`, { + method: 'POST', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json', + 'Authorization': `Bearer ${token}`, + }, + body: JSON.stringify({ context }), + }); + + const result = await response.json(); + + if (!response.ok) { + if (result.code === 'MA006') { + setError('이미 가입 신청된 회원입니다.'); + } else { + throw new Error(result.message || '모임 가입 신청에 실패했습니다.'); + } + return; + } + + alert('가입 신청이 완료되었습니다.'); + router.push(`/groups/${groupId}`); + } catch (error) { + setError(error instanceof Error ? error.message : '모임 가입 신청 중 오류가 발생했습니다.'); + } finally { + setIsSubmitting(false); + } + }; + + return ( +
+

모임 가입 신청

+
+