Skip to content

Commit

Permalink
feat(j-s): Service announcement for defenders (#16731)
Browse files Browse the repository at this point in the history
* Checkpoint

* Refactor AlertMessage

* Format date

* Cleanup

* Cleanup

* Merge

* Add key

* Refactor

* Remove console.log

* Import React

* Add action prop bacj

* Add action prop bacj

* Add action prop bacj

* Fix import

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Co-authored-by: Guðjón Guðjónsson <[email protected]>
  • Loading branch information
3 people authored Nov 13, 2024
1 parent de4bcc8 commit c40a213
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 35 deletions.
1 change: 1 addition & 0 deletions apps/judicial-system/web/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export { default as RulingAccordionItem } from './AccordionItems/RulingAccordion
export { default as RulingInput } from './RulingInput/RulingInput'
export { default as SectionHeading } from './SectionHeading/SectionHeading'
export { default as ServiceAnnouncement } from './ServiceAnnouncement/ServiceAnnouncement'
export { strings as serviceAnnouncementStrings } from './ServiceAnnouncement/ServiceAnnouncement.strings'
export { default as ServiceInterruptionBanner } from './ServiceInterruptionBanner/ServiceInterruptionBanner'
export { default as SignedDocument } from './SignedDocument/SignedDocument'
export { default as OverviewHeader } from './OverviewHeader/OverviewHeader'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ import { FC, useCallback, useContext, useState } from 'react'
import { useIntl } from 'react-intl'
import { useRouter } from 'next/router'

import { Accordion, Box, Button } from '@island.is/island-ui/core'
import { Accordion, AlertMessage, Box, Button } from '@island.is/island-ui/core'
import * as constants from '@island.is/judicial-system/consts'
import { normalizeAndFormatNationalId } from '@island.is/judicial-system/formatters'
import {
formatDate,
normalizeAndFormatNationalId,
} from '@island.is/judicial-system/formatters'
import {
isCompletedCase,
isDefenceUser,
isProsecutionUser,
isSuccessfulServiceStatus,
} from '@island.is/judicial-system/types'
import { titles } from '@island.is/judicial-system-web/messages'
import {
Expand All @@ -25,26 +29,64 @@ import {
PageHeader,
PageLayout,
PageTitle,
serviceAnnouncementStrings,
useIndictmentsLawsBroken,
UserContext,
} from '@island.is/judicial-system-web/src/components'
import {
CaseIndictmentRulingDecision,
CaseState,
Defendant,
IndictmentDecision,
Subpoena,
UserRole,
} from '@island.is/judicial-system-web/src/graphql/schema'

import { ReviewDecision } from '../../PublicProsecutor/components/ReviewDecision/ReviewDecision'
import { strings } from './IndictmentOverview.strings'

interface ServiceAnnouncementProps {
defendant: Defendant
subpoena: Subpoena
}

const ServiceAnnouncement: FC<ServiceAnnouncementProps> = (props) => {
const { defendant, subpoena } = props
const { formatMessage } = useIntl()

const getTitle = (defendantName?: string | null): string => {
const successMessage = formatMessage(
serviceAnnouncementStrings.serviceStatusSuccess,
)

return defendantName
? `${successMessage} - ${defendantName}`
: successMessage
}

const getMessage = (
servedBy?: string | null,
serviceDate?: string | null,
): string => {
return [servedBy, formatDate(serviceDate, 'Pp')].filter(Boolean).join(', ')
}

return (
<AlertMessage
type="success"
title={getTitle(defendant.name)}
message={getMessage(subpoena.servedBy, subpoena.serviceDate)}
/>
)
}

const IndictmentOverview: FC = () => {
const router = useRouter()
const { workingCase, isLoadingWorkingCase, caseNotFound } =
useContext(FormContext)
const { user } = useContext(UserContext)

const { user } = useContext(UserContext)
const { formatMessage } = useIntl()
const router = useRouter()
const lawsBroken = useIndictmentsLawsBroken(workingCase)
const caseHasBeenReceivedByCourt = workingCase.state === CaseState.RECEIVED
const latestDate = workingCase.courtDate ?? workingCase.arraignmentDate
Expand All @@ -53,10 +95,16 @@ const IndictmentOverview: FC = () => {
const [modalVisible, setModalVisible] = useState<boolean>(false)
const [isReviewDecisionSelected, setIsReviewDecisionSelected] =
useState(false)

const hasLawsBroken = lawsBroken.size > 0
const hasMergeCases =
workingCase.mergedCases && workingCase.mergedCases.length > 0

const shouldDisplayReviewDecision =
isCompletedCase(workingCase.state) &&
workingCase.indictmentReviewer?.id === user?.id &&
Boolean(!workingCase.indictmentReviewDecision)

const canAddFiles =
!isCompletedCase(workingCase.state) &&
isDefenceUser(user) &&
Expand All @@ -69,6 +117,7 @@ const IndictmentOverview: FC = () => {
) &&
workingCase.indictmentDecision !==
IndictmentDecision.POSTPONING_UNTIL_VERDICT

const shouldDisplayGeneratedPdfFiles =
isProsecutionUser(user) ||
workingCase.defendants?.some(
Expand Down Expand Up @@ -96,10 +145,6 @@ const IndictmentOverview: FC = () => {
[router, workingCase.id],
)

const hasLawsBroken = lawsBroken.size > 0
const hasMergeCases =
workingCase.mergedCases && workingCase.mergedCases.length > 0

return (
<PageLayout
workingCase={workingCase}
Expand All @@ -124,6 +169,21 @@ const IndictmentOverview: FC = () => {
: formatMessage(strings.inProgressTitle)}
</PageTitle>
<CourtCaseInfo workingCase={workingCase} />
{isDefenceUser(user) &&
workingCase.defendants?.map((defendant) =>
(defendant.subpoenas ?? [])
.filter((subpoena) =>
isSuccessfulServiceStatus(subpoena.serviceStatus),
)
.map((subpoena) => (
<Box key={`${defendant.id}${subpoena.id}`} marginBottom={2}>
<ServiceAnnouncement
defendant={defendant}
subpoena={subpoena}
/>
</Box>
)),
)}
{caseHasBeenReceivedByCourt &&
workingCase.court &&
latestDate?.date &&
Expand Down
59 changes: 32 additions & 27 deletions libs/island-ui/core/src/lib/AlertMessage/AlertMessage.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import * as React from 'react'
import React, { FC, ReactNode, isValidElement } from 'react'
import { Text } from '../Text/Text'
import { Icon } from '../IconRC/Icon'
import { Icon as IconType } from '../IconRC/iconMap'
import { Colors } from '@island.is/island-ui/theme'
import { Box } from '../Box/Box'
import { Stack } from '../Stack/Stack'

export type AlertMessageType =
| 'error'
Expand Down Expand Up @@ -58,30 +57,32 @@ const variantStyles: VariantStyles = {
export interface AlertMessageProps {
type: AlertMessageType
testid?: string
action?: React.ReactNode
action?: ReactNode
}

type TitleAndOrMessage =
| {
title: string
message: string | React.ReactNode
message: string | ReactNode
}
| {
title?: never
message: string | React.ReactNode
message: string | ReactNode
}
| {
title: string
message?: never
}

export const AlertMessage: React.FC<
React.PropsWithChildren<AlertMessageProps & TitleAndOrMessage>
> = ({ type, title, message, action, testid }) => {
export const AlertMessage: FC<AlertMessageProps & TitleAndOrMessage> = ({
type,
title,
message,
testid,
action,
}) => {
const variant = variantStyles[type]

const onlyMessage = !title && !!message

return (
<Box
padding={[1, 1, 2]}
Expand All @@ -91,7 +92,7 @@ export const AlertMessage: React.FC<
borderWidth="standard"
data-testid={testid ?? 'alertMessage'}
>
<Box display="flex" alignItems={onlyMessage ? 'center' : 'flexStart'}>
<Box display="flex" alignItems="flexStart">
{variant.icon && (
<Box display="flex" marginRight={[1, 1, 2]}>
<Icon
Expand All @@ -102,22 +103,26 @@ export const AlertMessage: React.FC<
/>
</Box>
)}
<Box display="flex" width="full" flexDirection="column">
<Stack space={1}>
{!!title && (
<Text as="h5" variant="h5">
{title}
</Text>
)}
<Box
display="flex"
width="full"
flexDirection="column"
alignSelf="center"
>
{title && (
<Text as="h5" variant="h5" marginBottom={message ? 1 : 0}>
{title}
</Text>
)}
{message && (
<Box display="flex" alignItems="center">
{message &&
(React.isValidElement(message) ? (
message
) : (
<Box flexGrow={1}>
<Text variant="small">{message}</Text>
</Box>
))}
{isValidElement(message) ? (
message
) : (
<Box flexGrow={1}>
<Text variant="small">{message}</Text>
</Box>
)}
{action && (
<Box
display="flex"
Expand All @@ -129,7 +134,7 @@ export const AlertMessage: React.FC<
</Box>
)}
</Box>
</Stack>
)}
</Box>
</Box>
</Box>
Expand Down
2 changes: 2 additions & 0 deletions libs/island-ui/core/src/lib/Box/Box.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const Box = forwardRef<HTMLElement, BoxProps & TestSupport>(
columnGap,
rowGap,
alignItems,
alignSelf,
justifyContent,
textAlign,
border,
Expand Down Expand Up @@ -93,6 +94,7 @@ export const Box = forwardRef<HTMLElement, BoxProps & TestSupport>(
columnGap,
rowGap,
alignItems,
alignSelf,
justifyContent,
textAlign,
border,
Expand Down
40 changes: 40 additions & 0 deletions libs/island-ui/core/src/lib/Box/useBoxStyles.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,46 @@ export const alignItemsXl = styleVariants(
),
)

const alignSelfRules = {
flexStart: 'flex-start',
center: 'center',
flexEnd: 'flex-end',
baseline: 'baseline',
stretch: 'stretch',
}
export const alignSelf = styleVariants(
mapToStyleProperty(alignSelfRules, 'alignSelf'),
)

export const alignSelfSm = styleVariants(
mapToStyleProperty(alignSelfRules, 'alignSelf', (value, propertyName) =>
themeUtils.responsiveStyle({
sm: { [propertyName]: value },
}),
),
)
export const alignSelfMd = styleVariants(
mapToStyleProperty(alignSelfRules, 'alignSelf', (value, propertyName) =>
themeUtils.responsiveStyle({
md: { [propertyName]: value },
}),
),
)
export const alignSelfLg = styleVariants(
mapToStyleProperty(alignSelfRules, 'alignSelf', (value, propertyName) =>
themeUtils.responsiveStyle({
lg: { [propertyName]: value },
}),
),
)
export const alignSelfXl = styleVariants(
mapToStyleProperty(alignSelfRules, 'alignSelf', (value, propertyName) =>
themeUtils.responsiveStyle({
xl: { [propertyName]: value },
}),
),
)

const justifyContentRules = {
flexStart: 'flex-start',
center: 'center',
Expand Down
11 changes: 11 additions & 0 deletions libs/island-ui/core/src/lib/Box/useBoxStyles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export interface UseBoxStylesProps {
flexShrink?: keyof typeof styleRefs.flexShrink
flexGrow?: keyof typeof styleRefs.flexGrow
alignItems?: ResponsiveProp<keyof typeof styleRefs.alignItems>
alignSelf?: ResponsiveProp<keyof typeof styleRefs.alignSelf>
justifyContent?: ResponsiveProp<keyof typeof styleRefs.justifyContent>
textAlign?: ResponsiveProp<keyof typeof styleRefs.textAlign>
columnGap?: ResponsiveSpace
Expand Down Expand Up @@ -98,6 +99,7 @@ export const useBoxStyles = ({
rowGap,
columnGap,
alignItems,
alignSelf,
justifyContent,
textAlign,
border,
Expand Down Expand Up @@ -346,6 +348,15 @@ export const useBoxStyles = ({
styles.alignItemsLg,
styles.alignItemsXl,
),
alignSelf !== undefined &&
resolveResponsiveProp(
alignSelf,
styles.alignSelf,
styles.alignSelfSm,
styles.alignSelfMd,
styles.alignSelfLg,
styles.alignSelfXl,
),
justifyContent !== undefined &&
resolveResponsiveProp(
justifyContent,
Expand Down

0 comments on commit c40a213

Please sign in to comment.