Skip to content

Commit

Permalink
Revert "Merge pull request #180 from Make-A-Wish-Sopt/feature/175-use…
Browse files Browse the repository at this point in the history
…r/verifyAccount"

This reverts commit 35facfc, reversing
changes made to 05c0790.
  • Loading branch information
Me1e committed Jan 8, 2024
1 parent 35facfc commit 575c379
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 92 deletions.
24 changes: 1 addition & 23 deletions api/user.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { BANK_LIST } from '@/constant/bankList';
import { getAccessToken } from '@/utils/common/token';
import { client } from './common/axios';
import { API_VERSION_01, PATH_USER } from './path';
import { UseFormReturn } from 'react-hook-form';

import { DefaultResponseType, UserAccountDataResponseType } from '@/types/api/response';
import { AccountInfoType, WishesDataInputType } from '@/types/wishesType';
import { WishesDataInputType } from '@/types/wishesType';

const ACCESS_TOKEN = getAccessToken();

Expand Down Expand Up @@ -55,24 +54,3 @@ export const deleteUserInfo = async () => {

return data;
};

export const postVerifyAccount = async (accountInfo: AccountInfoType) => {
const bankCode = BANK_LIST.find((bank) => bank.name === accountInfo.bank)?.bankCode;

const response = await client.post<DefaultResponseType<number>>(
`${API_VERSION_01}${PATH_USER.ACCOUNT_VERIFY}`,
{
bankCode,
accountNumber: accountInfo.account,
name: accountInfo.name,
},
{
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${ACCESS_TOKEN}`,
},
},
);

return response.data;
};
53 changes: 5 additions & 48 deletions components/Common/Modal/BankInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import { StyledBtnBox } from '../Button';
import { StyledBox } from '../Box';
import AlertTextBox from '../AlertTextBox';
import { validation } from '@/validation/input';
import { usePostVerifyAccount } from '@/hooks/queries/user';
import { useEffect, useState } from 'react';

interface BankInputProps {
methods: UseFormReturn<WishesDataInputType, any, undefined>;
Expand All @@ -26,32 +24,6 @@ interface BankInputProps {
export default function BankInput(props: BankInputProps) {
const { methods } = props;
const { isOpen, handleToggle } = useModal();
const [btnState, setBtnState] = useState(false);

const { handleVerifyAccount, isSuccess, isReady, isAbused } = usePostVerifyAccount({
name: methods.getValues('name'),
bank: methods.getValues('bank'),
account: methods.getValues('account'),
});

const handleClick = () => {
if (!btnState) return;
handleVerifyAccount();
};

useEffect(() => {
if (
methods.watch('name') !== '' &&
methods.watch('bank') !== '' &&
methods.watch('account') !== '' &&
!isSuccess &&
!isAbused
) {
setBtnState(true);
} else {
setBtnState(false);
}
}, [methods.watch(), isSuccess, isAbused]); // isSuccess 추가 안해도 되네? 왜 이러지..

return (
<Styled.Container>
Expand All @@ -60,19 +32,14 @@ export default function BankInput(props: BankInputProps) {
</Styled.GuideBox>

<Styled.ItemWrapper>
<Input
placeholder="예금주명"
register={methods.register('name')}
disabled={isSuccess || isAbused}
/>
<Input placeholder="예금주명" register={methods.register('name')} />
</Styled.ItemWrapper>

<Styled.ItemWrapper onClick={handleToggle}>
<Input
boxType="inputBox--large"
placeholder="은행 선택"
register={methods.register('bank')}
disabled={isSuccess || isAbused}
>
<Image src={ArrowDownIc} alt="더 보기" />
</Input>
Expand All @@ -85,27 +52,17 @@ export default function BankInput(props: BankInputProps) {
inputType="number"
placeholder="계좌번호를 입력해주세요"
register={methods.register('account')}
disabled={isSuccess || isAbused}
/>
<Styled.AccountAuthButton
className={!btnState ? 'gray1_white' : 'mainBlue_white'}
onClick={handleClick}
>
<Styled.AccountAuthButton className="mainBlue_white">
{'계좌번호 확인'}
</Styled.AccountAuthButton>
</Styled.InputWrapper>
{validation.isIncludeHyphen(methods.watch('account')) && (
<AlertTextBox>{'(-)없이 숫자만 입력해주세요'}</AlertTextBox>
)}
{isReady && (
<AlertTextBox alertSuccess={isSuccess}>
{isSuccess
? '정상 계좌입니다'
: isAbused
? '4회 이상부터는 이용할 수 없습니다'
: '존재하지 않는 계좌번호입니다'}
</AlertTextBox>
)}

{/* 조건 기능 추가 */}
{/* {<AlertTextBox>{true ? '정상 계좌입니다' : '존재하지 않는 계좌번호입니다'}</AlertTextBox>} */}
</Styled.ItemWrapper>

{isOpen && (
Expand Down
2 changes: 1 addition & 1 deletion components/Wishes/WishesForm/BankInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export default function BankInfo(props: BankInfoProps) {
<InputContainer title="계좌번호 입력하기">
<BankInput methods={methods} />

<InputContainer title="휴대폰번호 입력하기">
<InputContainer title="전화번호 입력하기">
<Input
inputType="number"
placeholder="(-)없이 숫자만 입력해주세요"
Expand Down
21 changes: 2 additions & 19 deletions hooks/queries/user.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getUserAccount, postVerifyAccount, putUserAccount } from '@/api/user';
import { getUserAccount, putUserAccount } from '@/api/user';
import { QUERY_KEY } from '@/constant/queryKey';
import { AccountInfoType, WishesDataInputType } from '@/types/wishesType';
import { WishesDataInputType } from '@/types/wishesType';
import router from 'next/router';
import { UseFormReturn } from 'react-hook-form';
import { useMutation, useQuery } from 'react-query';
Expand All @@ -20,20 +20,3 @@ export function useGetUserAccount() {

return { userAccountData };
}

export function usePostVerifyAccount(accountInfo: AccountInfoType) {
const { mutate, data } = useMutation(() => postVerifyAccount(accountInfo));

/**
* 틀린 경우와 맞은 경우 둘 다 200으로 응답이 오고, success 값을 다르게 받음.
* (팝빌에서 예외처리 없이 받은 에러는(ex. 503) 200으로 응답이 오지 않지만, success 값은 false로 옴.)
* data는 일반적으로 null 이고, success가 false일 때 틀린 횟수를 data에 받아옴.
* 이 횟수가 4 이상이면, 잠금 처리.
*/
return {
handleVerifyAccount: mutate,
isSuccess: data ? data.success : false,
isReady: data !== undefined,
isAbused: data ? (data.data ? data.data >= 4 : false) : false,
};
}
2 changes: 1 addition & 1 deletion types/common/box/boxStyleType.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type BoxTypes = 'half' | 'large' | 'image' | 'custom';
export type BoxTypes = 'half' | 'large' | 'iamge' | 'custom';
export type InputBoxTypes = 'inputBox--half' | 'inputBox--large' | 'inputBox--calendar';
export type BtnBoxTypes = 'btn--half' | 'btn--large' | 'btn--custom';
export type ImageBoxTypes = 'imageBox--textarea' | 'imageBox--image';
Expand Down

0 comments on commit 575c379

Please sign in to comment.