diff --git a/src/apis/auth/index.ts b/src/apis/auth/index.ts index a73ba0e..89d50f2 100644 --- a/src/apis/auth/index.ts +++ b/src/apis/auth/index.ts @@ -54,3 +54,12 @@ export const deleteMyAccount = async () => { }); return response; }; + +export const getSignupPrefill = async (): Promise<{ name: string } | null> => { + try { + const response = await apiClient.get<{ name: string }>('users/signup/prefill'); + return response; + } catch { + return null; + } +}; diff --git a/src/pages/Auth/SignUp/StudentIdStep.tsx b/src/pages/Auth/SignUp/StudentIdStep.tsx index 99ec58f..b91a7f8 100644 --- a/src/pages/Auth/SignUp/StudentIdStep.tsx +++ b/src/pages/Auth/SignUp/StudentIdStep.tsx @@ -2,16 +2,24 @@ import { useState } from 'react'; import { useNavigate } from 'react-router-dom'; import { useSignupStore } from '@/stores/signupStore'; import StepLayout from './components/StepLayout'; +import { useSignupPrefill } from './hooks/useSignupPrefill'; function StudentIdStep() { const navigate = useNavigate(); const { studentId: savedStudentId, update } = useSignupStore(); const [studentId, setStudentId] = useState(savedStudentId ?? ''); + const { data: prefill, isPending } = useSignupPrefill(); const handleNext = () => { update({ studentId }); - navigate('/signup/name'); + + if (prefill?.name) { + update({ name: prefill.name }); + navigate('/signup/confirm'); + } else { + navigate('/signup/name'); + } }; return ( @@ -19,7 +27,7 @@ function StudentIdStep() { title="학번을 입력해주세요" description={`정확한 답변을 하지 않으면\n불이익이 발생할 수 있습니다.`} onNext={handleNext} - nextDisabled={!studentId.trim()} + nextDisabled={!studentId.trim() || isPending} > { + return useQuery({ + queryKey: ['signup', 'prefill'], + queryFn: getSignupPrefill, + }); +};