Skip to content

Commit

Permalink
feat(j-s): Create police case files screen (#8600)
Browse files Browse the repository at this point in the history
* Create police case files screen

* Basic page setup

* feat(j-s): rewrite useS3Upload hook

* feat(j-s): use new upload hook for each loke number

* feat(j-s): add retry and remove for useS3UploadV2

* feat(j-s): add error handling for upload

Co-authored-by: Ívar Oddsson <[email protected]>

* feat(j-s): memorize police file upload list

To avoid maximum depth rendering

* feat(j-s): move string to contentful

* docs(j-s): add to more explaination to comment

* refactor(j-s): change PageTitle to accept children

* fix(j-s): fix missing defaultMessage for contentful string

* fix(j-s): fix retry uploading file

Adding `id` from the beginning to file to be able to refrence it when
retrying. Setting precent and state to uploading for better user
experince when retrying a failed upload.

* feat(j-s): handle errors when delete file failes

* test(j-s): fix e2e test for indictments prosecutor flow

* refactor(j-s): move setting file upload state out of uploadToS3

Co-authored-by: Arnar Kári <[email protected]>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Oct 17, 2022
1 parent 0dc1d6d commit c66e9b6
Show file tree
Hide file tree
Showing 27 changed files with 581 additions and 67 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
INDICTMENTS_CASE_FILES_ROUTE,
INDICTMENTS_OVERVIEW_ROUTE,
INDICTMENTS_POLICE_CASE_FILES_ROUTE,
} from '@island.is/judicial-system/consts'
import { CaseType, UserRole } from '@island.is/judicial-system/types'

