Skip to content

Commit

Permalink
feat(service-portal): default defender and has chosen fields for subp…
Browse files Browse the repository at this point in the history
…oena (#16306)

* fix: def info and alert

* feat: add feature flag to resolver

* fix: move ff call to seperate function

* feat: add default choices ans has chosen + loading states

* fix: use type

* fix: undefined type issue

* fix: simplify check
  • Loading branch information
disaerna authored Oct 7, 2024
1 parent c51f52a commit 0a169cb
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 72 deletions.
21 changes: 21 additions & 0 deletions libs/api/domains/law-and-order/src/lib/helpers/mappers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
DefenderInfoDefenderChoiceEnum,
StateTagColorEnum,
SubpoenaDataDefaultDefenderChoiceEnum,
UpdateSubpoenaDtoDefenderChoiceEnum,
} from '@island.is/clients/judicial-system-sp'
import { CourtCaseStateTagColorEnum } from '../../models/courtCases.model'
Expand Down Expand Up @@ -46,6 +47,26 @@ export const mapDefenseChoiceForSubpoena = (
}
}

// Maps the application's internal representation of defense choices to the judicial system's representation.
export const mapDefenseChoiceForSubpoenaDefaultChoice = (
choice?: SubpoenaDataDefaultDefenderChoiceEnum,
): DefenseChoiceEnum => {
switch (choice) {
// Each case maps a local enum value to the corresponding value in the judicial system's enum.
case SubpoenaDataDefaultDefenderChoiceEnum.CHOOSE:
return DefenseChoiceEnum.CHOOSE
case SubpoenaDataDefaultDefenderChoiceEnum.WAIVE:
return DefenseChoiceEnum.WAIVE
case SubpoenaDataDefaultDefenderChoiceEnum.DELAY:
return DefenseChoiceEnum.DELAY
case SubpoenaDataDefaultDefenderChoiceEnum.DELEGATE:
return DefenseChoiceEnum.DELEGATE
default:
// Provides a default mapping if the input doesn't match any known value.
return DefenseChoiceEnum.DELAY
}
}

export const mapTagTypes = (
color?: StateTagColorEnum,
): CourtCaseStateTagColorEnum => {
Expand Down
41 changes: 25 additions & 16 deletions libs/api/domains/law-and-order/src/lib/law-and-order.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
DefenseChoices,
mapDefenseChoice,
mapDefenseChoiceForSubpoena,
mapDefenseChoiceForSubpoenaDefaultChoice,
mapTagTypes,
} from './helpers/mappers'

