Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(j-s): Add indictment count subtypes to IndictmentCount #17129

Merged
merged 19 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/judicial-system/api/infra/judicial-system-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ export const serviceSetup = (services: {
},
HIDDEN_FEATURES: {
dev: '',
staging: '',
prod: '',
staging: 'MULTIPLE_INDICTMENT_SUBTYPES',
prod: 'MULTIPLE_INDICTMENT_SUBTYPES',
},
})
.secrets({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import { GraphQLJSONObject } from 'graphql-type-json'
import { Field, ID, InputType } from '@nestjs/graphql'

import type { SubstanceMap } from '@island.is/judicial-system/types'
import { IndictmentCountOffense } from '@island.is/judicial-system/types'
import {
IndictmentCountOffense,
IndictmentSubtype,
} from '@island.is/judicial-system/types'

@InputType()
export class UpdateIndictmentCountInput {
Expand Down Expand Up @@ -53,4 +56,11 @@ export class UpdateIndictmentCountInput {
@IsOptional()
@Field(() => String, { nullable: true })
readonly legalArguments?: string

@Allow()
@IsOptional()
@IsArray()
@IsEnum(IndictmentSubtype, { each: true })
@Field(() => [IndictmentSubtype], { nullable: true })
readonly indictmentCountSubtypes?: IndictmentSubtype[]
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ import { GraphQLJSONObject } from 'graphql-type-json'
import { Field, ID, ObjectType, registerEnumType } from '@nestjs/graphql'

import type { SubstanceMap } from '@island.is/judicial-system/types'
import { IndictmentCountOffense } from '@island.is/judicial-system/types'
import {
IndictmentCountOffense,
IndictmentSubtype,
} from '@island.is/judicial-system/types'

registerEnumType(IndictmentCountOffense, { name: 'IndictmentCountOffense' })
registerEnumType(IndictmentSubtype, { name: 'IndictmentSubtype' })

@ObjectType()
export class IndictmentCount {
Expand Down Expand Up @@ -41,4 +45,7 @@ export class IndictmentCount {

@Field(() => String, { nullable: true })
readonly legalArguments?: string

@Field(() => [IndictmentSubtype], { nullable: true })
readonly indictmentCountSubtypes?: IndictmentSubtype[]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use strict'

oddsson marked this conversation as resolved.
Show resolved Hide resolved
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.sequelize.transaction((transaction) =>
queryInterface.addColumn(
'indictment_count',
'indictment_count_subtypes',
{
type: Sequelize.ARRAY(Sequelize.STRING),
allowNull: true,
defaultValue: [],
},
{ transaction },
),
)
},

async down(queryInterface) {
await queryInterface.removeColumn(
'indictment_count',
'indictment_count_subtypes',
)
},
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import {
import { ApiPropertyOptional } from '@nestjs/swagger'

import type { SubstanceMap } from '@island.is/judicial-system/types'
import { IndictmentCountOffense } from '@island.is/judicial-system/types'
import {
IndictmentCountOffense,
IndictmentSubtype,
} from '@island.is/judicial-system/types'

export class UpdateIndictmentCountDto {
@IsOptional()
Expand Down Expand Up @@ -50,4 +53,10 @@ export class UpdateIndictmentCountDto {
@IsString()
@ApiPropertyOptional({ type: String })
readonly legalArguments?: string

@IsOptional()
@IsArray()
@IsEnum(IndictmentSubtype, { each: true })
@ApiPropertyOptional({ enum: IndictmentSubtype, isArray: true })
readonly indictmentCountSubtypes?: IndictmentSubtype[]
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import {
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'

import type { SubstanceMap } from '@island.is/judicial-system/types'
import { IndictmentCountOffense } from '@island.is/judicial-system/types'
import {
IndictmentCountOffense,
IndictmentSubtype,
} from '@island.is/judicial-system/types'

import { Case } from '../../case/models/case.model'

Expand Down Expand Up @@ -69,4 +72,12 @@ export class IndictmentCount extends Model {
@Column({ type: DataType.TEXT, allowNull: true })
@ApiPropertyOptional({ type: String })
legalArguments?: string

@Column({
type: DataType.ARRAY(DataType.ENUM),
allowNull: true,
values: Object.values(IndictmentSubtype),
})
@ApiPropertyOptional({ enum: IndictmentSubtype, isArray: true })
indictmentCountSubtypes?: IndictmentSubtype[]
}
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ query Case($input: CaseQueryInput!) {
lawsBroken
incidentDescription
legalArguments
indictmentCountSubtypes
}
requestDriversLicenseSuspension
appealState
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { AnimatePresence } from 'framer-motion'
import { Box, Text } from '@island.is/island-ui/core'
import { formatDate } from '@island.is/judicial-system/formatters'
import {
Feature,
isCompletedCase,
isDefenceUser,
isDistrictCourtUser,
Expand All @@ -15,6 +16,7 @@ import {
isTrafficViolationCase,
} from '@island.is/judicial-system/types'
import {
FeatureContext,
FileNotFoundModal,
PdfButton,
SectionHeading,
Expand Down Expand Up @@ -71,12 +73,16 @@ const IndictmentCaseFilesList: FC<Props> = ({
}) => {
const { formatMessage } = useIntl()
const { user, limitedAccess } = useContext(UserContext)
const { features } = useContext(FeatureContext)
const { onOpen, fileNotFound, dismissFileNotFound } = useFileList({
caseId: workingCase.id,
connectedCaseParentId,
})

const showTrafficViolationCaseFiles = isTrafficViolationCase(workingCase)
const showTrafficViolationCaseFiles =
features.includes(Feature.MULTIPLE_INDICTMENT_SUBTYPES) ||
isTrafficViolationCase(workingCase)

const showSubpoenaPdf =
displayGeneratedPDFs &&
workingCase.defendants?.some(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FC, useEffect, useState } from 'react'
import { FC } from 'react'
import { IntlShape, MessageDescriptor, useIntl } from 'react-intl'

import { AlertMessage, Box, LoadingDots, Text } from '@island.is/island-ui/core'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ import router from 'next/router'
import { Box, InputFileUpload } from '@island.is/island-ui/core'
import { fileExtensionWhitelist } from '@island.is/island-ui/core/types'
import * as constants from '@island.is/judicial-system/consts'
import { isTrafficViolationCase } from '@island.is/judicial-system/types'
import {
Feature,
isTrafficViolationCase,
} from '@island.is/judicial-system/types'
import { titles } from '@island.is/judicial-system-web/messages'
import {
FeatureContext,
FormContentContainer,
FormContext,
FormFooter,
Expand All @@ -29,6 +33,7 @@ import * as strings from './CaseFiles.strings'
const CaseFiles = () => {
const { workingCase, isLoadingWorkingCase, caseNotFound } =
useContext(FormContext)
const { features } = useContext(FeatureContext)
const { formatMessage } = useIntl()
const {
uploadFiles,
Expand All @@ -41,7 +46,9 @@ const CaseFiles = () => {
workingCase.id,
)

const isTrafficViolationCaseCheck = isTrafficViolationCase(workingCase)
const isTrafficViolationCaseCheck =
features.includes(Feature.MULTIPLE_INDICTMENT_SUBTYPES) ||
isTrafficViolationCase(workingCase)
unakb marked this conversation as resolved.
Show resolved Hide resolved

const stepIsValid =
(isTrafficViolationCaseCheck ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ const Indictment = () => {
onChange={handleUpdateIndictmentCount}
setWorkingCase={setWorkingCase}
updateIndictmentCountState={updateIndictmentCountState}
></IndictmentCount>
/>
</AnimatePresence>
</Box>
</motion.div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { style } from '@vanilla-extract/css'

import { theme } from '@island.is/island-ui/theme'

export const indictmentSubtypesContainter = style({
display: 'flex',
flexWrap: 'wrap',
gap: theme.spacing[1],
marginBottom: theme.spacing[2],
})

export const indictmentSubtypesItem = style({
flex: `1 1 calc(50% - ${theme.spacing[1]}px)`,
whiteSpace: 'nowrap',
})
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,9 @@ export const indictmentCount = defineMessages({
'Telst háttsemi þessi varða við {articles} umferðarlaga nr. 77/2019.',
description: 'Notaður sem sjálfgefinn texti í heimfærslu svæði.',
},
selectIndictmentSubtype: {
id: 'judicial.system.core:indictments_indictment.indictment_count.select_indictment_subtype',
defaultMessage: 'Veldu sakarefni',
description: 'Notaður sem titill fyrir "Veldu sakarefni" svæði.',
},
})
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,28 @@ import { IntlShape, useIntl } from 'react-intl'
import {
Box,
Button,
Checkbox,
Icon,
Input,
Select,
Tag,
} from '@island.is/island-ui/core'
import { formatDate } from '@island.is/judicial-system/formatters'
import {
capitalize,
formatDate,
indictmentSubtypes,
} from '@island.is/judicial-system/formatters'
import {
CrimeScene,
IndictmentSubtype,
offenseSubstances,
Substance,
SubstanceMap,
} from '@island.is/judicial-system/types'
import {
BlueBox,
IndictmentInfo,
SectionHeading,
} from '@island.is/judicial-system-web/src/components'
import { IndictmentCountOffense } from '@island.is/judicial-system-web/src/graphql/schema'
import {
Expand All @@ -39,6 +46,7 @@ import { Substances as SubstanceChoices } from './Substances/Substances'
import { indictmentCount as strings } from './IndictmentCount.strings'
import { indictmentCountEnum as enumStrings } from './IndictmentCountEnum.strings'
import { indictmentCountSubstanceEnum as substanceStrings } from './IndictmentCountSubstanceEnum.strings'
import * as styles from './IndictmentCount.css'

interface Props {
indictmentCount: TIndictmentCount
Expand Down Expand Up @@ -338,6 +346,10 @@ export const IndictmentCount: FC<Props> = ({
const [legalArgumentsErrorMessage, setLegalArgumentsErrorMessage] =
useState<string>('')

const subtypes = indictmentCount.policeCaseNumber
? workingCase.indictmentSubtypes[indictmentCount.policeCaseNumber]
: []

const offensesOptions = useMemo(
() =>
Object.values(IndictmentCountOffense).map((offense) => ({
Expand Down Expand Up @@ -400,6 +412,21 @@ export const IndictmentCount: FC<Props> = ({
})
}

const handleSubtypeChange = (
subtype: IndictmentSubtype,
checked: boolean,
) => {
const currentSubtypes = new Set(
indictmentCount.indictmentCountSubtypes ?? [],
)

checked ? currentSubtypes.add(subtype) : currentSubtypes.delete(subtype)

handleIndictmentCountChanges({
indictmentCountSubtypes: Array.from(currentSubtypes),
})
}

return (
<BlueBox>
{onDelete && (
Expand Down Expand Up @@ -449,6 +476,39 @@ export const IndictmentCount: FC<Props> = ({
crimeScenes={workingCase.crimeScenes}
/>
</Box>
{subtypes.length > 1 && (
<Box marginBottom={2}>
<SectionHeading
title={formatMessage(strings.selectIndictmentSubtype)}
heading="h4"
/>
<div className={styles.indictmentSubtypesContainter}>
{subtypes.map((subtype: IndictmentSubtype) => (
<div
className={styles.indictmentSubtypesItem}
key={`${subtype}-${indictmentCount.id}`}
>
<Checkbox
name={`${subtype}-${indictmentCount.id}`}
value={subtype}
label={capitalize(indictmentSubtypes[subtype])}
checked={
indictmentCount.indictmentCountSubtypes?.includes(
subtype,
) ?? false
}
onChange={(evt) => {
handleSubtypeChange(subtype, evt.target.checked)
}}
backgroundColor="white"
large
filled
/>
</div>
))}
</div>
</Box>
)}
<Box marginBottom={2}>
<InputMask
mask={[/[A-Z]/i, /[A-Z]/i, /[A-Z]|[0-9]/i, /[0-9]/, /[0-9]/]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ import {
import * as constants from '@island.is/judicial-system/consts'
import {
AdvocateType,
Feature,
isTrafficViolationCase,
} from '@island.is/judicial-system/types'
import { core, titles } from '@island.is/judicial-system-web/messages'
import {
BlueBox,
CommentsInput,
FeatureContext,
FormContentContainer,
FormContext,
FormFooter,
Expand Down Expand Up @@ -63,6 +65,7 @@ const Processing: FC = () => {
isCaseUpToDate,
refreshCase,
} = useContext(FormContext)
const { features } = useContext(FeatureContext)
const { updateCase, transitionCase, setAndSendCaseToServer } = useCase()
const { formatMessage } = useIntl()
const { updateDefendant, updateDefendantState } = useDefendants()
Expand All @@ -73,7 +76,9 @@ const Processing: FC = () => {
deleteCivilClaimant,
} = useCivilClaimants()
const router = useRouter()
const isTrafficViolationCaseCheck = isTrafficViolationCase(workingCase)
const isTrafficViolationCaseCheck =
features.includes(Feature.MULTIPLE_INDICTMENT_SUBTYPES) ||
isTrafficViolationCase(workingCase)
const [civilClaimantNationalIdUpdate, setCivilClaimantNationalIdUpdate] =
useState<{ nationalId: string | null; civilClaimantId: string }>()
const [hasCivilClaimantChoice, setHasCivilClaimantChoice] =
Expand Down
Loading
Loading