Skip to content

Commit

Permalink
Parliamentary signee view
Browse files Browse the repository at this point in the history
  • Loading branch information
juni-haukur committed Sep 16, 2024
1 parent ef46b60 commit 11f5a84
Show file tree
Hide file tree
Showing 5 changed files with 255 additions and 34 deletions.
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
@@ -1,6 +1,6 @@
export const CollectionType = {
Presidential: 'Forsetakosningar',
Parliamentary: 'Alþingiskosningar',
Parliamentary: 'Alþingiskosning NÝTT TEST',
}

// will be fetched later on
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 any 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,31 +1,118 @@
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 { SignatureCollection } from '@island.is/api/schema'
import SignedList from '../SignedList'
import { SignatureCollection } from '../../../types/schema'

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

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>
{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
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import { Box } from '@island.is/island-ui/core'
import { useLocale } from '@island.is/localization'
import {
EmptyState,
IntroHeader,
THJODSKRA_SLUG,
} from '@island.is/service-portal/core'
import { IntroHeader } from '@island.is/service-portal/core'
import { m } from '../../lib/messages'
import OwnerView from './OwnerView'
import SigneeView from './SigneeView'
import { useGetCurrentCollection, useIsOwner } from '../../hooks'
import { CollectionType } from '../../lib/constants'
import { Skeleton } from '../../skeletons'

const SignatureListsParliamentary = () => {
const { formatMessage } = useLocale()
Expand All @@ -18,18 +14,13 @@ const SignatureListsParliamentary = () => {
const { currentCollection, loadingCurrentCollection } =
useGetCurrentCollection()

console.log(currentCollection)
console.log(isOwner)

return (
<Box>
<IntroHeader
title={formatMessage(m.pageTitle)}
intro={formatMessage(m.pageDescriptionSignee)}
/>
{currentCollection?.name === CollectionType.Parliamentary &&
!loadingIsOwner &&
!loadingCurrentCollection ? (
{!loadingIsOwner && !loadingCurrentCollection ? (
<Box>
{isOwner.success ? (
<OwnerView currentCollection={currentCollection} />
Expand All @@ -38,10 +29,7 @@ const SignatureListsParliamentary = () => {
)}
</Box>
) : (
<EmptyState
title={m.noCollectionIsActive}
description={m.noCollectionIsActiveDescription}
/>
<Skeleton />
)}
</Box>
)
Expand Down

0 comments on commit 11f5a84

Please sign in to comment.