Expand Down Expand Up @@ -123,36 +124,44 @@ export class LawAndOrderService {
async getSubpoena(user: User, id: string, locale: Locale) {
const { formatMessage } = await this.intlService.useIntl(namespaces, locale)

const subpoena: SubpoenaResponse | undefined | null =
await this.api.getSubpoena(id, user, locale)
const subpoena: SubpoenaResponse | null = await this.api.getSubpoena(
id,
user,
locale,
)

if (!isDefined(subpoena)) return null
const subpoenaData = subpoena.data
if (!isDefined(subpoenaData)) return null

const defenderChoice = subpoena?.defenderInfo?.defenderChoice
const defenderInfo = subpoena.defenderInfo
const defenderChoice = defenderInfo?.defenderChoice
const message = defenderChoice
? formatMessage(
DefenseChoices[subpoena?.defenderInfo.defenderChoice].message,
)
? formatMessage(DefenseChoices[defenderChoice].message)
: ''

const data: Subpoena = {
data: {
id: subpoena?.caseId ?? id,
hasBeenServed: subpoena?.data?.hasBeenServed,
chosenDefender: [message, subpoena?.defenderInfo?.defenderName]
id: subpoena.caseId ?? id,
hasBeenServed: subpoenaData.hasBeenServed,
chosenDefender: [message, defenderInfo?.defenderName]
.filter(isDefined)
.join(', '),
defenderChoice: mapDefenseChoiceForSubpoena(
subpoena?.defenderInfo?.defenderChoice,
defenderChoice: mapDefenseChoiceForSubpoena(defenderChoice),
defaultChoice: mapDefenseChoiceForSubpoenaDefaultChoice(
subpoenaData.defaultDefenderChoice,
),
canEditDefenderChoice: subpoena?.defenderInfo?.canEdit,
groups: subpoena?.data.groups,
courtContactInfo: subpoena?.defenderInfo?.courtContactInfo,
hasChosen: subpoenaData.hasChosenDefender,
canEditDefenderChoice: defenderInfo?.canEdit,
groups: subpoenaData.groups,
courtContactInfo: defenderInfo?.courtContactInfo,
},
actions: undefined,
texts: {
confirmation: subpoena?.data.alerts?.find(
confirmation: subpoenaData.alerts?.find(
(alert) => alert.type === AlertMessageTypeEnum.Success,
)?.message,
description: subpoena?.data.subtitle,
description: subpoenaData.subtitle,
},
}
return data
Expand Down
17 changes: 6 additions & 11 deletions libs/api/domains/law-and-order/src/models/subpoena.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,6 @@ import { Action } from './actions.model'
import { DefenseChoiceEnum } from './defenseChoiceEnum.model'
import { Group } from './group.model'

@ObjectType('LawAndOrderSubpoenaAlert')
export class Alert {
@Field({ nullable: true })
type?: string

@Field({ nullable: true })
message?: string
}
@ObjectType('LawAndOrderSubpoenaTexts')
export class Text {
@Field({ nullable: true })
Expand Down Expand Up @@ -43,14 +35,17 @@ export class Data {
@Field({ nullable: true })
courtContactInfo?: string

@Field(() => DefenseChoiceEnum)
defaultChoice!: DefenseChoiceEnum

@Field(() => Boolean, { nullable: true })
hasChosen?: boolean

@Field(() => DefenseChoiceEnum, { nullable: true })
defenderChoice?: DefenseChoiceEnum

@Field(() => [Group], { nullable: true })
groups?: Array<Group>

@Field(() => [Alert], { nullable: true })
alerts?: Array<Alert>
}

@ObjectType('LawAndOrderSubpoena')
Expand Down
17 changes: 15 additions & 2 deletions libs/clients/judicial-system-sp/src/clientConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -459,9 +459,22 @@
"type": "array",
"items": { "$ref": "#/components/schemas/AlertMessage" }
},
"hasBeenServed": { "type": "boolean" }
"hasBeenServed": { "type": "boolean" },
"hasChosenDefender": { "type": "boolean" },
"defaultDefenderChoice": {
"type": "string",
"enum": ["WAIVE", "CHOOSE", "DELAY", "DELEGATE"]
}
},
"required": ["title", "subtitle", "groups", "alerts", "hasBeenServed"]
"required": [
"title",
"subtitle",
"groups",
"alerts",
"hasBeenServed",
"hasChosenDefender",
"defaultDefenderChoice"
]
},
"DefenderInfo": {
"type": "object",
Expand Down
41 changes: 22 additions & 19 deletions libs/service-portal/core/src/components/IntroHeader/IntroHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import {
GridColumn,
GridRow,
Text,
LoadingDots,
GridColumnProps,
Box,
SkeletonLoader,
Stack,
} from '@island.is/island-ui/core'
import { IntroHeaderProps } from '@island.is/portals/core'
import InstitutionPanel from '../InstitutionPanel/InstitutionPanel'
Expand Down Expand Up @@ -39,28 +40,30 @@ export const IntroHeader = (props: IntroHeaderProps & Props) => {

const columnSpan = isMobile ? '8/8' : props.narrow ? '4/8' : '5/8'

if (props.loading) {
return (
<Box marginBottom={marginBottom ?? 4}>
<LoadingDots />
</Box>
)
}
return (
<GridRow marginBottom={marginBottom ?? 4}>
<GridColumn span={props.span ? props.span : columnSpan}>
<Text variant="h3" as={props.isSubheading ? 'h2' : 'h1'}>
{formatMessage(props.title)}
</Text>
{props.intro && (
<Text variant="default" paddingTop={1}>
{formatMessage(props.intro)}
</Text>
{props.loading ? (
<Stack space={2}>
<SkeletonLoader height={24} width={120} />
<SkeletonLoader height={24} width={300} />
</Stack>
) : (
<>
<Text variant="h3" as={props.isSubheading ? 'h2' : 'h1'}>
{formatMessage(props.title)}
</Text>
{props.intro && (
<Text variant="default" paddingTop={1}>
{formatMessage(props.intro)}
</Text>
)}
{props.introComponent && (
<Box paddingTop={1}>{props.introComponent}</Box>
)}
{props.children}
</>
)}
{props.introComponent && (
<Box paddingTop={1}>{props.introComponent}</Box>
)}
{props.children}
</GridColumn>
{!isMobile && props.serviceProviderSlug && organization && (
<GridColumn span={'2/8'} offset={'1/8'}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
toast,
GridColumn,
LoadingDots,
SkeletonLoader,
} from '@island.is/island-ui/core'
import { useLocale, useNamespaces } from '@island.is/localization'
import { Controller, FormProvider, useForm } from 'react-hook-form'
Expand Down Expand Up @@ -105,10 +106,9 @@ const DefenderChoices: FC<React.PropsWithChildren<Props>> = ({
{formatMessage(messages.chooseDefenderTitle)}
</Text>
)}
{loading && !error && <LoadingDots />}
{!loading && error && <Problem size="small" />}
{lawyers === null ? (
<Problem size="small" />
{loading ? (
<SkeletonLoader height={24} repeat={4} space={4} />
) : (
<FormProvider {...methods}>
<form onSubmit={methods.handleSubmit(handleSubmitForm)}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ query GetSubpoena($input: LawAndOrderSubpoenaInput!, $locale: String!) {
defenderChoice
canEditDefenderChoice
courtContactInfo
defaultChoice
hasChosen
groups {
label
items {
Expand All @@ -15,10 +17,6 @@ query GetSubpoena($input: LawAndOrderSubpoenaInput!, $locale: String!) {
link
}
}
alerts {
type
message
}
}
texts {
confirmation
Expand Down
40 changes: 23 additions & 17 deletions libs/service-portal/law-and-order/src/screens/Subpoena/Subpoena.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
Box,
Button,
Divider,
SkeletonLoader,
Text,
} from '@island.is/island-ui/core'
import {
Expand Down Expand Up @@ -43,7 +44,9 @@ const Subpoena = () => {
})

const subpoena = data?.lawAndOrderSubpoena

const [defenderPopUp, setDefenderPopUp] = useState<boolean>(false)

if (
subpoena?.data &&
(!isDefined(subpoena.data.hasBeenServed) ||
Expand All @@ -60,19 +63,18 @@ const Subpoena = () => {
intro={subpoena?.texts?.description ?? ''}
serviceProviderSlug={DOMSMALARADUNEYTID_SLUG}
serviceProviderTooltip={formatMessage(m.domsmalaraduneytidTooltip)}
children={
!loading &&
subpoena?.texts?.confirmation && (
<Box marginTop={4}>
<AlertMessage
type="success"
message={subpoena.texts.confirmation}
/>
</Box>
)
}
/>
>
{!loading && subpoena?.texts?.confirmation && (
<Box marginTop={4}>
<AlertMessage
type="success"
message={subpoena.texts.confirmation}
/>
</Box>
)}
</IntroHeader>

{loading && <SkeletonLoader space={2} repeat={4} height={24} />}
<Box marginTop={3} display="flex" flexWrap="wrap">
{!loading && subpoena?.data && (
<Box paddingRight={2} marginBottom={[1]}>
Expand Down Expand Up @@ -100,10 +102,10 @@ const Subpoena = () => {

{error && !loading && <Problem error={error} noBorder={false} />}

{subpoena?.data?.groups && subpoena.data.groups.length > 0 && (
{subpoena?.data?.groups?.length && (
<>
<InfoLines groups={subpoena.data.groups} loading={loading} />
{isDefined(subpoena?.data.defenderChoice) && (
{subpoena.data.hasChosen && isDefined(subpoena?.data.defenderChoice) && (
<>
<Box paddingTop={1} />
<InfoLine
Expand Down Expand Up @@ -137,8 +139,12 @@ const Subpoena = () => {
<Text>{formatMessage(messages.subpoenaInfoText2)}</Text>
</Box>

{!loading && subpoena.data.canEditDefenderChoice === null && (
<DefenderChoices id={id} refetch={refetch} />
{!loading && subpoena.data.hasChosen === false && (
<DefenderChoices
id={id}
refetch={refetch}
choice={subpoena.data.defaultChoice}
/>
)}

{defenderPopUp && (
Expand All @@ -156,7 +162,7 @@ const Subpoena = () => {
)}
</>
)}
{!loading && !error && subpoena?.data?.groups?.length === 0 && (
{!loading && !error && subpoena === null && (
<Problem
type="no_data"
noBorder={false}
Expand Down

0 comments on commit 0a169cb

Please sign in to comment.