{"version":3,"file":"style.module-c14d5ac8.js","sources":["../../../client-app/src/common/applicationPages/applicationStatusHelpers.ts","../../../client-app/src/common/components/Sign/SignCommon.tsx"],"sourcesContent":["import { assertDataIsNotResponse } from '@n2-common/asserts';\nimport { getApplicationIds } from '@n2-common/components/ApplicationContext';\nimport { N2ApplicationStatus } from '@n2-common/serverGeneratedTypings/n2ApplicationStatus';\nimport { N2MajorApplicationStatus } from '@n2-common/serverGeneratedTypings/n2MajorApplicationStatus';\nimport { generatePath, LoaderFunctionArgs, NavigateFunction, redirect, useLoaderData } from 'react-router-dom';\nimport { ApplicationStatusModel } from '../serverGeneratedTypings/applicationStatusModel';\nimport { getApplicationStatus } from '../services/legacyApplicationApiService';\nimport { navigateToStep, ApplicationPaths } from './ApplicationFormsHelpers';\nimport { logErrorToServerside } from '@n2-common/services/serverSideLogging';\nimport { ProductTypeForTracking } from '@n2-common/lib/gtm';\nimport { DocumentRequirement } from '@n2-common/components/UploadDocuments';\nimport { ActionState } from '@n2-common/ui/ActionList';\n\nexport const translationNamepaceFromProduct = (productType: ProductTypeForTracking) => {\n switch (productType) {\n case 'SA':\n return 'deposit';\n case 'CC':\n return 'cc';\n default:\n return 'common';\n }\n};\n\nexport const getDocumentationState = (requirements: DocumentRequirement[]): ActionState => {\n if (requirements === null) {\n return 'pending';\n }\n const pendingDocuments = requirements.filter((m) => !m.completed);\n return pendingDocuments.length > 0 ? 'ready' : 'completed';\n};\n\nexport const fetchApplicationStatusAndRedirectIfNotExpectedState = async (\n applicationId: string | null,\n applicantId: string,\n correctStateFunc: (applicationStatus: ApplicationStatusModel) => boolean,\n setApplicationStatus: (applicationStatus: ApplicationStatusModel) => void,\n navigate: NavigateFunction,\n navigateToCorrectStepFunc: (application: ApplicationStatusModel, applicantId: string, navigate: NavigateFunction) => void\n) => {\n if (!applicationId) {\n console.log('no applicationId');\n return;\n }\n const res = await getApplicationStatus(applicationId, applicantId);\n if (!correctStateFunc(res)) {\n navigateToCorrectStepFunc(res, applicantId, navigate);\n }\n setApplicationStatus(res);\n};\n\nexport const commonNavigateToCorrectStepForSingleApplicantProducts = (\n application: ApplicationStatusModel,\n applicantId: string,\n navigate: NavigateFunction\n) => {\n const target = __navigateTargetFromStatus(application, applicantId);\n if (target) {\n navigateToStep(target.path, target.applicationId, navigate, target.applicantId);\n }\n return;\n};\n\n// Internal function not intended to be used outside module. Only exported, to allow unittest.\nexport function __navigateTargetFromStatus(application: ApplicationStatusModel, applicantId: string) {\n if (application.Status === N2ApplicationStatus.Offer) {\n return { path: ApplicationPaths.offer, applicationId: application.ApplicationId, applicantId };\n }\n\n if (application.Status === N2ApplicationStatus.Completed) {\n return { path: ApplicationPaths.completed, applicationId: application.ApplicationId, applicantId };\n }\n\n if (application.Status === N2ApplicationStatus.InProgress) {\n return { path: ApplicationPaths.inProgress, applicationId: application.ApplicationId, applicantId };\n }\n\n switch (application.MajorStatus) {\n case N2MajorApplicationStatus.Declined:\n return {\n path: application.IsAgentApplication ? ApplicationPaths.declinedFromAgent : ApplicationPaths.declined,\n applicationId: application.ApplicationId,\n applicantId,\n };\n\n case N2MajorApplicationStatus.Cancelled:\n return { path: ApplicationPaths.canceled, applicationId: application.ApplicationId, applicantId };\n\n case N2MajorApplicationStatus.NotFound:\n return { path: ApplicationPaths.notFound, applicationId: application.ApplicationId, applicantId };\n }\n\n if (application.Status === N2ApplicationStatus.ReadyForSigning) {\n if (application.ApplicantCddPending) {\n return { path: ApplicationPaths.offer, applicationId: application.ApplicationId, applicantId };\n } else {\n return { path: ApplicationPaths.sign, applicationId: application.ApplicationId, applicantId };\n }\n }\n if (application.Status === N2ApplicationStatus.InProgressCustomerFinished) {\n return { path: ApplicationPaths.applicantActionsCompleted, applicationId: application.ApplicationId, applicantId };\n }\n\n if (application.Status === N2ApplicationStatus.ReadyForPinSelect) {\n return { path: ApplicationPaths.sign, applicationId: application.ApplicationId, applicantId };\n }\n\n console.log(`dont know where to navigate to with applicationStatus ${application.MajorStatus}, ${application.Status} `);\n return undefined as never;\n}\n\nfunction generatePathQuery(target: ReturnType) {\n const { path, applicantId, applicationId } = target;\n return generatePath(`${path}?applicationId=${applicationId}&applicantId=${applicantId}`);\n}\n\nexport function getRedirectUrl(applicationStatus: ApplicationStatusModel, applicantId: string) {\n const target = __navigateTargetFromStatus(applicationStatus, applicantId);\n if (target) {\n return generatePathQuery(target);\n }\n return ApplicationPaths.error;\n}\n/**\n * Function that redirects from requested url, and have guard for redirecting to same url (causing endles redirects).\n * Including serverside logging.\n */\nexport function safeRedirect(requestUrl: string, status: ApplicationStatusModel, applicantId: string) {\n const redirectUrl = getRedirectUrl(status, applicantId);\n if (requestUrl.includes(redirectUrl)) {\n const report = {\n requestUrl,\n redirectUrl,\n applicationStatus: status,\n };\n logErrorToServerside(`Invalid state resulting in endless redirect`, status.ApplicationId, applicantId, report);\n return redirect(generatePath(ApplicationPaths.error));\n }\n return redirect(redirectUrl);\n}\n\nexport async function applicationLoader({ request }: LoaderFunctionArgs) {\n const requestUrl = new URL(request.url);\n\n if (!requestUrl.searchParams.has('applicationId')) {\n return redirect(generatePath(ApplicationPaths.wizard));\n }\n try {\n const { applicantId, applicationId } = await getApplicationIds(request);\n\n const status = await getApplicationStatus(applicationId, applicantId);\n return redirect(getRedirectUrl(status, applicantId));\n } catch (err) {\n const applicationId = requestUrl.searchParams.get('applicationId');\n logErrorToServerside(`Could not load application`, applicationId, null, err);\n return redirect(generatePath(ApplicationPaths.error));\n }\n}\n\nexport function useApplicationIdsLoaderData() {\n const data = useLoaderData() as Awaited>;\n assertDataIsNotResponse(data);\n return data;\n}\n","import { createContext, useContext, useState, useEffect } from 'react';\nimport { useNavigate } from 'react-router-dom';\nimport { useApplicationIdContext } from '../ApplicationContext';\nimport { ApplicationSignStatusModel } from '../../serverGeneratedTypings/applicationSignStatusModel';\nimport { ApplicationStatusModel } from '../../serverGeneratedTypings/applicationStatusModel';\nimport { N2ApplicationStatus } from '../../serverGeneratedTypings/n2ApplicationStatus';\nimport { getApplicationSignStatus } from '@n2-common/services/legacyApplicationApiService';\nimport { logInfoToServerSide } from '../../services/serverSideLogging';\nimport { fetchApplicationStatusAndRedirectIfNotExpectedState } from '../../applicationPages/applicationStatusHelpers';\nimport { CommonStatusPageProps } from '../ApplicationStatusPage';\n\nexport interface ApplicationSignContextProps {\n applicationId: string;\n applicantId: string;\n isMainApplicant: boolean | null;\n applicationSignStatus: ApplicationSignStatusModel | null;\n applicationStatus: ApplicationStatusModel | null;\n}\n\nexport function applicationIsInValidStateForSigning(applicationStatus: ApplicationStatusModel) {\n if (applicationStatus.Status !== N2ApplicationStatus.ReadyForSigning) {\n return false;\n }\n if (applicationStatus.IsMainApplicant) {\n return !applicationStatus.ApplicantCddPending;\n } else {\n return !applicationStatus.CosignerCddPending;\n }\n}\n\nexport const ApplicationSignContext = createContext({\n applicantId: '',\n applicationId: '',\n isMainApplicant: null,\n applicationSignStatus: null,\n applicationStatus: null,\n});\n\nexport const useApplicationSignContext = () => {\n const res = useContext(ApplicationSignContext);\n if (!res) {\n throw new Error('ApplicationSignContext is not accessible if not used inside SignCommonComponent (ApplicationSignContextProvider).');\n }\n return res;\n};\n\ntype SignCommonComponentProps = /*InsuranceProps &*/ CommonStatusPageProps & React.PropsWithChildren;\n\nexport function SignCommonComponent({ children, navigateToCorrectStepFunc }: SignCommonComponentProps): JSX.Element {\n const navigate = useNavigate();\n const { applicationId, applicantId } = useApplicationIdContext();\n\n const [isMainApplicant, setIsMainApplicant] = useState(null);\n\n const [applicationSignStatus, setApplicationSignStatus] = useState(null);\n\n const [applicationStatus, setApplicationStatus] = useState(null);\n\n useEffect(() => {\n fetchApplicationStatusAndRedirectIfNotExpectedState(\n applicationId,\n applicantId,\n applicationIsInValidStateForSigning,\n setApplicationStatus,\n navigate,\n navigateToCorrectStepFunc\n );\n }, [applicationId, navigate, applicantId, navigateToCorrectStepFunc]);\n\n useEffect(() => {\n if (!applicationStatus) {\n return;\n }\n const mainApp = applicationStatus.IsMainApplicant;\n logInfoToServerSide(`Showing sign page for ${mainApp ? 'mainApplicant' : 'coApplicant'} `, applicationId, applicantId);\n setIsMainApplicant(mainApp);\n }, [applicationStatus, applicantId, applicationId]);\n\n\n useEffect(() => {\n const controller = new AbortController();\n if (!applicationId) {\n return;\n }\n getApplicationSignStatus(applicationId, controller.signal).then((res) => {\n setApplicationSignStatus(res);\n });\n return () => controller.abort();\n }, [applicationId]);\n\n return (\n \n {children}\n \n );\n}\n"],"names":["translationNamepaceFromProduct","productType","getDocumentationState","requirements","m","fetchApplicationStatusAndRedirectIfNotExpectedState","applicationId","applicantId","correctStateFunc","setApplicationStatus","navigate","navigateToCorrectStepFunc","res","getApplicationStatus","commonNavigateToCorrectStepForSingleApplicantProducts","application","target","__navigateTargetFromStatus","navigateToStep","N2ApplicationStatus","ApplicationPaths","N2MajorApplicationStatus","generatePathQuery","path","generatePath","getRedirectUrl","applicationStatus","safeRedirect","requestUrl","status","redirectUrl","report","logErrorToServerside","redirect","applicationLoader","request","getApplicationIds","err","applicationIsInValidStateForSigning","ApplicationSignContext","createContext","useApplicationSignContext","useContext","SignCommonComponent","children","useNavigate","useApplicationIdContext","isMainApplicant","setIsMainApplicant","useState","applicationSignStatus","setApplicationSignStatus","useEffect","mainApp","logInfoToServerSide","controller","getApplicationSignStatus","jsx"],"mappings":"4JAaa,MAAAA,GAAkCC,GAAwC,CACnF,OAAQA,EAAa,CACjB,IAAK,KACM,MAAA,UACX,IAAK,KACM,MAAA,KACX,QACW,MAAA,QACf,CACJ,EAEaC,GAAyBC,GAC9BA,IAAiB,KACV,UAEcA,EAAa,OAAQC,GAAM,CAACA,EAAE,SAAS,EACxC,OAAS,EAAI,QAAU,YAGtCC,EAAsD,MAC/DC,EACAC,EACAC,EACAC,EACAC,EACAC,IACC,CACD,GAAI,CAACL,EAAe,CAChB,QAAQ,IAAI,kBAAkB,EAC9B,MACJ,CACA,MAAMM,EAAM,MAAMC,EAAqBP,EAAeC,CAAW,EAC5DC,EAAiBI,CAAG,GACKD,EAAAC,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