From 5b7abb91bb74a115745f28f2a9c0a9da45edf8d5 Mon Sep 17 00:00:00 2001 From: veronikasif <54938148+veronikasif@users.noreply.github.com> Date: Thu, 16 May 2024 16:15:12 +0000 Subject: [PATCH] fix(parental-leave): Refactor Sync - VMST (#14436) * Small change after merge main * Changed MODIFY event to EDIT and added tiggerEvent to validateApplication in EDIT_OR_ADD_EMPLOYERS_AND_PERIODS * Removed shouldNotCall from getApplicationInformation query, use skip instead * [UUFV-415] Refactor Sync - VMST * Removed unused comments and made some changes * Fix SummaryTimeline label * Fixed merge conflict - 2 * Updated sync - use days from VMST and removed comments * Changes requested by coderabbitai * Updated setVMSTPeriods action so it only updates periods in specific states --------- Co-authored-by: karenbjorg <102811817+karenbjorg@users.noreply.github.com> --- .../src/lib/directorate-of-labour.resolver.ts | 5 - .../applicationInformationPeriod.model.ts | 3 + .../parental-leave/parental-leave.service.ts | 23 +++- .../templates/parental-leave/src/constants.ts | 8 +- .../review-groups/Periods.tsx | 8 +- .../src/fields/PeriodsRepeater/index.tsx | 4 +- .../fields/Review/review-groups/Periods.tsx | 8 +- .../src/fields/components/Timeline/Panel.tsx | 71 +++++++++--- .../fields/components/Timeline/Timeline.tsx | 1 + .../src/forms/EditsRequireAction.ts | 6 +- .../parental-leave/src/graphql/queries.ts | 4 +- .../src/lib/ParentalLeaveTemplate.ts | 101 ++++++++++++++---- .../validateLatestPeriodValidationSection.ts | 5 + .../parental-leave/src/lib/messages.ts | 20 ++++ .../src/lib/parentalLeaveTemplateUtils.ts | 49 ++++++++- .../src/lib/parentalLeaveUtils.spec.ts | 1 - .../src/lib/parentalLeaveUtils.ts | 60 ++++++----- .../templates/parental-leave/src/types.ts | 4 + libs/clients/vmst/src/clientConfig.yaml | 2 + 19 files changed, 293 insertions(+), 90 deletions(-) diff --git a/libs/api/domains/directorate-of-labour/src/lib/directorate-of-labour.resolver.ts b/libs/api/domains/directorate-of-labour/src/lib/directorate-of-labour.resolver.ts index b5cc378c1abfa..4f919ce9ed3e0 100644 --- a/libs/api/domains/directorate-of-labour/src/lib/directorate-of-labour.resolver.ts +++ b/libs/api/domains/directorate-of-labour/src/lib/directorate-of-labour.resolver.ts @@ -36,13 +36,8 @@ export class DirectorateOfLabourResolver { async getApplicationInformation( @Args('applicationId') applicationId: string, @Args('nationalId') nationalId: string, - @Args('shouldNotCall') shouldNotCall: boolean, @CurrentUser() user: User, ): Promise { - if (shouldNotCall) { - return null - } - if (nationalId == user.nationalId) { return this.directorateOfLabourService.getApplicationInfo(applicationId) } diff --git a/libs/api/domains/directorate-of-labour/src/models/applicationInformationPeriod.model.ts b/libs/api/domains/directorate-of-labour/src/models/applicationInformationPeriod.model.ts index cb0860904c3d2..089dae34c086d 100644 --- a/libs/api/domains/directorate-of-labour/src/models/applicationInformationPeriod.model.ts +++ b/libs/api/domains/directorate-of-labour/src/models/applicationInformationPeriod.model.ts @@ -22,4 +22,7 @@ export class ApplicationInformationPeriod { @Field(() => String) firstPeriodStart!: string + + @Field(() => String) + days!: string } diff --git a/libs/application/template-api-modules/src/lib/modules/templates/parental-leave/parental-leave.service.ts b/libs/application/template-api-modules/src/lib/modules/templates/parental-leave/parental-leave.service.ts index 726d2e6880e48..7b42943ddea52 100644 --- a/libs/application/template-api-modules/src/lib/modules/templates/parental-leave/parental-leave.service.ts +++ b/libs/application/template-api-modules/src/lib/modules/templates/parental-leave/parental-leave.service.ts @@ -787,9 +787,7 @@ export class ParentalLeaveService extends BaseTemplateApiService { } } catch (e) { this.logger.warn( - `Could not fetch applicationInformation on applicationId: {applicationId} with error: {error}` - .replace(`{${'applicationId'}}`, application.id) - .replace(`{${'error'}}`, e), + `Could not fetch applicationInformation on applicationId: ${application.id} with error: ${e}`, ) } } @@ -1533,4 +1531,23 @@ export class ParentalLeaveService extends BaseTemplateApiService { throw this.parseErrors(e as VMSTError) } } + + async setVMSTPeriods({ application }: TemplateApiModuleActionProps) { + try { + const applicationInformation = + await this.applicationInformationAPI.applicationGetApplicationInformation( + { + applicationId: application.id, + }, + ) + + return applicationInformation.periods + } catch (e) { + this.logger.warn( + `Could not fetch applicationInformation on applicationId: ${application.id} with error: ${e}`, + ) + } + + return null + } } diff --git a/libs/application/templates/parental-leave/src/constants.ts b/libs/application/templates/parental-leave/src/constants.ts index b0870badcbd2a..e22f3e9204998 100644 --- a/libs/application/templates/parental-leave/src/constants.ts +++ b/libs/application/templates/parental-leave/src/constants.ts @@ -23,7 +23,6 @@ export const NO_MULTIPLE_BIRTHS = '1' export const MINIMUM_PERIOD_LENGTH = 14 export enum PLEvents { - MODIFY = 'MODIFY', CLOSED = 'CLOSED', ADDITIONALDOCUMENTSREQUIRED = 'ADDITIONALDOCUMENTSREQUIRED', } @@ -35,7 +34,6 @@ export type Events = | { type: DefaultEvents.SUBMIT } | { type: DefaultEvents.ABORT } | { type: DefaultEvents.EDIT } - | { type: 'MODIFY' } // Ex: The user might modify their 'edits'. | { type: 'CLOSED' } // Ex: Close application | { type: 'ADDITIONALDOCUMENTSREQUIRED' } // Ex: VMST ask for more documents @@ -68,6 +66,12 @@ export enum ApiModuleActions { setChildrenInformation = 'setChildrenInformation', setBirthDateForNoPrimaryParent = 'setBirthDateForNoPrimaryParent', setBirthDate = 'setBirthDate', + /** + * Fetches and returns VMST periods for the given application. + * Need to add this to `onExit` in every state that reaches `EDIT_OR_ADD_EMPLOYERS_AND_PERIODS`, + * except states that are still pending employer approval. + */ + setVMSTPeriods = 'setVMSTPeriods', } export enum StartDateOptions { diff --git a/libs/application/templates/parental-leave/src/fields/EditOrAddEmployersAndPeriodsReview/review-groups/Periods.tsx b/libs/application/templates/parental-leave/src/fields/EditOrAddEmployersAndPeriodsReview/review-groups/Periods.tsx index 13dfe7dd6ef8d..98854d7298f55 100644 --- a/libs/application/templates/parental-leave/src/fields/EditOrAddEmployersAndPeriodsReview/review-groups/Periods.tsx +++ b/libs/application/templates/parental-leave/src/fields/EditOrAddEmployersAndPeriodsReview/review-groups/Periods.tsx @@ -39,13 +39,7 @@ const Periods: FC> = ({ return ( ) diff --git a/libs/application/templates/parental-leave/src/fields/PeriodsRepeater/index.tsx b/libs/application/templates/parental-leave/src/fields/PeriodsRepeater/index.tsx index 9e2ef9385a4df..ed89739f2eb28 100644 --- a/libs/application/templates/parental-leave/src/fields/PeriodsRepeater/index.tsx +++ b/libs/application/templates/parental-leave/src/fields/PeriodsRepeater/index.tsx @@ -70,8 +70,8 @@ const PeriodsRepeater: FC> = ({ variables: { applicationId: application.id, nationalId: application.applicant, - shouldNotCall: !shouldCall, }, + skip: !shouldCall, }) useEffect(() => { @@ -85,7 +85,7 @@ const PeriodsRepeater: FC> = ({ setRepeaterItems, setFieldLoadingState, ) - }, [loading]) + }, [loading]) // eslint-disable-line react-hooks/exhaustive-deps useEffect(() => { if (!editable) { diff --git a/libs/application/templates/parental-leave/src/fields/Review/review-groups/Periods.tsx b/libs/application/templates/parental-leave/src/fields/Review/review-groups/Periods.tsx index 81163b24ee63f..9c7cd32e53744 100644 --- a/libs/application/templates/parental-leave/src/fields/Review/review-groups/Periods.tsx +++ b/libs/application/templates/parental-leave/src/fields/Review/review-groups/Periods.tsx @@ -43,13 +43,7 @@ export const Periods = ({ return ( ) diff --git a/libs/application/templates/parental-leave/src/fields/components/Timeline/Panel.tsx b/libs/application/templates/parental-leave/src/fields/components/Timeline/Panel.tsx index 5629ed5d54bc5..0ec3c6594023c 100644 --- a/libs/application/templates/parental-leave/src/fields/components/Timeline/Panel.tsx +++ b/libs/application/templates/parental-leave/src/fields/components/Timeline/Panel.tsx @@ -1,7 +1,7 @@ import React, { FC } from 'react' import parseISO from 'date-fns/parseISO' -import { Box, Icon, Text } from '@island.is/island-ui/core' +import { Box, Icon, Text, Tooltip } from '@island.is/island-ui/core' import { useLocale } from '@island.is/localization' import { parentalLeaveFormMessages } from '../../../lib/messages' @@ -31,6 +31,7 @@ export const Panel: FC< const formatStyle = isMobile ? 'dd MMM' : 'dd MMM yyyy' const titleLabel = isMobile ? titleSmall : title const firstPeriodUsingActualDateOfBirth = periods?.[0]?.actualDob + return ( @@ -50,17 +51,63 @@ export const Panel: FC< {periods.map((p, index) => ( - {p.canDelete && editable && onDeletePeriod && ( - onDeletePeriod(p.startDate)} - > - + {editable && onDeletePeriod && ( + + {p.canDelete ? ( + // Period can be deleted + + + + ) : p.paid ? ( + // Period can't be deleted, period paid + + + + ) : ( + // Period can't be deleted, period in progress + + + + )} )} diff --git a/libs/application/templates/parental-leave/src/fields/components/Timeline/Timeline.tsx b/libs/application/templates/parental-leave/src/fields/components/Timeline/Timeline.tsx index aa33c9a47bafd..b8bb859d75a15 100644 --- a/libs/application/templates/parental-leave/src/fields/components/Timeline/Timeline.tsx +++ b/libs/application/templates/parental-leave/src/fields/components/Timeline/Timeline.tsx @@ -18,6 +18,7 @@ export interface TimelinePeriod { color?: string canDelete?: boolean rawIndex: number + paid?: boolean } interface TimelineProps { diff --git a/libs/application/templates/parental-leave/src/forms/EditsRequireAction.ts b/libs/application/templates/parental-leave/src/forms/EditsRequireAction.ts index b5233dec5f2aa..b16d284af48fb 100644 --- a/libs/application/templates/parental-leave/src/forms/EditsRequireAction.ts +++ b/libs/application/templates/parental-leave/src/forms/EditsRequireAction.ts @@ -4,7 +4,7 @@ import { buildSection, buildSubmitField, } from '@island.is/application/core' -import { Form } from '@island.is/application/types' +import { DefaultEvents, Form } from '@island.is/application/types' import Logo from '../assets/Logo' import { States as ApplicationStates } from '../constants' import { @@ -38,13 +38,13 @@ export const EditsRequireAction: Form = buildForm({ refetchApplicationAfterSubmit: true, actions: [ { - event: 'ABORT', + event: DefaultEvents.ABORT, name: parentalLeaveFormMessages.editFlow .editsNotApprovedDiscardButton, type: 'reject', }, { - event: 'MODIFY', + event: DefaultEvents.EDIT, name: parentalLeaveFormMessages.reviewScreen.buttonsEdit, type: 'sign', }, diff --git a/libs/application/templates/parental-leave/src/graphql/queries.ts b/libs/application/templates/parental-leave/src/graphql/queries.ts index 74bae1fbfcd2d..5c017e595d59a 100644 --- a/libs/application/templates/parental-leave/src/graphql/queries.ts +++ b/libs/application/templates/parental-leave/src/graphql/queries.ts @@ -31,12 +31,10 @@ export const GetApplicationInformation = gql` query GetApplicationInformation( $applicationId: String! $nationalId: String! - $shouldNotCall: Boolean! ) { getApplicationInformation( applicationId: $applicationId nationalId: $nationalId - shouldNotCall: $shouldNotCall ) { periods { from @@ -45,6 +43,8 @@ export const GetApplicationInformation = gql` paid firstPeriodStart rightsCodePeriod + days + approved } } } diff --git a/libs/application/templates/parental-leave/src/lib/ParentalLeaveTemplate.ts b/libs/application/templates/parental-leave/src/lib/ParentalLeaveTemplate.ts index ce60ac20cd629..2e1adc523ab17 100644 --- a/libs/application/templates/parental-leave/src/lib/ParentalLeaveTemplate.ts +++ b/libs/application/templates/parental-leave/src/lib/ParentalLeaveTemplate.ts @@ -55,9 +55,9 @@ import { getMultipleBirthRequestDays, getOtherParentId, getSelectedChild, + getSpouse, isParentWithoutBirthParent, otherParentApprovalStatePendingAction, - getSpouse, } from '../lib/parentalLeaveUtils' import { answerValidators } from './answerValidators' import { dataSchema } from './dataSchema' @@ -68,6 +68,7 @@ import { hasDateOfBirth, hasEmployer, needsOtherParentApproval, + restructureVMSTPeriods, } from './parentalLeaveTemplateUtils' export const birthDayLifeCycle: StateLifeCycle = { @@ -559,11 +560,19 @@ const ParentalLeaveTemplate: ApplicationTemplate< throwOnError: true, }), ], - onExit: defineTemplateApi({ - action: ApiModuleActions.setBirthDate, - externalDataId: 'dateOfBirth', - throwOnError: false, - }), + onExit: [ + defineTemplateApi({ + action: ApiModuleActions.setBirthDate, + externalDataId: 'dateOfBirth', + throwOnError: false, + }), + defineTemplateApi({ + action: ApiModuleActions.setVMSTPeriods, + triggerEvent: DefaultEvents.EDIT, + externalDataId: 'VMSTPeriods', + throwOnError: false, + }), + ], roles: [ { id: Roles.APPLICANT, @@ -855,11 +864,19 @@ const ParentalLeaveTemplate: ApplicationTemplate< ], }, lifecycle: birthDayLifeCycle, - onExit: defineTemplateApi({ - action: ApiModuleActions.setBirthDate, - externalDataId: 'dateOfBirth', - throwOnError: false, - }), + onExit: [ + defineTemplateApi({ + action: ApiModuleActions.setBirthDate, + externalDataId: 'dateOfBirth', + throwOnError: false, + }), + defineTemplateApi({ + action: ApiModuleActions.setVMSTPeriods, + triggerEvent: DefaultEvents.EDIT, + externalDataId: 'VMSTPeriods', + throwOnError: false, + }), + ], roles: [ { id: Roles.APPLICANT, @@ -924,6 +941,7 @@ const ParentalLeaveTemplate: ApplicationTemplate< 'removeNullPeriod', 'setNavId', 'createTempEmployers', + 'setVMSTPeriods', ], exit: [ 'removeAddedEmployers', @@ -1164,7 +1182,7 @@ const ParentalLeaveTemplate: ApplicationTemplate< }, historyLogs: [ { - onEvent: PLEvents.MODIFY, + onEvent: DefaultEvents.EDIT, logMessage: statesMessages.editHistoryLogMessage, }, { @@ -1192,7 +1210,7 @@ const ParentalLeaveTemplate: ApplicationTemplate< ], }, on: { - MODIFY: { + [DefaultEvents.EDIT]: { target: States.EDIT_OR_ADD_EMPLOYERS_AND_PERIODS, }, [DefaultEvents.ABORT]: { target: States.APPROVED }, @@ -1266,11 +1284,19 @@ const ParentalLeaveTemplate: ApplicationTemplate< throwOnError: true, }), ], - onExit: defineTemplateApi({ - action: ApiModuleActions.setBirthDate, - externalDataId: 'dateOfBirth', - throwOnError: false, - }), + onExit: [ + defineTemplateApi({ + action: ApiModuleActions.setBirthDate, + externalDataId: 'dateOfBirth', + throwOnError: false, + }), + defineTemplateApi({ + action: ApiModuleActions.setVMSTPeriods, + triggerEvent: DefaultEvents.EDIT, + externalDataId: 'VMSTPeriods', + throwOnError: false, + }), + ], roles: [ { id: Roles.APPLICANT, @@ -1328,7 +1354,7 @@ const ParentalLeaveTemplate: ApplicationTemplate< }, historyLogs: [ { - onEvent: PLEvents.MODIFY, + onEvent: DefaultEvents.EDIT, logMessage: statesMessages.editHistoryLogMessage, }, { @@ -1339,6 +1365,12 @@ const ParentalLeaveTemplate: ApplicationTemplate< ], }, lifecycle: birthDayLifeCycle, + onExit: defineTemplateApi({ + action: ApiModuleActions.setVMSTPeriods, + triggerEvent: DefaultEvents.EDIT, + externalDataId: 'VMSTPeriods', + throwOnError: false, + }), roles: [ { id: Roles.APPLICANT, @@ -1360,7 +1392,7 @@ const ParentalLeaveTemplate: ApplicationTemplate< ], }, on: { - MODIFY: { + [DefaultEvents.EDIT]: { target: States.EDIT_OR_ADD_EMPLOYERS_AND_PERIODS, }, [DefaultEvents.ABORT]: { @@ -2045,6 +2077,35 @@ const ParentalLeaveTemplate: ApplicationTemplate< return context }), + /** + * Copy VMST periods to periods. + * Applicant could have made changes on paper, so VMST most likely has the newest changes to periods. + */ + setVMSTPeriods: assign((context, event) => { + if (event.type !== DefaultEvents.EDIT) { + return context + } + const { application } = context + + /** + * Do not update periods if in these states. + * We may be overwriting older edits that have not reached VMST (e.g. still pending employer approval) + */ + if ( + application.state === States.EMPLOYER_WAITING_TO_ASSIGN_FOR_EDITS || + application.state === States.EMPLOYER_APPROVE_EDITS || + application.state === States.EMPLOYER_EDITS_ACTION + ) { + return context + } + const newPeriods = restructureVMSTPeriods(context) + + if (newPeriods.length > 0) { + set(application.answers, 'periods', newPeriods) + } + + return context + }), /** * Clear changeEmployerFile if applicant decides not to change employer info. */ diff --git a/libs/application/templates/parental-leave/src/lib/answerValidationSections/validateLatestPeriodValidationSection.ts b/libs/application/templates/parental-leave/src/lib/answerValidationSections/validateLatestPeriodValidationSection.ts index 1b9a61e9a831e..f95def28253ab 100644 --- a/libs/application/templates/parental-leave/src/lib/answerValidationSections/validateLatestPeriodValidationSection.ts +++ b/libs/application/templates/parental-leave/src/lib/answerValidationSections/validateLatestPeriodValidationSection.ts @@ -157,6 +157,11 @@ export const validateLatestPeriodValidationSection = ( } } + // Stop checking periods synced from VMST + if ('approved' in latestPeriod) { + return undefined + } + const validatedField = validatePeriod( latestPeriod, isFirstPeriod, diff --git a/libs/application/templates/parental-leave/src/lib/messages.ts b/libs/application/templates/parental-leave/src/lib/messages.ts index 32018522b2d7e..4dae5e5d4c757 100644 --- a/libs/application/templates/parental-leave/src/lib/messages.ts +++ b/libs/application/templates/parental-leave/src/lib/messages.ts @@ -912,6 +912,21 @@ export const parentalLeaveFormMessages = { defaultMessage: 'Engar breytingar fundust.', description: 'No changes were found.', }, + deletePeriod: { + id: 'pl.application:delete.period', + defaultMessage: 'Eyða tímabili', + description: 'Delete period', + }, + periodPaid: { + id: 'pl.application:period.paid', + defaultMessage: 'Búið að greiða', + description: 'Paid', + }, + periodInProgress: { + id: 'pl.application:period.in.progress', + defaultMessage: 'Tímabil í gangi, ekki hægt að breyta', + description: 'Period in progress, unable to edit', + }, additionalInformationSection: { id: 'pl.application:additional.information.section', defaultMessage: 'Viðbótarupplýsingar', @@ -1913,6 +1928,11 @@ export const parentalLeaveFormMessages = { defaultMessage: 'Tímabilinu {index} - {ratio}%', description: 'Period copy', }, + vmstPeriod: { + id: 'pl.application:review.vmst.period', + defaultMessage: 'Greiðslutímabil {index} - {ratio}%', + description: 'Payment period {index} - {ratio}%', + }, periodActualDob: { id: 'pl.application:review.period.actual.dob', defaultMessage: 'Raunverulegum fæðingardegi - {duration} mánuðir', diff --git a/libs/application/templates/parental-leave/src/lib/parentalLeaveTemplateUtils.ts b/libs/application/templates/parental-leave/src/lib/parentalLeaveTemplateUtils.ts index cfe39965f44d1..6c59741ee09d1 100644 --- a/libs/application/templates/parental-leave/src/lib/parentalLeaveTemplateUtils.ts +++ b/libs/application/templates/parental-leave/src/lib/parentalLeaveTemplateUtils.ts @@ -15,7 +15,7 @@ import { requiresOtherParentApproval, residentGrantIsOpenForApplication, } from '../lib/parentalLeaveUtils' -import { EmployerRow } from '../types' +import { EmployerRow, Period, YesOrNo } from '../types' export const allEmployersHaveApproved = (context: ApplicationContext) => { const employers = getValueViaPath( @@ -93,3 +93,50 @@ export const goToState = ( if (previousState === state) return true return false } + +export const restructureVMSTPeriods = (context: ApplicationContext) => { + const { application } = context + const { VMSTPeriods } = getApplicationExternalData(application.externalData) + const { periods } = getApplicationAnswers(application.answers) + + const today = new Date() + const newPeriods: Period[] = [] + VMSTPeriods?.forEach((period, index) => { + /* + ** VMST could change startDate but still return 'date_of_birth' + ** Make sure if period is in the past then we use the date they sent + */ + let firstPeriodStart = + period.firstPeriodStart === 'date_of_birth' + ? 'actualDateOfBirth' + : 'specificDate' + if (new Date(period.from).getTime() <= today.getTime()) { + firstPeriodStart = 'specificDate' + } + + let useLength = NO + if (firstPeriodStart === 'actualDateOfBirth') { + useLength = periods[0].useLength ?? NO + } + + if (!period.rightsCodePeriod.includes('DVAL')) { + // API returns multiple rightsCodePeriod in string ('M-L-GR, M-FS') + const rightsCodePeriod = period.rightsCodePeriod.split(',')[0] + const obj = { + startDate: period.from, + endDate: period.to, + ratio: period.ratio.split(',')[0], + rawIndex: index, + firstPeriodStart: firstPeriodStart, + useLength: useLength as YesOrNo, + rightCodePeriod: rightsCodePeriod, + daysToUse: period.days, + paid: period.paid, + approved: period.approved, + } + newPeriods.push(obj) + } + }) + + return newPeriods +} diff --git a/libs/application/templates/parental-leave/src/lib/parentalLeaveUtils.spec.ts b/libs/application/templates/parental-leave/src/lib/parentalLeaveUtils.spec.ts index 85e7884dcb647..301dd9ed598e0 100644 --- a/libs/application/templates/parental-leave/src/lib/parentalLeaveUtils.spec.ts +++ b/libs/application/templates/parental-leave/src/lib/parentalLeaveUtils.spec.ts @@ -1179,7 +1179,6 @@ describe('getApplicationExternalData', () => { }, }, }) - expect(getApplicationExternalData(application.externalData)).toEqual({ applicantGenderCode: 'Mock gender code', applicantName: 'Mock name', diff --git a/libs/application/templates/parental-leave/src/lib/parentalLeaveUtils.ts b/libs/application/templates/parental-leave/src/lib/parentalLeaveUtils.ts index 0129a106537ae..f2bf027d1fa05 100644 --- a/libs/application/templates/parental-leave/src/lib/parentalLeaveUtils.ts +++ b/libs/application/templates/parental-leave/src/lib/parentalLeaveUtils.ts @@ -157,35 +157,34 @@ export const formatPeriods = ( } } + const timelinePeriod = { + startDate: period.startDate, + endDate: period.endDate, + ratio: period.ratio, + duration: calculatedLength, + canDelete: canDelete, + title: formatMessage( + 'approved' in period + ? parentalLeaveFormMessages.reviewScreen.vmstPeriod + : parentalLeaveFormMessages.reviewScreen.period, + { + index: index + 1, + ratio: period.ratio, + }, + ), + rawIndex: period.rawIndex ?? index, + paid: period.paid, + } + if (isActualDob) { timelinePeriods.push({ + ...timelinePeriod, actualDob: isActualDob, - startDate: period.startDate, - endDate: period.endDate, - ratio: period.ratio, - duration: calculatedLength, - canDelete: canDelete, - title: formatMessage(parentalLeaveFormMessages.reviewScreen.period, { - index: index + 1, - ratio: period.ratio, - }), - rawIndex: period.rawIndex ?? index, }) } if (!isActualDob && period.startDate && period.endDate) { - timelinePeriods.push({ - startDate: period.startDate, - endDate: period.endDate, - ratio: period.ratio, - duration: calculatedLength, - canDelete: canDelete, - title: formatMessage(parentalLeaveFormMessages.reviewScreen.period, { - index: index + 1, - ratio: period.ratio, - }), - rawIndex: period.rawIndex ?? index, - }) + timelinePeriods.push(timelinePeriod) } }) @@ -571,6 +570,11 @@ export const getApplicationExternalData = ( ) as string } + const VMSTPeriods = getValueViaPath( + externalData, + 'VMSTPeriods.data', + ) as VMSTPeriod[] + return { applicantName, applicantGenderCode, @@ -581,6 +585,7 @@ export const getApplicationExternalData = ( userEmail, userPhoneNumber, dateOfBirth, + VMSTPeriods, } } @@ -1534,7 +1539,7 @@ export const synchronizeVMSTPeriods = ( setRepeaterItems: RepeaterProps['setRepeaterItems'], setFieldLoadingState: RepeaterProps['setFieldLoadingState'], ) => { - // If periods is not sync with VMST periods, sync it + // If periods is not in sync with VMST periods, sync it const newPeriods: Period[] = [] const temptVMSTPeriods: Period[] = [] const VMSTPeriods: VMSTPeriod[] = data?.getApplicationInformation?.periods @@ -1563,12 +1568,15 @@ export const synchronizeVMSTPeriods = ( firstPeriodStart: firstPeriodStart, useLength: NO as YesOrNo, rightCodePeriod: rightsCodePeriod, + daysToUse: period.days, + paid: period.paid, + approved: period.approved, } if (period.paid) { newPeriods.push(obj) } else if (isThisMonth(new Date(period.from))) { - if (today.getDay() >= 20) { + if (today.getDate() >= 20) { newPeriods.push(obj) } } else if (new Date(period.from).getTime() <= today.getTime()) { @@ -1635,7 +1643,9 @@ export const synchronizeVMSTPeriods = ( new Date(period.endDate).getTime() !== new Date(periods[i].endDate).getTime() || period.ratio !== periods[i].ratio || - period.firstPeriodStart !== periods[i].firstPeriodStart + period.firstPeriodStart !== periods[i].firstPeriodStart || + period.paid !== periods[i].paid || + period.approved !== periods[i].approved ) { isMustSync = true } diff --git a/libs/application/templates/parental-leave/src/types.ts b/libs/application/templates/parental-leave/src/types.ts index dd3411596fe2c..f649525949fa9 100644 --- a/libs/application/templates/parental-leave/src/types.ts +++ b/libs/application/templates/parental-leave/src/types.ts @@ -65,6 +65,8 @@ export interface VMSTPeriod { firstPeriodStart: string paid: boolean rightsCodePeriod: string + days: string + approved: boolean } export interface Period { @@ -76,6 +78,8 @@ export interface Period { daysToUse?: string rawIndex?: number rightCodePeriod?: string + paid?: boolean + approved?: boolean } export interface Payment { diff --git a/libs/clients/vmst/src/clientConfig.yaml b/libs/clients/vmst/src/clientConfig.yaml index fa7473de89ef1..c41490cacc6cb 100644 --- a/libs/clients/vmst/src/clientConfig.yaml +++ b/libs/clients/vmst/src/clientConfig.yaml @@ -433,6 +433,8 @@ components: type: string firstPeriodStart: type: string + days: + type: string ApplicationRights: type: object additionalProperties: false