diff --git a/libs/application/core/src/lib/fieldBuilders.ts b/libs/application/core/src/lib/fieldBuilders.ts index 1e6974824358..80e1184098c9 100644 --- a/libs/application/core/src/lib/fieldBuilders.ts +++ b/libs/application/core/src/lib/fieldBuilders.ts @@ -117,6 +117,8 @@ export const buildDateField = ( const { maxDate, minDate, + minYear, + maxYear, excludeDates, placeholder, backgroundColor = 'blue', @@ -129,6 +131,8 @@ export const buildDateField = ( placeholder, maxDate, minDate, + minYear, + maxYear, excludeDates, type: FieldTypes.DATE, component: FieldComponents.DATE, diff --git a/libs/application/template-api-modules/src/lib/modules/templates/aosh/work-accident-notification/work-accident-notification.service.ts b/libs/application/template-api-modules/src/lib/modules/templates/aosh/work-accident-notification/work-accident-notification.service.ts index 54839ce19a07..b078f12def46 100644 --- a/libs/application/template-api-modules/src/lib/modules/templates/aosh/work-accident-notification/work-accident-notification.service.ts +++ b/libs/application/template-api-modules/src/lib/modules/templates/aosh/work-accident-notification/work-accident-notification.service.ts @@ -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() @@ -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) => { diff --git a/libs/application/templates/aosh/work-accident-notification/project.json b/libs/application/templates/aosh/work-accident-notification/project.json index ab889cfaf462..a2309411789d 100644 --- a/libs/application/templates/aosh/work-accident-notification/project.json +++ b/libs/application/templates/aosh/work-accident-notification/project.json @@ -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}'" + } } } } diff --git a/libs/application/templates/aosh/work-accident-notification/src/fields/AccidentLocation/index.tsx b/libs/application/templates/aosh/work-accident-notification/src/fields/AccidentLocation/index.tsx index df31e4cfa436..69426791673e 100644 --- a/libs/application/templates/aosh/work-accident-notification/src/fields/AccidentLocation/index.tsx +++ b/libs/application/templates/aosh/work-accident-notification/src/fields/AccidentLocation/index.tsx @@ -42,7 +42,15 @@ export const AccidentLocation: FC> = ( ) const [minorGroupOptions, setMinorGroupOptions] = useState< WorkingEnvironmentDto[] - >([]) + >( + selectedMajorGroup + ? minorGroups.filter( + (group) => + group.code?.substring(0, 2) === + selectedMajorGroup?.value?.substring(0, 2), + ) + : [], + ) return ( @@ -56,7 +64,7 @@ export const AccidentLocation: FC> = ( label={formatMessage( accident.about.locationOfAccidentMajorGroup, )} - name="subMajorGroupSelect" + name="accident.accidentLocationParentGroup" options={majorGroups.map((option) => ({ label: option.name || '', value: option.code, @@ -80,7 +88,7 @@ export const AccidentLocation: FC> = ( /> ) }} - name={'subMajorGroup'} + name={'accident.accidentLocationParentGroup'} /> @@ -92,11 +100,12 @@ export const AccidentLocation: FC> = ( 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) => { @@ -113,7 +122,7 @@ export const AccidentLocation: FC> = ( /> ) }} - name={'subMajorGroup'} + name={'accident.accidentLocation'} /> diff --git a/libs/application/templates/aosh/work-accident-notification/src/fields/EmployeeStartTimeError/index.tsx b/libs/application/templates/aosh/work-accident-notification/src/fields/EmployeeStartTimeError/index.tsx index 03bcd17321be..2d9bfe513c0e 100644 --- a/libs/application/templates/aosh/work-accident-notification/src/fields/EmployeeStartTimeError/index.tsx +++ b/libs/application/templates/aosh/work-accident-notification/src/fields/EmployeeStartTimeError/index.tsx @@ -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: { @@ -23,6 +24,10 @@ export const EmployeeStartTimeError: FC< const { getValues } = useFormContext() const { formatMessage } = useLocale() const [inputError, setInputError] = useState(false) + const startDate = + getValueViaPath(application.answers, 'accident.date') ?? '' + const startTime = + getValueViaPath(application.answers, 'accident.time') ?? '' setBeforeSubmitCallback?.(async () => { const values = getValues('employee') @@ -48,7 +53,9 @@ export const EmployeeStartTimeError: FC< {inputError && ( - {formatMessage(employee.employee.errorMessage)} + {`${formatMessage(employee.employee.errorMessage)}, ${formatDate( + startDate, + )} ${startTime.slice(0, 2)}:${startTime.slice(2, 4)}`} )} diff --git a/libs/application/templates/aosh/work-accident-notification/src/forms/WorkAccidentNotificationForm/AccidentSection/about.ts b/libs/application/templates/aosh/work-accident-notification/src/forms/WorkAccidentNotificationForm/AccidentSection/about.ts index 96e389a19054..7c583e68c242 100644 --- a/libs/application/templates/aosh/work-accident-notification/src/forms/WorkAccidentNotificationForm/AccidentSection/about.ts +++ b/libs/application/templates/aosh/work-accident-notification/src/forms/WorkAccidentNotificationForm/AccidentSection/about.ts @@ -3,7 +3,6 @@ import { buildCustomField, buildDateField, buildDescriptionField, - buildHiddenInput, buildMultiField, buildSelectField, buildSubSection, @@ -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', @@ -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', }), diff --git a/libs/application/templates/aosh/work-accident-notification/src/forms/WorkAccidentNotificationForm/EmployeeSection/employee.ts b/libs/application/templates/aosh/work-accident-notification/src/forms/WorkAccidentNotificationForm/EmployeeSection/employee.ts index bb0fa88d47a3..afb361691175 100644 --- a/libs/application/templates/aosh/work-accident-notification/src/forms/WorkAccidentNotificationForm/EmployeeSection/employee.ts +++ b/libs/application/templates/aosh/work-accident-notification/src/forms/WorkAccidentNotificationForm/EmployeeSection/employee.ts @@ -3,7 +3,6 @@ import { buildCustomField, buildDateField, buildDescriptionField, - buildHiddenInput, buildMultiField, buildNationalIdWithNameField, buildSelectField, @@ -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`, @@ -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`, diff --git a/libs/application/templates/aosh/work-accident-notification/src/forms/WorkAccidentNotificationForm/InformationSection/companySection.ts b/libs/application/templates/aosh/work-accident-notification/src/forms/WorkAccidentNotificationForm/InformationSection/companySection.ts index 2575705bba0f..99818937fb19 100644 --- a/libs/application/templates/aosh/work-accident-notification/src/forms/WorkAccidentNotificationForm/InformationSection/companySection.ts +++ b/libs/application/templates/aosh/work-accident-notification/src/forms/WorkAccidentNotificationForm/InformationSection/companySection.ts @@ -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', @@ -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( application.externalData, @@ -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( application.externalData, @@ -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( application.externalData, @@ -105,7 +108,7 @@ export const companySection = buildSubSection({ }, }), buildSelectField({ - id: 'companyInformation.numberOfEmployees', + id: 'basicInformation.numberOfEmployees', title: information.labels.company.numberOfEmployees, width: 'half', required: true, diff --git a/libs/application/templates/aosh/work-accident-notification/src/forms/WorkAccidentNotificationForm/prerequisitesSection.ts b/libs/application/templates/aosh/work-accident-notification/src/forms/WorkAccidentNotificationForm/prerequisitesSection.ts index 11a5028f4ece..f7ef164ff598 100644 --- a/libs/application/templates/aosh/work-accident-notification/src/forms/WorkAccidentNotificationForm/prerequisitesSection.ts +++ b/libs/application/templates/aosh/work-accident-notification/src/forms/WorkAccidentNotificationForm/prerequisitesSection.ts @@ -4,7 +4,6 @@ import { buildDataProviderItem, buildSubmitField, coreMessages, - buildHiddenInput, } from '@island.is/application/core' import { externalData } from '../../lib/messages' import { diff --git a/libs/application/templates/aosh/work-accident-notification/src/lib/dataSchema.ts b/libs/application/templates/aosh/work-accident-notification/src/lib/dataSchema.ts index f2c032533d83..34fd239f7894 100644 --- a/libs/application/templates/aosh/work-accident-notification/src/lib/dataSchema.ts +++ b/libs/application/templates/aosh/work-accident-notification/src/lib/dataSchema.ts @@ -27,7 +27,7 @@ const accidentSchema = z.object({ wentWrong: z.string().min(1).max(499), }) -const companySchema = z.object({ +const basicCompanySchema = z.object({ nationalId: z .string() .refine( @@ -35,10 +35,13 @@ const companySchema = z.object({ 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(), @@ -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, @@ -208,6 +212,7 @@ export const WorkAccidentNotificationAnswersSchema = z.object({ export type WorkAccidentNotification = z.TypeOf< typeof WorkAccidentNotificationAnswersSchema > +export type BasicCompanyType = z.TypeOf export type CompanyType = z.TypeOf export type CompanyLaborProtectionType = z.TypeOf< typeof companyLaborProtectionSchema diff --git a/libs/application/templates/aosh/work-accident-notification/src/lib/messages/accident.ts b/libs/application/templates/aosh/work-accident-notification/src/lib/messages/accident.ts index 2b54f6e6b49b..185bde25b75e 100644 --- a/libs/application/templates/aosh/work-accident-notification/src/lib/messages/accident.ts +++ b/libs/application/templates/aosh/work-accident-notification/src/lib/messages/accident.ts @@ -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: { @@ -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: { @@ -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: { diff --git a/libs/application/templates/aosh/work-accident-notification/src/utils/getCompanyInformationForOverview.ts b/libs/application/templates/aosh/work-accident-notification/src/utils/getCompanyInformationForOverview.ts index 81a8637ffe61..bdc845fa82e8 100644 --- a/libs/application/templates/aosh/work-accident-notification/src/utils/getCompanyInformationForOverview.ts +++ b/libs/application/templates/aosh/work-accident-notification/src/utils/getCompanyInformationForOverview.ts @@ -6,7 +6,11 @@ import { } from '@island.is/application/types' import { information, overview } from '../lib/messages' import { format as formatKennitala } from 'kennitala' -import { CompanyLaborProtectionType, CompanyType } from '../lib/dataSchema' +import { + BasicCompanyType, + CompanyLaborProtectionType, + CompanyType, +} from '../lib/dataSchema' import { SizeOfTheEnterpriseDto, WorkplaceHealthAndSafetyDto, @@ -18,6 +22,10 @@ export const getCompanyInformationForOverview = ( externalData: ExternalData, formatMessage: FormatMessage, ) => { + const basicCompany = getValueViaPath( + answers, + 'basicInformation', + ) const company = getValueViaPath(answers, 'companyInformation') const companyLaborProtection = getValueViaPath( answers, @@ -34,13 +42,15 @@ export const getCompanyInformationForOverview = ( 'aoshData.data.workplaceHealthAndSafety', ) ?? [] const chosenSizeOfEnterprise = sizeOfEnterprises.find( - (size) => company?.numberOfEmployees === size?.code, + (size) => basicCompany?.numberOfEmployees === size?.code, ) return [ - company?.name ?? undefined, - company?.nationalId ? formatKennitala(company.nationalId) : undefined, - `${company?.address ?? ''}, ${company?.postnumber ?? ''}`, + basicCompany?.name ?? undefined, + basicCompany?.nationalId + ? formatKennitala(basicCompany.nationalId) + : undefined, + `${basicCompany?.address ?? ''}, ${basicCompany?.postnumber ?? ''}`, company?.industryClassification ?? undefined, chosenSizeOfEnterprise?.name ?? undefined, `${formatMessage(information.labels.workhealth.sectionTitle)}: ${ diff --git a/libs/application/templates/aosh/work-accident-notification/src/utils/index.ts b/libs/application/templates/aosh/work-accident-notification/src/utils/index.ts index e3e0d34b45e6..8dd880060ee4 100644 --- a/libs/application/templates/aosh/work-accident-notification/src/utils/index.ts +++ b/libs/application/templates/aosh/work-accident-notification/src/utils/index.ts @@ -9,3 +9,4 @@ export { isValidPhoneNumber, } from './dateManipulation' export { isCompany } from './isCompany' +export { formatDate } from './formatDate' diff --git a/libs/application/types/src/lib/Fields.ts b/libs/application/types/src/lib/Fields.ts index 3cbc342d2273..7fb277233888 100644 --- a/libs/application/types/src/lib/Fields.ts +++ b/libs/application/types/src/lib/Fields.ts @@ -313,6 +313,8 @@ export interface DateField extends InputField { component: FieldComponents.DATE maxDate?: MaybeWithApplicationAndField minDate?: MaybeWithApplicationAndField + minYear?: number + maxYear?: number excludeDates?: MaybeWithApplicationAndField backgroundColor?: DatePickerBackgroundColor onChange?(date: string): void diff --git a/libs/application/ui-fields/src/lib/DateFormField/DateFormField.tsx b/libs/application/ui-fields/src/lib/DateFormField/DateFormField.tsx index faeb76a86d30..3b90993c051d 100644 --- a/libs/application/ui-fields/src/lib/DateFormField/DateFormField.tsx +++ b/libs/application/ui-fields/src/lib/DateFormField/DateFormField.tsx @@ -41,6 +41,8 @@ export const DateFormField: FC> = ({ excludeDates, minDate, maxDate, + minYear, + maxYear, onChange, readOnly, } = field @@ -139,6 +141,8 @@ export const DateFormField: FC> = ({ excludeDates={finalExcludeDates} minDate={finalMinDate} maxDate={finalMaxDate} + minYear={minYear} + maxYear={maxYear} backgroundColor={backgroundColor} readOnly={readOnly} label={formatTextWithLocale(title, application, lang, formatMessage)}