Skip to content

Commit

Permalink
fix(service-portal): listid unsign (#16172)
Browse files Browse the repository at this point in the history
* fix(service-portal): listid unsign

* chore: nx format:write update dirty files

* minor tweaks

---------

Co-authored-by: andes-it <[email protected]>
  • Loading branch information
2 people authored and thoreyjona committed Oct 2, 2024
1 parent c70b7d6 commit e77610a
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 44 deletions.
15 changes: 10 additions & 5 deletions libs/portals/admin/signature-collection/src/lib/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,17 +195,17 @@ export const m = defineMessages({
/* Hætta við söfnun modal */
cancelCollectionButton: {
id: 'dmin-portal.signature-collection:cancelCollectionButton',
defaultMessage: 'Hætta við söfnun meðmæla',
defaultMessage: 'Eyða lista',
description: '',
},
cancelCollectionModalMessage: {
id: 'dmin-portal.signature-collection:cancelCollectionModalMessage',
defaultMessage: 'Þú ert að fara að hætta við söfnun meðmæla. Ertu viss?',
defaultMessage: 'Þú ert að fara að eyða þessum lista. Ertu viss?',
description: '',
},
cancelCollectionModalConfirmButton: {
id: 'dmin-portal.signature-collection:modalConfirmButton',
defaultMessage: 'Já, hætta við',
defaultMessage: 'Já, eyða lista',
description: '',
},
cancelCollectionModalCancelButton: {
Expand All @@ -215,12 +215,12 @@ export const m = defineMessages({
},
cancelCollectionModalToastError: {
id: 'dmin-portal.signature-collection:modalToastError',
defaultMessage: 'Ekki tókst að hætta við söfnun meðmæla',
defaultMessage: 'Ekki tókst að eyða lista',
description: '',
},
cancelCollectionModalToastSuccess: {
id: 'dmin-portal.signature-collection:cancelCollectionModalToastSuccess',
defaultMessage: 'Tókst að hætta við söfnun meðmæla',
defaultMessage: 'Tókst að eyða lista',
description: '',
},

Expand Down Expand Up @@ -460,6 +460,11 @@ export const m = defineMessages({
defaultMessage: 'Samtals fjöldi',
description: '',
},
totalListsPerConstituency: {
id: 'admin-portal.signature-collection:totalListsPerConstituency',
defaultMessage: 'Fjöldi lista: ',
description: '',
},
nationalIdsSuccess: {
id: 'admin-portal.signature-collection:nationalIdsSuccess',
defaultMessage: 'Kennitölur sem tókst að hlaða upp',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const ParliamentaryRoot = () => {
const { formatMessage } = useLocale()

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

return (
<GridContainer>
Expand Down Expand Up @@ -82,7 +82,10 @@ const ParliamentaryRoot = () => {
{collection?.areas.map((area) => (
<ActionCard
key={area.id}
eyebrow={'Fjöldi lista: XXX'}
eyebrow={
formatMessage(m.totalListsPerConstituency) +
allLists.filter((l) => l.area.name === area.name).length
}
heading={area.name}
cta={{
label: formatMessage(m.viewConstituency),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ const SignedList = ({
useNamespaces('sp.signatureCollection')
const { formatMessage } = useLocale()
const [modalIsOpen, setModalIsOpen] = useState(false)
const [listIdToUnsign, setListIdToUnsign] = useState<string | undefined>(
undefined,
)

// SignedList is typically singular, although it may consist of multiple entries, which in that case will all be invalid
const { signedLists, loadingSignedLists, refetchSignedLists } =
Expand All @@ -29,10 +32,7 @@ const SignedList = ({
const [unSign, { loading }] = useMutation(unSignList, {
variables: {
input: {
listId:
signedLists && signedLists?.length === 1
? signedLists[0].id
: undefined,
listId: listIdToUnsign,
},
},
})
Expand Down Expand Up @@ -85,7 +85,10 @@ const SignedList = ({
variant: 'text',
colorScheme: 'destructive',
},
onClick: () => setModalIsOpen(true),
onClick: () => {
setListIdToUnsign(list.id)
setModalIsOpen(true)
},
icon: undefined,
}
: undefined
Expand Down Expand Up @@ -120,41 +123,44 @@ const SignedList = ({
: undefined
}
/>
<Modal
id="unSignList"
isVisible={modalIsOpen}
toggleClose={false}
initialVisibility={false}
onCloseModal={() => setModalIsOpen(false)}
>
<Box display="block" width="full">
<Text variant="h2" marginTop={[5, 0]}>
{formatMessage(m.unSignList)}
</Text>
<Text variant="default" marginTop={2}>
{formatMessage(m.unSignModalMessage)}
</Text>
<Box
marginTop={[7, 10]}
marginBottom={5}
display="flex"
justifyContent="center"
>
<Button
loading={loading}
colorScheme="destructive"
onClick={() => {
onUnSignList()
}}
>
{formatMessage(m.unSignModalConfirmButton)}
</Button>
</Box>
</Box>
</Modal>
</Box>
)
})}
<Modal
id="unSignList"
isVisible={modalIsOpen}
toggleClose={false}
initialVisibility={false}
onCloseModal={() => {
setListIdToUnsign(undefined)
setModalIsOpen(false)
}}
>
<Box display="block" width="full">
<Text variant="h2" marginTop={[5, 0]}>
{formatMessage(m.unSignList)}
</Text>
<Text variant="default" marginTop={2}>
{formatMessage(m.unSignModalMessage)}
</Text>
<Box
marginTop={[7, 10]}
marginBottom={5}
display="flex"
justifyContent="center"
>
<Button
loading={loading}
colorScheme="destructive"
onClick={() => {
onUnSignList()
}}
>
{formatMessage(m.unSignModalConfirmButton)}
</Button>
</Box>
</Box>
</Modal>
</Box>
)}
</Box>
Expand Down

0 comments on commit e77610a

Please sign in to comment.