From 0567137b3c7bb31fcac0179f18e5cf751f295627 Mon Sep 17 00:00:00 2001 From: Haukur Ingi Date: Mon, 16 Sep 2024 09:04:45 +0000 Subject: [PATCH 1/6] initial setup parliamentary --- .../screens/Parliamentary/OwnerView/index.tsx | 19 ++++++++- .../Parliamentary/SigneeView/index.tsx | 7 +++- .../src/screens/Parliamentary/index.tsx | 42 +++++++++++++++---- 3 files changed, 57 insertions(+), 11 deletions(-) diff --git a/libs/service-portal/signature-collection/src/screens/Parliamentary/OwnerView/index.tsx b/libs/service-portal/signature-collection/src/screens/Parliamentary/OwnerView/index.tsx index b1f00d7303e9..51d8078a779a 100644 --- a/libs/service-portal/signature-collection/src/screens/Parliamentary/OwnerView/index.tsx +++ b/libs/service-portal/signature-collection/src/screens/Parliamentary/OwnerView/index.tsx @@ -14,10 +14,27 @@ 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 || '', + ) + + console.log(listsForOwner) return ( diff --git a/libs/service-portal/signature-collection/src/screens/Parliamentary/SigneeView/index.tsx b/libs/service-portal/signature-collection/src/screens/Parliamentary/SigneeView/index.tsx index 1701ddf89f7d..28937f6eb894 100644 --- a/libs/service-portal/signature-collection/src/screens/Parliamentary/SigneeView/index.tsx +++ b/libs/service-portal/signature-collection/src/screens/Parliamentary/SigneeView/index.tsx @@ -1,8 +1,13 @@ import { ActionCard, Box, Text } from '@island.is/island-ui/core' import { useLocale } from '@island.is/localization' import { m } from '../../../lib/messages' +import { SignatureCollection } from '@island.is/api/schema' -const SigneeView = () => { +const SigneeView = ({ + currentCollection, +}: { + currentCollection: SignatureCollection +}) => { const { formatMessage } = useLocale() return ( diff --git a/libs/service-portal/signature-collection/src/screens/Parliamentary/index.tsx b/libs/service-portal/signature-collection/src/screens/Parliamentary/index.tsx index 3ae328e2972a..b93a194ea342 100644 --- a/libs/service-portal/signature-collection/src/screens/Parliamentary/index.tsx +++ b/libs/service-portal/signature-collection/src/screens/Parliamentary/index.tsx @@ -1,24 +1,48 @@ import { Box } from '@island.is/island-ui/core' import { useLocale } from '@island.is/localization' -import { IntroHeader, THJODSKRA_SLUG } from '@island.is/service-portal/core' +import { + EmptyState, + IntroHeader, + THJODSKRA_SLUG, +} 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' const SignatureListsParliamentary = () => { const { formatMessage } = useLocale() + const { isOwner, loadingIsOwner } = useIsOwner() + const { currentCollection, loadingCurrentCollection } = + useGetCurrentCollection() + + console.log(currentCollection) + console.log(isOwner) + return ( - - + {currentCollection?.name === CollectionType.Parliamentary && + !loadingIsOwner && + !loadingCurrentCollection ? ( + + {isOwner.success ? ( + + ) : ( + + )} + + ) : ( + - - + )} ) } From 11f5a8408c1bfd2a76f857ef25633aa18e5eca0d Mon Sep 17 00:00:00 2001 From: Haukur Ingi Date: Mon, 16 Sep 2024 10:55:50 +0000 Subject: [PATCH 2/6] Parliamentary signee view --- .../src/forms/Done.ts | 2 +- .../signature-collection/src/lib/constants.ts | 2 +- .../Parliamentary/SignedList/index.tsx | 146 ++++++++++++++++++ .../Parliamentary/SigneeView/index.tsx | 119 ++++++++++++-- .../src/screens/Parliamentary/index.tsx | 20 +-- 5 files changed, 255 insertions(+), 34 deletions(-) create mode 100644 libs/service-portal/signature-collection/src/screens/Parliamentary/SignedList/index.tsx diff --git a/libs/application/templates/signature-collection/parliamentary-list-signing/src/forms/Done.ts b/libs/application/templates/signature-collection/parliamentary-list-signing/src/forms/Done.ts index 746305678d9c..e65e617c9965 100644 --- a/libs/application/templates/signature-collection/parliamentary-list-signing/src/forms/Done.ts +++ b/libs/application/templates/signature-collection/parliamentary-list-signing/src/forms/Done.ts @@ -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, }), diff --git a/libs/service-portal/signature-collection/src/lib/constants.ts b/libs/service-portal/signature-collection/src/lib/constants.ts index 04eb57fdee3a..0e26bc28bbe6 100644 --- a/libs/service-portal/signature-collection/src/lib/constants.ts +++ b/libs/service-portal/signature-collection/src/lib/constants.ts @@ -1,6 +1,6 @@ export const CollectionType = { Presidential: 'Forsetakosningar', - Parliamentary: 'Alþingiskosningar', + Parliamentary: 'Alþingiskosning NÝTT TEST', } // will be fetched later on diff --git a/libs/service-portal/signature-collection/src/screens/Parliamentary/SignedList/index.tsx b/libs/service-portal/signature-collection/src/screens/Parliamentary/SignedList/index.tsx new file mode 100644 index 000000000000..dbb10e38bbbe --- /dev/null +++ b/libs/service-portal/signature-collection/src/screens/Parliamentary/SignedList/index.tsx @@ -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 ( + + {!loadingSignedLists && !!signedLists?.length && ( + + {formatMessage(m.mySigneeListsHeader)} + {signedLists?.map((list: SignatureCollectionSignedList) => { + return ( + + 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 + } + /> + setModalIsOpen(false)} + > + + {formatMessage(m.unSignList)} + + + {formatMessage(m.unSignModalMessage)} + + + + + + + ) + })} + + )} + + ) +} + +export default SignedList diff --git a/libs/service-portal/signature-collection/src/screens/Parliamentary/SigneeView/index.tsx b/libs/service-portal/signature-collection/src/screens/Parliamentary/SigneeView/index.tsx index 28937f6eb894..14118b010312 100644 --- a/libs/service-portal/signature-collection/src/screens/Parliamentary/SigneeView/index.tsx +++ b/libs/service-portal/signature-collection/src/screens/Parliamentary/SigneeView/index.tsx @@ -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 ( - - {formatMessage(m.mySigneeListsHeader)} - - + {!user?.profile.actor && !loadingSignedLists && !loadingUserLists ? ( + + {listsForUser.length === 0 && signedLists.length === 0 && ( + + + + )} + + {/* Signed list */} + + + {/* Other available lists */} + + {listsForUser.length > 0 && ( + + {formatMessage(m.mySigneeListsByAreaHeader)} + + )} + + + {[...listsForUser]?.sort(sortAlpha('title')).map((list) => { + return ( + 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 + } + /> + ) + })} + + + + + ) : user?.profile.actor ? ( + + ) : ( + + )} ) } diff --git a/libs/service-portal/signature-collection/src/screens/Parliamentary/index.tsx b/libs/service-portal/signature-collection/src/screens/Parliamentary/index.tsx index b93a194ea342..746f36519ea8 100644 --- a/libs/service-portal/signature-collection/src/screens/Parliamentary/index.tsx +++ b/libs/service-portal/signature-collection/src/screens/Parliamentary/index.tsx @@ -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() @@ -18,18 +14,13 @@ const SignatureListsParliamentary = () => { const { currentCollection, loadingCurrentCollection } = useGetCurrentCollection() - console.log(currentCollection) - console.log(isOwner) - return ( - {currentCollection?.name === CollectionType.Parliamentary && - !loadingIsOwner && - !loadingCurrentCollection ? ( + {!loadingIsOwner && !loadingCurrentCollection ? ( {isOwner.success ? ( @@ -38,10 +29,7 @@ const SignatureListsParliamentary = () => { )} ) : ( - + )} ) From 8b05b2d87d27f18ac9897d41d5ae5a22df2498f2 Mon Sep 17 00:00:00 2001 From: Haukur Ingi Date: Mon, 16 Sep 2024 11:03:25 +0000 Subject: [PATCH 3/6] update urls for parliamentary --- .../parliamentary-list-creation/src/forms/Done.ts | 2 +- .../src/screens/Parliamentary/OwnerView/ViewList/Signees.tsx | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/libs/application/templates/signature-collection/parliamentary-list-creation/src/forms/Done.ts b/libs/application/templates/signature-collection/parliamentary-list-creation/src/forms/Done.ts index b649ebb9d418..267416ed6140 100644 --- a/libs/application/templates/signature-collection/parliamentary-list-creation/src/forms/Done.ts +++ b/libs/application/templates/signature-collection/parliamentary-list-creation/src/forms/Done.ts @@ -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, }), diff --git a/libs/service-portal/signature-collection/src/screens/Parliamentary/OwnerView/ViewList/Signees.tsx b/libs/service-portal/signature-collection/src/screens/Parliamentary/OwnerView/ViewList/Signees.tsx index 00407d53f316..93a93e8fd759 100644 --- a/libs/service-portal/signature-collection/src/screens/Parliamentary/OwnerView/ViewList/Signees.tsx +++ b/libs/service-portal/signature-collection/src/screens/Parliamentary/OwnerView/ViewList/Signees.tsx @@ -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) From 7538efcc1624ddcfd4bcd56ea81a9cf6de0c0542 Mon Sep 17 00:00:00 2001 From: Haukur Ingi Date: Mon, 16 Sep 2024 14:30:31 +0000 Subject: [PATCH 4/6] feedback --- .../src/screens/Parliamentary/SignedList/index.tsx | 2 +- .../signature-collection/src/screens/Parliamentary/index.tsx | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/libs/service-portal/signature-collection/src/screens/Parliamentary/SignedList/index.tsx b/libs/service-portal/signature-collection/src/screens/Parliamentary/SignedList/index.tsx index dbb10e38bbbe..7317f2874728 100644 --- a/libs/service-portal/signature-collection/src/screens/Parliamentary/SignedList/index.tsx +++ b/libs/service-portal/signature-collection/src/screens/Parliamentary/SignedList/index.tsx @@ -36,7 +36,7 @@ const SignedList = () => { await unSign().then(({ data }) => { if ( ( - data as any as { + data as unknown as { signatureCollectionUnsign: SignatureCollectionSuccess } ).signatureCollectionUnsign.success diff --git a/libs/service-portal/signature-collection/src/screens/Parliamentary/index.tsx b/libs/service-portal/signature-collection/src/screens/Parliamentary/index.tsx index 746f36519ea8..25dacff04fdf 100644 --- a/libs/service-portal/signature-collection/src/screens/Parliamentary/index.tsx +++ b/libs/service-portal/signature-collection/src/screens/Parliamentary/index.tsx @@ -19,6 +19,7 @@ const SignatureListsParliamentary = () => { {!loadingIsOwner && !loadingCurrentCollection ? ( From 3723cde9c251f6ed65f38cdeadbb248e6e48d847 Mon Sep 17 00:00:00 2001 From: Haukur Ingi Date: Mon, 16 Sep 2024 14:31:47 +0000 Subject: [PATCH 5/6] more --- .../src/screens/Parliamentary/OwnerView/index.tsx | 2 -- .../signature-collection/src/screens/Parliamentary/index.tsx | 3 ++- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/libs/service-portal/signature-collection/src/screens/Parliamentary/OwnerView/index.tsx b/libs/service-portal/signature-collection/src/screens/Parliamentary/OwnerView/index.tsx index 51d8078a779a..5337b7b86c23 100644 --- a/libs/service-portal/signature-collection/src/screens/Parliamentary/OwnerView/index.tsx +++ b/libs/service-portal/signature-collection/src/screens/Parliamentary/OwnerView/index.tsx @@ -34,8 +34,6 @@ const OwnerView = ({ currentCollection?.id || '', ) - console.log(listsForOwner) - return ( diff --git a/libs/service-portal/signature-collection/src/screens/Parliamentary/index.tsx b/libs/service-portal/signature-collection/src/screens/Parliamentary/index.tsx index 25dacff04fdf..021a9d9198ed 100644 --- a/libs/service-portal/signature-collection/src/screens/Parliamentary/index.tsx +++ b/libs/service-portal/signature-collection/src/screens/Parliamentary/index.tsx @@ -1,6 +1,6 @@ import { Box } from '@island.is/island-ui/core' import { useLocale } from '@island.is/localization' -import { IntroHeader } from '@island.is/service-portal/core' +import { IntroHeader, THJODSKRA_SLUG } from '@island.is/service-portal/core' import { m } from '../../lib/messages' import OwnerView from './OwnerView' import SigneeView from './SigneeView' @@ -20,6 +20,7 @@ const SignatureListsParliamentary = () => { title={formatMessage(m.pageTitle)} intro={formatMessage(m.pageDescriptionSignee)} serviceProviderTooltip={formatMessage(m.infoProviderTooltip)} + serviceProviderSlug={THJODSKRA_SLUG} /> {!loadingIsOwner && !loadingCurrentCollection ? ( From 6b31ed3885b9d5285336791c1804b1a1792be628 Mon Sep 17 00:00:00 2001 From: Haukur Ingi Date: Mon, 16 Sep 2024 14:54:30 +0000 Subject: [PATCH 6/6] refactor is parliamentary check --- .../src/hooks/graphql/queries.ts | 1 + .../signature-collection/src/lib/constants.ts | 2 +- .../Parliamentary/SigneeView/index.tsx | 18 ++++++++++-------- .../src/screens/Parliamentary/index.tsx | 19 +++++++++++++++---- 4 files changed, 27 insertions(+), 13 deletions(-) diff --git a/libs/service-portal/signature-collection/src/hooks/graphql/queries.ts b/libs/service-portal/signature-collection/src/hooks/graphql/queries.ts index b3ef1936d8b2..55a7b6a24cb9 100644 --- a/libs/service-portal/signature-collection/src/hooks/graphql/queries.ts +++ b/libs/service-portal/signature-collection/src/hooks/graphql/queries.ts @@ -144,6 +144,7 @@ export const GetCurrentCollection = gql` startTime name isActive + isPresidential status areas { id diff --git a/libs/service-portal/signature-collection/src/lib/constants.ts b/libs/service-portal/signature-collection/src/lib/constants.ts index 0e26bc28bbe6..04eb57fdee3a 100644 --- a/libs/service-portal/signature-collection/src/lib/constants.ts +++ b/libs/service-portal/signature-collection/src/lib/constants.ts @@ -1,6 +1,6 @@ export const CollectionType = { Presidential: 'Forsetakosningar', - Parliamentary: 'Alþingiskosning NÝTT TEST', + Parliamentary: 'Alþingiskosningar', } // will be fetched later on diff --git a/libs/service-portal/signature-collection/src/screens/Parliamentary/SigneeView/index.tsx b/libs/service-portal/signature-collection/src/screens/Parliamentary/SigneeView/index.tsx index 14118b010312..78cb34ff9c49 100644 --- a/libs/service-portal/signature-collection/src/screens/Parliamentary/SigneeView/index.tsx +++ b/libs/service-portal/signature-collection/src/screens/Parliamentary/SigneeView/index.tsx @@ -34,14 +34,16 @@ const SigneeView = ({ {!user?.profile.actor && !loadingSignedLists && !loadingUserLists ? ( - {listsForUser.length === 0 && signedLists.length === 0 && ( - - - - )} + {currentCollection.isPresidential && + listsForUser.length === 0 && + signedLists.length === 0 && ( + + + + )} {/* Signed list */} diff --git a/libs/service-portal/signature-collection/src/screens/Parliamentary/index.tsx b/libs/service-portal/signature-collection/src/screens/Parliamentary/index.tsx index 021a9d9198ed..e84d9872468d 100644 --- a/libs/service-portal/signature-collection/src/screens/Parliamentary/index.tsx +++ b/libs/service-portal/signature-collection/src/screens/Parliamentary/index.tsx @@ -1,6 +1,10 @@ import { Box } from '@island.is/island-ui/core' import { useLocale } from '@island.is/localization' -import { IntroHeader, THJODSKRA_SLUG } from '@island.is/service-portal/core' +import { + EmptyState, + IntroHeader, + THJODSKRA_SLUG, +} from '@island.is/service-portal/core' import { m } from '../../lib/messages' import OwnerView from './OwnerView' import SigneeView from './SigneeView' @@ -24,10 +28,17 @@ const SignatureListsParliamentary = () => { /> {!loadingIsOwner && !loadingCurrentCollection ? ( - {isOwner.success ? ( - + {!currentCollection?.isPresidential ? ( + isOwner.success ? ( + + ) : ( + + ) ) : ( - + )} ) : (