Skip to content
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

Feature/sign up api 쿼리키 포맷 통일 #863 #871

Merged
merged 3 commits into from
Jan 18, 2024
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
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) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍😆

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
Loading