Skip to content

Commit

Permalink
feat(service-portal): Signee view for parliamentary signature collect…
Browse files Browse the repository at this point in the history
…ion (#16019)

* initial setup parliamentary

* Parliamentary signee view

* update urls for parliamentary

* feedback

* more

* refactor is parliamentary check

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
juni-haukur and kodiakhq[bot] authored Sep 16, 2024
1 parent a4803a3 commit a5c9f5c
Show file tree
Hide file tree
Showing 8 changed files with 314 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const Done: Form = buildForm({
buildMessageWithLinkButtonField({
id: 'done.goToServicePortal',
title: '',
url: '/minarsidur/min-gogn/listar/medmaelasofnun',
url: '/minarsidur/min-gogn/listar/althingis-medmaelasofnun',
buttonTitle: m.linkFieldButtonTitle,
message: m.linkFieldMessage,
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const Done: Form = buildForm({
buildMessageWithLinkButtonField({
id: 'done.goToServicePortal',
title: '',
url: '/minarsidur/min-gogn/listar/medmaelasofnun',
url: '/minarsidur/min-gogn/listar/althingis-medmaelasofnun',
buttonTitle: m.linkFieldButtonTitle,
message: m.linkFieldMessage,
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ export const GetCurrentCollection = gql`
startTime
name
isActive
isPresidential
status
areas {
id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ const Signees = () => {
useNamespaces('sp.signatureCollection')
const { formatMessage } = useLocale()
const { pathname } = useLocation()
const listId = pathname.replace('/min-gogn/listar/medmaelasofnun/', '')
const listId = pathname.replace(
'/min-gogn/listar/althingis-medmaelasofnun/',
'',
)

const [searchTerm, setSearchTerm] = useState('')
const { listSignees, loadingSignees } = useGetListSignees(listId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,25 @@ import { useLocale } from '@island.is/localization'
import { m } from '../../../lib/messages'
import AddConstituency from './modals/AddConstituency'
import DeletePerson from './modals/DeletePerson'
import {
useGetListsForOwner,
useGetListsForUser,
useIsOwner,
} from '../../../hooks'
import { useAuth } from '@island.is/auth/react'
import { SignatureCollection } from '@island.is/api/schema'

const OwnerView = () => {
const OwnerView = ({
currentCollection,
}: {
currentCollection: SignatureCollection
}) => {
const navigate = useNavigate()
const { formatMessage } = useLocale()
const { userInfo: user } = useAuth()
const { listsForOwner, loadingOwnerLists } = useGetListsForOwner(
currentCollection?.id || '',
)

return (
<Stack space={8}>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
import { ActionCard, Box, Button, Text, toast } from '@island.is/island-ui/core'
import { useLocale } from '@island.is/localization'
import { m } from '../../../lib/messages'
import { Modal } from '@island.is/service-portal/core'
import { useState } from 'react'
import { useGetSignedList } from '../../../hooks'
import format from 'date-fns/format'
import { useMutation } from '@apollo/client'
import { unSignList } from '../../../hooks/graphql/mutations'
import {
SignatureCollectionSignedList,
SignatureCollectionSuccess,
} from '@island.is/api/schema'

const SignedList = () => {
const { formatMessage } = useLocale()
const [modalIsOpen, setModalIsOpen] = useState(false)

// SignedList is typically singular, although it may consist of multiple entries, which in that case will all be invalid
const { signedLists, loadingSignedLists, refetchSignedLists } =
useGetSignedList()

const [unSign, { loading }] = useMutation(unSignList, {
variables: {
input: {
listId:
signedLists && signedLists?.length === 1
? signedLists[0].id
: undefined,
},
},
})

const onUnSignList = async () => {
try {
await unSign().then(({ data }) => {
if (
(
data as unknown as {
signatureCollectionUnsign: SignatureCollectionSuccess
}
).signatureCollectionUnsign.success
) {
toast.success(formatMessage(m.unSignSuccess))
setModalIsOpen(false)
refetchSignedLists()
} else {
setModalIsOpen(false)
}
})
} catch (e) {
toast.error(formatMessage(m.unSignError))
}
}

return (
<Box>
{!loadingSignedLists && !!signedLists?.length && (
<Box marginTop={[5, 7]}>
<Text marginBottom={2}>{formatMessage(m.mySigneeListsHeader)}</Text>
{signedLists?.map((list: SignatureCollectionSignedList) => {
return (
<Box marginBottom={3} key={list.id}>
<ActionCard
heading={list.title}
eyebrow={`${
list.isDigital
? formatMessage(m.signedTime)
: formatMessage(m.uploadedTime)
} ${format(new Date(list.signedDate), 'dd.MM.yyyy')}`}
text={formatMessage(m.collectionTitle)}
cta={
list.canUnsign
? {
label: formatMessage(m.unSignList),
buttonType: {
variant: 'text',
colorScheme: 'destructive',
},
onClick: () => setModalIsOpen(true),
icon: undefined,
}
: undefined
}
tag={
list.isValid && !list.active
? {
label: formatMessage(m.collectionClosed),
variant: 'red',
outlined: true,
}
: list.isValid && !list.isDigital
? {
label: formatMessage(m.paperUploadedSignature),
variant: 'blue',
outlined: true,
}
: !list.isValid
? {
label: formatMessage(m.signatureIsInvalid),
variant: 'red',
outlined: false,
}
: undefined
}
/>
<Modal
id="unSignList"
isVisible={modalIsOpen}
toggleClose={false}
initialVisibility={false}
onCloseModal={() => setModalIsOpen(false)}
>
<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>
</Modal>
</Box>
)
})}
</Box>
)}
</Box>
)
}

export default SignedList
Original file line number Diff line number Diff line change
@@ -1,26 +1,120 @@
import { ActionCard, Box, Text } from '@island.is/island-ui/core'
import {
ActionCard,
AlertMessage,
Box,
Button,
Stack,
Text,
} from '@island.is/island-ui/core'
import { useLocale } from '@island.is/localization'
import { EmptyState } from '@island.is/service-portal/core'
import { useGetListsForUser, useGetSignedList } from '../../../hooks'
import format from 'date-fns/format'
import { Skeleton } from '../../../skeletons'
import { useAuth } from '@island.is/auth/react'
import { sortAlpha } from '@island.is/shared/utils'
import { m } from '../../../lib/messages'
import SignedList from '../SignedList'
import { SignatureCollection } from '../../../types/schema'

const SigneeView = ({
currentCollection,
}: {
currentCollection: SignatureCollection
}) => {
const { userInfo: user } = useAuth()

const SigneeView = () => {
const { formatMessage } = useLocale()
const { signedLists, loadingSignedLists } = useGetSignedList()
const { listsForUser, loadingUserLists } = useGetListsForUser(
currentCollection?.id,
)

return (
<Box>
<Text marginBottom={3} variant="h4">
{formatMessage(m.mySigneeListsHeader)}
</Text>
<ActionCard
backgroundColor="white"
heading={'Listi A - Reykjavík norður'}
eyebrow={'Skrifað undir: 07.04.2024'}
text={formatMessage(m.parliamentaryElectionsTitle)}
tag={{
label: formatMessage(m.collectionClosed),
variant: 'red',
outlined: true,
}}
/>
{!user?.profile.actor && !loadingSignedLists && !loadingUserLists ? (
<Box>
{currentCollection.isPresidential &&
listsForUser.length === 0 &&
signedLists.length === 0 && (
<Box marginTop={10}>
<EmptyState
title={m.noCollectionIsActive}
description={m.noCollectionIsActiveDescription}
/>
</Box>
)}
<Box marginTop={[2, 7]}>
{/* Signed list */}
<SignedList />

{/* Other available lists */}
<Box marginTop={[5, 10]}>
{listsForUser.length > 0 && (
<Text marginBottom={2}>
{formatMessage(m.mySigneeListsByAreaHeader)}
</Text>
)}

<Stack space={3}>
{[...listsForUser]?.sort(sortAlpha('title')).map((list) => {
return (
<ActionCard
key={list.id}
backgroundColor="white"
heading={list.title}
eyebrow={
formatMessage(m.endTime) +
' ' +
format(new Date(list.endTime), 'dd.MM.yyyy')
}
text={formatMessage(m.collectionTitle)}
cta={
new Date(list.endTime) > new Date() && !list.maxReached
? {
label: formatMessage(m.signList),
variant: 'text',
icon: 'arrowForward',
disabled: !!signedLists.length,
onClick: () => {
window.open(
`${document.location.origin}${list.slug}`,
)
},
}
: undefined
}
tag={
new Date(list.endTime) < new Date()
? {
label: formatMessage(m.collectionClosed),
variant: 'red',
outlined: true,
}
: list.maxReached
? {
label: formatMessage(m.collectionMaxReached),
variant: 'red',
outlined: true,
}
: undefined
}
/>
)
})}
</Stack>
</Box>
</Box>
</Box>
) : user?.profile.actor ? (
<AlertMessage
type="warning"
title={formatMessage(m.actorNoAccessTitle)}
message={m.actorNoAccessDescription.defaultMessage}
/>
) : (
<Skeleton />
)}
</Box>
)
}
Expand Down
Loading

0 comments on commit a5c9f5c

Please sign in to comment.