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

Commit

Permalink
feat(i18n): translate stats details page
Browse files Browse the repository at this point in the history
  • Loading branch information
igorkamyshev committed May 12, 2019
1 parent 2b5c80e commit 6e82ef2
Show file tree
Hide file tree
Showing 18 changed files with 234 additions and 128 deletions.
7 changes: 6 additions & 1 deletion front/pages/internal/categories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ import { GroupBy } from '@shared/enum/GroupBy'
import { createRangeForGroup } from '@front/helpers/createRangeForGroup'
import { getFirstTransactionDate } from '@front/domain/money/selectors/getFirstTransactionDate'
import { Categories } from '@front/features/statistics/features/details/categories'
import { pageWithTranslation, Namespace } from '@front/domain/i18n'

interface Query {
group?: GroupBy
}

export default class CateogiesPage extends React.Component<Query> {
class CateogiesPage extends React.Component<Query> {
public static isSecure = true

public static async getInitialProps({
Expand Down Expand Up @@ -45,3 +46,7 @@ export default class CateogiesPage extends React.Component<Query> {
return <Categories group={group} />
}
}

export default pageWithTranslation([Namespace.Stats, Namespace.Months])(
CateogiesPage,
)
7 changes: 6 additions & 1 deletion front/pages/internal/sources.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ import { createRangeForGroup } from '@front/helpers/createRangeForGroup'
import { getFirstTransactionDate } from '@front/domain/money/selectors/getFirstTransactionDate'
import { Sources } from '@front/features/statistics/features/details/sources'
import { fetchStatsSources } from '@front/domain/money/actions/fetchStatsSources'
import { pageWithTranslation, Namespace } from '@front/domain/i18n'

interface Query {
group?: GroupBy
}

export default class SourcesPage extends React.Component<Query> {
class SourcesPage extends React.Component<Query> {
public static isSecure = true

public static async getInitialProps({
Expand Down Expand Up @@ -45,3 +46,7 @@ export default class SourcesPage extends React.Component<Query> {
return <Sources group={group} />
}
}

export default pageWithTranslation([Namespace.Stats, Namespace.Months])(
SourcesPage,
)
2 changes: 1 addition & 1 deletion front/src/domain/i18n/pageWithTranslation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const pageWithTranslation = (namespaces: Namespace | Namespace[]) => (
public render() {
return (
<I18nProvider namespaces={namespacesRequired}>
<Page />
<Page {...this.props} />
</I18nProvider>
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { GroupBy } from '@shared/enum/GroupBy'
import { getStatsCategories } from '@front/domain/money/selectors/getStatsCategories'
import { fetchStatsCategories } from '@front/domain/money/actions/fetchStatsCategories'
import { useTranslation } from '@front/domain/i18n'

import { Detail } from '../generic'

Expand All @@ -9,9 +10,12 @@ interface Props {
}

export const Categories = ({ group }: Props) => {
const { t } = useTranslation()

return (
<Detail
detailType="categories"
detailTitle={t('common:nav.categories')}
fetchData={fetchStatsCategories}
getData={getStatsCategories}
toAmount={({ outcome }) => outcome}
Expand Down
29 changes: 12 additions & 17 deletions front/src/features/statistics/features/details/generic/Detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Option } from 'tsoption'
import useMedia from 'use-media'
import { useMappedState } from 'redux-react-hook'
import { useState, useMemo } from 'react'
import { sortBy, capitalize } from 'lodash'
import { sortBy } from 'lodash'

import { GroupBy } from '@shared/enum/GroupBy'
import { Container } from '@front/ui/components/layout/container'
Expand All @@ -22,7 +22,6 @@ import { Api } from '@front/domain/api'
import { PeriodChooser } from './features/period-chooser'
import { useDateRange } from './helpers/useDateRange'
import * as styles from './Detail.css'
import { GroupChooser } from './features/group-chooser'

interface Data {
name: string
Expand All @@ -32,6 +31,7 @@ interface Data {
interface Props<T> {
group?: GroupBy
detailType: string
detailTitle: string
fetchData: (
from: Date,
to: Date,
Expand All @@ -53,6 +53,7 @@ interface Props<T> {
export const Detail = <T extends object = any>({
group,
detailType,
detailTitle,
fetchData,
getData,
toAmount,
Expand All @@ -79,24 +80,18 @@ export const Detail = <T extends object = any>({

return (
<Container>
<PageHeader
title={capitalize(detailType)}
onBack={() => pushRoute('/app/stats')}
/>
<PageHeader title={detailTitle} onBack={() => pushRoute('/app/stats')} />

<section className={styles.categories}>
<aside className={styles.aside}>
<GroupChooser group={group} detailType={detailType} />
{group && (
<PeriodChooser
setPreviousPeriodNumber={setPreviousPeriodNumber}
previousPeriodNumber={previousPeriodNumber}
detailType={detailType}
from={from}
to={to}
group={group}
/>
)}
<PeriodChooser
setPreviousPeriodNumber={setPreviousPeriodNumber}
previousPeriodNumber={previousPeriodNumber}
detailType={detailType}
from={from}
to={to}
group={group}
/>
</aside>

<div className={styles.chart}>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { useCallback } from 'react'
import { GroupBy } from '@shared/enum/GroupBy'
import { Button, ButtonType } from '@front/ui/components/form/button'
import { useTranslation } from '@front/domain/i18n'

interface Props {
group?: GroupBy
previousPeriodNumber: number
setPreviousPeriodNumber: (t: (v: number) => number) => void
}

export const Prev = ({ group, setPreviousPeriodNumber }: Props) => {
const back = useCallback(() => setPreviousPeriodNumber(v => v + 1), [
setPreviousPeriodNumber,
])

const { t } = useTranslation()

if (!group) {
return null
}

return (
<Button onClick={back} type={ButtonType.Text}>
{t(`stats:details.prev-${group}`)}
</Button>
)
}

export const Next = ({
group,
previousPeriodNumber,
setPreviousPeriodNumber,
}: Props) => {
const next = useCallback(() => setPreviousPeriodNumber(v => v - 1), [
setPreviousPeriodNumber,
])

const { t } = useTranslation()

if (!group || previousPeriodNumber <= 0) {
return null
}

return (
<Button onClick={next} type={ButtonType.Text}>
{t(`stats:details.next-${group}`)}
</Button>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Button, ButtonType } from '@front/ui/components/form/button'
import { pushRoute } from '@front/features/routing'
import { GroupBy } from '@shared/enum/GroupBy'
import { useTranslation } from '@front/domain/i18n'

interface Props {
group?: GroupBy
detailType: string
}

export const ShowMonth = ({ group, detailType }: Props) => {
const showMonth = !group || group !== GroupBy.Month
const { t } = useTranslation()

return showMonth ? (
<Button
onClick={() => pushRoute(`/app/stats/${detailType}/month`)}
type={ButtonType.Secondary}
>
{t('stats:details.show-month')}
</Button>
) : null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Button, ButtonType } from '@front/ui/components/form/button'
import { pushRoute } from '@front/features/routing'
import { GroupBy } from '@shared/enum/GroupBy'
import { useTranslation } from '@front/domain/i18n'

interface Props {
group?: GroupBy
detailType: string
}

export const ShowWhole = ({ group, detailType }: Props) => {
const showWhole = !!group
const { t } = useTranslation()

return showWhole ? (
<Button
onClick={() => pushRoute(`/app/stats/${detailType}`)}
type={ButtonType.Secondary}
>
{t('stats:details.show-whole')}
</Button>
) : null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Button, ButtonType } from '@front/ui/components/form/button'
import { pushRoute } from '@front/features/routing'
import { GroupBy } from '@shared/enum/GroupBy'
import { useTranslation } from '@front/domain/i18n'

interface Props {
group?: GroupBy
detailType: string
}

export const ShowYear = ({ group, detailType }: Props) => {
const showYear = !group || group !== GroupBy.Year
const { t } = useTranslation()

return showYear ? (
<Button
onClick={() => pushRoute(`/app/stats/${detailType}/year`)}
type={ButtonType.Secondary}
>
{t('stats:details.show-year')}
</Button>
) : null
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.card {
display: grid;
grid-template-rows: 1fr 1fr;
gap: 16px;
}
Loading

0 comments on commit 6e82ef2

Please sign in to comment.