Skip to content

Commit

Permalink
fix(work-accident-notification): work accident bug fixes (#16922)
Browse files Browse the repository at this point in the history
* moving part of companyinfo to basicinfo to stop autofill

* some fixes

* extract strings

* fix inputs being empty on back button click

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
2 people authored and jonnigs committed Nov 26, 2024
1 parent 54290b2 commit bbb1396
Show file tree
Hide file tree
Showing 15 changed files with 84 additions and 49 deletions.
4 changes: 4 additions & 0 deletions libs/application/core/src/lib/fieldBuilders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ export const buildDateField = (
const {
maxDate,
minDate,
minYear,
maxYear,
excludeDates,
placeholder,
backgroundColor = 'blue',
Expand All @@ -129,6 +131,8 @@ export const buildDateField = (
placeholder,
maxDate,
minDate,
minYear,
maxYear,
excludeDates,
type: FieldTypes.DATE,
component: FieldComponents.DATE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ import {
} from '@island.is/clients/work-accident-ver'
import {
getDateAndTime,
getValueList,
mapVictimData,
} from './work-accident-notification.utils'
import { getValueViaPath } from '@island.is/application/core'
import { TemplateApiError } from '@island.is/nest/problem'

@Injectable()
Expand Down Expand Up @@ -57,20 +55,20 @@ export class WorkAccidentNotificationTemplateService extends BaseTemplateApiServ
const answers = application.answers as unknown as WorkAccidentNotification
const payload = {
accidentForCreationDto: {
companySSN: answers.companyInformation.nationalId,
companySSN: answers.basicInformation.nationalId,
sizeOfEnterprise: parseInt(
answers.companyInformation.numberOfEmployees,
answers.basicInformation.numberOfEmployees,
10,
),
nameOfBranchOrDepartment:
answers.companyInformation.nameOfBranch ??
answers.companyInformation.name,
answers.basicInformation.name,
address:
answers.companyInformation.addressOfBranch ??
answers.companyInformation.address,
answers.basicInformation.address,
postcode:
answers.companyInformation.postnumberOfBranch?.slice(0, 3) ??
answers.companyInformation.postnumber.slice(0, 3),
answers.basicInformation.postnumber.slice(0, 3),
workplaceHealthAndSafety:
answers.companyLaborProtection.workhealthAndSafetyOccupation?.map(
(code: string) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
"targets": {
"lint": {
"executor": "@nx/eslint:lint"
},
"extract-strings": {
"executor": "nx:run-commands",
"options": {
"command": "yarn ts-node -P libs/localization/tsconfig.lib.json libs/localization/scripts/extract 'libs/application/templates/aosh/work-accident-notification/src/**/*.{js,ts,tsx}'"
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,15 @@ export const AccidentLocation: FC<React.PropsWithChildren<FieldBaseProps>> = (
)
const [minorGroupOptions, setMinorGroupOptions] = useState<
WorkingEnvironmentDto[]
>([])
>(
selectedMajorGroup
? minorGroups.filter(
(group) =>
group.code?.substring(0, 2) ===
selectedMajorGroup?.value?.substring(0, 2),
)
: [],
)

return (
<Box paddingTop={2}>
Expand All @@ -56,7 +64,7 @@ export const AccidentLocation: FC<React.PropsWithChildren<FieldBaseProps>> = (
label={formatMessage(
accident.about.locationOfAccidentMajorGroup,
)}
name="subMajorGroupSelect"
name="accident.accidentLocationParentGroup"
options={majorGroups.map((option) => ({
label: option.name || '',
value: option.code,
Expand All @@ -80,7 +88,7 @@ export const AccidentLocation: FC<React.PropsWithChildren<FieldBaseProps>> = (
/>
)
}}
name={'subMajorGroup'}
name={'accident.accidentLocationParentGroup'}
/>
</GridColumn>
<GridColumn span={['1/1', '1/2']} paddingBottom={2}>
Expand All @@ -92,11 +100,12 @@ export const AccidentLocation: FC<React.PropsWithChildren<FieldBaseProps>> = (
label={formatMessage(
accident.about.locationOfAccidentMinorGroup,
)}
name="subMajorGroupSelect"
name="accident.accidentLocation"
options={minorGroupOptions.map((group) => ({
label: group.name || '',
value: group.code,
}))}
isDisabled={!selectedMajorGroup}
value={selectedMinorGroup}
backgroundColor="blue"
onChange={(v) => {
Expand All @@ -113,7 +122,7 @@ export const AccidentLocation: FC<React.PropsWithChildren<FieldBaseProps>> = (
/>
)
}}
name={'subMajorGroup'}
name={'accident.accidentLocation'}
/>
</GridColumn>
</GridRow>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { useFormContext } from 'react-hook-form'
import { employee } from '../../lib/messages'
import { useLocale } from '@island.is/localization'
import { WorkAccidentNotification } from '../../lib/dataSchema'
import { dateIsWithin36Hours } from '../../utils'
import { dateIsWithin36Hours, formatDate } from '../../utils'
import { getValueViaPath } from '@island.is/application/core'

interface EmployeeStartTimeErrorProps {
field: {
Expand All @@ -23,6 +24,10 @@ export const EmployeeStartTimeError: FC<
const { getValues } = useFormContext<WorkAccidentNotification>()
const { formatMessage } = useLocale()
const [inputError, setInputError] = useState<boolean>(false)
const startDate =
getValueViaPath<string>(application.answers, 'accident.date') ?? ''
const startTime =
getValueViaPath<string>(application.answers, 'accident.time') ?? ''

setBeforeSubmitCallback?.(async () => {
const values = getValues('employee')
Expand All @@ -48,7 +53,9 @@ export const EmployeeStartTimeError: FC<
{inputError && (
<Box>
<ErrorMessage id={field.id}>
{formatMessage(employee.employee.errorMessage)}
{`${formatMessage(employee.employee.errorMessage)}, ${formatDate(
startDate,
)} ${startTime.slice(0, 2)}:${startTime.slice(2, 4)}`}
</ErrorMessage>
</Box>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
buildCustomField,
buildDateField,
buildDescriptionField,
buildHiddenInput,
buildMultiField,
buildSelectField,
buildSubSection,
Expand Down Expand Up @@ -34,6 +33,7 @@ export const aboutSection = buildSubSection({
width: 'half',
required: true,
minDate: new Date('1.1.2020'),
maxDate: new Date(),
}),
buildTextField({
id: 'accident.time',
Expand Down Expand Up @@ -155,11 +155,8 @@ export const aboutSection = buildSubSection({
title: accident.about.locationOfAccidentHeading,
marginTop: 3,
}),
buildHiddenInput({
id: 'accident.accidentLocationParentGroup',
}),
buildCustomField({
id: 'accident.accidentLocation',
id: 'accident',
title: '',
component: 'AccidentLocation',
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
buildCustomField,
buildDateField,
buildDescriptionField,
buildHiddenInput,
buildMultiField,
buildNationalIdWithNameField,
buildSelectField,
Expand Down Expand Up @@ -118,6 +117,9 @@ export const employeeSubSection = (index: number) =>
width: 'half',
required: true,
title: employee.employee.startDate,
maxDate: new Date(),
minYear: 1940,
maxYear: new Date().getFullYear(),
}),
buildSelectField({
id: `employee[${index}].employmentTime`,
Expand Down Expand Up @@ -235,18 +237,6 @@ export const employeeSubSection = (index: number) =>
titleVariant: 'h5',
marginTop: 3,
}),
buildHiddenInput({
id: `employee[${index}].victimsOccupationMajor`,
}),
buildHiddenInput({
id: `employee[${index}].victimsOccupationSubMajor`,
}),
buildHiddenInput({
id: `employee[${index}].victimsOccupationMinor`,
}),
buildHiddenInput({
id: `employee[${index}].victimsOccupationUnit`,
}),
buildCustomField(
{
id: `employee[${index}].victimsOccupation`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ export const companySection = buildSubSection({
},
}),
buildDescriptionField({
id: 'companyInformation.description',
id: 'basicInformation.description',
title: information.labels.company.descriptionField,
titleVariant: 'h5',
}),
buildTextField({
id: 'companyInformation.nationalId',
id: 'basicInformation.nationalId',
title: information.labels.company.nationalId,
backgroundColor: 'white',
width: 'half',
Expand All @@ -59,10 +59,11 @@ export const companySection = buildSubSection({
},
}),
buildTextField({
id: 'companyInformation.name',
id: 'basicInformation.name',
title: information.labels.company.name,
backgroundColor: 'white',
width: 'half',
readOnly: true,
defaultValue: (application: Application) => {
const name = getValueViaPath<string>(
application.externalData,
Expand All @@ -73,10 +74,11 @@ export const companySection = buildSubSection({
},
}),
buildTextField({
id: 'companyInformation.address',
id: 'basicInformation.address',
title: information.labels.company.address,
backgroundColor: 'white',
width: 'half',
readOnly: true,
defaultValue: (application: Application) => {
const streetAddress = getValueViaPath<string>(
application.externalData,
Expand All @@ -87,10 +89,11 @@ export const companySection = buildSubSection({
},
}),
buildTextField({
id: 'companyInformation.postnumber',
id: 'basicInformation.postnumber',
title: information.labels.company.postNumberAndTown,
backgroundColor: 'white',
width: 'half',
readOnly: true,
defaultValue: (application: Application) => {
const postalCode = getValueViaPath<string>(
application.externalData,
Expand All @@ -105,7 +108,7 @@ export const companySection = buildSubSection({
},
}),
buildSelectField({
id: 'companyInformation.numberOfEmployees',
id: 'basicInformation.numberOfEmployees',
title: information.labels.company.numberOfEmployees,
width: 'half',
required: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
buildDataProviderItem,
buildSubmitField,
coreMessages,
buildHiddenInput,
} from '@island.is/application/core'
import { externalData } from '../../lib/messages'
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,21 @@ const accidentSchema = z.object({
wentWrong: z.string().min(1).max(499),
})

const companySchema = z.object({
const basicCompanySchema = z.object({
nationalId: z
.string()
.refine(
(nationalId) =>
nationalId && nationalId.length !== 0 && kennitala.isValid(nationalId),
),
address: z.string(),
addressOfBranch: z.string().optional(),
name: z.string(),
numberOfEmployees: z.string(),
postnumber: z.string(),
})

const companySchema = z.object({
addressOfBranch: z.string().optional(),
nameOfBranch: z.string().optional(), // VER needs to confirm requirement here for individuals vs company
postnumberOfBranch: z.string().optional(),
industryClassification: z.string().optional(),
Expand Down Expand Up @@ -191,6 +194,7 @@ const projectPurchaseSchema = z

export const WorkAccidentNotificationAnswersSchema = z.object({
approveExternalData: z.boolean().refine((v) => v),
basicInformation: basicCompanySchema,
companyInformation: companySchema,
companyLaborProtection: companyLaborProtectionSchema,
accident: accidentSchema,
Expand All @@ -208,6 +212,7 @@ export const WorkAccidentNotificationAnswersSchema = z.object({
export type WorkAccidentNotification = z.TypeOf<
typeof WorkAccidentNotificationAnswersSchema
>
export type BasicCompanyType = z.TypeOf<typeof basicCompanySchema>
export type CompanyType = z.TypeOf<typeof companySchema>
export type CompanyLaborProtectionType = z.TypeOf<
typeof companyLaborProtectionSchema
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export const accident = {
wasDoingPlaceholder: {
id: 'aosh.wan.application:accident.about.wasDoingPlaceholder#markdown',
defaultMessage:
'Tilgreinið hvaða verkfæri eða vélar voru notaðar.\nDæmi:\n - Vann með handborvél\n - Vann með handborvél',
'Tilgreinið hvaða verkfæri eða vélar voru notaðar.\nDæmi:\n - Vann með handborvél\n - Var að styðja sjúkling á leið til baðherbergis',
description: 'Placeholder of wasDoing text area',
},
wentWrongTitle: {
Expand All @@ -95,7 +95,7 @@ export const accident = {
wenWrongPlaceholder: {
id: 'aosh.wan.application:accident.about.wenWrongPlaceholder#markdown',
defaultMessage:
'Tilgreinið hvaða verkfæri eða vélar voru notaðar.\nDæmi:\n - Vann með handborvél\n - Vann með handborvél',
'Tilgreinið hvaða verkfæri, vélar eða byrði áttu þátt í því.\nDæmi:\n - Borinn brotnaði í efninu\n - Sjúklingurinn gat skyndilega ekki staðið á fótunum',
description: 'Placeholder of wentWrong text area',
},
howTitle: {
Expand All @@ -106,7 +106,7 @@ export const accident = {
howPlaceholder: {
id: 'aosh.wan.application:accident.about.howPlaceholder#markdown',
defaultMessage:
'Tilgreinið hvaða verkfæri eða vélar voru notaðar.\nDæmi:\n - Vann með handborvél\n - Vann með handborvél',
'Tilgreinið hvaða verkfæri, vélar eða byrði var orsök slyssins.\nDæmi:\n - Borinn lenti í hendinni\n - Við að reyna að halda sjúklingnum uppi hrasaði slasaði og fékk hnykk á bakið',
description: 'Placeholder of how text area',
},
locationOfAccidentHeading: {
Expand Down
Loading

0 comments on commit bbb1396

Please sign in to comment.