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

chore(j-s): Add ability to choose if there are civil claims in a case #16091

Merged
merged 6 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,9 @@ export const strings = defineMessages({
description:
'Notaður sem titill á innsend gögn hluta á dómskjalaskjá í ákærum.',
},
civilClaimsTitle: {
id: 'judicial.system.core:indictment_case_files_list.civil_claims_title',
defaultMessage: 'Einkaréttarkröfur',
description: 'Notaður sem titill á dómskjalaskjá í ákærum.',
},
})
Original file line number Diff line number Diff line change
Expand Up @@ -230,14 +230,15 @@ const IndictmentCaseFilesList: FC<Props> = ({
)}
</Box>
) : null}
{civilClaims &&
{workingCase.hasCivilClaims &&
civilClaims &&
civilClaims.length > 0 &&
(isDistrictCourtUser(user) ||
isProsecutionUser(user) ||
isDefenceUser(user)) && (
<Box marginBottom={5}>
<Text variant="h4" as="h4" marginBottom={1}>
{formatMessage(caseFiles.civilClaimSection)}
{formatMessage(strings.civilClaimsTitle)}
</Text>
<RenderFiles
caseFiles={civilClaims}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const caseFiles = defineMessages({
civilClaimSection: {
id: 'judicial.system.core:indictments.case_files.civil_claim_section',
defaultMessage: 'Bótakröfur',
description: 'Titill á bótakröfur hluta á dómskjalaskjá í ákærum.',
description: 'Titill á Bótakröfur hluta á dómskjalaskjá í ákærum.',
},
criminalRecordUpdateSection: {
id: 'judicial.system.core:indictments.case_files.criminal_record_update_section',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,12 @@ const CaseFiles = () => {
onRetry={(file) => handleRetry(file, updateUploadFile)}
/>
</Box>
<Box component="section" marginBottom={10}>
<Box
component="section"
marginBottom={
workingCase.hasCivilClaims || isTrafficViolationCaseCheck ? 5 : 10
}
>
<SectionHeading
title={formatMessage(strings.caseFiles.otherDocumentsSection)}
/>
Expand All @@ -172,29 +177,34 @@ const CaseFiles = () => {
onRetry={(file) => handleRetry(file, updateUploadFile)}
/>
</Box>
<Box component="section" marginBottom={10}>
<SectionHeading
title={formatMessage(strings.caseFiles.civilClaimSection)}
/>
<InputFileUpload
fileList={uploadFiles.filter(
(file) => file.category === CaseFileCategory.CIVIL_CLAIM,
)}
accept={Object.values(fileExtensionWhitelist)}
header={formatMessage(strings.caseFiles.inputFieldLabel)}
buttonLabel={formatMessage(strings.caseFiles.buttonLabel)}
onChange={(files) =>
handleUpload(
addUploadFiles(files, {
category: CaseFileCategory.CIVIL_CLAIM,
}),
updateUploadFile,
)
}
onRemove={(file) => handleRemove(file, removeUploadFile)}
onRetry={(file) => handleRetry(file, updateUploadFile)}
/>
</Box>
{workingCase.hasCivilClaims && (
<Box
component="section"
marginBottom={isTrafficViolationCaseCheck ? 5 : 10}
>
<SectionHeading
title={formatMessage(strings.caseFiles.civilClaimSection)}
/>
<InputFileUpload
fileList={uploadFiles.filter(
(file) => file.category === CaseFileCategory.CIVIL_CLAIM,
)}
accept={Object.values(fileExtensionWhitelist)}
header={formatMessage(strings.caseFiles.inputFieldLabel)}
buttonLabel={formatMessage(strings.caseFiles.buttonLabel)}
onChange={(files) =>
handleUpload(
addUploadFiles(files, {
category: CaseFileCategory.CIVIL_CLAIM,
}),
updateUploadFile,
)
}
onRemove={(file) => handleRemove(file, removeUploadFile)}
onRetry={(file) => handleRetry(file, updateUploadFile)}
/>
</Box>
)}
{isTrafficViolationCaseCheck && (
<Box marginBottom={10}>
<PdfButton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -458,44 +458,46 @@ const Indictment = () => {
/>
</BlueBox>
</Box>
<Box marginBottom={6}>
<SectionHeading title={formatMessage(strings.civilDemandsTitle)} />
<BlueBox>
<Input
name="civilDemands"
label={formatMessage(strings.civilDemandsLabel)}
placeholder={formatMessage(strings.civilDemandsPlaceholder)}
value={workingCase.civilDemands ?? ''}
errorMessage={civilDemandsErrorMessage}
hasError={civilDemandsErrorMessage !== ''}
onChange={(event) =>
removeTabsValidateAndSet(
'civilDemands',
event.target.value,
['empty'],
setWorkingCase,
civilDemandsErrorMessage,
setCivilDemandsErrorMessage,
)
}
onBlur={(event) =>
validateAndSendToServer(
'civilDemands',
event.target.value,
['empty'],
workingCase,
updateCase,
setCivilDemandsErrorMessage,
)
}
textarea
autoComplete="off"
required
rows={7}
autoExpand={{ on: true, maxHeight: 300 }}
/>
</BlueBox>
</Box>
{workingCase.hasCivilClaims && (
<Box marginBottom={6}>
<SectionHeading title={formatMessage(strings.civilDemandsTitle)} />
<BlueBox>
<Input
name="civilDemands"
label={formatMessage(strings.civilDemandsLabel)}
placeholder={formatMessage(strings.civilDemandsPlaceholder)}
value={workingCase.civilDemands ?? ''}
errorMessage={civilDemandsErrorMessage}
hasError={civilDemandsErrorMessage !== ''}
onChange={(event) =>
removeTabsValidateAndSet(
'civilDemands',
event.target.value,
['empty'],
setWorkingCase,
civilDemandsErrorMessage,
setCivilDemandsErrorMessage,
)
}
onBlur={(event) =>
validateAndSendToServer(
'civilDemands',
event.target.value,
['empty'],
workingCase,
updateCase,
setCivilDemandsErrorMessage,
)
}
textarea
autoComplete="off"
required
rows={7}
autoExpand={{ on: true, maxHeight: 300 }}
/>
</BlueBox>
</Box>
)}
<Box marginBottom={10}>
<PdfButton
caseId={workingCase.id}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { FC, useCallback, useContext } from 'react'
import { FC, useCallback, useContext, useState } from 'react'
import { useIntl } from 'react-intl'
import { useRouter } from 'next/router'

import { Box, RadioButton, Text } from '@island.is/island-ui/core'
import { Box, RadioButton, Text, UploadFile } from '@island.is/island-ui/core'
import * as constants from '@island.is/judicial-system/consts'
import { isTrafficViolationCase } from '@island.is/judicial-system/types'
import { titles } from '@island.is/judicial-system-web/messages'
Expand All @@ -20,6 +20,7 @@ import {
} from '@island.is/judicial-system-web/src/components'
import RequiredStar from '@island.is/judicial-system-web/src/components/RequiredStar/RequiredStar'
import {
CaseFileCategory,
CaseState,
CaseTransition,
DefendantPlea,
Expand All @@ -29,6 +30,7 @@ import {
useCase,
useDefendants,
useOnceOn,
useS3Upload,
} from '@island.is/judicial-system-web/src/utils/hooks'
import { isProcessingStepValidIndictments } from '@island.is/judicial-system-web/src/utils/validate'

Expand All @@ -46,12 +48,15 @@ const Processing: FC = () => {
isCaseUpToDate,
refreshCase,
} = useContext(FormContext)
const { updateCase, transitionCase } = useCase()
const { updateCase, transitionCase, setAndSendCaseToServer } = useCase()
const { handleRemove } = useS3Upload(workingCase.id)
const { formatMessage } = useIntl()
const { updateDefendant, updateDefendantState } = useDefendants()
const router = useRouter()
const isTrafficViolationCaseCheck = isTrafficViolationCase(workingCase)

const [hasCivilClaimsChoice, setHasCivilClaimsChoice] = useState<boolean>()

const initialize = useCallback(async () => {
if (!workingCase.court) {
await updateCase(workingCase.id, {
Expand Down Expand Up @@ -96,6 +101,36 @@ const Processing: FC = () => {
[updateDefendantState, setWorkingCase, workingCase.id, updateDefendant],
)

const handleHasCivilClaimsChange = async (hasCivilClaims: boolean) => {
setHasCivilClaimsChoice(hasCivilClaims)

setAndSendCaseToServer(
[{ hasCivilClaims, force: true }],
workingCase,
setWorkingCase,
)

if (hasCivilClaims === false) {
gudjong marked this conversation as resolved.
Show resolved Hide resolved
const civilClaims = workingCase.caseFiles?.filter(
(caseFile) => caseFile.category === CaseFileCategory.CIVIL_CLAIM,
)

if (!civilClaims) {
return
}

setAndSendCaseToServer(
[{ civilDemands: null, force: true }],
workingCase,
setWorkingCase,
)

for (const civilClaim of civilClaims) {
handleRemove(civilClaim as UploadFile)
}
}
}

return (
<PageLayout
workingCase={workingCase}
Expand Down Expand Up @@ -190,12 +225,57 @@ const Processing: FC = () => {
))}
</Box>
)}
<Box component="section" marginBottom={10}>
<Box component="section" marginBottom={5}>
<CommentsInput
workingCase={workingCase}
setWorkingCase={setWorkingCase}
/>
</Box>
<Box
component="section"
marginBottom={workingCase.hasCivilClaims === true ? 5 : 10}
>
<BlueBox>
<SectionHeading
title={formatMessage(strings.hasCivilClaims)}
marginBottom={2}
heading="h4"
required
/>
<Box display="flex">
<Box width="half" marginRight={1}>
<RadioButton
name="hasCivilClaims"
id="civil_caim_yes"
label={formatMessage(strings.yes)}
large
backgroundColor="white"
onChange={() => handleHasCivilClaimsChange(true)}
checked={
hasCivilClaimsChoice === true ||
(hasCivilClaimsChoice === undefined &&
workingCase.hasCivilClaims === true)
}
/>
</Box>
<Box width="half" marginLeft={1}>
<RadioButton
name="hasCivilClaims"
id="civil_caim_no"
label={formatMessage(strings.no)}
large
backgroundColor="white"
onChange={() => handleHasCivilClaimsChange(false)}
checked={
hasCivilClaimsChoice === false ||
(hasCivilClaimsChoice === undefined &&
workingCase.hasCivilClaims === false)
}
/>
</Box>
</Box>
</BlueBox>
</Box>
</FormContentContainer>
<FormContentContainer isFooter>
<FormFooter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,22 @@ export const strings = {
description:
'Notaður sem texti í "Tekur ekki afstöðu" valmöguleikanum á Málsmeðferðarskjánum.',
}),
hasCivilClaims: defineMessage({
id: 'judicial.system.indictments:processing.has_civil_claims',
defaultMessage: 'Er bótakrafa?',
description:
'Notaður sem titill fyrir "Er bótakrafa?" valmöguleikana við einkaréttarkröfu á Málsmeðferðarskjánum.',
}),
yes: defineMessage({
id: 'judicial.system.indictments:processing.yes',
defaultMessage: 'Já',
description:
'Notaður sem texti í "Já" valmöguleikanum við einkaréttarkröfu á Málsmeðferðarskjánum.',
}),
no: defineMessage({
id: 'judicial.system.indictments:processing.no',
defaultMessage: 'Nei',
description:
'Notaður sem texti í "Nei" valmöguleikanum við einkaréttarkröfu á Málsmeðferðarskjánum.',
}),
}
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ const useS3Upload = (caseId: string) => {
)

const handleRemove = useCallback(
async (file: TUploadFile, callback: (file: TUploadFile) => void) => {
async (file: TUploadFile, callback?: (file: TUploadFile) => void) => {
try {
if (file.id) {
const { data } = await remove(file.id)
Expand All @@ -421,7 +421,7 @@ const useS3Upload = (caseId: string) => {
throw new Error('Failed to delete file')
}

callback(file)
callback && callback(file)
}
} catch {
toast.error(formatMessage(strings.removeFailed))
Expand Down
9 changes: 8 additions & 1 deletion apps/judicial-system/web/src/utils/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,15 @@ export const isProcessingStepValidIndictments = (
return validate([[defendant.defendantPlea, ['empty']]]).isValid
})

const hasCivilClaimSelected =
workingCase.hasCivilClaims !== null &&
workingCase.hasCivilClaims !== undefined

return Boolean(
workingCase.prosecutor && workingCase.court && defendantsAreValid(),
workingCase.prosecutor &&
workingCase.court &&
hasCivilClaimSelected &&
defendantsAreValid(),
)
}

Expand Down