Skip to content

Commit

Permalink
Unify NoResultsError component
Browse files Browse the repository at this point in the history
  • Loading branch information
selankon committed Aug 22, 2024
1 parent 55a65c3 commit d3f7dfb
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 29 deletions.
10 changes: 4 additions & 6 deletions src/components/Accounts/Details/Elections.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Flex, Text } from '@chakra-ui/react'
import { AccountData } from '@vocdoni/sdk'
import { Trans } from 'react-i18next'
import { Trans, useTranslation } from 'react-i18next'
import { LoadingCards } from '~components/Layout/Loading'
import { RoutedPagination } from '~components/Pagination/Pagination'
import { RoutedPaginationProvider, useRoutedPagination } from '~components/Pagination/PaginationProvider'
Expand All @@ -14,12 +14,10 @@ interface OrgComponentProps {
}

const AccountElections = ({ org }: OrgComponentProps) => {
const { t } = useTranslation()

if (org.electionIndex === 0) {
return (
<Text>
<Trans i18nKey={'account.no_elections'}>No elections yet!</Trans>
</Text>
)
return <NoResultsError msg={t('account.no_elections', { defaultValue: 'No elections yet!' })} />
}

return (
Expand Down
7 changes: 2 additions & 5 deletions src/components/Accounts/Details/Transfers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const AccountTransfers = (txProps: AccountTransfersProps) => {
const AccountTransfersTable = ({ txCount, org }: AccountTransfersProps) => {
const { page } = usePagination()
const { formatDistance } = useDateFns()
const { t } = useTranslation()

const { data, isLoading, isError, error } = useAccountTransfers({
address: org.address,
Expand All @@ -74,11 +75,7 @@ const AccountTransfersTable = ({ txCount, org }: AccountTransfersProps) => {
})

if (txCount === 0) {
return (
<Text>
<Trans i18nKey={'account.transfers.no_transfers'}>No transfers yet!</Trans>
</Text>
)
return <NoResultsError msg={t('account.transfers.no_transfers', { defaultValue: 'No transfers yet!' })} />
}

if (!txCount || isLoading) {
Expand Down
7 changes: 6 additions & 1 deletion src/components/Layout/ContentError.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import { Trans, useTranslation } from 'react-i18next'

export const NoResultsError = ({ msg }: { msg?: string }) => {
const { t } = useTranslation()
return <Text>{msg ?? t('errors.no_results', { defaultValue: 'Looks like there are no results to show.' })}</Text>
return (
<Alert status='info'>
<AlertIcon />
{msg ?? t('errors.no_results', { defaultValue: 'Looks like there are nothing to show.' })}
</Alert>
)
}

export type ContentErrorType = Error | undefined | null | string
Expand Down
13 changes: 4 additions & 9 deletions src/components/Process/Detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import { FallbackHeaderImg, RoutePath } from '~constants'
import { useElectionKeys, useElectionVotesList } from '~queries/processes'
import { ucfirst } from '~utils/strings'
import { RouteParamsTabs } from '~components/Layout/RouteParamsTabs'
import { NoResultsError } from '~components/Layout/ContentError'

const Detail = () => {
const { election } = useElection()
Expand Down Expand Up @@ -161,10 +162,7 @@ const Detail = () => {
{election.description?.default ? (
<ElectionDescription />
) : (
<Alert status='warning'>
<AlertIcon />
<Trans i18nKey={'process.no_description'}>No description set!</Trans>
</Alert>
<NoResultsError msg={t('process.no_description', { defaultValue: 'No description set!' })} />
)}
</TabPanel>
<TabPanel>
Expand Down Expand Up @@ -221,13 +219,10 @@ const ElectionKeys = ({ electionId }: { electionId: string }) => {
const EnvelopeExplorer = () => {
const { election: e } = useElection()
const election = e as PublishedElection
const { t } = useTranslation()

if (!election || election.voteCount === 0) {
return (
<Text>
<Trans i18nKey={'election.no_votes_yet'}>No votes yet!</Trans>
</Text>
)
return <NoResultsError msg={t('election.no_votes_yet', { defaultValue: 'No votes yet!' })} />
}

return (
Expand Down
7 changes: 2 additions & 5 deletions src/components/Transactions/TransactionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,9 @@ const TransactionsListCards = ({
error: Error | null
height?: number
}) => {
const { t } = useTranslation()
if (!data || (data && data.transactions.length <= 0)) {
return (
<Text>
<Trans i18nKey={'blocks.no_txs_on_block'}>There are no transactions.</Trans>
</Text>
)
return <NoResultsError msg={t('blocks.no_txs_on_block', { defaultValue: 'There are no transactions' })} />
}

if (isLoading) {
Expand Down
2 changes: 1 addition & 1 deletion src/i18n/locales/ca.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
},
"errors": {
"content_error": "Sembla que el contingut al qual intentaves accedir ha generat un error.",
"no_results": "Sembla que no hi ha resultats per mostrar."
"no_results": "Sembla que no hi ha res a mostrar."
},
"featured": {
"a_cutting_edge_voting_protocol": "Un protocol de votació avançat",
Expand Down
2 changes: 1 addition & 1 deletion src/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
},
"errors": {
"content_error": "Looks like the content you were accessing threw an error.",
"no_results": "Looks like there are no results to show."
"no_results": "Looks like there are nothing to show."
},
"featured": {
"a_cutting_edge_voting_protocol": "A cutting edge voting protocol",
Expand Down
2 changes: 1 addition & 1 deletion src/i18n/locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
},
"errors": {
"content_error": "Parece que el contenido al que accediste arrojó un error.",
"no_results": "Parece que no hay resultados para mostrar."
"no_results": "Parece que no hay nada para mostrar."
},
"featured": {
"a_cutting_edge_voting_protocol": "Un protocolo de votación de vanguardia",
Expand Down

0 comments on commit d3f7dfb

Please sign in to comment.