Skip to content

Commit

Permalink
Merge pull request #871 from KEEPER31337/feature/signUpApi_쿼리키_포맷_통일_…
Browse files Browse the repository at this point in the history
…#863

Feature/sign up api 쿼리키 포맷 통일 #863
  • Loading branch information
publdaze authored Jan 18, 2024
2 parents 2c2edbb + e3ac143 commit 7e941a5
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
23 changes: 14 additions & 9 deletions src/api/signUpApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import axios from 'axios';
import { SignUpDuplication, SignUpInfo } from './dto';

export const signUpKeys = {
idDuplication: (loginId: string) => ['sighUp', 'duplication', 'loginId', loginId] as const,
emailDuplication: (email: string) => ['sighUp', 'duplication', 'email', email] as const,
studentIdDuplication: (studentId: string) => ['sighUp', 'duplication', 'studentId', studentId] as const,
base: ['sighUp'] as const,
duplication: () => [...signUpKeys.base, 'exists'] as const,
loginIdDuplication: (params: { loginId: string }) => [...signUpKeys.duplication(), 'loginId', params] as const,
emailDuplication: (params: { email: string }) => [...signUpKeys.duplication(), 'email', params] as const,
studentIdDuplication: (params: { studentId: string }) => [...signUpKeys.duplication(), 'studentId', params] as const,
};

const useSignUpMutation = () => {
Expand All @@ -21,21 +23,24 @@ const useEmailAuthMutation = () => {
};

const useCheckLoginIdDuplicationQuery = ({ loginId, enabled }: { loginId: string; enabled: boolean }) => {
const fetcher = () => axios.get('/sign-up/exists/login-id', { params: { loginId } }).then(({ data }) => data);
const params = { loginId };
const fetcher = () => axios.get('/sign-up/exists/login-id', { params }).then(({ data }) => data);

return useQuery<SignUpDuplication>(signUpKeys.idDuplication(loginId), fetcher, { enabled });
return useQuery<SignUpDuplication>(signUpKeys.loginIdDuplication(params), fetcher, { enabled });
};

const useCheckEmailDuplicationQuery = ({ email, enabled }: { email: string; enabled: boolean }) => {
const fetcher = () => axios.get('/sign-up/exists/email', { params: { email } }).then(({ data }) => data);
const params = { email };
const fetcher = () => axios.get('/sign-up/exists/email', { params }).then(({ data }) => data);

return useQuery<SignUpDuplication>(signUpKeys.emailDuplication(email), fetcher, { enabled });
return useQuery<SignUpDuplication>(signUpKeys.emailDuplication(params), fetcher, { enabled });
};

const useCheckStudentIdDuplicationQuery = ({ studentId, enabled }: { studentId: string; enabled: boolean }) => {
const fetcher = () => axios.get('/sign-up/exists/student-id', { params: { studentId } }).then(({ data }) => data);
const params = { studentId };
const fetcher = () => axios.get('/sign-up/exists/student-id', { params }).then(({ data }) => data);

return useQuery<SignUpDuplication>(signUpKeys.studentIdDuplication(studentId), fetcher, { enabled });
return useQuery<SignUpDuplication>(signUpKeys.studentIdDuplication(params), fetcher, { enabled });
};

export {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Profile/Modal/EditAccountModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ const EditPasswordSection = () => {
rules={{
required: COMMON.error.required,
validate: {
confirmMatchPassward: (value) => {
confirmMatchPassword: (value) => {
if (getValues('newPassword') !== value) return CONFIRM_PASSWORD_MSG.error.mismatch;
setPasswordConfirmSuccessMsg(CONFIRM_PASSWORD_MSG.success.match);
return undefined;
Expand Down
5 changes: 3 additions & 2 deletions src/pages/SignUp/Section/SignUpFirstInputSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ interface SignUpFirstInputSectionProps {
}

const SignUpFirstInputSection = ({ setCurrentStep }: SignUpFirstInputSectionProps) => {
// REVIEW useForm 사용하는데 별도의 state가 필요한 지 점검 필요
const [loginIdState, setLoginIdState] = useState('');
const [checkLoginIdDuplicateEnabled, setCheckLoginIdDuplicateEnabled] = useState(false);
const [passwordConfirmSuccessMsg, setPasswordConfirmSuccessMsg] = useState<string>('');
Expand Down Expand Up @@ -62,7 +63,7 @@ const SignUpFirstInputSection = ({ setCurrentStep }: SignUpFirstInputSectionProp

if (isLoginIdDuplicate.duplicate === false) {
setCheckLoginIdDuplicateEnabled(false);
queryClient.setQueryData(signUpKeys.idDuplication(loginIdState), undefined);
queryClient.setQueryData(signUpKeys.loginIdDuplication({ loginId: loginIdState }), undefined);
}
}, [watch('loginId')]);

Expand Down Expand Up @@ -139,7 +140,7 @@ const SignUpFirstInputSection = ({ setCurrentStep }: SignUpFirstInputSectionProp
rules={{
required: COMMON.error.required,
validate: {
confirmMatchPassward: (value) => {
confirmMatchPassword: (value) => {
if (getValues('password') !== value) return CONFIRM_PASSWORD_MSG.error.mismatch;
setPasswordConfirmSuccessMsg(CONFIRM_PASSWORD_MSG.success.match);
return undefined;
Expand Down
3 changes: 2 additions & 1 deletion src/pages/SignUp/Section/SignUpSecondInputSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ interface SignUpFirstInputSectionProps {
}

const SignUpSecondInputSection = ({ setCurrentStep }: SignUpFirstInputSectionProps) => {
// REVIEW useForm 사용하는데 별도의 state가 필요한 지 점검 필요
const [studentIdState, setStudentIdState] = useState('');
const [checkStudentIdDuplicateEnabled, setCheckStudentIdDuplicateEnabled] = useState(false);
const setSignUpPageState = useSetRecoilState(signUpPageState);
Expand Down Expand Up @@ -68,7 +69,7 @@ const SignUpSecondInputSection = ({ setCurrentStep }: SignUpFirstInputSectionPro

if (isStudentIdDuplicate.duplicate === false) {
setCheckStudentIdDuplicateEnabled(false);
queryClient.setQueryData(signUpKeys.studentIdDuplication(studentIdState), undefined);
queryClient.setQueryData(signUpKeys.studentIdDuplication({ studentId: studentIdState }), undefined);
}
}, [watch('studentId')]);

Expand Down

0 comments on commit 7e941a5

Please sign in to comment.