-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
89db445
commit d8bc72e
Showing
8 changed files
with
127 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// input에 숫자가 아닌 부분을 찾아서 제거 | ||
// 숫자 단위에 , 가 필요하면 input value값에 .toLocaleString() | ||
export const numeric = (input: string) => { | ||
return Number(input.replace(/[^0-9]/g, '')); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,93 @@ | ||
import React from 'react' | ||
import ExpensesAmount from './ExpensesAmount' | ||
import { styled } from 'styled-components' | ||
import ExpensesTag from './ExpensesTag' | ||
import DepositTag from './DepositTag' | ||
import React, { useState } from 'react'; | ||
import ExpensesAmount from './ExpensesAmount'; | ||
import ExpensesTag from './ExpensesTag'; | ||
import DepositTag from './DepositTag'; | ||
import PaymentMethod from './PaymentMethod'; | ||
import { numeric } from '../common/Numeric'; | ||
import { createdExpense } from '@/lib/api/Api'; | ||
import { styled } from 'styled-components'; | ||
|
||
function Modal() { | ||
const [type, setType] = useState<string | undefined>(''); | ||
const [amount, setAmount] = useState(0); | ||
const [tag, setTag] = useState(''); | ||
const [paymentMethod, setPaymentMethod] = useState(''); | ||
|
||
const handleButtonClick = ( | ||
e: React.MouseEvent<HTMLButtonElement, MouseEvent>, | ||
) => { | ||
const formType = e.currentTarget.dataset.formType; | ||
setType(formType); | ||
}; | ||
|
||
const handleAmountChange = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
const input = e.target.value; | ||
setAmount(numeric(input)); | ||
}; | ||
|
||
const handleTagChange = (tags: string) => { | ||
setTag(tags); | ||
}; | ||
|
||
const handleMethodChange = (tags: string) => { | ||
setPaymentMethod(tags); | ||
}; | ||
|
||
const handleSubmit = async () => { | ||
const data = { | ||
amount, | ||
category: tag, | ||
date: new Date().toISOString(), | ||
}; | ||
await createdExpense(data); | ||
}; | ||
|
||
return ( | ||
<Container> | ||
<ExpensesAmount /> | ||
<ExpensesTag /> | ||
<DepositTag /> | ||
<ButtonCotainer> | ||
<DepositButton data-form-type="deposit" onClick={handleButtonClick}> | ||
입금 | ||
</DepositButton> | ||
<ExpenseButton data-form-type="expense" onClick={handleButtonClick}> | ||
지출 | ||
</ExpenseButton> | ||
</ButtonCotainer> | ||
<ExpensesAmount amount={amount} handleAmountChange={handleAmountChange} /> | ||
{type === 'deposit' ? ( | ||
<DepositTag handleTagChange={handleTagChange} /> | ||
) : type === 'expense' ? ( | ||
<ExpensesTag handleTagChange={handleTagChange} /> | ||
) : null} | ||
{type === 'deposit' ? null : type === 'expense' ? ( | ||
<PaymentMethod handleMethodChange={handleMethodChange} /> | ||
) : null} | ||
<Submit onClick={handleSubmit}>확인</Submit> | ||
</Container> | ||
) | ||
); | ||
} | ||
|
||
const Container = styled.div ` | ||
display:flex; | ||
const Container = styled.div` | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
align-items: center; | ||
` | ||
`; | ||
|
||
const ButtonCotainer = styled.div` | ||
display: flex; | ||
gap: 50px; | ||
justify-content: center; | ||
`; | ||
|
||
const DepositButton = styled.button` | ||
width: 100px; | ||
height: 30px; | ||
`; | ||
|
||
const ExpenseButton = styled.button` | ||
width: 100px; | ||
height: 30px; | ||
`; | ||
|
||
export default Modal | ||
const Submit = styled.button``; | ||
export default Modal; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import Dropdown from './Dropdown'; | ||
|
||
interface PaymentTagProps { | ||
handleMethodChange: (tags: string) => void; | ||
} | ||
|
||
function PaymentTag({ handleMethodChange }: PaymentTagProps) { | ||
const PaymentTags = [ | ||
'현금', | ||
'체크카드', | ||
'신용카드' | ||
]; | ||
|
||
return ( | ||
<Dropdown options={PaymentTags} onSelect={handleMethodChange} /> | ||
); | ||
} | ||
|
||
export default PaymentTag; |