Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(portals-admin): Set up for Parliamentary Lists #15892

Merged
merged 25 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 52 additions & 2 deletions libs/portals/admin/signature-collection/src/lib/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ export const m = defineMessages({
},
signatureListsTitle: {
id: 'admin-portal.signature-collection:signatureLists',
defaultMessage: 'Meðmælasafnanir',
defaultMessage: 'Forsetakosningar',
description: '',
},
signatureListsConstituencyTitle: {
id: 'admin-portal.signature-collection:signatureListsConstituencyTitle',
defaultMessage: 'Kjördæmi',
description: '',
},
signatureListsDescription: {
Expand Down Expand Up @@ -150,6 +155,11 @@ export const m = defineMessages({
defaultMessage: 'Skoða söfnun',
description: '',
},
viewConstituency: {
id: 'admin-portal.signature-collection:viewConstituency',
defaultMessage: 'Skoða kjördæmi',
description: '',
},
noLists: {
id: 'admin-portal.signature-collection:noLists',
defaultMessage: 'Engin söfnun í gangi',
Expand Down Expand Up @@ -417,7 +427,7 @@ export const m = defineMessages({
compareListsDescription: {
id: 'admin-portal.signature-collection:compareListsDescription',
defaultMessage:
'Fulltrúar í yfirkjörstjórnum og frambjóðendur geta ekki mælt með framboði.',
'Fulltrúar í yfirkjörstjórnum og frambjóðendur geta ekki mælt með framboði',
description: '',
},
compareListsModalDescription: {
Expand Down Expand Up @@ -482,6 +492,46 @@ export const m = defineMessages({
},
})

export const parliamentaryMessages = defineMessages({
listTitle: {
id: 'admin-portal.signature-collection-parliamentary:listTitle',
defaultMessage: 'Alþingiskosningar',
description: '',
},
signatureListsTitle: {
id: 'admin-portal.signature-collection-parliamentary:signatureLists',
defaultMessage: 'Alþingiskosningar',
description: '',
},
signatureListsDescription: {
id: 'admin-portal.signature-collection-parliamentary:signatureListsDescription',
defaultMessage: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
description: '',
},
signatureListsIntro: {
id: 'admin-portal.signature-collection-parliamentary:signatureListsIntro',
defaultMessage:
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed etiam, ut inquit, in vita et in voluptate locum ponamus, isdem et in dolore et in odio.',
description: '',
},
compareListsButton: {
id: 'admin-portal.signature-collection-parliamentary:compareListsButton',
defaultMessage: 'Bera saman',
description: '',
},
compareListsDescription: {
id: 'admin-portal.signature-collection-parliamentary:compareListsDescription',
defaultMessage: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit',
description: '',
},
singleConstituencyIntro: {
id: 'admin-portal.signature-collection-parliamentary:singleConstituencyIntro',
defaultMessage:
'Hér er yfirlit yfir allar meðmælasafnanir sem stofnaðar hafa verið í',
description: '',
},
})

export const createCollectionErrorMessages = defineMessages({
age: {
id: 'admin-portal.signature-collection:error.age',
Expand Down
13 changes: 9 additions & 4 deletions libs/portals/admin/signature-collection/src/lib/navigation.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
import { PortalNavigationItem } from '@island.is/portals/core'
import { SignatureCollectionPaths } from './paths'
import { m } from './messages'
import { m, parliamentaryMessages } from './messages'

export const signatureCollectionNavigation: PortalNavigationItem = {
name: m.signatureListsTitle,
icon: {
icon: 'settings',
icon: 'receipt',
},
description: m.signatureListsDescription,
path: SignatureCollectionPaths.SignatureLists,
path: SignatureCollectionPaths.ParliamentaryRoot,
children: [
{
name: parliamentaryMessages.listTitle,
path: SignatureCollectionPaths.ParliamentaryRoot,
activeIfExact: true,
},
{
name: m.collectionTitle,
path: SignatureCollectionPaths.SignatureLists,
path: SignatureCollectionPaths.PresidentialLists,
activeIfExact: true,
},
],
Expand Down
10 changes: 8 additions & 2 deletions libs/portals/admin/signature-collection/src/lib/paths.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
export enum SignatureCollectionPaths {
SignatureLists = '/medmaelasofnun',
SignatureList = '/medmaelasofnun/:id',
// Presidential
PresidentialLists = '/medmaelasofnun',
PresidentialList = '/medmaelasofnun/:listId',

// Parliamentary
ParliamentaryRoot = '/althingiskosningar',
ParliamentaryConstituency = '/althingiskosningar/:constituencyName',
ParliamentaryConstituencyList = '/althingiskosningar/:constituencyName/:listId',
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import type { WrappedLoaderFn } from '@island.is/portals/core'
import {
AllListsDocument,
AllListsQuery,
} from './graphql/getAllSignatureLists.generated'
import {
SignatureCollection,
SignatureCollectionList,
} from '@island.is/api/schema'
import {
CollectionDocument,
CollectionQuery,
} from './graphql/getCollectionStatus.generated'
} from './allListsGraphql/getCollectionStatus.generated'
import {
AllListsDocument,
AllListsQuery,
} from './allListsGraphql/getAllSignatureLists.generated'

export interface ListsLoaderReturn {
allLists: SignatureCollectionList[]
Expand All @@ -19,9 +19,7 @@ export interface ListsLoaderReturn {
}

export const listsLoader: WrappedLoaderFn = ({ client }) => {
return async ({
params,
}): Promise<{
return async (): Promise<{
allLists: SignatureCollectionList[]
collectionStatus: string
collection: SignatureCollection
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import type { WrappedLoaderFn } from '@island.is/portals/core'
import {
ListbyidDocument,
ListbyidQuery,
} from './graphql/getSignatureList.generated'
import {
SignatureCollectionList,
SignatureCollectionSignature,
} from '@island.is/api/schema'
import {
ListStatusDocument,
ListStatusQuery,
} from './graphql/getListStatus.generated'
ListbyidDocument,
ListbyidQuery,
} from './listGraphql/getSignatureList.generated'
import {
SignaturesDocument,
SignaturesQuery,
} from './graphql/getListSignees.generated'
} from './listGraphql/getListSignees.generated'
import {
ListStatusDocument,
ListStatusQuery,
} from './listGraphql/getListStatus.generated'

export const listLoader: WrappedLoaderFn = ({ client }) => {
return async ({
Expand All @@ -29,7 +29,7 @@ export const listLoader: WrappedLoaderFn = ({ client }) => {
fetchPolicy: 'network-only',
variables: {
input: {
listId: params.id,
listId: params.listId,
},
},
})
Expand All @@ -39,7 +39,7 @@ export const listLoader: WrappedLoaderFn = ({ client }) => {
fetchPolicy: 'network-only',
variables: {
input: {
listId: params.id,
listId: params.listId,
},
},
})
Expand All @@ -49,7 +49,7 @@ export const listLoader: WrappedLoaderFn = ({ client }) => {
fetchPolicy: 'network-only',
variables: {
input: {
listId: params.id,
listId: params.listId,
},
},
})
Expand Down
41 changes: 35 additions & 6 deletions libs/portals/admin/signature-collection/src/module.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,20 @@ import { PortalModule } from '@island.is/portals/core'
import { lazy } from 'react'
import { m } from './lib/messages'
import { SignatureCollectionPaths } from './lib/paths'
import { listsLoader } from './screens/AllLists/AllLists.loader'
import { AdminPortalScope } from '@island.is/auth/scopes'
import { listLoader } from './screens/List/List.loader'
import { listsLoader } from './loaders/AllLists.loader'
import { listLoader } from './loaders/List.loader'

const AllLists = lazy(() => import('./screens/AllLists'))
const List = lazy(() => import('./screens/List'))
/* parliamentary */
const ParliamentaryRoot = lazy(() => import('./screens-parliamentary'))
const ParliamentaryConstituency = lazy(() =>
import('./screens-parliamentary/Constituency'),
)
const ParliamentaryList = lazy(() => import('./screens-parliamentary/List'))

/* presidential */
const AllLists = lazy(() => import('./screens-presidential/AllLists'))
const List = lazy(() => import('./screens-presidential/List'))

const allowedScopes: string[] = [
AdminPortalScope.signatureCollectionManage,
Expand All @@ -20,9 +28,30 @@ export const signatureCollectionModule: PortalModule = {
enabled: ({ userInfo }) =>
userInfo.scopes.some((scope) => allowedScopes.includes(scope)),
routes: (props) => [
/* ------ Parliamentary ------ */
{
name: m.signatureListsTitle,
path: SignatureCollectionPaths.ParliamentaryRoot,
element: <ParliamentaryRoot />,
loader: listsLoader(props),
},
{
name: m.signatureListsConstituencyTitle,
path: SignatureCollectionPaths.ParliamentaryConstituency,
element: <ParliamentaryConstituency />,
loader: listsLoader(props),
},
albinagu marked this conversation as resolved.
Show resolved Hide resolved
{
name: m.singleList,
path: SignatureCollectionPaths.ParliamentaryConstituencyList,
element: <ParliamentaryList />,
loader: listLoader(props),
},
albinagu marked this conversation as resolved.
Show resolved Hide resolved

/* ------ Presidential ------ */
{
name: m.signatureListsTitle,
path: SignatureCollectionPaths.SignatureLists,
path: SignatureCollectionPaths.PresidentialLists,
element: (
<AllLists
allowedToProcess={props.userInfo.scopes.some(
Expand All @@ -34,7 +63,7 @@ export const signatureCollectionModule: PortalModule = {
},
{
name: m.singleList,
path: SignatureCollectionPaths.SignatureList,
path: SignatureCollectionPaths.PresidentialList,
element: (
<List
allowedToProcess={props.userInfo.scopes.some(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import { IntroHeader, PortalNavigation } from '@island.is/portals/core'
import { signatureCollectionNavigation } from '../../lib/navigation'
import { useLocale } from '@island.is/localization'
import { m, parliamentaryMessages } from '../../lib/messages'
import {
ActionCard,
Box,
GridColumn,
GridContainer,
GridRow,
Stack,
Text,
} from '@island.is/island-ui/core'
import { useLoaderData, useNavigate, useParams } from 'react-router-dom'
import { SignatureCollectionPaths } from '../../lib/paths'
import { ListsLoaderReturn } from '../../loaders/AllLists.loader'
import CreateCollection from '../../shared-components/createCollection'

export const Constituency = () => {
const { formatMessage } = useLocale()
const navigate = useNavigate()

const { collection, allLists } = useLoaderData() as ListsLoaderReturn
const { constituencyName } = useParams() as { constituencyName: string }

const constituencyLists = allLists.filter(
(list) => list.area.name === constituencyName,
)

return (
<GridContainer>
<GridRow direction="row">
<GridColumn
span={['12/12', '5/12', '5/12', '3/12']}
offset={['0', '7/12', '7/12', '0']}
>
<PortalNavigation
navigation={signatureCollectionNavigation}
title={formatMessage(m.signatureListsTitle)}
/>
</GridColumn>
<GridColumn
paddingTop={[5, 5, 5, 0]}
offset={['0', '0', '0', '1/12']}
span={['12/12', '12/12', '12/12', '8/12']}
>
<IntroHeader
title={constituencyName}
intro={
formatMessage(parliamentaryMessages.singleConstituencyIntro) +
' ' +
constituencyName
}
imgPosition="right"
imgHiddenBelow="sm"
/>
<GridRow>
<GridColumn span={'12/12'}>
<Box
marginBottom={3}
display="flex"
justifyContent="spaceBetween"
alignItems="center"
>
<Text variant="eyebrow">
{formatMessage(m.totalListResults) +
': ' +
constituencyLists.length}
</Text>
{constituencyLists?.length > 0 && (
<CreateCollection collectionId={collection?.id} />
)}
</Box>
<Stack space={3}>
{constituencyLists.map((list) => (
<ActionCard
key={list.id}
eyebrow={constituencyName}
heading={list.title.split(' - ')[0]}
progressMeter={{
currentProgress: list.numberOfSignatures ?? 0,
maxProgress: list.area.min,
withLabel: true,
}}
cta={{
label: formatMessage(m.viewList),
variant: 'text',
onClick: () => {
navigate(
SignatureCollectionPaths.ParliamentaryConstituencyList.replace(
':constituencyName',
constituencyName,
).replace(':listId', list.id),
)
},
}}
/>
))}
</Stack>
</GridColumn>
</GridRow>
</GridColumn>
</GridRow>
</GridContainer>
)
}

export default Constituency
Loading
Loading