Skip to content

Commit

Permalink
[TS-926] Only display available months in TR applications
Browse files Browse the repository at this point in the history
  • Loading branch information
veronikasif committed Oct 16, 2024
1 parent e6329ee commit 097fa34
Show file tree
Hide file tree
Showing 8 changed files with 280 additions and 164 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,51 @@ import {
buildCustomField,
buildFileUploadField,
buildForm,
buildHiddenInputWithWatchedValue,
buildMultiField,
buildRadioField,
buildSection,
buildSelectField,
buildSubSection,
buildSubmitField,
buildSubSection,
buildTextField,
} from '@island.is/application/core'
import Logo from '@island.is/application/templates/social-insurance-administration-core/assets/Logo'
import {
Application,
DefaultEvents,
Form,
FormModes,
FormValue,
YES,
} from '@island.is/application/types'
BankAccountType,
fileUploadSharedProps,
TaxLevelOptions,
} from '@island.is/application/templates/social-insurance-administration-core/lib/constants'
import { socialInsuranceAdministrationMessage } from '@island.is/application/templates/social-insurance-administration-core/lib/messages'
import {
friendlyFormatIBAN,
friendlyFormatSWIFT,
getBankIsk,
typeOfBankInfo,
getCurrencies,
getYesNoOptions,
getTaxOptions,
getYesNoOptions,
typeOfBankInfo,
} from '@island.is/application/templates/social-insurance-administration-core/lib/socialInsuranceAdministrationUtils'
import Logo from '@island.is/application/templates/social-insurance-administration-core/assets/Logo'
import { additionalSupportForTheElderyFormMessage } from '../lib/messages'
import { socialInsuranceAdministrationMessage } from '@island.is/application/templates/social-insurance-administration-core/lib/messages'
import {
BankAccountType,
fileUploadSharedProps,
MONTHS,
TaxLevelOptions,
} from '@island.is/application/templates/social-insurance-administration-core/lib/constants'
import {
getApplicationExternalData,
getAvailableYears,
} from '../lib/additionalSupportForTheElderlyUtils'
Application,
DefaultEvents,
Form,
FormModes,
FormValue,
YES,
} from '@island.is/application/types'
import {
applicantInformationMultiField,
buildFormConclusionSection,
} from '@island.is/application/ui-forms'
import { getApplicationAnswers } from '../lib/additionalSupportForTheElderlyUtils'
import isEmpty from 'lodash/isEmpty'
import {
getApplicationAnswers,
getApplicationExternalData,
getAvailableMonths,
getAvailableYears,
} from '../lib/additionalSupportForTheElderlyUtils'
import { additionalSupportForTheElderyFormMessage } from '../lib/messages'

