Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/apis/auth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};
12 changes: 10 additions & 2 deletions src/pages/Auth/SignUp/StudentIdStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,32 @@ 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 (
<StepLayout
title="학번을 입력해주세요"
description={`정확한 답변을 하지 않으면\n불이익이 발생할 수 있습니다.`}
onNext={handleNext}
nextDisabled={!studentId.trim()}
nextDisabled={!studentId.trim() || isPending}
>
<input
type="text"
Expand Down
9 changes: 9 additions & 0 deletions src/pages/Auth/SignUp/hooks/useSignupPrefill.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { useQuery } from '@tanstack/react-query';
import { getSignupPrefill } from '@/apis/auth';

export const useSignupPrefill = () => {
return useQuery({
queryKey: ['signup', 'prefill'],
queryFn: getSignupPrefill,
});
};