This repository has been archived by the owner on May 10, 2020. It is now read-only.
-
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.
Merge pull request #41 from igorkamyshev/history-layout
History layout
- Loading branch information
Showing
22 changed files
with
337 additions
and
120 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,3 @@ | ||
.container { | ||
max-width: 500px; | ||
|
||
@media (max-width: 768px) { | ||
width: 100%; | ||
} | ||
} | ||
|
||
.form { | ||
display: grid; | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
.header { | ||
display: flex; | ||
align-items: flex-end; | ||
padding-top: 8px; | ||
padding-bottom: 8px; | ||
|
||
& > * { | ||
margin-right: 16px; | ||
} | ||
|
||
@media (max-width: 576px) { | ||
flex-direction: column; | ||
align-items: stretch; | ||
|
||
& > *:not(:first-child) { | ||
margin-top: 16px; | ||
margin-right: 0px; | ||
} | ||
} | ||
} | ||
|
||
.title { | ||
margin-bottom: 0px; | ||
} | ||
|
||
.dataSet { | ||
display: grid; | ||
|
||
grid-template: | ||
'outcomes incomes' | ||
/ 1fr 1fr; | ||
|
||
@media (max-width: 576px) { | ||
grid-template: | ||
'outcomes' | ||
'incomes'; | ||
} | ||
|
||
gap: 16px; | ||
padding-top: 8px; | ||
padding-bottom: 8px; | ||
} | ||
|
||
.outcomes { | ||
grid-area: outcomes; | ||
} | ||
|
||
.incomes { | ||
grid-area: incomes; | ||
} |
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,54 +1,72 @@ | ||
import { useCallback, useEffect, useState } from 'react' | ||
import { endOfMonth, startOfMonth } from 'date-fns' | ||
import { useCallback, useEffect, useMemo, useState } from 'react' | ||
import { useDispatch, useMappedState } from 'redux-react-hook' | ||
|
||
import { fetchHistory } from '@front/domain/money/actions/fetchHistory' | ||
import { getFirstTransactionDate } from '@front/domain/money/selectors/getFirstTransactionDate' | ||
import { getHistory } from '@front/domain/money/selectors/getHistory' | ||
import { getHistoryFetchingStatus } from '@front/domain/money/selectors/getHistoryFetchingStatus' | ||
import { Loader } from '@front/ui/molecules/loader' | ||
import { Groupment } from '@front/ui/organisms/groupment' | ||
import { Period } from '@front/ui/organisms/period' | ||
import { GroupBy } from '@shared/enum/GroupBy' | ||
|
||
import * as styles from './History.css' | ||
import { Incomes } from './organisms/Incomes' | ||
import { Outcomes } from './organisms/Outcomes' | ||
|
||
export const History = () => { | ||
const firstTransactionDate = useMappedState(getFirstTransactionDate) | ||
interface Props { | ||
className?: string | ||
} | ||
|
||
const groupBy = GroupBy.Month | ||
|
||
export const History = ({ className }: Props) => { | ||
const fetching = useMappedState(getHistoryFetchingStatus) | ||
const dispatch = useDispatch() | ||
|
||
const [from, setFrom] = useState(firstTransactionDate) | ||
const [to, setTo] = useState(new Date()) | ||
const [groupBy, setGroupBy] = useState(GroupBy.Year) | ||
const [from, setFrom] = useState(startOfMonth(new Date())) | ||
const [to, setTo] = useState(endOfMonth(new Date())) | ||
|
||
const updateTriggers = [from, to, groupBy] | ||
const [actualFrom, actualTo] = useMemo( | ||
() => [startOfMonth(from), endOfMonth(to)], | ||
[from, to], | ||
) | ||
|
||
const historySelector = useCallback( | ||
getHistory(from, to, groupBy), | ||
updateTriggers, | ||
getHistory(actualFrom, actualTo, groupBy), | ||
[actualFrom, actualTo], | ||
) | ||
const history = useMappedState(historySelector) | ||
|
||
useEffect(() => { | ||
dispatch(fetchHistory(from, to, groupBy) as any) | ||
}, updateTriggers) | ||
useEffect( | ||
() => { | ||
dispatch(fetchHistory(actualFrom, actualTo, groupBy) as any) | ||
}, | ||
[actualFrom, actualTo], | ||
) | ||
|
||
return ( | ||
<> | ||
<h2>History</h2> | ||
<Groupment groupBy={groupBy} updateGroupBy={setGroupBy} /> | ||
<Period start={from} updateStart={setFrom} end={to} updateEnd={setTo} /> | ||
<section className={className}> | ||
<header className={styles.header}> | ||
<h2 className={styles.title}>History</h2> | ||
<Period start={from} updateStart={setFrom} end={to} updateEnd={setTo} /> | ||
</header> | ||
<Loader status={fetching}> | ||
{history.nonEmpty() && | ||
history.get().map(({ title, incomes, outcomes }) => ( | ||
<div key={title}> | ||
<h3>{title}</h3> | ||
<Incomes incomes={incomes} /> | ||
<Outcomes outcomes={outcomes} /> | ||
<div key={title} className={styles.dataSet}> | ||
<Outcomes | ||
outcomes={outcomes} | ||
periodName={title} | ||
className={styles.outcomes} | ||
/> | ||
<Incomes | ||
incomes={incomes} | ||
periodName={title} | ||
className={styles.incomes} | ||
/> | ||
</div> | ||
))} | ||
</Loader> | ||
</> | ||
</section> | ||
) | ||
} |
43 changes: 28 additions & 15 deletions
43
front/src/features/app/features/history/organisms/Incomes.tsx
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,22 +1,35 @@ | ||
import { Option } from 'tsoption' | ||
|
||
import { displayMoney } from '@front/helpers/displayMoney' | ||
import { displayNullableDate } from '@front/helpers/displayNullableDtae' | ||
import { Table } from '@front/ui/molecules/table' | ||
import { IncomeModel } from '@shared/models/money/IncomeModel' | ||
|
||
interface Props { | ||
incomes: IncomeModel[] | ||
className?: string | ||
periodName: string | ||
} | ||
|
||
const columns = { | ||
date: { | ||
title: 'Date', | ||
transform: displayNullableDate, | ||
}, | ||
amount: { | ||
title: 'Amount', | ||
}, | ||
source: { | ||
title: 'Source', | ||
}, | ||
} | ||
|
||
export const Incomes = ({ incomes }: Props) => ( | ||
<> | ||
<h4>Incomes</h4> | ||
{incomes.map(({ amount, currency, source, date }) => ( | ||
<p key={`${amount}-${date}`}> | ||
{Option.of(date) | ||
.map(_ => _.toDateString()) | ||
.getOrElse('')} | ||
{' — '} | ||
{amount / 100} {currency} ({source}) | ||
</p> | ||
))} | ||
</> | ||
export const Incomes = ({ incomes, periodName, className }: Props) => ( | ||
<Table | ||
title={`Incomes: ${periodName}`} | ||
className={className} | ||
data={incomes.map(income => ({ | ||
...income, | ||
amount: displayMoney(income.amount, income.currency), | ||
}))} | ||
columns={columns} | ||
/> | ||
) |
Oops, something went wrong.