Skip to content

Commit

Permalink
fix(admin): sc collection statuses (#16501)
Browse files Browse the repository at this point in the history
* fix(admin): sc collection statuses

* finishups

* tweak

* chore: nx format:write update dirty files

* compare lists status tweak

---------

Co-authored-by: andes-it <builders@andes.is>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Oct 22, 2024
1 parent 6ea4498 commit 08013ea
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 43 deletions.
21 changes: 21 additions & 0 deletions libs/portals/admin/signature-collection/src/lib/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,27 @@ export const m = defineMessages({
defaultMessage: 'Opna fyrir úrvinnslu',
description: '',
},
collectionReviewedTitle: {
id: 'admin-portal.signature-collection:collectionReviewedTitle',
defaultMessage: 'Meðmælasöfnun vegna framboðs til Alþingis lokið',
description: '',
},
collectionReviewedMessage: {
id: 'admin-portal.signature-collection:collectionReviewedMessage',
defaultMessage:
'Nú hefur úrvinnslu verið lokið á öllum listum í öllum kjördæmum.',
description: '',
},
collectionProcessedTitle: {
id: 'admin-portal.signature-collection:collectionProcessedTitle',
defaultMessage: 'Úrvinnsla meðmælasöfnunar lokið',
description: '',
},
collectionProcessedMessage: {
id: 'admin-portal.signature-collection:collectionReviewedTitle',
defaultMessage: 'Nú er hægt að framlengja stökum listum.',
description: '',
},
listReviewedModalDescription: {
id: 'admin-portal.signature-collection:listReviewedModalDescription#markdown',
defaultMessage:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ import electionsCommitteeLogo from '../../../assets/electionsCommittee.svg'
import nationalRegistryLogo from '../../../assets/nationalRegistry.svg'
import { useSignatureCollectionAdminRemoveListMutation } from './removeList.generated'
import { useSignatureCollectionAdminRemoveCandidateMutation } from './removeCandidate.generated'
import { SignatureCollectionList } from '@island.is/api/schema'
import {
CollectionStatus,
SignatureCollectionList,
} from '@island.is/api/schema'

export const Constituency = ({
allowedToProcess,
Expand All @@ -41,7 +44,8 @@ export const Constituency = ({
const navigate = useNavigate()
const { revalidate } = useRevalidator()

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

const constituencyLists = allLists.filter(
Expand Down Expand Up @@ -127,7 +131,7 @@ export const Constituency = ({
': ' +
constituencyLists.length}
</Text>
{allowedToProcess && constituencyLists?.length > 0 && (
{allowedToProcess && (
<CreateCollection
collectionId={collection?.id}
areaId={areaId}
Expand Down Expand Up @@ -158,7 +162,9 @@ export const Constituency = ({
},
}}
tag={
allowedToProcess && list.active
allowedToProcess &&
list.active &&
collectionStatus === CollectionStatus.InitialActive
? {
label: 'Cancel collection',
renderTag: () => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,12 @@ const List = ({ allowedToProcess }: { allowedToProcess: boolean }) => {
? formatMessage(m.listStatusReviewedStatusAlert)
: formatMessage(m.listStatusActiveAlert)
}
type={listStatus === ListStatus.Reviewed ? 'success' : undefined}
type={
listStatus === ListStatus.Reviewed ||
listStatus === ListStatus.Inactive
? 'success'
: undefined
}
/>
<ActionExtendDeadline
listId={list.id}
Expand All @@ -101,7 +106,9 @@ const List = ({ allowedToProcess }: { allowedToProcess: boolean }) => {
)}
{allowedToProcess && (
<Box>
{!list.active && <PaperSignees listId={list.id} />}
{!list.active && !list.reviewed && (
<PaperSignees listId={list.id} />
)}
<ActionReviewComplete listId={list.id} listStatus={listStatus} />
</Box>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ import {
useIdentityQuery,
} from './identityAndCanSignLookup.generated'
import { useSignatureCollectionAdminUploadPaperSignatureMutation } from './uploadPaperSignee.generated'
import { useRevalidator } from 'react-router-dom'

export const PaperSignees = ({ listId }: { listId: string }) => {
useNamespaces('sp.signatureCollection')
const { formatMessage } = useLocale()
const { revalidate } = useRevalidator()
const { control, reset } = useForm()

const [nationalIdInput, setNationalIdInput] = useState('')
Expand Down Expand Up @@ -76,6 +78,7 @@ export const PaperSignees = ({ listId }: { listId: string }) => {
toast.error(formatMessage(m.paperSigneeError))
}
reset()
revalidate()
setNationalIdTypo(false)
setName('')
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
Breadcrumbs,
Table as T,
Text,
AlertMessage,
} from '@island.is/island-ui/core'
import { useLocale } from '@island.is/localization'
import { IntroHeader, PortalNavigation } from '@island.is/portals/core'
Expand All @@ -24,6 +25,8 @@ import nationalRegistryLogo from '../../assets/nationalRegistry.svg'
import { useState } from 'react'
import { useSignatureCollectionSignatureLookupQuery } from './findSignature.generated'
import { SkeletonSingleRow } from '../shared-components/compareLists/skeleton'
import { CollectionStatus } from '@island.is/api/schema'
import ActionCompleteCollectionProcessing from '../shared-components/completeCollectionProcessing'

const ParliamentaryRoot = ({
allowedToProcess,
Expand All @@ -33,7 +36,8 @@ const ParliamentaryRoot = ({
const { formatMessage } = useLocale()

const navigate = useNavigate()
const { collection, allLists } = useLoaderData() as ListsLoaderReturn
const { collection, collectionStatus, allLists } =
useLoaderData() as ListsLoaderReturn

const [searchTerm, setSearchTerm] = useState('')

Expand Down Expand Up @@ -179,41 +183,80 @@ const ParliamentaryRoot = ({
</Box>
))}
<Stack space={3}>
{collection?.areas.map((area) => (
<ActionCard
key={area.id}
eyebrow={
formatMessage(m.totalListsPerConstituency) +
allLists.filter((l) => l.area.name === area.name).length
}
heading={area.name}
cta={{
label: formatMessage(m.viewConstituency),
variant: 'text',
onClick: () => {
navigate(
SignatureCollectionPaths.ParliamentaryConstituency.replace(
':constituencyName',
area.name,
),
)
},
}}
tag={
allLists
.filter((l) => l.area.name === area.name)
.every((l) => l.reviewed === true)
? {
label: formatMessage(m.confirmListReviewed),
variant: 'mint',
outlined: true,
}
: undefined
}
/>
))}
{collection?.areas.map((area) => {
const areaLists = allLists.filter(
(l) => l.area.name === area.name,
)
return (
<ActionCard
key={area.id}
eyebrow={
formatMessage(m.totalListsPerConstituency) +
areaLists.length
}
heading={area.name}
cta={{
label: formatMessage(m.viewConstituency),
variant: 'text',
onClick: () => {
navigate(
SignatureCollectionPaths.ParliamentaryConstituency.replace(
':constituencyName',
area.name,
),
)
},
}}
tag={
areaLists.length > 0 &&
areaLists.every((l) => l.reviewed === true)
? {
label: formatMessage(m.confirmListReviewed),
variant: 'mint',
outlined: true,
}
: undefined
}
/>
)
})}
</Stack>
{allowedToProcess && <CompareLists collectionId={collection?.id} />}
{allowedToProcess && (
<Box>
{(collectionStatus === CollectionStatus.InInitialReview ||
collectionStatus === CollectionStatus.InReview) && (
<CompareLists collectionId={collection?.id} />
)}
{(collectionStatus === CollectionStatus.InitialActive ||
collectionStatus === CollectionStatus.InInitialReview) && (
<ActionCompleteCollectionProcessing
collectionId={collection?.id}
canProcess={
!!allLists.length &&
allLists.every((l) => l.reviewed === true)
}
/>
)}
</Box>
)}
{collectionStatus === CollectionStatus.Processed && (
<Box marginTop={8}>
<AlertMessage
type="success"
title={formatMessage(m.collectionProcessedTitle)}
message={formatMessage(m.collectionProcessedMessage)}
/>
</Box>
)}
{collectionStatus === CollectionStatus.InReview && (
<Box marginTop={8}>
<AlertMessage
type="success"
title={formatMessage(m.collectionReviewedTitle)}
message={formatMessage(m.collectionReviewedMessage)}
/>
</Box>
)}
</GridColumn>
</GridRow>
</GridContainer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ import {
import { format as formatNationalId } from 'kennitala'
import electionsCommitteeLogo from '../../../assets/electionsCommittee.svg'
import nationalRegistryLogo from '../../../assets/nationalRegistry.svg'
import ActionCompleteCollectionProcessing from './components/completeCollectionProcessing'
import ListInfo from '../../shared-components/listInfoAlert'
import EmptyState from '../../shared-components/emptyState'
import ReviewCandidates from './components/reviewCandidates'
import CompareLists from '../../shared-components/compareLists'
import { ListsLoaderReturn } from '../../loaders/AllLists.loader'
import CreateCollection from '../../shared-components/createCollection'
import ActionCompleteCollectionProcessing from '../../shared-components/completeCollectionProcessing'

const Lists = ({ allowedToProcess }: { allowedToProcess: boolean }) => {
const { formatMessage } = useLocale()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { useLocale } from '@island.is/localization'
import { Box, Button, Text, toast } from '@island.is/island-ui/core'
import { m } from '../../../../lib/messages'
import { m } from '../../lib/messages'
import { useState } from 'react'
import { Modal } from '@island.is/react/components'
import { useRevalidator } from 'react-router-dom'
import { useProcessCollectionMutation } from './finishCollectionProcess.generated'

const ActionCompleteCollectionProcessing = ({
collectionId,
canProcess,
}: {
collectionId: string
canProcess?: boolean
}) => {
const { formatMessage } = useLocale()
const [modalSubmitReviewIsOpen, setModalSubmitReviewIsOpen] = useState(false)
Expand Down Expand Up @@ -45,6 +47,7 @@ const ActionCompleteCollectionProcessing = ({
colorScheme="destructive"
variant="text"
onClick={() => setModalSubmitReviewIsOpen(true)}
disabled={!canProcess}
>
{formatMessage(m.completeCollectionProcessing)}
</Button>
Expand Down

0 comments on commit 08013ea

Please sign in to comment.