Skip to content
This repository has been archived by the owner on May 11, 2021. It is now read-only.

Commit

Permalink
feat(stats): add stub for sources/categories data
Browse files Browse the repository at this point in the history
  • Loading branch information
igorkamyshev committed Mar 6, 2019
1 parent f29745a commit f3e4188
Show file tree
Hide file tree
Showing 9 changed files with 135 additions and 15 deletions.
21 changes: 10 additions & 11 deletions front/src/features/statistics/Statistics.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@
display: grid;

grid-template:
'header header '
'agenda sources'
'charts charts '
'header header'
'aside charts'
'aside charts'
'aside charts'
/ 1fr 2fr;

align-items: end;
gap: 16px;

@media (max-width: 768px) {
grid-template:
'header'
'agenda'
'sources'
'aside'
'charts';
}
}
Expand All @@ -23,12 +22,12 @@
grid-area: header;
}

.agenda {
grid-area: agenda;
}
.aside {
grid-area: aside;

.sources {
grid-area: sources;
& > *:not(:last-child) {
margin-bottom: 16px;
}
}

.charts {
Expand Down
10 changes: 7 additions & 3 deletions front/src/features/statistics/Statistics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { Tabs, Tab } from '@front/ui/components/layout/tabs'
import { Yearly } from './features/yearly'
import { Monthly } from './features/monthly'
import { ThisMonth } from './features/this-month'
import { Categories } from './features/categories'
import { Sources } from './features/sources'
import * as styles from './Statistics.css'

export const Statistics = () => {
Expand All @@ -20,9 +22,11 @@ export const Statistics = () => {
<CurrencySwitch currency={currency} updateCurrency={setCurrency} />
</ControlHeader>

<ThisMonth className={styles.agenda} />

<p className={styles.sources}>...</p>
<aside className={styles.aside}>
<ThisMonth />
<Categories currency={currency} />
<Sources currency={currency} />
</aside>

<Tabs className={styles.charts}>
<Tab title="Monthly">
Expand Down
49 changes: 49 additions & 0 deletions front/src/features/statistics/features/categories/Categories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { useMemo } from 'react'
import { sortBy } from 'lodash'

import { Currency } from '@shared/enum/Currency'
import { displayMoney } from '@shared/helpers/displayMoney'
import { Table } from '@front/ui/components/layout/table'

interface Props {
className?: string
currency: Currency
}

export const Categories = ({ className, currency }: Props) => {
const columns = useMemo(
() => ({
source: {
title: 'Category',
},
amount: {
title: 'Amount',
transform: displayMoney(currency),
},
}),
[currency],
)

const fakeDate = useMemo(
() =>
sortBy(
[
{ source: 'Cafe', amount: 50000 },
{ source: 'Lunch', amount: 40000 },
{ source: 'Travel', amount: 45000 },
],
'-amount',
),
[],
)

return (
<Table
title="Where was the money spent"
columns={columns}
data={fakeDate}
hideHeader
className={className}
/>
)
}
1 change: 1 addition & 0 deletions front/src/features/statistics/features/categories/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { Categories } from './Categories'
49 changes: 49 additions & 0 deletions front/src/features/statistics/features/sources/Sources.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { useMemo } from 'react'
import { sortBy } from 'lodash'

import { Table } from '@front/ui/components/layout/table'
import { displayMoney } from '@shared/helpers/displayMoney'
import { Currency } from '@shared/enum/Currency'

interface Props {
className?: string
currency: Currency
}

export const Sources = ({ className, currency }: Props) => {
const columns = useMemo(
() => ({
source: {
title: 'Source',
},
amount: {
title: 'Amount',
transform: displayMoney(currency),
},
}),
[currency],
)

const fakeDate = useMemo(
() =>
sortBy(
[
{ source: 'Breadhead', amount: 50000 },
{ source: 'Netology', amount: 40000 },
{ source: 'Whatever', amount: 45000 },
],
'-amount',
),
[],
)

return (
<Table
title="Sources of income"
columns={columns}
data={fakeDate}
hideHeader
className={className}
/>
)
}
1 change: 1 addition & 0 deletions front/src/features/statistics/features/sources/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { Sources } from './Sources'
3 changes: 3 additions & 0 deletions front/src/ui/components/layout/table/AntTable.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.ant-table-title {
border-radius: 2px;
}
8 changes: 8 additions & 0 deletions front/src/ui/components/layout/table/Table.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.title {
font-weight: 500;
font-size: 16px;
margin-left: 8px;
margin-bottom: 4px;
margin-top: 4px;
color: rgba(0, 0, 0, 0.85);
}
8 changes: 7 additions & 1 deletion front/src/ui/components/layout/table/Table.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { Table as AntTable } from 'antd'
import { ReactNode, useMemo } from 'react'

import * as styles from './Table.css'
import './AntTable.css?CSSModulesDisable'

interface Column {
title: string
transform?: (v: any) => ReactNode
Expand All @@ -15,13 +18,15 @@ interface Props<Data extends Array<{}>> {
columns: Columns
className?: string
title: string
hideHeader?: boolean
}

export const Table = <Data extends Array<{}>>({
className,
data,
columns,
title,
hideHeader = false,
}: Props<Data>) => {
const adoptedData = useMemo(
() =>
Expand Down Expand Up @@ -50,7 +55,8 @@ export const Table = <Data extends Array<{}>>({
bordered
size="middle"
pagination={false}
title={() => title}
showHeader={!hideHeader}
title={() => <div className={styles.title}>{title}</div>}
/>
)
}

0 comments on commit f3e4188

Please sign in to comment.