Expand All @@ -23,6 +23,6 @@ describe(`${INDICTMENTS_CASE_FILES_ROUTE}/:id`, () => {

it('should navigate to the correct page on continue', () => {
cy.getByTestid('continueButton').click()
cy.url().should('contain', INDICTMENTS_OVERVIEW_ROUTE)
cy.url().should('contain', INDICTMENTS_POLICE_CASE_FILES_ROUTE)
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {
INDICTMENTS_POLICE_CASE_FILES_ROUTE,
INDICTMENTS_OVERVIEW_ROUTE,
} from '@island.is/judicial-system/consts'
import { CaseType, UserRole } from '@island.is/judicial-system/types'

import { makeCourt, mockCase, makeProsecutor, intercept } from '../../../utils'

describe(`${INDICTMENTS_POLICE_CASE_FILES_ROUTE}/:id`, () => {
beforeEach(() => {
const caseData = mockCase(CaseType.MURDER)
const caseDataAddition = {
...caseData,
prosecutor: makeProsecutor(),
court: makeCourt(),
}

cy.login(UserRole.PROSECUTOR)
cy.stubAPIResponses()
intercept(caseDataAddition)
cy.visit(`${INDICTMENTS_POLICE_CASE_FILES_ROUTE}/test_id`)
})

it('should navigate to the correct page on continue', () => {
cy.getByTestid('continueButton').click()
cy.url().should('contain', INDICTMENTS_OVERVIEW_ROUTE)
})
})
5 changes: 5 additions & 0 deletions apps/judicial-system/web/messages/Core/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,9 @@ export const errors = defineMessages({
defaultMessage: 'Ekki tókst að afrita hlekk',
description: 'Notaður sem villuskilaboð þegar ekki gengur að afrita hlekk',
},
failedDeleteFile: {
id: 'judicial.system.core:errors.failed_delete_file',
defaultMessage: 'Ekki tókst að eyða skrá',
description: 'Notaður sem villuskilaboð þegar ekki gengur að eyða skrá',
},
})
7 changes: 7 additions & 0 deletions apps/judicial-system/web/messages/Core/sections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@ export const sections = {
description:
'Notaður sem texti fyrir Dómskjöl skref í hliðarstiku í ákærum hjá sækjendum',
},
policeCaseFiles: {
id:
'judicial.system.core:sections.indictment_case_prosecutor_section.police_case_files',
defaultMessage: 'Málsgögn',
description:
'Notaður sem texti fyrir Málsgögn skref í hliðarstiku í ákærum hjá sækjendum',
},
overview: {
id:
'judicial.system.core:sections.indictment_case_prosecutor_section.overview',
Expand Down
7 changes: 7 additions & 0 deletions apps/judicial-system/web/messages/Core/titles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ export const titles = {
description:
'Notaður sem titill fyrir Dómskjöl skjá hjá saksóknara í ákærum',
}),
policeCaseFiles: defineMessage({
id:
'judicial.system.core:titles.prosecutor.indictments.police_case_files',
defaultMessage: 'Málsgögn - Réttarvörslugátt',
description:
'Notaður sem titill fyrir Málsgögn skjá hjá saksóknara í ákærum',
}),
overview: defineMessage({
id: 'judicial.system.core:titles.prosecutor.indictments.overview',
defaultMessage: 'Yfirlit ákæru - Réttarvörslugátt',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import Defendant from '@island.is/judicial-system-web/src/routes/Prosecutor/Indictments/Defendant'
import Defendant from '@island.is/judicial-system-web/src/routes/Prosecutor/Indictments/Defendant/Defendant'

export default Defendant
3 changes: 3 additions & 0 deletions apps/judicial-system/web/pages/krafa/akaera/malsgogn/[id].ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import PoliceCaseFiles from '@island.is/judicial-system-web/src/routes/Prosecutor/Indictments/PoliceCaseFiles/PoliceCaseFilesRoute'

export default PoliceCaseFiles
2 changes: 1 addition & 1 deletion apps/judicial-system/web/pages/krafa/ny/akaera.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import Defendant from '@island.is/judicial-system-web/src/routes/Prosecutor/Indictments/Defendant'
import Defendant from '@island.is/judicial-system-web/src/routes/Prosecutor/Indictments/Defendant/Defendant'
export default Defendant
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ const CaseQuery = gql`
state
key
category
policeCaseNumber
}
isAppealDeadlineExpired
isAppealGracePeriodExpired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@ import React from 'react'

import { Box, Text } from '@island.is/island-ui/core'

interface Props {
title: string
}
const PageTitle: React.FC<Props> = ({ title }) => (
const PageTitle: React.FC = ({ children }) => (
<Box marginBottom={7}>
<Text as="h1" variant="h1">
{title}
{children}
</Text>
</Box>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const CourtRecord: React.FC = () => {
>
<PageHeader title={formatMessage(titles.court.indictments.courtRecord)} />
<FormContentContainer>
<PageTitle title={formatMessage(m.title)} />
<PageTitle>{formatMessage(m.title)}</PageTitle>
<CourtCaseInfo workingCase={workingCase} />
<Box component="section" marginBottom={5}>
<AlertMessage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const HearingArrangements: React.FC = () => {
title={formatMessage(titles.court.indictments.prosecutorAndDefender)}
/>
<FormContentContainer>
<PageTitle title={formatMessage(m.title)} />
<PageTitle>{formatMessage(m.title)}</PageTitle>
<CourtCaseInfo workingCase={workingCase} />
<Box component="section" marginBottom={5}>
<SectionHeading title={formatMessage(m.selectProsecutorHeading)} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ const Subpoena: React.FC = () => {
>
<PageHeader title={formatMessage(titles.court.indictments.subpoena)} />
<FormContentContainer>
<PageTitle title={formatMessage(strings.title)} />
<PageTitle>{formatMessage(strings.title)}</PageTitle>
<CourtCaseInfo workingCase={workingCase} />
<Box component="section" marginBottom={5}>
<SectionHeading
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ const CaseFiles: React.FC = () => {
onRetry={handleRetry}
/>
</Box>
<Box component="section" marginBottom={5}>
<Box component="section" marginBottom={7}>
<Box marginBottom={3} display="inlineFlex">
<Text variant="h3" as="h3">
{formatMessage(strings.caseFiles.sections.costBreakdown)}
Expand All @@ -145,57 +145,11 @@ const CaseFiles: React.FC = () => {
onRetry={handleRetry}
/>
</Box>
<Box component="section" marginBottom={5}>
<Box marginBottom={3} display="inlineFlex">
<Text variant="h3" as="h3">
{formatMessage(strings.caseFiles.sections.caseFileContents)}
</Text>
</Box>
<Text color="red400" as="span" variant="h3">
{` *`}
</Text>

<InputFileUpload
fileList={files.filter(
(file) => file.category === CaseFileCategory.CASE_FILE_CONTENTS,
)}
header={formatMessage(strings.caseFiles.sections.inputFieldLabel)}
buttonLabel={formatMessage(strings.caseFiles.sections.buttonLabel)}
onChange={(files) =>
handleS3Upload(files, false, CaseFileCategory.CASE_FILE_CONTENTS)
}
onRemove={handleRemoveFromS3}
onRetry={handleRetry}
/>
</Box>
<Box component="section" marginBottom={10}>
<Box marginBottom={3} display="inlineFlex">
<Text variant="h3" as="h3">
{formatMessage(strings.caseFiles.sections.caseFile)}
</Text>
</Box>
<Text color="red400" as="span" variant="h3">
{` *`}
</Text>

<InputFileUpload
fileList={files.filter(
(file) => file.category === CaseFileCategory.CASE_FILE,
)}
header={formatMessage(strings.caseFiles.sections.inputFieldLabel)}
buttonLabel={formatMessage(strings.caseFiles.sections.buttonLabel)}
onChange={(files) =>
handleS3Upload(files, false, CaseFileCategory.CASE_FILE)
}
onRemove={handleRemoveFromS3}
onRetry={handleRetry}
/>
</Box>
</FormContentContainer>
<FormContentContainer isFooter>
<FormFooter
previousUrl={`${constants.INDICTMENTS_PROCESSING_ROUTE}/${workingCase.id}`}
nextUrl={`${constants.INDICTMENTS_OVERVIEW_ROUTE}/${workingCase.id}`}
nextUrl={`${constants.INDICTMENTS_POLICE_CASE_FILES_ROUTE}/${workingCase.id}`}
nextIsDisabled={!allFilesUploaded}
nextIsLoading={isLoadingWorkingCase}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import {
DefendantInfo,
PoliceCaseNumbers,
usePoliceCaseNumbers,
} from '../components'
} from '../../components'

const Defendant: React.FC = () => {
const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ const Overview: React.FC = () => {
previousUrl={
caseHasBeenSentToCourt
? constants.CASES_ROUTE
: `${constants.INDICTMENTS_CASE_FILES_ROUTE}/${workingCase.id}`
: `${constants.INDICTMENTS_POLICE_CASE_FILES_ROUTE}/${workingCase.id}`
}
nextButtonText={formatMessage(strings.overview.nextButtonText, {
isNewIndictment,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { defineMessage, defineMessages } from 'react-intl'

export const policeCaseFiles = {
heading: defineMessage({
id: 'judicial.system.core:police_case_files_route.heading',
defaultMessage: 'Málsgögn',
description: 'Notaður sem titill á Málsgögn skrefi í ákærum.',
}),
infoBox: defineMessage({
id: 'judicial.system.core:police_case_files_route.info_box',
defaultMessage:
'Gögn sem er hlaðið upp hér fyrir neðan verða sameinuð í eitt PDF skjal og efnisyfirlit sjálfkrafa búið til.',
description: 'Notaður sem texti í info boxi í Málsgögn skrefi í ákærum.',
}),
policeCaseNumberSectionHeading: defineMessage({
id:
'judicial.system.core:police_case_files_route.police_case_number_section_heading',
defaultMessage: 'Gögn úr LÖKE-máli {policeCaseNumber}',
description:
'Notaður sem fyrirsögn fyrir hvert Löke númer á Málsgögn skrefi í ákærum.',
}),
inputFileUpload: defineMessages({
header: {
id:
'judicial.system.core:police_case_files_route.input_file_upload.header',
defaultMessage: 'Dragðu skrár hingað til að hlaða upp',
description:
'Notaður fyrir texta í svæði sem hægt er að draga skrá á til að hlaða þeim upp.',
},
buttonLabel: {
id:
'judicial.system.core:police_case_files_route.input_file_upload.button_label',
defaultMessage: 'Velja gögn til að hlaða upp',
description:
'Notaður fyrir texta í takka sem hægt er að ýta á til að velja skrár til að hlaða upp.',
},
}),
}
Loading

0 comments on commit c66e9b6

Please sign in to comment.