Skip to content

Commit 91aac3a

Browse files
authored
Add elections select in mobile nav (#1001)
1 parent f3cee10 commit 91aac3a

File tree

2 files changed

+66
-4
lines changed

2 files changed

+66
-4
lines changed

web/src/components/LanguageSelector/LanguageSelector.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { useTranslation } from 'react-i18next';
55
import { Label } from '../ui/label';
66

77
export const LanguageSelector: FC = () => {
8-
const { i18n } = useTranslation(); // not passing any namespace will use the defaultNS (by default set to 'translation')
8+
const { i18n } = useTranslation(); // not passing any namespace will use the defaultNS (by default set to 'translation')
99
const router = useRouter();
1010

1111
const changeLanguage = (lng: string) => {
@@ -16,7 +16,7 @@ export const LanguageSelector: FC = () => {
1616
const options = [
1717
{
1818
label: 'English',
19-
value: 'en',
19+
value: 'en-US',
2020
},
2121
{
2222
label: 'Română',
@@ -27,7 +27,7 @@ export const LanguageSelector: FC = () => {
2727
<div className='px-4 py-2 space-y-2 '>
2828
<Label>Language</Label>
2929
<Select
30-
defaultValue={localStorage.getItem('i18nextLng') || 'en'}
30+
defaultValue={localStorage.getItem('i18nextLng') || 'en-US'}
3131
onValueChange={(value) => changeLanguage(value)}>
3232
<SelectTrigger className='w-full'>
3333
<SelectValue placeholder='Select language' />

web/src/components/layout/Header/Header.tsx

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,20 @@ import {
1111
DropdownMenuSeparator,
1212
DropdownMenuTrigger,
1313
} from '@/components/ui/dropdown-menu';
14+
import {
15+
Select,
16+
SelectContent,
17+
SelectGroup,
18+
SelectItem,
19+
SelectLabel,
20+
SelectSeparator,
21+
SelectTrigger,
22+
SelectValue,
23+
} from '@/components/ui/select';
1424
import { Skeleton } from '@/components/ui/skeleton';
1525
import { AuthContext } from '@/context/auth.context';
1626
import { useCurrentElectionRoundStore } from '@/context/election-round.store';
27+
import { ElectionEvent } from '@/features/election-event/models/election-event';
1728
import { electionRoundKeys } from '@/features/election-rounds/queries';
1829
import { staticDataKeys } from '@/hooks/query-keys';
1930
import { sleep } from '@/lib/utils';
@@ -28,7 +39,7 @@ import { sortBy } from 'lodash';
2839
import { Fragment, useContext, useEffect, useMemo, useState } from 'react';
2940
import { ElectionRoundStatus, type FunctionComponent } from '../../../common/types';
3041
import Logo from './Logo';
31-
import { ElectionEvent } from '@/features/election-event/models/election-event';
42+
import { Label } from '@/components/ui/label';
3243

3344
const navigation = [
3445
{ name: 'Dashboard', to: '/', roles: ['PlatformAdmin', 'NgoAdmin'] },
@@ -312,7 +323,58 @@ const Header = (): FunctionComponent => {
312323
{item.name}
313324
</Disclosure.Button>
314325
))}
326+
{userRole !== 'NgoAdmin' ? (
327+
<></>
328+
) : status === 'pending' ? (
329+
<Skeleton className='w-[360px] h-[26px] mr-2 rounded-lg bg-secondary-300 text-secondary-900 hover:bg-secondary-300/90' />
330+
) : (
331+
<div className='px-4 py-2 space-y-2 '>
332+
<Label>Elecction rounds</Label>
333+
<Select
334+
defaultValue={selectedElectionRound?.id ?? ''}
335+
onValueChange={(value) => {
336+
const electionRound = electionRounds?.find((er) => er.id === value);
337+
handleSelectElectionRound(electionRound);
338+
}}>
339+
<SelectTrigger className='w-full'>
340+
<SelectValue placeholder='Select language' />
341+
</SelectTrigger>
342+
<SelectContent>
343+
<SelectGroup>
344+
<SelectLabel>Active & Upcomming elections</SelectLabel>
345+
{activeElections?.map((electionRound) => (
346+
<SelectItem key={electionRound.id} value={electionRound.id}>
347+
<div className='flex items-center gap-2'>
348+
{electionRound?.status === ElectionRoundStatus.NotStarted ? (
349+
<PauseCircleIcon className='w-4 h-4 text-slate-700' />
350+
) : null}
351+
{electionRound?.status === ElectionRoundStatus.Started ? (
352+
<PlayCircleIcon className='w-4 h-4 text-green-700' />
353+
) : null}
354+
<div className='truncate max-w-[340px]' title={electionRound.title}>
355+
{electionRound.title}
356+
</div>
357+
</div>
358+
</SelectItem>
359+
))}
360+
<SelectSeparator />
361+
<SelectLabel>Archived elections</SelectLabel>
362+
{archivedElections?.map((electionRound) => (
363+
<SelectItem key={electionRound.id} value={electionRound.id}>
364+
<div className='flex items-center gap-2'>
365+
<StopCircleIcon className='w-4 h-4 text-yellow-700' />
315366

367+
<div className='truncate max-w-[340px]' title={electionRound.title}>
368+
{electionRound.title}
369+
</div>
370+
</div>
371+
</SelectItem>
372+
))}
373+
</SelectGroup>
374+
</SelectContent>
375+
</Select>
376+
</div>
377+
)}
316378
<LanguageSelector />
317379
<Disclosure.Button
318380
key='Sign Out'

0 commit comments

Comments
 (0)