forked from milzipmoza-developers/tecobrary-admin-client-v2
-
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.
[milzipmoza-developers#1] refactor - LongTermRentHistories 컴포넌트로 분리
- Loading branch information
1 parent
887ab2d
commit 63435fb
Showing
5 changed files
with
124 additions
and
38 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,31 @@ | ||
import {Row} from "react-bootstrap"; | ||
import RentHistoryItem from "../atoms/RentHistoryItem"; | ||
import * as React from "react"; | ||
import {IHistory} from "../../pages/dashboard"; | ||
|
||
const RentHistoryElement = (history: IHistory) => { | ||
|
||
const formatDate = (rentDate: string) => { | ||
const date = new Date(rentDate); | ||
return `${date.getFullYear()}년 ${date.getMonth() + 1}월 ${date.getDate()}일` | ||
}; | ||
|
||
const calculateTerm = (criteria: string) => { | ||
const now = new Date(); | ||
const past = new Date(criteria); | ||
const diff = Math.abs(now.getTime() - past.getTime()); | ||
return Math.ceil(diff / (1000 * 3600 * 24)).toString(); | ||
}; | ||
|
||
return ( | ||
<Row className="rent-history-element"> | ||
<RentHistoryItem sm={3}>{`${formatDate(history.rentDate)}`}</RentHistoryItem> | ||
<RentHistoryItem sm={2}>{`${calculateTerm(history.rentDate)} 일 전`}</RentHistoryItem> | ||
<RentHistoryItem sm={3}>{history.title}</RentHistoryItem> | ||
<RentHistoryItem sm={2}>{history.serialNumber}</RentHistoryItem> | ||
<RentHistoryItem sm={2}>{history.userName}</RentHistoryItem> | ||
</Row> | ||
); | ||
}; | ||
|
||
export default RentHistoryElement |
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,23 @@ | ||
import {ListGroup} from "react-bootstrap"; | ||
import RentHistoryElement from "../molecules/RentHistoryElement"; | ||
import * as React from "react"; | ||
import {IHistory} from "../../pages/dashboard"; | ||
|
||
interface IProps { | ||
histories: IHistory[]; | ||
} | ||
|
||
const RentHistoryList = ({histories}: IProps) => ( | ||
<ListGroup className="rent-history-list" variant="flush"> | ||
{histories.map((history: IHistory, i: number) => ( | ||
<ListGroup.Item key={i}> | ||
<RentHistoryElement rentDate={history.rentDate} | ||
title={history.title} | ||
serialNumber={history.serialNumber} | ||
userName={history.userName}/> | ||
</ListGroup.Item> | ||
))} | ||
</ListGroup> | ||
); | ||
|
||
export default RentHistoryList; |
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 {Card} from "react-bootstrap"; | ||
import RentHistoryList from "../organisms/RentHistoryList"; | ||
import * as React from "react"; | ||
import {IHistory} from "../../pages/dashboard"; | ||
|
||
interface IProps { | ||
histories: IHistory[]; | ||
} | ||
|
||
const LongTermRentHistories = ({histories}: IProps) => ( | ||
<Card style={{height: '270px'}}> | ||
<Card.Header as="h5">장기 대여자</Card.Header> | ||
<div style={{overflow: 'scroll'}}> | ||
<RentHistoryList histories={histories}/> | ||
</div> | ||
</Card> | ||
); | ||
|
||
export default LongTermRentHistories; |
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