From a48618f57b0aadc25d710adbc30c6cbe2b70f278 Mon Sep 17 00:00:00 2001 From: abcxj123 Date: Sat, 8 Jun 2024 18:20:14 +0900 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=EB=A8=B8=EB=8B=88=EB=B0=95?= =?UTF-8?q?=EC=8A=A4=202=EC=B0=A8=20api=20=EC=97=B0=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/apis/apiClient.ts | 15 +++++++++++- src/apis/interfaces/accountApi.ts | 9 ++++++- src/pages/moneyBox/Sending.tsx | 39 +++++++++++++++---------------- src/types/account.d.ts | 4 ++++ 4 files changed, 45 insertions(+), 22 deletions(-) diff --git a/src/apis/apiClient.ts b/src/apis/apiClient.ts index c280ce7..beb3e31 100644 --- a/src/apis/apiClient.ts +++ b/src/apis/apiClient.ts @@ -3,7 +3,11 @@ import { getCookie } from '../utils/cookie'; import { usersApi } from './interfaces/usersApi'; import { accountApi } from './interfaces/accountApi'; import { UserType, SavePointType, StepType } from '../types/users'; -import { AccountReqType, AccountType } from '../types/account'; +import { + AccountPwdCheckType, + AccountReqType, + AccountType, +} from '../types/account'; import { alarmApi } from './interfaces/alarmApi'; import { API_BASE_URL } from './url'; import { moneyBoxApi } from './interfaces/moneyBoxApi'; @@ -92,6 +96,15 @@ export class ApiClient return response.data; } + async postAccountPasswordCheck(reqData: AccountPwdCheckType) { + const response = await this.axiosInstance.request<{ message: string }>({ + method: 'post', + url: '/account/password', + data: reqData, + }); + return response.data; + } + //---------transaction--------- async getTransactionHistory(accountId: number, year: number, month: number) { const response = await this.axiosInstance.request({ diff --git a/src/apis/interfaces/accountApi.ts b/src/apis/interfaces/accountApi.ts index 8dccdbd..3bde8a7 100644 --- a/src/apis/interfaces/accountApi.ts +++ b/src/apis/interfaces/accountApi.ts @@ -1,5 +1,12 @@ -import { AccountReqType, AccountType } from '../../types/account'; +import { + AccountPwdCheckType, + AccountReqType, + AccountType, +} from '../../types/account'; export interface accountApi { getAccount(type: AccountReqType): Promise; + postAccountPasswordCheck( + reqData: AccountPwdCheckType + ): Promise<{ message: string }>; } diff --git a/src/pages/moneyBox/Sending.tsx b/src/pages/moneyBox/Sending.tsx index e101b4e..c7ca986 100644 --- a/src/pages/moneyBox/Sending.tsx +++ b/src/pages/moneyBox/Sending.tsx @@ -30,7 +30,7 @@ export const Sending = () => { receiveAccount: string; }; - const { data: accountData, isSuccess: querySuccess } = useQuery({ + const { data: accountData } = useQuery({ queryKey: ['accounts'], queryFn: () => { const res = ApiClient.getInstance().getAccount({ @@ -82,6 +82,17 @@ export const Sending = () => { }, }); + const { mutate: passwordCheck, data: passwordData } = useMutation({ + mutationKey: ['passwordCheck'], + mutationFn: (password: string) => { + const res = ApiClient.getInstance().postAccountPasswordCheck({ + accountNumber: data.sendAccount, + password: password, + }); + return res; + }, + }); + useEffect(() => { if (mutateSuccess0 || mutateSuccess1) { setPage(page + 1); @@ -146,18 +157,18 @@ export const Sending = () => { setIsActive(false); setShowModal2(false); return; - } else if (page === 4 && pwdCheck()) { + } else if (page === 4 && passwordData?.message === 'match') { if (data.sendAccount === data.receiveAccount) { sendingMoneyBox(); } else { - console.log( - Number(String(price).replaceAll(',', '')), - data.sendAccount, - data.receiveAccount - ); sending(); } return; + } else if (page === 4 && passwordData?.message === 'mismatch') { + setIsPwdCorrect(false); + setIsActive(false); + setRe(!re); + return; } else if (page === 5) { navigate('/moneyBox'), { @@ -205,25 +216,13 @@ export const Sending = () => { const checkPwdCondition = () => { if (pwdRef.current.map((p) => p?.value).join('').length === 4) { + passwordCheck(pwdRef.current.map((p) => p?.value).join('')); setIsActive(true); } else { setIsActive(false); } }; - const pwdCheck = () => { - // 실제 비밀번호와 비교하는 작업 필요 - if (pwdRef.current.map((p) => p?.value).join('') === '1234') { - setIsPwdCorrect(true); - return true; - } else { - setIsPwdCorrect(false); - setIsActive(false); - setRe(!re); - return false; - } - }; - useEffect(() => { data.sendAccount && setPage(2); }, []); diff --git a/src/types/account.d.ts b/src/types/account.d.ts index 84b413c..8bd3c9d 100644 --- a/src/types/account.d.ts +++ b/src/types/account.d.ts @@ -11,3 +11,7 @@ export type AccountReqType = { savingsAccount: boolean; moneyboxAccount: boolean; }; +export type AccountPwdCheckType = { + accountNumber: string; + password: string; +}; From 0d30a594956d96caca2e05ba5a5500478eb09c82 Mon Sep 17 00:00:00 2001 From: abcxj123 Date: Sat, 8 Jun 2024 18:34:36 +0900 Subject: [PATCH 2/2] =?UTF-8?q?feat:=20useQuery=20=EC=98=B5=EC=85=98=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/moneyBox/Sending.tsx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/pages/moneyBox/Sending.tsx b/src/pages/moneyBox/Sending.tsx index c7ca986..e36cbf7 100644 --- a/src/pages/moneyBox/Sending.tsx +++ b/src/pages/moneyBox/Sending.tsx @@ -30,7 +30,7 @@ export const Sending = () => { receiveAccount: string; }; - const { data: accountData } = useQuery({ + const accountQuery = useQuery({ queryKey: ['accounts'], queryFn: () => { const res = ApiClient.getInstance().getAccount({ @@ -42,6 +42,7 @@ export const Sending = () => { }); return res; }, + enabled: false, }); const { mutate: sending, isSuccess: mutateSuccess0 } = useMutation({ @@ -224,7 +225,11 @@ export const Sending = () => { }; useEffect(() => { - data.sendAccount && setPage(2); + if (data.sendAccount) { + setPage(2); + } else { + accountQuery.refetch(); + } }, []); return ( @@ -232,7 +237,7 @@ export const Sending = () => { {showModal && ( showModalHandler()}>
- {accountData?.map((account, idx) => ( + {accountQuery.data?.map((account, idx) => (