diff --git a/packages/client/src/pages/nickname/index.tsx b/packages/client/src/pages/nickname/index.tsx index 0c77d343..f21f2e83 100644 --- a/packages/client/src/pages/nickname/index.tsx +++ b/packages/client/src/pages/nickname/index.tsx @@ -17,30 +17,31 @@ export default function Nickname() { const toast = toastController(); const [nickname, setNickname] = useState(''); - const handleNicknameSubmit = async (nickname: string) => { - const socket = getQuizSocket(); - const sid = await emitEventWithAck(socket, 'session', { - pinCode: pinCode, - nickname: nickname, - }); - if (!sid) { - toast.warning('방이 가득 찼습니다.'); - navigate(`/`); - } - setCookie('sid', sid); - socket.emit('participant notice', { pinCode: pinCode }); - navigate(`/quiz/wait/${pinCode}`); - }; + const handleNicknameSubmit = async (e: React.FormEvent) => { + e.preventDefault(); - const handleKeyDown = (e: React.KeyboardEvent) => { - if (e.key === 'Enter') { - handleNicknameSubmit(nickname); + const socket = getQuizSocket(); + try { + const sid = await emitEventWithAck(socket, 'session', { + pinCode: pinCode, + nickname: nickname, + }); + if (!sid) { + toast.warning('방이 가득 찼습니다.'); + navigate(`/`); + return; + } + setCookie('sid', sid); + socket.emit('participant notice', { pinCode: pinCode }); + navigate(`/quiz/wait/${pinCode}`); + } catch (error) { + toast.error('닉네임 등록 중 문제가 발생했습니다.'); } }; return (
-
+
-
+ ); }