Skip to content

Commit

Permalink
Merge pull request #63 from Hana4Team/feat/#56
Browse files Browse the repository at this point in the history
[Feature/#56] ๋จธ๋‹ˆ๋ฐ•์Šค api ์—ฐ๊ฒฐ
  • Loading branch information
abcxj123 authored Jun 10, 2024
2 parents 3cc36e2 + 21eddac commit 9625399
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 21 deletions.
10 changes: 10 additions & 0 deletions src/apis/apiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { getCookie } from '../utils/cookie';
import { usersApi } from './interfaces/usersApi';
import { accountApi } from './interfaces/accountApi';
import {
AccountPwdCheckType,
AccountReqType,
AccountType,
OpenedDepositSavingReqType,
Expand Down Expand Up @@ -179,6 +180,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<TransactionHistoryType>({
Expand Down
4 changes: 4 additions & 0 deletions src/apis/interfaces/accountApi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
AccountPwdCheckType,
AccountReqType,
AccountType,
OpenedDepositSavingReqType,
Expand All @@ -7,6 +8,9 @@ import {

export interface accountApi {
getAccount(type: AccountReqType): Promise<AccountType[]>;
postAccountPasswordCheck(
reqData: AccountPwdCheckType
): Promise<{ message: string }>;
postOpendMoneyBox(
password: string,
productsId: number
Expand Down
46 changes: 25 additions & 21 deletions src/pages/moneyBox/Sending.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const Sending = () => {
receiveAccount: string;
};

const { data: accountData, isSuccess: querySuccess } = useQuery({
const accountQuery = useQuery({
queryKey: ['accounts'],
queryFn: () => {
const res = ApiClient.getInstance().getAccount({
Expand All @@ -42,6 +42,7 @@ export const Sending = () => {
});
return res;
},
enabled: false,
});

const { mutate: sending, isSuccess: mutateSuccess0 } = useMutation({
Expand Down Expand Up @@ -82,6 +83,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);
Expand Down Expand Up @@ -146,18 +158,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'),
{
Expand Down Expand Up @@ -205,35 +217,27 @@ 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;
useEffect(() => {
if (data.sendAccount) {
setPage(2);
} else {
setIsPwdCorrect(false);
setIsActive(false);
setRe(!re);
return false;
accountQuery.refetch();
}
};

useEffect(() => {
data.sendAccount && setPage(2);
}, []);

return (
<>
{showModal && (
<ChoiceMenu title='์ถœ๊ธˆ๊ณ„์ขŒ์„ ํƒ' onClose={() => showModalHandler()}>
<div className='flex flex-col'>
{accountData?.map((account, idx) => (
{accountQuery.data?.map((account, idx) => (
<AccountDetailItem
key={idx}
title={account.name}
Expand Down
4 changes: 4 additions & 0 deletions src/types/account.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ export type AccountReqType = {
savingsAccount: boolean;
moneyboxAccount: boolean;
};
export type AccountPwdCheckType = {
accountNumber: string;
password: string;
};
export type OpenedDepositSavingReqType = {
payment: number;
endDate: string;
Expand Down

0 comments on commit 9625399

Please sign in to comment.