-
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.
* Refactor paths names * Fix paths variables * Implement elections list * Add debounceTime to InputSearch * Implement useQuery params * Implement process by type * Use no total count paginator * Delete comment * Bump chakra-components * Bump extended-sdk * Fix lintern issues * Delete font family I delete the fontFamily attribute because is inherited from the old explorer and is not actually needed for the moment. On a near future we probably will style the explorer adding custom fonts, so a this moment is not needed to define this... * Refactor file name
- Loading branch information
Showing
18 changed files
with
409 additions
and
35 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import React from 'react' | ||
import { ElectionStatus } from '@vocdoni/sdk' | ||
import { ElectionStatusBadge as ComponentsStatusBadge } from '@vocdoni/chakra-components' | ||
|
||
export const ElectionStatusBadge = ({ status }: { status: ElectionStatus }) => { | ||
switch (status) { | ||
case ElectionStatus.ONGOING: | ||
return <ComponentsStatusBadge bg={'#f3fccc'} color={'#74af07'} variant={'vocdoni'} /> | ||
case ElectionStatus.RESULTS: | ||
case ElectionStatus.ENDED: | ||
return <ComponentsStatusBadge bg={'#fff3d6'} color={'#db7d24'} variant={'vocdoni'} /> | ||
case ElectionStatus.UPCOMING: | ||
return <ComponentsStatusBadge bg={'#d1fdfa'} color={'#1588b9'} variant={'vocdoni'} /> | ||
case ElectionStatus.PAUSED: | ||
case ElectionStatus.CANCELED: | ||
return <ComponentsStatusBadge bg={'#fee4d6'} color={'#d62736'} variant={'vocdoni'} /> | ||
default: | ||
return <></> | ||
} | ||
} |
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,51 @@ | ||
import { Card, CardBody, Flex, HStack } from '@chakra-ui/react' | ||
import { ElectionProvider, OrganizationProvider, useElection } from '@vocdoni/react-providers' | ||
import { InvalidElection, PublishedElection } from '@vocdoni/sdk' | ||
import { ElectionSchedule, ElectionTitle } from '@vocdoni/chakra-components' | ||
import { ElectionStatusBadge } from '~components/Organizations/StatusBadge' | ||
import { SmallOrganizationCard } from '~components/Organizations/Card' | ||
|
||
/** | ||
* Show election card information | ||
* @param id If id provided it will fetch the election from the API | ||
* @param election already loaded election info to show | ||
* @constructor | ||
*/ | ||
const ElectionCard = ({ id, election }: { id?: string; election?: PublishedElection }) => { | ||
return ( | ||
<ElectionProvider id={id} election={election}> | ||
<ElectionCardContent /> | ||
</ElectionProvider> | ||
) | ||
} | ||
|
||
const ElectionCardContent = () => { | ||
const { election } = useElection() | ||
|
||
if (election instanceof InvalidElection || !election) return null | ||
|
||
return ( | ||
<Card direction={'row'} alignItems='center' overflow={'scroll'} pl={4}> | ||
<CardBody> | ||
<Flex direction={'column'} align={'start'} gap={4}> | ||
<HStack> | ||
<ElectionStatusBadge status={election.status} /> | ||
<ElectionSchedule | ||
showRemaining | ||
fontWeight={'normal'} | ||
fontSize={'sm'} | ||
textAlign={'start'} | ||
fontStyle={'normal'} | ||
/> | ||
</HStack> | ||
<ElectionTitle textAlign={'start'} fontWeight={'bold'} wordBreak='break-all' fontSize='lg' /> | ||
</Flex> | ||
<OrganizationProvider id={election.organizationId}> | ||
<SmallOrganizationCard id={election.organizationId} /> | ||
</OrganizationProvider> | ||
</CardBody> | ||
</Card> | ||
) | ||
} | ||
|
||
export default ElectionCard |
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,126 @@ | ||
import { useParams } from 'react-router-dom' | ||
import { RoutedPaginationProvider } from '~components/Pagination/PaginationProvider' | ||
import { RoutedPagination } from '~components/Pagination/Pagination' | ||
import LoadingError from '~src/layout/LoadingError' | ||
import { LoadingCards } from '~src/layout/Loading' | ||
import { useProcessesCount, useProcessList } from '~queries/processes' | ||
import ElectionCard from './Card' | ||
import { processListPath } from '~src/router' | ||
import { Trans, useTranslation } from 'react-i18next' | ||
import useQueryParams from '~src/router/use-query-params' | ||
import { InputSearch } from '~src/layout/Inputs' | ||
import { IElectionListFilter } from '@vocdoni/sdk' | ||
import { Button, Checkbox, Flex } from '@chakra-ui/react' | ||
import { isEmpty } from '~utils/objects' | ||
|
||
type FilterQueryParams = { | ||
[K in keyof Omit<IElectionListFilter, 'organizationId'>]: string | ||
} | ||
|
||
export const ProcessSearchBox = () => { | ||
const { t } = useTranslation() | ||
const { queryParams, setQueryParams } = useQueryParams<FilterQueryParams>() | ||
|
||
return ( | ||
<Flex direction={{ base: 'column', lg: 'row' }} align={'center'} justify={'end'} gap={4}> | ||
<Checkbox | ||
onChange={(e) => setQueryParams({ ...queryParams, withResults: e.target.checked ? 'true' : undefined })} | ||
> | ||
<Trans i18nKey='process.show_with_results'>Show only processes with results</Trans> | ||
</Checkbox> | ||
<Flex justify='flex-end'> | ||
<InputSearch | ||
maxW={'300px'} | ||
placeholder={t('process.search_by')} | ||
onChange={(value: string) => { | ||
setQueryParams({ ...queryParams, electionId: value }) | ||
}} | ||
debounceTime={500} | ||
/> | ||
</Flex> | ||
</Flex> | ||
) | ||
} | ||
|
||
export const ProcessByTypeFilter = () => { | ||
const { t } = useTranslation() | ||
const { queryParams, setQueryParams } = useQueryParams<FilterQueryParams>() | ||
|
||
const processStatusFilters = [ | ||
{ | ||
label: t('process.by_status_all'), | ||
value: undefined, | ||
}, | ||
{ | ||
label: t('process.by_status_all_active'), | ||
value: 'READY', | ||
}, | ||
{ | ||
label: t('process.by_status_paused'), | ||
value: 'PAUSED', | ||
}, | ||
{ | ||
label: t('process.by_status_ended'), | ||
value: 'ENDED', | ||
}, | ||
] | ||
|
||
return ( | ||
<Flex align={'center'} justify={'center'} gap={4} wrap={'wrap'}> | ||
{processStatusFilters.map((filter, i) => ( | ||
<Button | ||
flex={{ base: 'none', md: '1' }} | ||
key={i} | ||
onClick={() => setQueryParams({ ...queryParams, status: filter.value })} | ||
> | ||
{filter.label} | ||
</Button> | ||
))} | ||
</Flex> | ||
) | ||
} | ||
|
||
export const PaginatedProcessList = () => { | ||
const { page }: { page?: number } = useParams() | ||
const { data: processCount, isLoading: isLoadingCount } = useProcessesCount() | ||
const count = processCount || 0 | ||
const { queryParams: processFilters } = useQueryParams<FilterQueryParams>() | ||
|
||
// If no filters applied we can calculate the total pages using process total count | ||
let totalPages: number | undefined = undefined | ||
if (isEmpty(processFilters)) { | ||
totalPages = Math.ceil(count / 10) | ||
} | ||
|
||
const { | ||
data: processes, | ||
isLoading: isLoadingOrgs, | ||
isError, | ||
error, | ||
} = useProcessList({ | ||
page: Number(page || 0), | ||
filters: { | ||
electionId: processFilters.electionId, | ||
// organizationId: processFilters.electionId, | ||
status: processFilters.status as IElectionListFilter['status'], | ||
withResults: processFilters.withResults ? processFilters.withResults === 'true' : undefined, | ||
}, | ||
}) | ||
|
||
const isLoading = isLoadingCount || isLoadingOrgs | ||
|
||
if (isLoading) { | ||
return <LoadingCards /> | ||
} | ||
|
||
if (!processes || processes?.elections.length === 0 || isError) { | ||
return <LoadingError error={error} /> | ||
} | ||
|
||
return ( | ||
<RoutedPaginationProvider totalPages={totalPages} path={processListPath}> | ||
{processes?.elections.map((election, i) => <ElectionCard key={i} election={election} />)} | ||
<RoutedPagination /> | ||
</RoutedPaginationProvider> | ||
) | ||
} |
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,13 +1,31 @@ | ||
import { Input, InputGroup, InputLeftElement, InputProps } from '@chakra-ui/react' | ||
import { BiSearchAlt } from 'react-icons/bi' | ||
import { debounce } from '~utils/debounce' | ||
import { ChangeEvent } from 'react' | ||
|
||
export const InputSearch = ({ | ||
debounceTime = 0, | ||
onChange, | ||
...props | ||
}: { | ||
debounceTime?: number | ||
onChange?: (event: string) => void | ||
} & Omit<InputProps, 'onChange'>) => { | ||
const debouncedSearch = debounce((value: string) => { | ||
if (onChange) onChange(value) | ||
}, debounceTime) | ||
|
||
export const InputSearch = (props: InputProps) => { | ||
return ( | ||
<InputGroup> | ||
<InputLeftElement pointerEvents='none'> | ||
<BiSearchAlt color={'lightText'} /> | ||
</InputLeftElement> | ||
<Input {...props} /> | ||
<Input | ||
{...props} | ||
onChange={(event: ChangeEvent<HTMLInputElement>) => { | ||
debouncedSearch(event.target.value) | ||
}} | ||
/> | ||
</InputGroup> | ||
) | ||
} |
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
Oops, something went wrong.
ec7668d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
π Published on https://vocdoni-explorer-stg.netlify.app as production
π Deployed on https://667016ac41e4c3338bf8150b--vocdoni-explorer-stg.netlify.app
ec7668d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
π Published on https://vocdoni-explorer-dev.netlify.app as production
π Deployed on https://667016c1225373324f2ee08a--vocdoni-explorer-dev.netlify.app