From b1623cc0dd0e15bb3ef79e6a138c2b16244e9705 Mon Sep 17 00:00:00 2001 From: albinagu <47886428+albinagu@users.noreply.github.com> Date: Mon, 7 Oct 2024 13:21:38 +0000 Subject: [PATCH] fix(portals-admin): locklist (#16279) * fix(portals-admin): locklist * tweak * msg id fix * tweak --------- Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- .../signature-collection/src/lib/messages.ts | 19 ++++- .../List/paperSignees/index.tsx | 1 + .../src/screens-parliamentary/index.tsx | 2 +- .../completeReview/index.tsx | 51 ++++++------ .../completeReview/lockList/index.tsx | 78 +++++++++++++++++++ .../completeReview/lockList/lockList.graphql | 6 ++ 6 files changed, 126 insertions(+), 31 deletions(-) create mode 100644 libs/portals/admin/signature-collection/src/shared-components/completeReview/lockList/index.tsx create mode 100644 libs/portals/admin/signature-collection/src/shared-components/completeReview/lockList/lockList.graphql diff --git a/libs/portals/admin/signature-collection/src/lib/messages.ts b/libs/portals/admin/signature-collection/src/lib/messages.ts index 80f2890f11c3..da266b710980 100644 --- a/libs/portals/admin/signature-collection/src/lib/messages.ts +++ b/libs/portals/admin/signature-collection/src/lib/messages.ts @@ -422,7 +422,7 @@ export const m = defineMessages({ }, confirmListReviewedToggleBack: { id: 'admin-portal.signature-collection:confirmListReviewedToggleBack', - defaultMessage: 'Aflæsa úrvinnslu', + defaultMessage: 'Opna fyrir úrvinnslu', description: '', }, listReviewedModalDescription: { @@ -463,9 +463,24 @@ export const m = defineMessages({ defaultMessage: 'Úrvinnslu lokið', description: '', }, + lockList: { + id: 'admin-portal.signature-collection:lockList', + defaultMessage: 'Læsa söfnun', + description: '', + }, + lockListSuccess: { + id: 'admin-portal.signature-collection:lockListSuccess', + defaultMessage: 'Tókst að læsa söfnun', + description: '', + }, + lockListError: { + id: 'admin-portal.signature-collection:lockListError', + defaultMessage: 'Ekki tókst að læsa söfnun', + description: '', + }, toggleReviewError: { id: 'admin-portal.signature-collection:toggleReviewError', - defaultMessage: 'Ekki tókst loka úrvinnslu', + defaultMessage: 'Ekki tókst að loka úrvinnslu', description: '', }, toggleCollectionProcessSuccess: { diff --git a/libs/portals/admin/signature-collection/src/screens-parliamentary/List/paperSignees/index.tsx b/libs/portals/admin/signature-collection/src/screens-parliamentary/List/paperSignees/index.tsx index 083cb10e2b7b..60556c7d06de 100644 --- a/libs/portals/admin/signature-collection/src/screens-parliamentary/List/paperSignees/index.tsx +++ b/libs/portals/admin/signature-collection/src/screens-parliamentary/List/paperSignees/index.tsx @@ -44,6 +44,7 @@ export const PaperSignees = ({ listId }: { listId: string }) => { listId, }, }, + skip: !nationalId.isValid(nationalIdInput) || !name, }) useEffect(() => { diff --git a/libs/portals/admin/signature-collection/src/screens-parliamentary/index.tsx b/libs/portals/admin/signature-collection/src/screens-parliamentary/index.tsx index 9ae00b303039..3a0b0b940abf 100644 --- a/libs/portals/admin/signature-collection/src/screens-parliamentary/index.tsx +++ b/libs/portals/admin/signature-collection/src/screens-parliamentary/index.tsx @@ -41,7 +41,7 @@ const ParliamentaryRoot = ({ variables: { input: { collectionId: collection?.id, - nationalId: searchTerm, + nationalId: searchTerm.replace(/[^0-9]/g, ''), }, }, skip: searchTerm.replace(/[^0-9]/g, '').length !== 10, diff --git a/libs/portals/admin/signature-collection/src/shared-components/completeReview/index.tsx b/libs/portals/admin/signature-collection/src/shared-components/completeReview/index.tsx index a7ad2862538a..96b5b1488381 100644 --- a/libs/portals/admin/signature-collection/src/shared-components/completeReview/index.tsx +++ b/libs/portals/admin/signature-collection/src/shared-components/completeReview/index.tsx @@ -6,6 +6,7 @@ import { useToggleListReviewMutation } from './toggleListReview.generated' import { useRevalidator } from 'react-router-dom' import { m } from '../../lib/messages' import { ListStatus } from '../../lib/utils' +import LockList from './lockList' const ActionReviewComplete = ({ listId, @@ -15,43 +16,38 @@ const ActionReviewComplete = ({ listStatus: string }) => { const { formatMessage } = useLocale() - const [modalSubmitReviewIsOpen, setModalSubmitReviewIsOpen] = useState(false) - const [toggleListReviewMutation, { loading }] = useToggleListReviewMutation() const { revalidate } = useRevalidator() + + const [modalSubmitReviewIsOpen, setModalSubmitReviewIsOpen] = useState(false) const listReviewed = listStatus && listStatus === ListStatus.Reviewed const modalText = listReviewed ? formatMessage(m.confirmListReviewedToggleBack) : formatMessage(m.confirmListReviewed) - const toggleReview = async () => { - try { - const res = await toggleListReviewMutation({ - variables: { - input: { - listId, - }, - }, - }) - if (res.data?.signatureCollectionAdminToggleListReview.success) { - toast.success(formatMessage(m.toggleReviewSuccess)) - setModalSubmitReviewIsOpen(false) - revalidate() - } else { - toast.error(formatMessage(m.toggleReviewError)) - } - } catch (e) { - toast.error(e.message) - } - } + const [toggleListReview, { loading }] = useToggleListReviewMutation({ + variables: { + input: { + listId, + }, + }, + onCompleted: () => { + setModalSubmitReviewIsOpen(false) + revalidate() + toast.success(formatMessage(m.toggleReviewSuccess)) + }, + onError: () => { + toast.error(formatMessage(m.toggleReviewError)) + }, + }) return ( - + + diff --git a/libs/portals/admin/signature-collection/src/shared-components/completeReview/lockList/index.tsx b/libs/portals/admin/signature-collection/src/shared-components/completeReview/lockList/index.tsx new file mode 100644 index 000000000000..8cf2e5903495 --- /dev/null +++ b/libs/portals/admin/signature-collection/src/shared-components/completeReview/lockList/index.tsx @@ -0,0 +1,78 @@ +import { useLocale } from '@island.is/localization' +import { Box, Button, Text, toast } from '@island.is/island-ui/core' +import { useState } from 'react' +import { Modal } from '@island.is/react/components' +import { useRevalidator } from 'react-router-dom' +import { m } from '../../../lib/messages' +import { ListStatus } from '../../../lib/utils' +import { useSignatureCollectionLockListMutation } from './lockList.generated' + +const ActionLockList = ({ + listId, + listStatus, +}: { + listId: string + listStatus: string +}) => { + const { formatMessage } = useLocale() + const { revalidate } = useRevalidator() + + const [modalLockListIsOpen, setModalLockListIsOpen] = useState(false) + + const [lockList, { loading: loadingLockList }] = + useSignatureCollectionLockListMutation({ + variables: { + input: { + listId, + }, + }, + onCompleted: () => { + setModalLockListIsOpen(false) + revalidate() + toast.success(formatMessage(m.lockListSuccess)) + }, + onError: () => { + toast.error(formatMessage(m.lockListError)) + }, + }) + + return ( + + + setModalLockListIsOpen(false)} + label={''} + closeButtonLabel={''} + > + + {formatMessage(m.lockList)} + + + + + + + ) +} + +export default ActionLockList diff --git a/libs/portals/admin/signature-collection/src/shared-components/completeReview/lockList/lockList.graphql b/libs/portals/admin/signature-collection/src/shared-components/completeReview/lockList/lockList.graphql new file mode 100644 index 000000000000..f67084926da8 --- /dev/null +++ b/libs/portals/admin/signature-collection/src/shared-components/completeReview/lockList/lockList.graphql @@ -0,0 +1,6 @@ +mutation SignatureCollectionLockList($input: SignatureCollectionListIdInput!) { + signatureCollectionLockList(input: $input) { + reasons + success + } +}