-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
5 changed files
with
223 additions
and
12 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,87 @@ | ||
import React from 'react'; | ||
import { Link } from 'react-router-dom'; | ||
import { Button, List, Popover, Typography } from 'antd'; | ||
import { MoreOutlined } from '@ant-design/icons'; | ||
import moment from 'moment'; | ||
import styled from 'styled-components'; | ||
import * as Color from '../../constants/colors'; | ||
import * as Type from '../../types'; | ||
import routes from '../../routes'; | ||
import StockTransaction from './StockTransaction'; | ||
|
||
interface NoteListProps { | ||
loading: boolean; | ||
notes: Array<Type.Note>; | ||
onClickUpdateNoteButton: (noteId: number) => () => void; | ||
onDeleteNote: (noteId: number) => () => void; | ||
filterStockTransactions: (note: Type.Note) => Array<Array<Type.StockTransaction>>; | ||
} | ||
|
||
const Container = styled.div` | ||
background-color: ${Color.WHITE}; | ||
box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.1); | ||
padding: 20px; | ||
`; | ||
|
||
const Title = styled(Typography.Title)` | ||
color: ${Color.BLUE_2}; | ||
margin-bottom: 30px !important; | ||
`; | ||
|
||
const MoreButton = styled(MoreOutlined)` | ||
font-size: 20px; | ||
`; | ||
|
||
const SmallButton = styled(Button)` | ||
padding: 4px 5px; | ||
`; | ||
|
||
const StockTransactionButton = styled(Button)` | ||
margin-right: 10px; | ||
`; | ||
|
||
const NoteList: React.VFC<NoteListProps> = ({ | ||
loading, | ||
notes, | ||
onClickUpdateNoteButton, | ||
onDeleteNote, | ||
filterStockTransactions, | ||
}) => { | ||
return ( | ||
<Container> | ||
<Title level={3}>투자노트 목록</Title> | ||
<List | ||
loading={loading} | ||
itemLayout="horizontal" | ||
dataSource={notes} | ||
renderItem={(note) => ( | ||
<List.Item> | ||
<List.Item.Meta | ||
title={<Link to={routes.note.detail(note.id)}>{note.title}</Link>} | ||
description={moment(note.investmentDate).format('YYYY년 MM월 DD일')} | ||
/> | ||
<StockTransaction stockTransactions={note.stockTransactions} /> | ||
<Popover | ||
placement="topRight" | ||
trigger="click" | ||
content={ | ||
<div> | ||
<SmallButton type="link" onClick={onClickUpdateNoteButton(note.id)}> | ||
수정 | ||
</SmallButton> | ||
<SmallButton type="link" onClick={onDeleteNote(note.id)}> | ||
삭제 | ||
</SmallButton> | ||
</div> | ||
} | ||
> | ||
<MoreButton /> | ||
</Popover> | ||
</List.Item> | ||
)} | ||
/> | ||
</Container> | ||
); | ||
}; | ||
|
||
export default NoteList; |
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,89 @@ | ||
import React, { useCallback, useState } from 'react'; | ||
import styled from 'styled-components'; | ||
import { Button, Modal, Table } from 'antd'; | ||
import * as TransactionType from '../../constants/transactionType'; | ||
import * as Type from '../../types'; | ||
import { addCommaToNumber } from '../../lib/number'; | ||
|
||
interface StockTransactionProps { | ||
stockTransactions: Array<Type.StockTransaction>; | ||
} | ||
|
||
interface StockTransactionModalProps { | ||
isModalVisible: boolean; | ||
stockTransactions: Array<Type.StockTransaction>; | ||
} | ||
|
||
const StockTransactionButton = styled(Button)` | ||
margin-right: 10px; | ||
`; | ||
|
||
const columns = [ | ||
{ | ||
title: '종목명', | ||
dataIndex: 'companyName', | ||
key: 'companyName', | ||
}, | ||
{ | ||
title: '거래량(주)', | ||
dataIndex: 'quantity', | ||
key: 'quantity', | ||
}, | ||
{ | ||
title: '1주당 가격(원)', | ||
dataIndex: 'tradedPrice', | ||
key: 'tradedPrice', | ||
}, | ||
{ | ||
title: '총 거래가(원)', | ||
dataIndex: 'totalPrice', | ||
key: 'totalPrice', | ||
}, | ||
]; | ||
|
||
const StockTransaction: React.VFC<StockTransactionProps> = ({ stockTransactions }) => { | ||
const transactionTypes: Array<Type.TransactionType> = [TransactionType.BUY, TransactionType.SELL]; | ||
|
||
return ( | ||
<div> | ||
{transactionTypes.map((type) => { | ||
const filteredStockTransactions = stockTransactions.filter((s) => s.transactionType === type); | ||
|
||
if (filteredStockTransactions.length === 0) { | ||
return null; | ||
} | ||
return ( | ||
<> | ||
<StockTransactionButton | ||
danger={type === TransactionType.SELL} | ||
onClick={() => | ||
Modal.info({ | ||
title: type === TransactionType.BUY ? '매수내역' : '매도내역', | ||
content: ( | ||
<Table | ||
columns={columns} | ||
dataSource={filteredStockTransactions.map((s, idx) => ({ | ||
key: idx, | ||
companyName: s.stockDetail.companyName, | ||
quantity: addCommaToNumber(s.quantity), | ||
tradedPrice: addCommaToNumber(s.tradedPrice), | ||
totalPrice: addCommaToNumber(s.quantity * s.tradedPrice), | ||
}))} | ||
/> | ||
), | ||
onOk() {}, | ||
width: 900, | ||
}) | ||
} | ||
> | ||
{type === TransactionType.BUY ? '매수 ' : '매도 '} | ||
{filteredStockTransactions.length}건 | ||
</StockTransactionButton> | ||
</> | ||
); | ||
})} | ||
</div> | ||
); | ||
}; | ||
|
||
export default StockTransaction; |
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