Skip to content

Commit

Permalink
Remove process filters from the sidebar
Browse files Browse the repository at this point in the history
Created a new buttongroup component to hold them
  • Loading branch information
elboletaire committed Jan 23, 2025
1 parent b58fc04 commit 2c945c5
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 9 deletions.
9 changes: 2 additions & 7 deletions src/components/Dashboard/Menu/Options.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useEffect, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { HiSquares2X2 } from 'react-icons/hi2'
import { IoIosSettings } from 'react-icons/io'
import { generatePath, matchPath, useLocation } from 'react-router-dom'
import { matchPath, useLocation } from 'react-router-dom'
import { Routes } from '~src/router/routes'
import { DashboardMenuItem } from './Item'
import { OrganizationSwitcher } from './OrganizationSwitcher'
Expand All @@ -27,13 +27,8 @@ export const DashboardMenuOptions = () => {
// },
{
label: t('voting_processes'),
route: Routes.dashboard.processes,
icon: HiSquares2X2,
children: [
{ label: t('all'), route: generatePath(Routes.dashboard.processes, { page: 1 }) },
{ label: t('active'), route: generatePath(Routes.dashboard.processes, { status: 'ready', page: 1 }) },
{ label: t('finished'), route: generatePath(Routes.dashboard.processes, { status: 'results', page: 1 }) },
// { label: t('draft'), route: '#draft' },
],
},
// {
// label: t('organization.census'),
Expand Down
39 changes: 39 additions & 0 deletions src/components/Process/ProcessStatusFilters.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { Button, ButtonGroup, ButtonGroupProps } from '@chakra-ui/react'
import { Trans } from 'react-i18next'
import { generatePath, NavLink } from 'react-router-dom'
import { Routes } from '~routes'

type ProcessStatusFilterProps = ButtonGroupProps & {
status?: string
}

const ProcessStatusFilter = ({ status, ...rest }: ProcessStatusFilterProps) => (
<ButtonGroup isAttached {...rest}>
<Button
size='xs'
as={NavLink}
to={generatePath(Routes.dashboard.processes, { page: 1 })}
isActive={status === undefined}
>
<Trans i18nKey='all'>All</Trans>
</Button>
<Button
size='xs'
as={NavLink}
to={generatePath(Routes.dashboard.processes, { status: 'ready', page: 1 })}
isActive={status === 'ready'}
>
<Trans i18nKey='active'>Active</Trans>
</Button>
<Button
size='xs'
as={NavLink}
to={generatePath(Routes.dashboard.processes, { status: 'results', page: 1 })}
isActive={status === 'results'}
>
<Trans i18nKey='finished'>Finished</Trans>
</Button>
</ButtonGroup>
)

export default ProcessStatusFilter
6 changes: 4 additions & 2 deletions src/elements/dashboard/processes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import { useTranslation } from 'react-i18next'
import { useLoaderData, useOutletContext, useParams } from 'react-router-dom'
import { DashboardContents } from '~components/Layout/Dashboard'
import Votings from '~components/Organization/Dashboard/Votings'
import ProcessStatusFilter from '~components/Process/ProcessStatusFilters'
import { DashboardLayoutContext } from '~elements/LayoutDashboard'

const OrganizationVotings = () => {
const { t } = useTranslation()
const { setBack, setTitle } = useOutletContext<DashboardLayoutContext>()
const data = useLoaderData()
const data = useLoaderData() as ElectionListWithPagination
const { status } = useParams<{ status?: string }>()

// Set page title
Expand All @@ -19,7 +20,8 @@ const OrganizationVotings = () => {
}, [setTitle, setBack])

return (
<DashboardContents>
<DashboardContents display='flex' flexDirection='column'>
<ProcessStatusFilter status={status} alignSelf='end' />
<Votings data={data as ElectionListWithPagination} status={status} />
</DashboardContents>
)
Expand Down
1 change: 1 addition & 0 deletions tsconfig.paths.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"~elements/*": ["elements/*"],
"~i18n": ["i18n/index.ts"],
"~i18n/*": ["i18n/*"],
"~routes": ["router/routes/index.ts"],
"~theme": ["theme/index.ts"],
"~theme/*" : ["theme/*"],
"~utils/*": ["utils/*"],
Expand Down

0 comments on commit 2c945c5

Please sign in to comment.