{"version":3,"file":"index-6ab8eabe.js","sources":["../../../client-app/src/common/applicationPages/InsurancePage/index.tsx"],"sourcesContent":["import { useEffect, useState } from 'react';\nimport { useNavigate } from 'react-router-dom';\nimport { fetchApplicationStatusAndRedirectIfNotExpectedState } from '../applicationStatusHelpers';\nimport { ApplicationStatusModel } from '../../serverGeneratedTypings/applicationStatusModel';\nimport { N2MajorApplicationStatus } from '../../serverGeneratedTypings/n2MajorApplicationStatus';\nimport { pollForExpectedApplicationState, setPpi } from '../../services/legacyApplicationApiService';\nimport { Button, ButtonRowContainer, CheckBox, Headline, Hero, RadioButton, useDismissableErrorMessage } from '../../ui';\nimport style from './style.module.scss';\nimport { useApplicationIdContext } from '../../components/ApplicationContext';\nimport { N2ApplicationStatus } from '../../serverGeneratedTypings/n2ApplicationStatus';\nimport { ApplicationPaths, navigateToStep } from '../ApplicationFormsHelpers';\nimport { trackSectionView } from '../../lib/gtm';\nimport { SubmitProgressBox } from '@n2-common/ui/SubmitProgress';\nimport { useTranslation } from 'react-i18next';\nimport { SubmitState } from '@n2-common/components/MultiStageOnePageWizard/types';\nimport { CommonStatusPageProps } from '@n2-common/components/ApplicationStatusPage';\nimport { logErrorToServerside } from '@n2-common/services/serverSideLogging';\nimport { errorToAction } from '../applicationErrorHelper';\n\nexport function applicationIsInValidStateForInsurance(applicationStatus: ApplicationStatusModel) {\n if (applicationStatus.MajorStatus !== N2MajorApplicationStatus.Aproved) {\n return false;\n }\n if (!applicationStatus.IsMainApplicant) {\n return false;\n }\n if (!applicationStatus.EligiblePPI) {\n return false;\n }\n return true;\n}\n\ntype InsuranceProps = {\n areYouSureYouDoNotWantPpiBox: JSX.Element;\n}\n\n\nexport function AreYouSureYouDoNotWantPpiBox(): JSX.Element {\n const { country } = useApplicationIdContext();\n switch (country) {\n case 'FI':\n return (\n \n

\n Pyydämme sinua harkitsemaan päätöstäsi uudelleen!\n


\n

\n Lainaturvavakuutus on turva sinulle ja läheisillesi sairastumisen, työttömyyden tai menehtymisen sattuessa.\n Kuolemantapauksessa vakuutus korvaa kokonaissaldon jopa 50 000 euroon asti.\n

\n
\n

Huomioithan, että vakuutusta ei voi ostaa jälkeenpäin!

\n
\n );\n case 'NO':\n return (\n \n

\n Vi ber deg vurdere en gang til om du ønsker en betalingsforsikring. Betalingsforsikringen kan dekke ditt månedlige avdrag ved\n sykdom og arbeidsledighet/permittering. Dersom du skulle dø kan lånet bli nedbetalt av betalingsforsikringen med inntil kr 500 000,-\n


\n

Vi gjør oppmerksom på at det bare mulig å kjøpe forsikringen når du tar opp et lån.

\n
\n );\n default:\n return <>;\n }\n}\n\ntype CombinedInsuranceProps = InsuranceProps &CommonStatusPageProps & React.PropsWithChildren;\n\nfunction InsurancePage({ children, navigateToCorrectStepFunc, areYouSureYouDoNotWantPpiBox }: CombinedInsuranceProps): JSX.Element {\n const navigate = useNavigate();\n const { setErrorMessage, ErrorOutput } = useDismissableErrorMessage();\n const { t } = useTranslation('common');\n const [submitState, setSubmitState] = useState('NotSent');\n\n const { applicationId, applicantId, country, productType } = useApplicationIdContext();\n\n const [applicationStatus, setApplicationStatus] = useState(null);\n const [wantsPpi, setWantsPpi] = useState(null);\n const [agressToTerms, setAgressToTerms] = useState(false);\n const [showError, setShowError] = useState(false);\n const [showMustAccept, setShowMustAccept] = useState(false);\n\n useEffect(() => {\n document.title = t('Ppi.Title');\n }, [t]);\n\n useEffect(() => {\n fetchApplicationStatusAndRedirectIfNotExpectedState(\n applicationId,\n applicantId,\n applicationIsInValidStateForInsurance,\n setApplicationStatus,\n navigate,\n navigateToCorrectStepFunc\n );\n }, [applicationId, navigate, applicantId, navigateToCorrectStepFunc]);\n\n useEffect(() => {\n trackSectionView(productType, country, '3.3', 'PPI');\n }, [country, productType]);\n\n const onSubmit = async () => {\n if (wantsPpi === null || !applicationStatus) {\n setShowError(true);\n setSubmitState('Error');\n return;\n }\n if (wantsPpi && !agressToTerms) {\n setShowMustAccept(true);\n setSubmitState('Error');\n return;\n }\n try {\n setSubmitState('Submitted');\n await setPpi(wantsPpi, applicationId, applicantId);\n\n setSubmitState('Processing');\n await pollForExpectedApplicationState(\n applicationId,\n applicantId,\n (res: ApplicationStatusModel) => res.Status === N2ApplicationStatus.ReadyForSigning\n );\n } catch (err) {\n const action = errorToAction(err, onSubmit, applicationId, applicantId);\n if (action) {\n setErrorMessage(action);\n return;\n } else {\n // What happened here?\n logErrorToServerside('Unhandled error when submitting PPI', applicationId, applicantId, err);\n navigateToStep(ApplicationPaths.error, applicationId, navigate, applicantId);\n }\n }\n navigateToStep(ApplicationPaths.sign, applicationId, navigate, applicantId);\n };\n\n const onChangeFunc = (val: boolean) => {\n setWantsPpi(val);\n setShowError(false);\n };\n\n const onChangeAgreesToTermFunc = (val: boolean) => {\n setAgressToTerms(val);\n setShowMustAccept(false);\n };\n\n return (\n <>\n {applicationId && applicationStatus ? (\n
\n ('Ppi.Submitted')}\n processingText={t('Ppi.Processing')}\n >\n {t('Ppi.Headline')}\n\n \n

\n
\n {t('Ppi.Legend')}\n onChangeFunc(e.target.value === 'on')}\n label={t('Ppi.YesLabel')}\n >\n {wantsPpi && (\n ('Ppi.AcceptTerms') : false}\n name=\"agreeppiterms\"\n id=\"agreeppiterms\"\n onChange={(e) => onChangeAgreesToTermFunc(e.target.checked)}\n label={t('Ppi.AgreementCheckboxLabel')}\n >\n )}\n ('Ppi.PleaseSelect') : false}\n name=\"ppi\"\n id=\"ppi_no\"\n onChange={(e) => onChangeFunc(e.target.value !== 'on')}\n label={t('Ppi.NoLabel')}\n >\n
\n
\n {wantsPpi === false && areYouSureYouDoNotWantPpiBox}\n \n {(wantsPpi === true || wantsPpi === false) && \n }\n \n {children}\n
\n ) : (\n <>\n )}\n \n \n );\n}\n\nexport default InsurancePage;\n"],"names":["applicationIsInValidStateForInsurance","applicationStatus","N2MajorApplicationStatus","AreYouSureYouDoNotWantPpiBox","country","useApplicationIdContext","Hero","style","jsx","Fragment","InsurancePage","children","navigateToCorrectStepFunc","areYouSureYouDoNotWantPpiBox","navigate","useNavigate","setErrorMessage","ErrorOutput","useDismissableErrorMessage","useTranslation","submitState","setSubmitState","useState","applicationId","applicantId","productType","setApplicationStatus","wantsPpi","setWantsPpi","agressToTerms","setAgressToTerms","showError","setShowError","showMustAccept","setShowMustAccept","useEffect","fetchApplicationStatusAndRedirectIfNotExpectedState","trackSectionView","onSubmit","setPpi","pollForExpectedApplicationState","res","N2ApplicationStatus","err","action","errorToAction","logErrorToServerside","navigateToStep","ApplicationPaths","onChangeFunc","val","onChangeAgreesToTermFunc","jsxs","SubmitProgressBox","Headline","RadioButton","e","CheckBox","ButtonRowContainer","Button"],"mappings":"iTAmBO,SAASA,EAAsCC,EAA2C,CAOzF,MANA,EAAAA,EAAkB,cAAgBC,EAAyB,SAG3D,CAACD,EAAkB,iBAGnB,CAACA,EAAkB,YAI3B,CAOO,SAASE,IAA4C,CAClD,KAAA,CAAE,QAAAC,GAAYC,IACpB,OAAQD,EAAS,CACb,IAAK,KACD,cACKE,EAAK,CAAA,GAAG,YAAY,UAAWC,EAAM,iBAClC,SAAA,CAAAC,EAAAA,IAAC,KAAE,SAEC,mDAAA,CAAA,QAAK,KAAE,EAAA,EACPA,EAAAA,IAAC,KAAE,SAGP,yLAAA,CAAA,QACC,KAAE,EAAA,EACHA,EAAAA,IAAC,KAAE,SAAsD,wDAAA,CAAA,CAC7D,CAAA,CAAA,EAER,IAAK,KACD,cACKF,EAAK,CAAA,GAAG,YAAY,UAAWC,EAAM,iBAClC,SAAA,CAAAC,EAAAA,IAAC,KAAE,SAGH,oQAAA,CAAA,QAAK,KAAE,EAAA,EACPA,EAAAA,IAAC,KAAE,SAAmF,qFAAA,CAAA,CAC1F,CAAA,CAAA,EAER,QACI,OAASA,EAAA,IAAAC,WAAA,CAAA,CAAA,CACjB,CACJ,CAIA,SAASC,GAAc,CAAE,SAAAC,EAAU,0BAAAC,EAA2B,6BAAAC,GAAqE,CAC/H,MAAMC,EAAWC,IACX,CAAE,gBAAAC,EAAiB,YAAAC,CA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