Skip to content

Commit

Permalink
[Fix]현금 api요청시 money 타입 변동
Browse files Browse the repository at this point in the history
money의 타입을 number->string으로 변동
Issues #70
  • Loading branch information
김병현 authored and 김병현 committed Sep 13, 2023
1 parent 4ab5ed0 commit 95aabf0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
16 changes: 8 additions & 8 deletions client/src/components/Profile/cashModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ const CashModal: React.FC<CashModalProps> = ({ onClose }) => {

const dispatch = useDispatch();
const moneyId = useSelector((state: RootState) => state.cash.moneyId);
const moneyAmount = useSelector((state: RootState) => state.cash.moneyAmount) || 0;
const moneyAmount = useSelector((state: RootState) => state.cash.moneyAmount) || '0';

const createCashMutation = useCreateCash();
const { data: cashData, isLoading } = useGetCash(moneyId);
const updateCashMutation = useResetCash();

const [cashInput, setCashInput] = useState<number>(0);
const [initialAmount, setInitialAmount] = useState<number>(0); // 현금 생성을 위한 상태 변수
const [cashInput, setCashInput] = useState<string>('0');
const [initialAmount, setInitialAmount] = useState<string>('0'); // 현금 생성을 위한 상태 변수

// 현금 생성 및 cashId 전역 저장
const handleCreateCash = () => {
Expand All @@ -42,7 +42,7 @@ const CashModal: React.FC<CashModalProps> = ({ onClose }) => {
const handleCashReset = () => {
if (moneyId) {
const numericCashId = parseInt(moneyId, 10); // cashId를 숫자로 변환
const numericCashAmount = Number(cashInput); // cashInput을 숫자로 변환
const numericCashAmount =cashInput; // cashInput을 숫자로 변환
updateCashMutation.mutate({ moneyId: numericCashId, money: numericCashAmount }, {
onSuccess: () => {
dispatch(setMoneyAmount(numericCashAmount)); // 현금 금액을 입력한 금액으로 리셋
Expand All @@ -63,9 +63,9 @@ const CashModal: React.FC<CashModalProps> = ({ onClose }) => {
{/* 현금 생성 입력창 및 버튼 추가 */}
<div>
<CashCreationInput
type="number"
type="string"
value={initialAmount}
onChange={e => setInitialAmount(Number(e.target.value))}
onChange={e => setInitialAmount(e.target.value)}
placeholder={cashCreationPlaceholder}
/>
<CreateCashButton onClick={handleCreateCash}>{createCashButtonText}</CreateCashButton>
Expand All @@ -74,9 +74,9 @@ const CashModal: React.FC<CashModalProps> = ({ onClose }) => {
<p>현재 현금: {isLoading ? 'Loading...' : moneyAmount.toLocaleString()}</p>
<div>
<CashInput
type="number"
type="string"
value={cashInput}
onChange={e => setCashInput(Number(e.target.value))}
onChange={e => setCashInput(e.target.value)}
placeholder={cashInputPlaceholder}
/>
<ReceiveButton onClick={handleCashReset}>{resetButtonText}</ReceiveButton>
Expand Down
7 changes: 4 additions & 3 deletions client/src/hooks/useCash.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { useQuery, useMutation } from 'react-query';
import axios from 'axios';

const BASE_URL = 'http://ec2-13-125-246-160.ap-northeast-2.compute.amazonaws.com';
const BASE_URL = 'http://ec2-13-125-246-160.ap-northeast-2.compute.amazonaws.com:8080';

const getAuthHeader = () => {
const authToken = localStorage.getItem('authToken');
return {
'Authorization': `${authToken}`
};

};

export const useCreateCash = () => {
return useMutation((initialAmount: number) => axios.post(`${BASE_URL}/cash`, { "money": initialAmount }, {
return useMutation((initialAmount: string) => axios.post(`${BASE_URL}/cash`, { "money": initialAmount }, {
headers: getAuthHeader()
}));
}
Expand Down Expand Up @@ -41,7 +42,7 @@ export const useGetCash = (moneyId: string | null) => {
}

export const useResetCash = () => {
return useMutation((data: { moneyId: number, money: number }) => axios.patch(`${BASE_URL}/cash/${data.moneyId}`, { "money": data.money }, {
return useMutation((data: { moneyId: number, money: string }) => axios.patch(`${BASE_URL}/cash/${data.moneyId}`, { "money": data.money }, {
headers: getAuthHeader()
}));
}

0 comments on commit 95aabf0

Please sign in to comment.