Skip to content

Commit

Permalink
feat(j-s): Subpoena type decision on court overview screen (#15432)
Browse files Browse the repository at this point in the history
* feat(j-s): Subpoena type decision on court overview screen

* Update Subpoena.tsx

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Co-authored-by: lommi <jonorn@gmail.com>
  • Loading branch information
3 people authored and oskarjs committed Aug 20, 2024
1 parent 63b88e0 commit ea75616
Show file tree
Hide file tree
Showing 5 changed files with 176 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,18 @@ import {
CaseState,
IndictmentDecision,
} from '@island.is/judicial-system-web/src/graphql/schema'
import { useDefendants } from '@island.is/judicial-system-web/src/utils/hooks'

import { SubpoenaType } from '../../components'
import ReturnIndictmentModal from '../ReturnIndictmentCaseModal/ReturnIndictmentCaseModal'
import { strings } from './Overview.strings'

const IndictmentOverview = () => {
const router = useRouter()
const { workingCase, isLoadingWorkingCase, caseNotFound, setWorkingCase } =
useContext(FormContext)
const { updateDefendantState, updateDefendant } = useDefendants()

const { formatMessage } = useIntl()
const lawsBroken = useIndictmentsLawsBroken(workingCase)
const [modalVisible, setModalVisible] = useState<'RETURN_INDICTMENT'>()
Expand All @@ -39,8 +43,26 @@ const IndictmentOverview = () => {
const caseHasBeenReceivedByCourt = workingCase.state === CaseState.RECEIVED

const handleNavigationTo = useCallback(
(destination: string) => router.push(`${destination}/${workingCase.id}`),
[router, workingCase.id],
async (destination: string) => {
if (workingCase.defendants) {
const promises = workingCase.defendants.map((defendant) =>
updateDefendant({
caseId: workingCase.id,
defendantId: defendant.id,
subpoenaType: defendant.subpoenaType,
}),
)

const allDataSentToServer = await Promise.all(promises)

if (!allDataSentToServer.every(Boolean)) {
return
}
}

router.push(`${destination}/${workingCase.id}`)
},
[router, updateDefendant, workingCase.defendants, workingCase.id],
)

return (
Expand Down Expand Up @@ -86,6 +108,19 @@ const IndictmentOverview = () => {
<IndictmentCaseFilesList workingCase={workingCase} />
</Box>
)}
{workingCase.defendants && (
<Box component="section" marginBottom={5}>
{
<SubpoenaType
defendants={workingCase.defendants}
workingCase={workingCase}
setWorkingCase={setWorkingCase}
updateDefendantState={updateDefendantState}
required={false}
/>
}
</Box>
)}
</FormContentContainer>
<FormContentContainer isFooter>
<FormFooter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ import React, { FC, useCallback, useContext, useState } from 'react'
import { useIntl } from 'react-intl'
import router from 'next/router'

import { Box, RadioButton, Text } from '@island.is/island-ui/core'
import { Box } from '@island.is/island-ui/core'
import * as constants from '@island.is/judicial-system/consts'
import { core, titles } from '@island.is/judicial-system-web/messages'
import {
BlueBox,
CourtArrangements,
CourtCaseInfo,
FormContentContainer,
Expand All @@ -20,10 +19,8 @@ import {
SectionHeading,
useCourtArrangements,
} from '@island.is/judicial-system-web/src/components'
import {
NotificationType,
SubpoenaType,
} from '@island.is/judicial-system-web/src/graphql/schema'
import { NotificationType } from '@island.is/judicial-system-web/src/graphql/schema'
import { SubpoenaType } from '@island.is/judicial-system-web/src/routes/Court/components'
import type { stepValidationsType } from '@island.is/judicial-system-web/src/utils/formHelper'
import {
useCase,
Expand All @@ -33,7 +30,6 @@ import { hasSentNotification } from '@island.is/judicial-system-web/src/utils/st
import { isSubpoenaStepValid } from '@island.is/judicial-system-web/src/utils/validate'

import { subpoena as strings } from './Subpoena.strings'
import * as styles from './Subpoena.css'

const Subpoena: FC = () => {
const { workingCase, setWorkingCase, isLoadingWorkingCase, caseNotFound } =
Expand Down Expand Up @@ -114,64 +110,18 @@ const Subpoena: FC = () => {
<FormContentContainer>
<PageTitle>{formatMessage(strings.title)}</PageTitle>
<CourtCaseInfo workingCase={workingCase} />
<Box component="section" marginBottom={5}>
<SectionHeading
title={formatMessage(strings.subpoenaTypeTitle)}
required
/>
{workingCase.defendants?.map((defendant, index) => (
<Box
key={defendant.id}
marginBottom={index === workingCase.defendants?.length ? 0 : 3}
>
<BlueBox>
<Text as="h4" variant="h4" marginBottom={2}>
{defendant.name}
</Text>
<Box className={styles.subpoenaTypeGrid}>
<RadioButton
large
name="subpoenaType"
id={`subpoenaTypeAbsence${defendant.id}`}
backgroundColor="white"
label={formatMessage(strings.subpoenaTypeAbsence)}
checked={defendant.subpoenaType === SubpoenaType.ABSENCE}
onChange={() => {
updateDefendantState(
{
caseId: workingCase.id,
defendantId: defendant.id,
subpoenaType: SubpoenaType.ABSENCE,
},
setWorkingCase,
)
}}
disabled={isArraignmentDone}
/>
<RadioButton
large
name="subpoenaType"
id={`subpoenaTypeArrest${defendant.id}`}
backgroundColor="white"
label={formatMessage(strings.subpoenaTypeArrest)}
checked={defendant.subpoenaType === SubpoenaType.ARREST}
onChange={() => {
updateDefendantState(
{
caseId: workingCase.id,
defendantId: defendant.id,
subpoenaType: SubpoenaType.ARREST,
},
setWorkingCase,
)
}}
disabled={isArraignmentDone}
/>
</Box>
</BlueBox>
</Box>
))}
</Box>
{workingCase.defendants && (
<Box component="section" marginBottom={5}>
{
<SubpoenaType
defendants={workingCase.defendants}
workingCase={workingCase}
setWorkingCase={setWorkingCase}
updateDefendantState={updateDefendantState}
/>
}
</Box>
)}
<Box component="section" marginBottom={5}>
<SectionHeading
title={formatMessage(strings.courtArrangementsHeading)}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { defineMessages } from 'react-intl'

export const strings = defineMessages({
title: {
id: 'judicial.system.core:court.subpoena_type.title',
defaultMessage: 'Tegund fyrirkalls',
description:
'Notaður sem titill fyrir Tegund fyrirkalls hluta á Fyrirkalls skjá í dómaraflæði í ákærum.',
},
absence: {
id: 'judicial.system.core:court.subpoena_type.absence',
defaultMessage: 'Útivistarfyrirkall',
description:
'Notaður sem texti fyrir Útivistarfyrirkall valkost á Fyrirkalls skjá í dómaraflæði í ákærum.',
},
arrest: {
id: 'judicial.system.core:court.subpoena_type.arrest',
defaultMessage: 'Handtökufyrirkall',
description:
'Notaður sem texti fyrir Handtökufyrirkall valkost á Fyrirkalls skjá í dómaraflæði í ákærum.',
},
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import React, { Dispatch, FC, SetStateAction } from 'react'
import { useIntl } from 'react-intl'

import { Box, RadioButton, Text } from '@island.is/island-ui/core'
import { SubpoenaType as SubpoenaTypeEnum } from '@island.is/judicial-system/types'
import {
BlueBox,
SectionHeading,
} from '@island.is/judicial-system-web/src/components'
import {
Case,
Defendant,
UpdateDefendantInput,
} from '@island.is/judicial-system-web/src/graphql/schema'

import { strings } from './SubpoenaType.strings'
import * as styles from '../../Indictments/Subpoena/Subpoena.css'

interface SubpoenaTypeProps {
defendants: Defendant[]
workingCase: Case
setWorkingCase: Dispatch<SetStateAction<Case>>
updateDefendantState: (
update: UpdateDefendantInput,
setWorkingCase: React.Dispatch<React.SetStateAction<Case>>,
) => void
required?: boolean
}

const SubpoenaType: FC<SubpoenaTypeProps> = ({
defendants,
workingCase,
setWorkingCase,
updateDefendantState,
required = true,
}) => {
const { formatMessage } = useIntl()
const isArraignmentDone = Boolean(workingCase.indictmentDecision)
return (
<>
<SectionHeading
title={formatMessage(strings.title)}
required={required}
/>
{defendants.map((defendant, index) => (
<Box
key={defendant.id}
marginBottom={index === defendants.length ? 0 : 3}
>
<BlueBox>
<Text as="h4" variant="h4" marginBottom={2}>
{defendant.name}
</Text>
<Box className={styles.subpoenaTypeGrid}>
<RadioButton
large
name="subpoenaType"
id={`subpoenaTypeAbsence${defendant.id}`}
backgroundColor="white"
label={formatMessage(strings.absence)}
checked={defendant.subpoenaType === SubpoenaTypeEnum.ABSENCE}
onChange={() => {
updateDefendantState(
{
caseId: workingCase.id,
defendantId: defendant.id,
subpoenaType: SubpoenaTypeEnum.ABSENCE,
},
setWorkingCase,
)
}}
disabled={isArraignmentDone}
/>
<RadioButton
large
name="subpoenaType"
id={`subpoenaTypeArrest${defendant.id}`}
backgroundColor="white"
label={formatMessage(strings.arrest)}
checked={defendant.subpoenaType === SubpoenaTypeEnum.ARREST}
onChange={() => {
updateDefendantState(
{
caseId: workingCase.id,
defendantId: defendant.id,
subpoenaType: SubpoenaTypeEnum.ARREST,
},
setWorkingCase,
)
}}
disabled={isArraignmentDone}
/>
</Box>
</BlueBox>
</Box>
))}
</>
)
}

export default SubpoenaType
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ export { default as ReceptionAndAssignment } from './ReceptionAndAssignment/Rece
export { default as RulingModifiedModal } from './RulingModifiedModal/RulingModifiedModal'
export { default as RegistrarRequestRulingSignatureModal } from './RulingModifiedModal/RegistrarRequestRulingSignatureModal'
export { default as JudgeRequestRulingSignatureModal } from './RulingModifiedModal/JudgeRequestRulingSignatureModal'
export { default as SubpoenaType } from './SubpoenaType/SubpoenaType'

0 comments on commit ea75616

Please sign in to comment.