Skip to content

Commit

Permalink
fix(parental-leave): Refactor Sync - VMST (#14436)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
2 people authored and jonnigs committed May 17, 2024
1 parent 79a1c90 commit 5b7abb9
Show file tree
Hide file tree
Showing 19 changed files with 293 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<ApplicationInformation | null> {
if (shouldNotCall) {
return null
}

if (nationalId == user.nationalId) {
return this.directorateOfLabourService.getApplicationInfo(applicationId)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,7 @@ export class ApplicationInformationPeriod {

@Field(() => String)
firstPeriodStart!: string

@Field(() => String)
days!: string
}
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
)
}
}
Expand Down Expand Up @@ -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
}
}
8 changes: 6 additions & 2 deletions libs/application/templates/parental-leave/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}
Expand All @@ -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

Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,7 @@ const Periods: FC<React.PropsWithChildren<ReviewScreenProps>> = ({
return (
<DataValue
key={`SummaryTimeline-${index}`}
label={formatMessage(
parentalLeaveFormMessages.reviewScreen.period,
{
index: index + 1,
ratio: period.ratio,
},
)}
label={period.title}
value={value}
/>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ const PeriodsRepeater: FC<React.PropsWithChildren<ScreenProps>> = ({
variables: {
applicationId: application.id,
nationalId: application.applicant,
shouldNotCall: !shouldCall,
},
skip: !shouldCall,
})

useEffect(() => {
Expand All @@ -85,7 +85,7 @@ const PeriodsRepeater: FC<React.PropsWithChildren<ScreenProps>> = ({
setRepeaterItems,
setFieldLoadingState,
)
}, [loading])
}, [loading]) // eslint-disable-line react-hooks/exhaustive-deps

useEffect(() => {
if (!editable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,7 @@ export const Periods = ({
return (
<DataValue
key={`SummaryTimeline-${index}`}
label={formatMessage(
parentalLeaveFormMessages.reviewScreen.period,
{
index: index + 1,
ratio: period.ratio,
},
)}
label={period.title}
value={value}
/>
)
Expand Down
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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 (
<Box className={styles.panel}>
<Box className={styles.panelRow}>
Expand All @@ -50,17 +51,63 @@ export const Panel: FC<

{periods.map((p, index) => (
<Box className={styles.panelRow} key={index}>
{p.canDelete && editable && onDeletePeriod && (
<Box
className={styles.deleteIcon}
onClick={() => onDeletePeriod(p.startDate)}
>
<Icon
color="dark200"
icon="removeCircle"
size="medium"
type="outline"
/>
{editable && onDeletePeriod && (
<Box className={styles.deleteIcon}>
{p.canDelete ? (
// Period can be deleted
<Tooltip
placement="right"
text={formatMessage(
parentalLeaveFormMessages.shared.deletePeriod,
)}
>
<button
type="button"
onClick={() => onDeletePeriod(p.startDate)}
>
<Icon
color="dark200"
icon="removeCircle"
size="medium"
type="outline"
/>
</button>
</Tooltip>
) : p.paid ? (
// Period can't be deleted, period paid
<Tooltip
placement="right"
text={formatMessage(
parentalLeaveFormMessages.shared.periodPaid,
)}
>
<button type="button">
<Icon
color="mint600"
icon="checkmarkCircle"
size="medium"
type="filled"
/>
</button>
</Tooltip>
) : (
// Period can't be deleted, period in progress
<Tooltip
placement="right"
text={formatMessage(
parentalLeaveFormMessages.shared.periodInProgress,
)}
>
<button type="button">
<Icon
color="mint600"
icon="checkmarkCircle"
size="medium"
type="outline"
/>
</button>
</Tooltip>
)}
</Box>
)}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface TimelinePeriod {
color?: string
canDelete?: boolean
rawIndex: number
paid?: boolean
}

interface TimelineProps {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -45,6 +43,8 @@ export const GetApplicationInformation = gql`
paid
firstPeriodStart
rightsCodePeriod
days
approved
}
}
}
Expand Down
Loading

0 comments on commit 5b7abb9

Please sign in to comment.