{ "version": 3, "sources": ["../javascripts/actions/current-financial-information.ts", "../javascripts/actions/credit-application.ts"], "sourcesContent": ["import type { Dispatch as ReduxDispatch } from '@reduxjs/toolkit';\n\nimport type { BaseAction } from '../@types/actions';\nimport type { FinancialConfiguration, FinancialInformation } from '../@types/finance';\nimport * as http from '../Http';\nimport { buildPostRequest } from '../Http/requestTemplates';\nimport type { RootState } from '../reducers';\nimport requestCache from '../utils/request-cache';\n\nexport const REQ_GET_CURRENT_FINANCE_INFORMATION = 'REQ/GET_CURRENT_FINANCE_INFORMATION';\nexport const RCV_GET_CURRENT_FINANCE_INFORMATION = 'RCV/GET_CURRENT_FINANCE_INFORMATION';\ntype REQ_GET_CURRENT_FINANCE_INFORMATION_TYPE = BaseAction<\n typeof REQ_GET_CURRENT_FINANCE_INFORMATION\n>;\ntype RCV_GET_CURRENT_FINANCE_INFORMATION_TYPE = BaseAction<\n typeof RCV_GET_CURRENT_FINANCE_INFORMATION\n> & {\n response: FinancialInformation;\n};\n\nexport const RESET_CURRENT_FINANCE_INFORMATION =\n 'CURRENT_FINANCE_INFORMATION/RESET_CURRENT_FINANCE_INFORMATION';\ntype RESET_CURRENT_FINANCE_INFORMATION_TYPE = BaseAction;\n\nexport const REQUEST_FAILED = 'CURRENT_FINANCE_INFORMATION/REQUEST_FAILED';\n\ntype REQUEST_FAILED_TYPE = BaseAction & {\n action: typeof REQ_GET_CURRENT_FINANCE_INFORMATION;\n};\n\nexport type CURRENT_FINANCIAL_INFORMATION_ACTION =\n | REQ_GET_CURRENT_FINANCE_INFORMATION_TYPE\n | RCV_GET_CURRENT_FINANCE_INFORMATION_TYPE\n | RESET_CURRENT_FINANCE_INFORMATION_TYPE\n | REQUEST_FAILED_TYPE;\n\ntype Dispatch = ReduxDispatch;\n\nexport const getCurrentFinancialInformation =\n (vehicleId: string, _configuration: FinancialConfiguration, branchId?: string) =>\n async (dispatch: Dispatch, getState: () => RootState) => {\n const state = getState();\n const { currentFinancialInformation, defaultFinancialInformation } = state;\n\n const configuration: FinancialConfiguration = {\n downPayment: Math.round(_configuration.downPayment),\n duration: Math.round(_configuration.duration),\n residual: _configuration.residual,\n };\n\n const isValidPayload = isValid(\n configuration,\n currentFinancialInformation,\n defaultFinancialInformation,\n );\n if (!isValidPayload) {\n return;\n }\n\n if (requestCache.isPending(REQ_GET_CURRENT_FINANCE_INFORMATION)) {\n return;\n }\n requestCache.isPending(REQ_GET_CURRENT_FINANCE_INFORMATION, true);\n\n try {\n dispatch({ type: REQ_GET_CURRENT_FINANCE_INFORMATION });\n\n const response = await http.json(\n `/api/financial-information/${vehicleId}${branchId ? `?branchId=${branchId}` : ''}`,\n buildPostRequest(configuration),\n );\n http.validateResponse(response);\n dispatch({\n type: RCV_GET_CURRENT_FINANCE_INFORMATION,\n response: response.response,\n });\n } catch (_e) {\n dispatch({ type: REQUEST_FAILED, action: REQ_GET_CURRENT_FINANCE_INFORMATION });\n }\n requestCache.isPending(REQ_GET_CURRENT_FINANCE_INFORMATION, false);\n };\n\nconst isValid = (\n configuration: FinancialConfiguration,\n currentFinancialInformation: any,\n defaultFinancialInformation: any,\n): boolean => {\n const financialInformation: FinancialInformation | null =\n currentFinancialInformation.current || defaultFinancialInformation.default;\n\n if (!configuration || !financialInformation) {\n return false;\n }\n\n const { duration, residual, downPayment } = financialInformation;\n\n let isValidDuration = true;\n let isValidResidual = true;\n let isValidDownPayment = true;\n\n if (duration) {\n isValidDuration =\n configuration.duration >= duration.min && configuration.duration <= duration.max;\n }\n\n if (residual) {\n isValidResidual =\n configuration.residual >= residual.min && configuration.residual <= residual.max;\n }\n\n if (downPayment) {\n isValidDownPayment =\n configuration.downPayment >= downPayment.min && configuration.downPayment <= downPayment.max;\n }\n\n return isValidDuration && isValidResidual && isValidDownPayment;\n};\n\nexport const resetCurrentFinancialInformation = () => (dispatch: Dispatch) => {\n dispatch({ type: RESET_CURRENT_FINANCE_INFORMATION });\n};\n", "import type { Dispatch as ReduxDispatch } from '@reduxjs/toolkit';\nimport type { BaseAction } from '../@types/actions';\n\nexport const REQ_PERSIST_CREDIT_APPLICATION_DATA = 'REQ/PERSIST_CREDIT_APPLICATION_DATA';\nexport type REQ_PERSIST_CREDIT_APPLICATION_DATA_TYPE = BaseAction<\n typeof REQ_PERSIST_CREDIT_APPLICATION_DATA\n> & {\n ssn?: string;\n email?: string;\n estimatedMileage?: string | number;\n telephone?: string;\n};\n\nexport type CREDIT_APPLICATION_ACTION = REQ_PERSIST_CREDIT_APPLICATION_DATA_TYPE;\n\ntype Dispatch = ReduxDispatch;\n\nexport const save =\n (ssn?: string, email?: string, estimatedMileage?: string | number, telephone?: string) =>\n (dispatch: Dispatch) =>\n dispatch({\n type: REQ_PERSIST_CREDIT_APPLICATION_DATA,\n ssn,\n email,\n estimatedMileage,\n telephone,\n });\n"], "mappings": "4GASO,IAAMA,EAAsC,sCACtCC,EAAsC,sCAUtCC,EACX,gEAGWC,EAAiB,6CAcjBC,EACX,CAACC,EAAmBC,EAAwCC,IAC5D,MAAOC,EAAoBC,IAA8B,CACvD,IAAMC,EAAQD,EAAS,EACjB,CAAE,4BAAAE,EAA6B,4BAAAC,CAA4B,EAAIF,EAE/DG,EAAwC,CAC5C,YAAa,KAAK,MAAMP,EAAe,WAAW,EAClD,SAAU,KAAK,MAAMA,EAAe,QAAQ,EAC5C,SAAUA,EAAe,QAC3B,EAOA,GALuBQ,EACrBD,EACAF,EACAC,CACF,GAKI,CAAAG,EAAa,UAAUf,CAAmC,EAG9D,CAAAe,EAAa,UAAUf,EAAqC,EAAI,EAEhE,GAAI,CACFQ,EAAS,CAAE,KAAMR,CAAoC,CAAC,EAEtD,IAAMgB,EAAW,MAAWC,EAC1B,8BAA8BZ,CAAS,GAAGE,EAAW,aAAaA,CAAQ,GAAK,EAAE,GACjFW,EAAiBL,CAAa,CAChC,EACKM,EAAiBH,CAAQ,EAC9BR,EAAS,CACP,KAAMP,EACN,SAAUe,EAAS,QACrB,CAAC,CACH,MAAa,CACXR,EAAS,CAAE,KAAML,EAAgB,OAAQH,CAAoC,CAAC,CAChF,CACAe,EAAa,UAAUf,EAAqC,EAAK,EACnE,EAEIc,EAAU,CACdD,EACAF,EACAC,IACY,CACZ,IAAMQ,EACJT,EAA4B,SAAWC,EAA4B,QAErE,GAAI,CAACC,GAAiB,CAACO,EACrB,MAAO,GAGT,GAAM,CAAE,SAAAC,EAAU,SAAAC,EAAU,YAAAC,CAAY,EAAIH,EAExCI,EAAkB,GAClBC,EAAkB,GAClBC,EAAqB,GAEzB,OAAIL,IACFG,EACEX,EAAc,UAAYQ,EAAS,KAAOR,EAAc,UAAYQ,EAAS,KAG7EC,IACFG,EACEZ,EAAc,UAAYS,EAAS,KAAOT,EAAc,UAAYS,EAAS,KAG7EC,IACFG,EACEb,EAAc,aAAeU,EAAY,KAAOV,EAAc,aAAeU,EAAY,KAGtFC,GAAmBC,GAAmBC,CAC/C,EAEaC,EAAmC,IAAOnB,GAAuB,CAC5EA,EAAS,CAAE,KAAMN,CAAkC,CAAC,CACtD,ECrHO,IAAM0B,EAAsC,sCActCC,EACX,CAACC,EAAcC,EAAgBC,EAAoCC,IAClEC,GACCA,EAAS,CACP,KAAMN,EACN,IAAAE,EACA,MAAAC,EACA,iBAAAC,EACA,UAAAC,CACF,CAAC", "names": ["REQ_GET_CURRENT_FINANCE_INFORMATION", "RCV_GET_CURRENT_FINANCE_INFORMATION", "RESET_CURRENT_FINANCE_INFORMATION", "REQUEST_FAILED", "getCurrentFinancialInformation", "vehicleId", "_configuration", "branchId", "dispatch", "getState", "state", "currentFinancialInformation", "defaultFinancialInformation", "configuration", "isValid", "request_cache_default", "response", "json", "buildPostRequest", "validateResponse", "financialInformation", "duration", "residual", "downPayment", "isValidDuration", "isValidResidual", "isValidDownPayment", "resetCurrentFinancialInformation", "REQ_PERSIST_CREDIT_APPLICATION_DATA", "save", "ssn", "email", "estimatedMileage", "telephone", "dispatch"] }