From 8485488e8d23027fcf373c6eab89885aec327bd9 Mon Sep 17 00:00:00 2001 From: selankon Date: Mon, 15 Jan 2024 11:12:02 +0100 Subject: [PATCH] Fix #160 Add InvalidElection badge --- .../pages/elections/components/ElectionCard.tsx | 14 +++++++++++--- .../elections/components/ElectionTypeBadge.tsx | 9 +++++++++ components/pages/elections/details/index.tsx | 14 +++++++++----- i18n/locales/ca.json | 3 ++- i18n/locales/en.json | 3 ++- i18n/locales/es.json | 3 ++- 6 files changed, 35 insertions(+), 11 deletions(-) diff --git a/components/pages/elections/components/ElectionCard.tsx b/components/pages/elections/components/ElectionCard.tsx index a56b719..987af1e 100644 --- a/components/pages/elections/components/ElectionCard.tsx +++ b/components/pages/elections/components/ElectionCard.tsx @@ -1,11 +1,15 @@ import { ProcessTimeLeft } from '@components/blocks/process_time_left'; import { getPath } from '@components/pages/app/components/get-links'; import { CustomElectionStatusBadge } from '@components/pages/elections/components/ElectionStatusBadge'; -import { AnonVoteBadge, ArchivedBadge } from '@components/pages/elections/components/ElectionTypeBadge'; +import { + AnonVoteBadge, + ArchivedBadge, + InvalidElectionBadge, +} from '@components/pages/elections/components/ElectionTypeBadge'; import { PROCESS_DETAILS } from '@const/routes'; import useExtendedElection from '@hooks/use-extended-election'; import { ElectionProvider, OrganizationProvider } from '@vocdoni/react-providers'; -import { IElectionSummary, PublishedElection } from '@vocdoni/sdk'; +import { IElectionSummary, InvalidElection, PublishedElection } from '@vocdoni/sdk'; import styled from 'styled-components'; import { BodyWrapper, @@ -40,13 +44,17 @@ const InnerCard = ({ electionId, electionSummary, hideEntity, ...rest }: Process const title = election?.title?.default ?? electionId; const organizationId = election?.organizationId ?? electionSummary?.organizationId ?? null; const status = election?.status ?? PublishedElection.getStatus(electionSummary?.status, startDate) ?? null; + const isInvalid = election instanceof InvalidElection; const loading = electionLoading && !electionSummary; const Top = () => ( + {isInvalid && } {election?.fromArchive ? : } - {!election?.fromArchive && } + {!isInvalid && !election?.fromArchive && ( + + )} {anonymous && } ); diff --git a/components/pages/elections/components/ElectionTypeBadge.tsx b/components/pages/elections/components/ElectionTypeBadge.tsx index 45b2e06..ae6fbcb 100644 --- a/components/pages/elections/components/ElectionTypeBadge.tsx +++ b/components/pages/elections/components/ElectionTypeBadge.tsx @@ -33,3 +33,12 @@ export const ArchivedBadge = () => { const { i18n } = useTranslation(); return {i18n.t('vote.badge.archived')}; }; + +export const InvalidElectionBadge = () => { + const { i18n } = useTranslation(); + return ( + + {i18n.t('vote.badge.invalid')} + + ); +}; diff --git a/components/pages/elections/details/index.tsx b/components/pages/elections/details/index.tsx index 0bdcb94..c00313a 100644 --- a/components/pages/elections/details/index.tsx +++ b/components/pages/elections/details/index.tsx @@ -13,14 +13,14 @@ import useExtendedElection from '@hooks/use-extended-election'; import { DateDiffType, localizedDateDiff, localizedStartEndDateDiff } from '@lib/date'; import { colors } from '@theme/colors'; import { ElectionDescription } from '@vocdoni/chakra-components'; -import { CensusTypeEnum, ElectionStatus } from '@vocdoni/sdk'; +import { CensusTypeEnum, ElectionStatus, InvalidElection } from '@vocdoni/sdk'; import { useTranslation } from 'react-i18next'; import styled from 'styled-components'; import { CensusOriginBadge } from '../components/ElectionCensusOrigin-badge'; import { EnvelopeExplorer } from '../components/ElectionEnvelopeExplorer'; import { EncryptionKeys } from '../components/ElectionKeys'; import { ProcessModeBadge } from '../components/ElectionProcessmodeBadge'; -import { AnonVoteBadge, ElectionTypeBadge, ArchivedBadge } from '../components/ElectionTypeBadge'; +import { AnonVoteBadge, ArchivedBadge, ElectionTypeBadge, InvalidElectionBadge } from '../components/ElectionTypeBadge'; import { ResultsCard } from '../components/ResultsCard'; const ProcessesDetailPage = () => { @@ -28,6 +28,7 @@ const ProcessesDetailPage = () => { const dateDiffStr = resolveLocalizedDateDiff(election.startDate, election.endDate, election.status); const id = election.id; const organizationId = election.organizationId; + const isInvalid = election instanceof InvalidElection; const { i18n } = useTranslation(); @@ -53,9 +54,11 @@ const ProcessesDetailPage = () => { - - {dateDiffStr} - + {!isInvalid && ( + + {dateDiffStr} + + )} {i18n.t('processes.details.created_on')} {localizedDateDiff(election.startDate)} @@ -64,6 +67,7 @@ const ProcessesDetailPage = () => { {/* Labels and badges */} + {isInvalid && } {election.fromArchive && } diff --git a/i18n/locales/ca.json b/i18n/locales/ca.json index 952e3ef..16715eb 100644 --- a/i18n/locales/ca.json +++ b/i18n/locales/ca.json @@ -339,7 +339,8 @@ "vote": { "badge": { "anonymous": "Anònim", - "archived": "Arxivat" + "archived": "Arxivat", + "invalid": "Invalida" }, "loading_results": "Carregant resultats", "no_questions_yet": "Encara no hi ha preguntes", diff --git a/i18n/locales/en.json b/i18n/locales/en.json index a8551bc..0bc81d1 100644 --- a/i18n/locales/en.json +++ b/i18n/locales/en.json @@ -339,7 +339,8 @@ "vote": { "badge": { "anonymous": "Anonymous", - "archived": "Archived" + "archived": "Archived", + "invalid": "Invalid" }, "loading_results": "Loading results", "no_questions_yet": "No questions yet", diff --git a/i18n/locales/es.json b/i18n/locales/es.json index e5a7c28..dd06dbc 100644 --- a/i18n/locales/es.json +++ b/i18n/locales/es.json @@ -339,7 +339,8 @@ "vote": { "badge": { "anonymous": "Anónimo", - "archived": "Archivada" + "archived": "Archivada", + "invalid": "Invalida" }, "loading_results": "Cargando resultados", "no_questions_yet": "No hay preguntas aún",