-
Notifications
You must be signed in to change notification settings - Fork 2
refactor: 중복확인 로직 useMutation으로 변경 #394
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
6a6f536
203e4c5
9b2a3bb
1352988
e3f3814
bb698a8
4f6edd1
c018d31
b7a8da8
e4646d4
45e81d5
7bee9f1
85ce73c
404d75d
8a07a6d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,5 +1,4 @@ | ||||||||||||||||||
| import { userMutations } from '@apis/user/user-mutations'; | ||||||||||||||||||
| import { userQueries } from '@apis/user/user-queries'; | ||||||||||||||||||
| import Button from '@components/button/button/button'; | ||||||||||||||||||
| import Input from '@components/input/input'; | ||||||||||||||||||
| import { zodResolver } from '@hookform/resolvers/zod'; | ||||||||||||||||||
|
|
@@ -21,7 +20,7 @@ import { | |||||||||||||||||
| } from '@pages/sign-up/constants/validation'; | ||||||||||||||||||
| import { type UserInfoFormValues, UserInfoSchema } from '@pages/sign-up/schema/validation-schema'; | ||||||||||||||||||
| import type { NicknameStatus } from '@pages/sign-up/types/nickname-types'; | ||||||||||||||||||
| import { useMutation, useQuery } from '@tanstack/react-query'; | ||||||||||||||||||
| import { useMutation } from '@tanstack/react-query'; | ||||||||||||||||||
| import { useEffect, useState } from 'react'; | ||||||||||||||||||
| import { useForm } from 'react-hook-form'; | ||||||||||||||||||
| import type { postUserInfoRequest } from '@/shared/types/user-types'; | ||||||||||||||||||
|
|
@@ -52,7 +51,7 @@ const SignupStep = () => { | |||||||||||||||||
|
|
||||||||||||||||||
| const userInfoMutation = useMutation(userMutations.USER_INFO()); | ||||||||||||||||||
| const agreementInfoMutaion = useMutation(userMutations.AGREEMENT_INFO()); | ||||||||||||||||||
| const { refetch: refetchNicknameCheck } = useQuery(userQueries.NICKNAME_CHECK(nicknameValue)); | ||||||||||||||||||
| const { mutateAsync: checkNickname } = useMutation(userMutations.NICKNAME_CHECK()); | ||||||||||||||||||
|
|
||||||||||||||||||
| const informationLength = informationValue.length ?? 0; | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
@@ -103,8 +102,8 @@ const SignupStep = () => { | |||||||||||||||||
| if (!isNicknameValid) return; | ||||||||||||||||||
| setNicknameStatus('checking'); | ||||||||||||||||||
| try { | ||||||||||||||||||
| const { data } = await refetchNicknameCheck(); | ||||||||||||||||||
| setNicknameStatus(data ? 'available' : 'duplicate'); | ||||||||||||||||||
| const available = await checkNickname({ nickname: nicknameValue }); | ||||||||||||||||||
| setNicknameStatus(available ? 'available' : 'duplicate'); | ||||||||||||||||||
| } catch { | ||||||||||||||||||
|
Comment on lines
+105
to
107
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 경합(race) 조건: 응답/입력 불일치 시 잘못된 상태 표시 가능 요청 당시 닉네임을 캡처해 비교하세요. 공백 트림도 권장. - const available = await checkNickname({ nickname: nicknameValue });
- setNicknameStatus(available ? 'available' : 'duplicate');
+ const requested = nicknameValue.trim();
+ const available = await checkNickname({ nickname: requested });
+ if (requested !== (watch('nickname') ?? '').trim()) return;
+ setNicknameStatus(available ? 'available' : 'duplicate');📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||
| setNicknameStatus('idle'); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
경합(race) 조건: 응답 도착 시 닉네임이 바뀐 경우 오표시 가능
요청 시점의 닉네임과 응답 시점의 현재 값이 다르면 상태 업데이트를 스킵해야 합니다. 또한 공백은 트림해서 전송을 권장합니다.
📝 Committable suggestion
🤖 Prompt for AI Agents