Skip to content

Commit

Permalink
chore(accident-notification): organize utils (#17250)
Browse files Browse the repository at this point in the history
* feat: start of procure for accident notifications

* feat: solve merge conflicts

* chore: solve merge conflicts

* fix: typo in message

* chore: simplify conditions and small clean up

* chore: remove unused functions

* chore: make mapUserToRole slightly cleaner

* chore: more concise if statement

* chore: organize utils

* chore: re export

* fix: import in spec file

* fix: github build

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
jonnigs and kodiakhq[bot] authored Dec 19, 2024
1 parent a27fc37 commit 62ed00f
Show file tree
Hide file tree
Showing 110 changed files with 2,260 additions and 2,397 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,37 @@
import { Box, Button, Tag, Text } from '@island.is/island-ui/core'
import { Box, Button, Tag, TagVariant, Text } from '@island.is/island-ui/core'
import { useLocale } from '@island.is/localization'
import React, { FC } from 'react'
import * as styles from './ReviewSection.css'
import { ReviewSectionProps } from './types'
import { MessageDescriptor } from 'react-intl'

export const StatusStep: FC<React.PropsWithChildren<ReviewSectionProps>> = ({
export type ActionProps = {
title: string
description: string
fileNames?: string
actionButtonTitle: string
hasActionButtonIcon?: boolean
showAlways?: boolean
cta?: () => void
}

type Props = {
title: string
description: string
hasActionMessage: boolean
action?: ActionProps
visible?: boolean
tagText: MessageDescriptor | string
tagVariant: TagVariant
}

export const StatusStep = ({
title,
description,
tagVariant = 'blue',
tagText = 'Í bið',
hasActionMessage,
action,
visible = true,
}) => {
}: Props) => {
const { formatMessage } = useLocale()
const handleOnCTAButtonClick = () => {
action?.cta && action.cta()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,43 +1,10 @@
import { TagVariant } from '@island.is/island-ui/core'
import { MessageDescriptor } from '@formatjs/intl'

export interface ActionProps {
title: string
description: string
fileNames?: string
actionButtonTitle: string
hasActionButtonIcon?: boolean
showAlways?: boolean
cta?: () => void
}

export enum AccidentNotificationStatusEnum {
ACCEPTED = 'ACCEPTED',
REFUSED = 'REFUSED',
INPROGRESS = 'INPROGRESS',
INPROGRESSWAITINGFORDOCUMENT = 'INPROGRESSWAITINGFORDOCUMENT',
}

export interface ReviewSectionProps {
title: string
description: string
hasActionMessage: boolean
action?: ActionProps
visible?: boolean
tagText: MessageDescriptor | string
tagVariant: TagVariant
}

export interface Steps {
title: string
description: string
hasActionMessage: boolean
action?: ActionProps
visible?: boolean
tagText: MessageDescriptor | string
tagVariant: TagVariant
}

export interface SubmittedApplicationData {
data?: {
documentId: string
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,33 @@
import { FormatMessage, FormValue } from '@island.is/application/types'
import {
FormatMessage,
FormValue,
TagVariant,
} from '@island.is/application/types'
import { inReview } from '../../lib/messages'
import { AccidentNotificationStatusEnum, Steps } from './StatusStep/types'
import { AccidentNotificationStatusEnum } from './StatusStep/types'
import { getValueViaPath } from '@island.is/application/core'
import { ReviewApprovalEnum } from '../../types'
import { AccidentNotificationStatus } from '@island.is/api/schema'
import {
hasReceivedAllDocuments,
hasReceivedConfirmation,
isInjuredAndRepresentativeOfCompanyOrInstitute,
shouldRequestReview,
} from '../../utils'
import { hasReceivedConfirmation } from '../../utils/hasReceivedConfirmation'
} from '../../utils/miscUtils'

import { AccidentNotificationAnswers } from '../..'
import { MessageDescriptor } from 'react-intl'
import { ActionProps } from './StatusStep'
import { hasReceivedAllDocuments } from '../../utils/documentUtils'

type Steps = {
title: string
description: string
hasActionMessage: boolean
action?: ActionProps
visible?: boolean
tagText: MessageDescriptor | string
tagVariant: TagVariant
}

export const tagMapperApplicationStatus = {
[AccidentNotificationStatusEnum.ACCEPTED]: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@ import { useFormContext } from 'react-hook-form'
import { getAccidentStatusQuery } from '../../hooks/useLazyStatusOfNotification'
import { inReview } from '../../lib/messages'
import { ReviewApprovalEnum, SubmittedApplicationData } from '../../types'
import {
getErrorMessageForMissingDocuments,
isUniqueAssignee,
} from '../../utils'
import { isUniqueAssignee } from '../../utils/miscUtils'
import { StatusStep } from './StatusStep'
import { ApplicationStatusProps } from './StatusStep/types'
import { getStatusAndApproval, getSteps } from './applicationStatusUtils'
import { getErrorMessageForMissingDocuments } from '../../utils/documentUtils'

export const ApplicationStatus = ({
goToScreen,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import { IsHealthInsuredInput } from '@island.is/api/schema'
import { FieldBaseProps } from '@island.is/application/types'
import { FieldBaseProps, NO, YES } from '@island.is/application/types'
import { Box, Input } from '@island.is/island-ui/core'
import { useLocale } from '@island.is/localization'
import { DatePickerController } from '@island.is/shared/form-fields'
import React, { FC, useCallback, useEffect, useState } from 'react'
import { useCallback, useEffect, useState } from 'react'
import { Controller, useFormContext } from 'react-hook-form'
import { NO, YES } from '../../utils/constants'
import { useLazyIsHealthInsured } from '../../hooks/useLazyIsHealthInsured'
import { AccidentNotification } from '../../lib/dataSchema'
import { accidentDetails } from '../../lib/messages'

export const DateOfAccident: FC<React.PropsWithChildren<FieldBaseProps>> = ({
export const DateOfAccident = ({
application,
field,
error,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
import { Box, Bullet, BulletList, Text } from '@island.is/island-ui/core'
import { Colors } from '@island.is/island-ui/theme'
import { useLocale } from '@island.is/localization'
import React, { FC } from 'react'
import { MessageDescriptor } from 'react-intl'
import * as styles from './FormOverview.css'
import cn from 'classnames'

interface ValueLineProps {
type ValueLineProps = {
label: string | MessageDescriptor
value: string | MessageDescriptor
color?: Colors
}

export const ValueLine: FC<React.PropsWithChildren<ValueLineProps>> = ({
label,
value,
color,
}) => {
export const ValueLine = ({ label, value, color }: ValueLineProps) => {
const { formatMessage } = useLocale()

return (
Expand All @@ -32,10 +27,7 @@ interface FileValueLineProps {
files: MessageDescriptor[] | undefined
}

export const FileValueLine: FC<React.PropsWithChildren<FileValueLineProps>> = ({
label,
files,
}) => {
export const FileValueLine = ({ label, files }: FileValueLineProps) => {
const { formatMessage } = useLocale()

return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { formatText } from '@island.is/application/core'
import { FieldBaseProps, FormValue } from '@island.is/application/types'
import { FieldBaseProps, FormValue, YES } from '@island.is/application/types'
import {
formatPhoneNumber,
ReviewGroup,
Expand All @@ -17,8 +17,7 @@ import format from 'date-fns/format'
import is from 'date-fns/locale/is'
import parseISO from 'date-fns/parseISO'
import kennitala from 'kennitala'
import React, { FC } from 'react'
import { States, YES } from '../../utils/constants'
import { States } from '../../utils/constants'
import { AccidentNotification } from '../../lib/dataSchema'
import {
accidentDetails,
Expand All @@ -38,42 +37,50 @@ import {
sportsClubInfo,
workMachine,
} from '../../lib/messages'
import * as styles from './FormOverview.css'
import { FileValueLine, ValueLine } from './ValueLine'
import {
getAttachmentTitles,
returnMissingDocumentsList,
} from '../../utils/documentUtils'
import {
getWorkplaceData,
hideLocationAndPurpose,
isAgricultureAccident,
isFishermanAccident,
isGeneralWorkplaceAccident,
isHomeActivitiesAccident,
isMachineRelatedAccident,
isProfessionalAthleteAccident,
} from '../../utils/occupationUtils'
import {
isReportingOnBehalfOfChild,
isReportingOnBehalfOfEmployee,
isReportingOnBehalfOfInjured,
} from '../../utils/reportingUtils'
import { hideLocationAndPurpose } from '../../utils/miscUtils'
import {
isHomeActivitiesAccident,
isWorkAccident,
returnMissingDocumentsList,
} from '../../utils'
import * as styles from './FormOverview.css'
import { FileValueLine, ValueLine } from './ValueLine'
} from '../../utils/accidentUtils'

interface SubmittedApplicationData {
data?: {
documentId: string
}
}

interface FormOverviewProps {
type Props = {
field: {
props: {
isAssignee: boolean
}
}
}

export const FormOverview: FC<
React.PropsWithChildren<FieldBaseProps & FormOverviewProps>
> = ({ application, goToScreen, field }) => {
export const FormOverview = ({
application,
goToScreen,
field,
}: FieldBaseProps & Props) => {
const isAssignee = field?.props?.isAssignee || false
const answers = application.answers as AccidentNotification
const { formatMessage } = useLocale()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ import { Application, DefaultEvents } from '@island.is/application/types'
import { SUBMIT_APPLICATION } from '@island.is/application/graphql'
import { Box, Button, Icon, ModalBase, Text } from '@island.is/island-ui/core'
import { useLocale } from '@island.is/localization'
import React, { FC } from 'react'
import { inReview } from '../../lib/messages'
import * as styles from './ConfirmationModal.css'

type ConfirmationModalProps = {
type Props = {
visibility: boolean
setVisibility: (visibility: boolean) => void
title: string
Expand All @@ -20,9 +19,7 @@ type ConfirmationModalProps = {
refetch?: () => void
}

export const ConfirmationModal: FC<
React.PropsWithChildren<ConfirmationModalProps>
> = ({
export const ConfirmationModal = ({
visibility,
setVisibility,
title,
Expand All @@ -33,7 +30,7 @@ export const ConfirmationModal: FC<
application,
comment = '',
refetch,
}) => {
}: Props) => {
const { formatMessage } = useLocale()
const [submitApplication, { loading: loadingSubmit }] = useMutation(
SUBMIT_APPLICATION,
Expand Down Expand Up @@ -68,6 +65,7 @@ export const ConfirmationModal: FC<
const closeModal = () => {
setVisibility(false)
}

return (
<ModalBase
baseId="confirmationModal"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
import { useState } from 'react'
import { getValueViaPath } from '@island.is/application/core'
import { DefaultEvents, FieldBaseProps } from '@island.is/application/types'
import { Box, Button, Divider, Text } from '@island.is/island-ui/core'
import { useLocale } from '@island.is/localization'
import { InputController } from '@island.is/shared/form-fields'
import React, { FC, useState } from 'react'
import { inReview, overview, thirdPartyComment } from '../../lib/messages'
import { ReviewApprovalEnum } from '../../types'
import { FormOverview } from '../FormOverview'
import { ConfirmationModal } from './ConfirmationModal'

interface FormOverviewInReviewProps {
type Props = {
field: {
props: {
isAssignee: boolean
}
}
}

export const FormOverviewInReview: FC<
React.PropsWithChildren<FormOverviewInReviewProps & FieldBaseProps>
> = ({ application, field, refetch, goToScreen }) => {
export const FormOverviewInReview = ({
application,
field,
refetch,
goToScreen,
}: Props & FieldBaseProps) => {
const isAssignee = field?.props?.isAssignee || false
const { formatMessage } = useLocale()
const reviewApproval = getValueViaPath(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { FieldBaseProps } from '@island.is/application/types'
import React, { FC } from 'react'
import { useFormContext } from 'react-hook-form'
import { AccidentNotification } from '../../lib/dataSchema'
import { isInjuredAndRepresentativeOfCompanyOrInstitute } from '../../utils'
import { isInjuredAndRepresentativeOfCompanyOrInstitute } from '../../utils/miscUtils'

interface HiddenInformationProps {
type Props = {
field: {
props: {
id: string
}
}
}

export const HiddenInformation: FC<
React.PropsWithChildren<FieldBaseProps & HiddenInformationProps>
> = ({ application, field }) => {
export const HiddenInformation = ({
application,
field,
}: Props & FieldBaseProps) => {
const { register, setValue } = useFormContext()
const { id } = field.props

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import { FieldBaseProps } from '@island.is/application/types'
import { Box, Button, Inline, Text } from '@island.is/island-ui/core'
import { useLocale } from '@island.is/localization'
import React, { FC } from 'react'
import { powerOfAttorney } from '../../lib/messages'

export const ProxyDocument: FC<
React.PropsWithChildren<FieldBaseProps>
> = () => {
export const ProxyDocument = () => {
const { formatMessage } = useLocale()
return (
<Box marginBottom={2}>
Expand Down
Loading

0 comments on commit 62ed00f

Please sign in to comment.