Skip to content

Commit

Permalink
fix(portals-admin): allow delete list & double tag
Browse files Browse the repository at this point in the history
  • Loading branch information
albina committed Oct 31, 2024
1 parent 72d681b commit f5065a6
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 82 deletions.
5 changes: 5 additions & 0 deletions libs/portals/admin/signature-collection/src/lib/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,11 @@ export const m = defineMessages({
defaultMessage: 'Læsa söfnun',
description: '',
},
listOpen: {
id: 'admin-portal.signature-collection:listOpened',
defaultMessage: 'Söfnun í gangi',
description: '',
},
listLocked: {
id: 'admin-portal.signature-collection:listLocked',
defaultMessage: 'Lista læst',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ import electionsCommitteeLogo from '../../../assets/electionsCommittee.svg'
import nationalRegistryLogo from '../../../assets/nationalRegistry.svg'
import { useSignatureCollectionAdminRemoveListMutation } from './removeList.generated'
import { useSignatureCollectionAdminRemoveCandidateMutation } from './removeCandidate.generated'
import {
CollectionStatus,
SignatureCollectionList,
} from '@island.is/api/schema'
import { SignatureCollectionList } from '@island.is/api/schema'

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

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

const constituencyLists = allLists.filter(
Expand Down Expand Up @@ -160,92 +156,98 @@ export const Constituency = ({
},
}}
tag={
allowedToProcess &&
list.active &&
collectionStatus === CollectionStatus.InitialActive
allowedToProcess
? {
label: 'Cancel collection',
renderTag: () => (
<DialogPrompt
baseId="cancel_collection_dialog"
title={
formatMessage(m.cancelCollectionButton) +
' - ' +
list.area?.name
}
description={
candidatesListCount[list.candidate.id] === 1
? formatMessage(
m.cancelCollectionModalMessageLastList,
)
: formatMessage(
m.cancelCollectionModalMessage,
)
}
ariaLabel="delete"
disclosureElement={
<Tag outlined variant="red">
<Box display="flex" alignItems="center">
<Icon
icon="trash"
size="small"
type="outline"
/>
</Box>
</Tag>
}
onConfirm={() => {
removeList({
variables: {
input: {
listId: list.id,
},
},
})

if (
label:
!list.active && !list.reviewed
? formatMessage(m.listLocked)
: !list.active && list.reviewed
? formatMessage(m.confirmListReviewed)
: formatMessage(m.listOpen),
variant:
!list.active && !list.reviewed
? 'blueberry'
: !list.active && list.reviewed
? 'mint'
: 'blue',
outlined: false,
renderTag: (cld) => (
<Box
display="flex"
alignItems="center"
columnGap={1}
>
{cld}
<DialogPrompt
baseId="cancel_collection_dialog"
title={
formatMessage(m.cancelCollectionButton) +
' - ' +
list.area?.name
}
description={
candidatesListCount[list.candidate.id] === 1
) {
removeCandidate({
? formatMessage(
m.cancelCollectionModalMessageLastList,
)
: formatMessage(
m.cancelCollectionModalMessage,
)
}
ariaLabel="delete"
disclosureElement={
<Tag outlined variant="red">
<Box display="flex" alignItems="center">
<Icon
icon="trash"
size="small"
type="outline"
/>
</Box>
</Tag>
}
onConfirm={() => {
removeList({
variables: {
input: {
candidateId: list.candidate.id,
listId: list.id,
},
},
})

if (
candidatesListCount[list.candidate.id] ===
1
) {
removeCandidate({
variables: {
input: {
candidateId: list.candidate.id,
},
},
})
}
}}
buttonTextConfirm={
candidatesListCount[list.candidate.id] === 1
? formatMessage(
m.cancelCollectionAndCandidateModalConfirmButton,
)
: formatMessage(
m.cancelCollectionModalConfirmButton,
)
}
}}
buttonTextConfirm={
candidatesListCount[list.candidate.id] === 1
? formatMessage(
m.cancelCollectionAndCandidateModalConfirmButton,
)
: formatMessage(
m.cancelCollectionModalConfirmButton,
)
}
buttonPropsConfirm={{
variant: 'primary',
colorScheme: 'destructive',
}}
buttonTextCancel={formatMessage(
m.cancelCollectionModalCancelButton,
)}
/>
buttonPropsConfirm={{
variant: 'primary',
colorScheme: 'destructive',
}}
buttonTextCancel={formatMessage(
m.cancelCollectionModalCancelButton,
)}
/>
</Box>
),
}
: !list.active && !list.reviewed
? {
label: formatMessage(m.listLocked),
variant: 'blueberry',
outlined: false,
}
: !list.active && list.reviewed
? {
label: formatMessage(m.confirmListReviewed),
variant: 'mint',
outlined: false,
}
: undefined
}
/>
Expand Down

0 comments on commit f5065a6

Please sign in to comment.