export const AdditionalSupportForTheElderlyForm: Form = buildForm({
id: 'AdditionalSupportForTheElderlyDraft',
Expand Down Expand Up @@ -352,7 +353,24 @@ export const AdditionalSupportForTheElderlyForm: Form = buildForm({
width: 'half',
placeholder:
socialInsuranceAdministrationMessage.period.monthDefaultText,
options: MONTHS,
options: (application: Application) => {
const { selectedYear } = getApplicationAnswers(
application.answers,
)

return getAvailableMonths(selectedYear)
},
condition: (answers) => {
const { selectedYear, selectedYearHiddenInput } =
getApplicationAnswers(answers)

return selectedYear === selectedYearHiddenInput
},
}),
buildHiddenInputWithWatchedValue({
// Needed to trigger an update on options in the select above
id: 'period.hiddenInput',
watchValue: 'period.year',
}),
],
}),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
import { getValueViaPath } from '@island.is/application/core'
import {
BankAccountType,
MONTHS,
TaxLevelOptions,
} from '@island.is/application/templates/social-insurance-administration-core/lib/constants'
import {
AdditionalInformation,
Attachments,
BankInfo,
FileType,
PaymentInfo,
} from '@island.is/application/templates/social-insurance-administration-core/types'
import {
Application,
ExternalData,
Expand All @@ -7,22 +19,17 @@ import {
import addMonths from 'date-fns/addMonths'
import subMonths from 'date-fns/subMonths'
import { AttachmentLabel, AttachmentTypes } from './constants'
import {
FileType,
Attachments,
AdditionalInformation,
BankInfo,
PaymentInfo,
} from '@island.is/application/templates/social-insurance-administration-core/types'
import {
BankAccountType,
TaxLevelOptions,
} from '@island.is/application/templates/social-insurance-administration-core/lib/constants'

export const getApplicationAnswers = (answers: Application['answers']) => {
const selectedYear = getValueViaPath(answers, 'period.year') as string

const selectedMonth = getValueViaPath(answers, 'period.month') as string

const selectedYearHiddenInput = getValueViaPath(
answers,
'period.hiddenInput',
) as string

const applicantPhonenumber = getValueViaPath(
answers,
'applicant.phoneNumber',
Expand Down Expand Up @@ -86,6 +93,7 @@ export const getApplicationAnswers = (answers: Application['answers']) => {
applicantPhonenumber,
selectedYear,
selectedMonth,
selectedYearHiddenInput,
comment,
additionalAttachments,
additionalAttachmentsRequired,
Expand Down Expand Up @@ -230,6 +238,24 @@ export const getAvailableYears = () => {
)
}

// returns available months for selected year, since available period is
// 3 months back in time and 6 months in the future.
export const getAvailableMonths = (selectedYear: string) => {
if (!selectedYear) return []

const threeMonthsBackInTime = subMonths(new Date(), 3)
const sixMonthsInTheFuture = addMonths(new Date(), 6)

let months = MONTHS
if (threeMonthsBackInTime.getFullYear().toString() === selectedYear) {
months = months.slice(threeMonthsBackInTime.getMonth() + 1, months.length)
} else if (sixMonthsInTheFuture.getFullYear().toString() === selectedYear) {
months = months.slice(0, sixMonthsInTheFuture.getMonth() + 1)
}

return months
}

export const isEligible = (externalData: ExternalData): boolean => {
const { isEligible } = getApplicationExternalData(externalData)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,33 @@
import {
buildAlertMessageField,
buildCustomField,
buildDescriptionField,
buildFileUploadField,
buildForm,
buildHiddenInputWithWatchedValue,
buildMultiField,
buildPhoneField,
buildRadioField,
buildSection,
buildSelectField,
buildSubSection,
buildSubmitField,
buildTextField,
buildCustomField,
buildRadioField,
buildFileUploadField,
buildAlertMessageField,
buildSelectField,
buildDescriptionField,
} from '@island.is/application/core'
import Logo from '@island.is/application/templates/social-insurance-administration-core/assets/Logo'
import {
BankAccountType,
fileUploadSharedProps,
} from '@island.is/application/templates/social-insurance-administration-core/lib/constants'
import { socialInsuranceAdministrationMessage } from '@island.is/application/templates/social-insurance-administration-core/lib/messages'
import {
friendlyFormatIBAN,
friendlyFormatSWIFT,
getBankIsk,
getCurrencies,
getYesNoOptions,
typeOfBankInfo,
} from '@island.is/application/templates/social-insurance-administration-core/lib/socialInsuranceAdministrationUtils'
import {
Application,
DefaultEvents,
Expand All @@ -22,32 +37,18 @@ import {
NationalRegistrySpouse,
YES,
} from '@island.is/application/types'
import { householdSupplementFormMessage } from '../lib/messages'
import { socialInsuranceAdministrationMessage } from '@island.is/application/templates/social-insurance-administration-core/lib/messages'
import { buildFormConclusionSection } from '@island.is/application/ui-forms'
import * as kennitala from 'kennitala'
import isEmpty from 'lodash/isEmpty'
import { HouseholdSupplementHousing, maritalStatuses } from '../lib/constants'
import {
isExistsCohabitantOlderThan25,
getApplicationAnswers,
getApplicationExternalData,
getAvailableMonths,
getAvailableYears,
isExistsCohabitantOlderThan25,
} from '../lib/householdSupplementUtils'
import {
BankAccountType,
MONTHS,
fileUploadSharedProps,
} from '@island.is/application/templates/social-insurance-administration-core/lib/constants'
import { buildFormConclusionSection } from '@island.is/application/ui-forms'
import isEmpty from 'lodash/isEmpty'
import {
friendlyFormatIBAN,
friendlyFormatSWIFT,
getBankIsk,
typeOfBankInfo,
getCurrencies,
getYesNoOptions,
} from '@island.is/application/templates/social-insurance-administration-core/lib/socialInsuranceAdministrationUtils'
import Logo from '@island.is/application/templates/social-insurance-administration-core/assets/Logo'
import * as kennitala from 'kennitala'
import { householdSupplementFormMessage } from '../lib/messages'

export const HouseholdSupplementForm: Form = buildForm({
id: 'HouseholdSupplementDraft',
Expand Down Expand Up @@ -530,7 +531,24 @@ export const HouseholdSupplementForm: Form = buildForm({
width: 'half',
placeholder:
socialInsuranceAdministrationMessage.period.monthDefaultText,
options: MONTHS,
options: (application: Application) => {
const { selectedYear } = getApplicationAnswers(
application.answers,
)

return getAvailableMonths(selectedYear)
},
condition: (answers) => {
const { selectedYear, selectedYearHiddenInput } =
getApplicationAnswers(answers)

return selectedYear === selectedYearHiddenInput
},
}),
buildHiddenInputWithWatchedValue({
// Needed to trigger an update on options in the select above
id: 'period.hiddenInput',
watchValue: 'period.year',
}),
],
}),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
import { getValueViaPath } from '@island.is/application/core'
import {
HouseholdSupplementHousing,
AttachmentLabel,
AttachmentTypes,
} from './constants'
BankAccountType,
MONTHS,
} from '@island.is/application/templates/social-insurance-administration-core/lib/constants'
import {
Attachments,
BankInfo,
FileType,
PaymentInfo,
} from '@island.is/application/templates/social-insurance-administration-core/types'
import {
Application,
YesOrNo,
YES,
ExternalData,
YES,
YesOrNo,
} from '@island.is/application/types'
import addMonths from 'date-fns/addMonths'
import subYears from 'date-fns/subYears'
import * as kennitala from 'kennitala'
import { FileUpload } from '../types'
import {
Attachments,
BankInfo,
FileType,
PaymentInfo,
} from '@island.is/application/templates/social-insurance-administration-core/types'
import {
BankAccountType,
MONTHS,
} from '@island.is/application/templates/social-insurance-administration-core/lib/constants'
AttachmentLabel,
AttachmentTypes,
HouseholdSupplementHousing,
} from './constants'

export const getApplicationAnswers = (answers: Application['answers']) => {
const applicantPhonenumber = getValueViaPath(
Expand Down Expand Up @@ -55,6 +55,11 @@ export const getApplicationAnswers = (answers: Application['answers']) => {

const selectedMonth = getValueViaPath(answers, 'period.month') as string

const selectedYearHiddenInput = getValueViaPath(
answers,
'period.hiddenInput',
) as string

const additionalAttachments = getValueViaPath(
answers,
'fileUploadAdditionalFiles.additionalDocuments',
Expand Down Expand Up @@ -102,6 +107,7 @@ export const getApplicationAnswers = (answers: Application['answers']) => {
leaseAgreementAttachments,
selectedYear,
selectedMonth,
selectedYearHiddenInput,
additionalAttachments,
additionalAttachmentsRequired,
comment,
Expand Down
Loading

0 comments on commit 097fa34

Please sign in to comment.