Skip to content

Commit

Permalink
fix(portals-admin): locklist (#16279)
Browse files Browse the repository at this point in the history
* fix(portals-admin): locklist

* tweak

* msg id fix

* tweak

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
albinagu and kodiakhq[bot] authored Oct 7, 2024
1 parent ea6cc03 commit b1623cc
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 31 deletions.
19 changes: 17 additions & 2 deletions libs/portals/admin/signature-collection/src/lib/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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 loka úrvinnslu',
description: '',
},
toggleCollectionProcessSuccess: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export const PaperSignees = ({ listId }: { listId: string }) => {
listId,
},
},
skip: !nationalId.isValid(nationalIdInput) || !name,
})

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 (
<Box marginTop={20}>
<Box display="flex" justifyContent="flexEnd">
<Box display="flex" justifyContent="spaceBetween">
<LockList listId={listId} listStatus={listStatus} />
<Button
iconType="outline"
variant="ghost"
icon={listReviewed ? 'lockOpened' : 'lockClosed'}
colorScheme={listReviewed ? 'default' : 'destructive'}
icon={listReviewed ? 'reload' : 'checkmark'}
onClick={() => setModalSubmitReviewIsOpen(true)}
>
{modalText}
Expand All @@ -75,10 +71,9 @@ const ActionReviewComplete = ({
<Button
iconType="outline"
variant="ghost"
onClick={() => toggleReview()}
onClick={() => toggleListReview()}
loading={loading}
icon={listReviewed ? 'lockOpened' : 'lockClosed'}
colorScheme={listReviewed ? 'default' : 'destructive'}
icon={listReviewed ? 'reload' : 'checkmark'}
>
{modalText}
</Button>
Expand Down
Original file line number Diff line number Diff line change
@@ -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 (
<Box>
<Button
iconType="outline"
variant="ghost"
icon="lockClosed"
colorScheme="destructive"
onClick={() => setModalLockListIsOpen(true)}
>
{formatMessage(m.lockList)}
</Button>
<Modal
id="toggleLockList"
isVisible={modalLockListIsOpen}
title={formatMessage(m.lockList)}
onClose={() => setModalLockListIsOpen(false)}
label={''}
closeButtonLabel={''}
>
<Box marginTop={5}>
<Text>{formatMessage(m.lockList)}</Text>
<Box display="flex" justifyContent="flexEnd" marginTop={5}>
<Button
iconType="outline"
variant="ghost"
onClick={() => lockList()}
loading={loadingLockList}
icon="lockClosed"
colorScheme="destructive"
>
{formatMessage(m.lockList)}
</Button>
</Box>
</Box>
</Modal>
</Box>
)
}

export default ActionLockList
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
mutation SignatureCollectionLockList($input: SignatureCollectionListIdInput!) {
signatureCollectionLockList(input: $input) {
reasons
success
}
}

0 comments on commit b1623cc

Please sign in to comment.