@mychoice/mychoice-sdk-modules 2.2.28 → 2.2.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/esm/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
2
2
  import { ErrorBoundary } from 'react-error-boundary';
3
- import { AppTypes, isMyChoiceLike, TitleForm, TooltipForm, IconDelete, ColorVariablesTypes, InputTypes, InputForm, InputFormPhone, InputFormEmail, InputFormLicence, SelectForm, getFormattedDate, DateTypes, getDateOptions, ButtonForm, defaultBrokerPhone, DriverPriorityTypes, SizeTypes, ButtonBase, CategoryTypes, ColorTypes, defaultLocalIndex, liabilityOptions, accidentBenefitsOptionalOptions, coverageOptions, lossOfUseOptions, liabilityForDamageOptions, limitedWaiverOfDepreciationOptions, OfferDetail, CompanyRoleTypes, OperationHoursInfo, OfferHeader, OfferPrice, ButtonTypes, ButtonVariantTypes, IconDropdownArrow, InsuranceTypes, HeaderNavGroup, ButtonMenu, DeviceTypes, IconLoaderPrimary, getInsuranceType, RequestStatusTypes, formatPostalCode, IconLoaderSecondary, postalCodeFormat, useEffectOnce, carCondition, carStatus, carWinterTiresCheck, carKeepPlace, carUsagePurpose, firstDriveDistanceList, yearlyDriveDistanceList, numberWithCommas, VehiclePrimaryUseTypes, businessUsePercentOptions, addDaysToDate, comprehensiveCoverage, collisionCoverage, maritalStatusOptions, subYearsFromDate, occupationOptions, genderOptions, applicantRelationshipOptions, addYearsToDate, checkDateIsSpecial, DriverLicenceTypes, getDifferenceInYears, getDifferenceInMonths, compareDates, yesNoOptions, getLicenceTypeOptions, getDisabledLicenceTypes, addMonthsToDate, getMinDate, getMinDateByYears, CheckboxForm, insuranceCancellationReasonOptions, subMonthsFromDate, DriverListTypes, licenceSuspensionsReasonOptions, trafficTicketsGroupOptions, ValidationStatusTypes, getPlaceholderEmail, QuoteEdit, homeOwnerTypeOptions, tenantBuildingStructureOptions, condoBuildingStructureOptions, homeBuildingStructureOptions, residentsOptions, insuredYearsOptions, getInsuranceYearsOptions, ApplicantListTypes, claimTypeOptions, exteriorFinishOptions, constructionTypeOptions, garageTypeOptions, getNumericOptions, fireHallDistanceOptions, fireHydrantDistanceOptions, primaryHeatingTypeOptions, auxHeatingTypeOptions, InfoMessage, ppOptions, homeCoverageOptions, homeLiabilityOptions, lifeInsuranceTypeOptions, lifeInsuranceOntarioTypeOptions, lifeCoverageOptions, smokerOptions, MychoiceStep, Step, IconClock, ButtonArrow, DirectionTypes, ButtonTabArrow, ButtonTab, ButtonTabMobile, NavigationCar, NavigationPerson, NavigationDiscount, NavigationQuotes, NavigationAddress, NavigationProperty, ModalTypes } from '@mychoice/mychoice-sdk-components';
3
+ import { AppTypes, isMyChoiceLike, TitleForm, TooltipForm, IconDelete, ColorVariablesTypes, InputTypes, InputForm, InputFormPhone, InputFormEmail, InputFormLicence, SelectForm, getFormattedDate, DateTypes, getDateOptions, ButtonForm, defaultBrokerPhone, DriverPriorityTypes, SizeTypes, ButtonBase, CategoryTypes, ColorTypes, defaultLocalIndex, liabilityOptions, accidentBenefitsOptionalOptions, coverageOptions, lossOfUseOptions, liabilityForDamageOptions, limitedWaiverOfDepreciationOptions, OfferDetail, CompanyRoleTypes, OperationHoursInfo, OfferHeader, OfferPrice, ButtonTypes, ButtonVariantTypes, IconDropdownArrow, InsuranceTypes, HeaderNavGroup, ButtonMenu, DeviceTypes, IconLoaderPrimary, getInsuranceType, RequestStatusTypes, formatPostalCode, IconLoaderSecondary, postalCodeFormat, useEffectOnce, carCondition, carStatus, carWinterTiresCheck, carKeepPlace, carUsagePurpose, firstDriveDistanceList, yearlyDriveDistanceList, numberWithCommas, VehiclePrimaryUseTypes, businessUsePercentOptions, addDaysToDate, comprehensiveCoverage, collisionCoverage, maritalStatusOptions, subYearsFromDate, occupationOptions, genderOptions, applicantRelationshipOptions, addYearsToDate, checkDateIsSpecial, DriverLicenceTypes, getDifferenceInYears, getDifferenceInMonths, compareDates, yesNoOptions, getLicenceTypeOptions, getDisabledLicenceTypes, addMonthsToDate, getMinDate, CheckboxForm, insuranceCancellationReasonOptions, subMonthsFromDate, getMinDateByYears, DriverListTypes, licenceSuspensionsReasonOptions, trafficTicketsGroupOptions, ValidationStatusTypes, getPlaceholderEmail, QuoteEdit, homeOwnerTypeOptions, tenantBuildingStructureOptions, condoBuildingStructureOptions, homeBuildingStructureOptions, residentsOptions, insuredYearsOptions, getInsuranceYearsOptions, ApplicantListTypes, claimTypeOptions, exteriorFinishOptions, constructionTypeOptions, garageTypeOptions, getNumericOptions, fireHallDistanceOptions, fireHydrantDistanceOptions, primaryHeatingTypeOptions, auxHeatingTypeOptions, InfoMessage, ppOptions, homeCoverageOptions, homeLiabilityOptions, lifeInsuranceTypeOptions, lifeInsuranceOntarioTypeOptions, lifeCoverageOptions, smokerOptions, MychoiceStep, Step, IconClock, ButtonArrow, DirectionTypes, ButtonTabArrow, ButtonTab, ButtonTabMobile, NavigationCar, NavigationPerson, NavigationDiscount, NavigationQuotes, NavigationAddress, NavigationProperty, ModalTypes } from '@mychoice/mychoice-sdk-components';
4
4
  import { useStoreAppConfig, useStoreFormCarVehicle, useStoreFormCarDriverBase, useStoreFormCarDiscount, StoreFormCarDiscountActionTypes, useStoreFormCarQuote, CarQuoteDataHandler, useValidationCarDiscount, StoreFormCarVehicleActionTypes, useStoreFormHomeDiscount, useStorePartner, useStoreDeviceType, useStoreAppLoader, useStoreAppModal, StoreConfigAppModalActionTypes, useHandlerPostal, useHandlerCarMake, useHandlerCarModel, useProvince, useAbReform, useValidationVehicle, useAutofillCarForm, StoreFormCarDriverBaseActionTypes, useStoreFormCarConfig, useStoreFormCarDriverInfo, StoreFormCarDriverInfoActionTypes, useStoreFormCarDriverLicence, addDayToDate, StoreFormCarDriverLicenceActionTypes, useStoreFormCarDriverInsurance, StoreFormCarDriverInsuranceActionTypes, useStoreFormCarDriverCancellation, StoreFormCarDriverCancellationActionTypes, useStoreFormCarDriverSuspension, StoreFormCarDriverSuspensionActionTypes, useStoreFormCarDriverAccident, StoreFormCarDriverAccidentActionTypes, useStoreFormCarDriverTicket, StoreFormCarDriverTicketActionTypes, useValidationDriver, useHandlerCarQuoterEmail, useHandlerCarQuoterPhone, useStoreFormHomeDwelling, useStoreFormHomePostal, useStoreFormHomeApplicantBase, StoreFormHomePostalActionTypes, StoreFormHomeDwellingActionTypes, StoreConfigAppConfigActionTypes, StoreFormHomeApplicantBaseActionTypes, useValidationAddress, useStoreFormHomeApplicantInfo, StoreFormHomeDiscountActionTypes, StoreFormHomeApplicantInfoActionTypes, useStoreFormHomeApplicantInsurance, StoreFormHomeApplicantInsuranceActionTypes, useStoreFormHomeApplicantCancellation, StoreFormHomeApplicantCancellationActionTypes, useStoreFormHomeApplicantClaim, StoreFormHomeApplicantClaimActionTypes, useValidationApplicant, useValidationDwelling, useStoreFormHomeQuote, HomeQuoteDataHandler, useValidationHomeDiscount, useHandlerHomeQuoterEmail, useHandlerHomeQuoterPhone, useStoreFormLifeCoverage, StoreFormLifeCoverageActionTypes, useValidationCoverage, useAutofillLifeForm, useStoreFormLifeQuote, useStoreFormLifeApplicant, LifeQuoteDataHandler, useValidationLifeApplicant, useHandlerLifeQuoterEmail, useHandlerLifeQuoterPhone, StoreFormLifeApplicantActionTypes, useStoreFormCarPostal, useStoreFormLifePostal, ClearFormDataHandler, useStoreAppDevice, useStoreClient, useHandlerAuth, useHandlerPartner, StoreConfigAppLoaderActionTypes, StoreFormCarConfigActionTypes, StoreFormCarPostalActionTypes, StoreFormCarQuoteActionTypes, StoreFormHomeQuoteActionTypes, StoreFormLifePostalActionTypes, StoreFormLifeQuoteActionTypes, StoreClientActionTypes, StoreConfigAppDeviceActionTypes, StoreProvider, initHttpResponse } from '@mychoice/mychoice-sdk-store';
5
5
  import { useNavigate, useLocation, BrowserRouter, Routes, Route, Navigate } from 'react-router-dom';
6
6
  import React, { useState, useEffect, useCallback, useRef, useMemo } from 'react';
@@ -125,7 +125,7 @@ const SwitchButtonBox = (props) => {
125
125
  }
126
126
  return '';
127
127
  };
128
- const isAnswered = activeId === true || activeId === false;
128
+ const isAnswered = activeId !== '' && activeId !== undefined && activeId !== null;
129
129
  const handleClick = useCallback((selectedItem) => () => {
130
130
  setActiveId(selectedItem.value);
131
131
  if (onChange) {
@@ -208,8 +208,8 @@ const BlockVehLinks = () => {
208
208
  const { vehicleState: { items: vehicles } } = useStoreFormCarVehicle();
209
209
  const { driverState: { items: drivers } } = useStoreFormCarDriverBase();
210
210
  const { discountState: { vehlinks, occVehlinks, inValidation }, dispatchDiscountState } = useStoreFormCarDiscount();
211
- // Spec: 2 drivers / 2 vehicles — ask only for Vehicle1; system assigns the other driver as PO on Vehicle2.
212
- const isTwoByTwo = drivers.length === 2 && vehicles.length === 2;
211
+ const equalCounts = drivers.length === vehicles.length;
212
+ const askedVehicleCount = equalCounts ? vehicles.length - 1 : vehicles.length;
213
213
  const assignPrimary = (driverIndex, vehicleIndex) => {
214
214
  dispatchDiscountState({
215
215
  type: StoreFormCarDiscountActionTypes.FormCarDiscountVehlinkSelect,
@@ -217,31 +217,31 @@ const BlockVehLinks = () => {
217
217
  });
218
218
  };
219
219
  useEffect(() => {
220
- if (!isTwoByTwo)
220
+ if (!equalCounts || drivers.length <= 1)
221
221
  return;
222
- const v1 = vehlinks.find((l) => l.vehicleIndex === 0 && l.priority === DriverPriorityTypes.Prn);
223
- if (!v1 || v1.driverIndex < 0)
222
+ const primaryOf = (vehicleIndex) => vehlinks.find((l) => l.vehicleIndex === vehicleIndex && l.priority === DriverPriorityTypes.Prn)?.driverIndex ?? -1;
223
+ const askedDrivers = new Set();
224
+ for (let vehicleIndex = 0; vehicleIndex < askedVehicleCount; vehicleIndex += 1) {
225
+ const po = primaryOf(vehicleIndex);
226
+ if (po < 0)
227
+ return;
228
+ askedDrivers.add(po);
229
+ }
230
+ if (askedDrivers.size !== askedVehicleCount)
224
231
  return;
225
- const otherDriverIndex = drivers.findIndex((_, index) => index !== v1.driverIndex);
226
- if (otherDriverIndex < 0)
232
+ const remainingDriver = drivers.findIndex((_, driverIndex) => !askedDrivers.has(driverIndex));
233
+ if (remainingDriver < 0)
227
234
  return;
228
- const v2 = vehlinks.find((l) => l.vehicleIndex === 1 && l.priority === DriverPriorityTypes.Prn);
229
- if (v2?.driverIndex === otherDriverIndex)
235
+ const lastVehicleIndex = vehicles.length - 1;
236
+ if (primaryOf(lastVehicleIndex) === remainingDriver)
230
237
  return;
231
- assignPrimary(otherDriverIndex, 1);
232
- }, [isTwoByTwo, vehlinks, drivers]);
238
+ assignPrimary(remainingDriver, lastVehicleIndex);
239
+ }, [equalCounts, askedVehicleCount, vehlinks, drivers, vehicles]);
233
240
  if (drivers.length <= 1) {
234
241
  return null;
235
242
  }
236
243
  const handlePrimaryDriverChange = (vehicleIndex) => ({ value }) => {
237
- const driverIndex = Number(value);
238
- assignPrimary(driverIndex, vehicleIndex);
239
- if (isTwoByTwo && vehicleIndex === 0) {
240
- const otherDriverIndex = drivers.findIndex((_, index) => index !== driverIndex);
241
- if (otherDriverIndex >= 0) {
242
- assignPrimary(otherDriverIndex, 1);
243
- }
244
- }
244
+ assignPrimary(value === '' ? -1 : Number(value), vehicleIndex);
245
245
  };
246
246
  const handleOccDriverChange = (driverIndex) => ({ value }) => {
247
247
  dispatchDiscountState({
@@ -259,24 +259,32 @@ const BlockVehLinks = () => {
259
259
  const unassignedDrivers = drivers
260
260
  .map((driver, index) => ({ driver, index }))
261
261
  .filter(({ index }) => !primaryDriverIndices.includes(index));
262
- const vehiclesToAsk = isTwoByTwo ? vehicles.slice(0, 1) : vehicles;
262
+ const vehiclesToAsk = vehicles.slice(0, askedVehicleCount);
263
+ const primaryQuestionsAnswered = vehiclesToAsk.every((_vehicle, vehicleIndex) => vehlinks.some((l) => l.vehicleIndex === vehicleIndex
264
+ && l.priority === DriverPriorityTypes.Prn
265
+ && l.driverIndex >= 0));
266
+ const primaryQuestionsAreUnique = new Set(primaryDriverIndices).size >= vehicles.length;
267
+ const shouldAskOccasional = drivers.length > vehicles.length
268
+ && vehicles.length > 1
269
+ && primaryQuestionsAnswered
270
+ && primaryQuestionsAreUnique;
263
271
  return (jsxs(Fragment, { children: [jsx(LabelFormBox, { title: "Since there are multiple drivers in this quote, please tell us who drives which vehicle the most. Please provide an answer that most accurately describes your situation." }), vehiclesToAsk.map((vehicle, vehicleIndex) => {
264
272
  const { year, make, model } = vehicle;
265
273
  const selectedPrimary = vehlinks.find((l) => l.vehicleIndex === vehicleIndex && l.priority === DriverPriorityTypes.Prn);
266
274
  const isPrimaryAnswered = selectedPrimary !== undefined && selectedPrimary.driverIndex >= 0;
267
- // Show all drivers so the user can freely reselect / re-order primaries.
275
+ const previousPrimaryDriverIndices = new Set(vehlinks
276
+ .filter((l) => l.vehicleIndex < vehicleIndex
277
+ && l.priority === DriverPriorityTypes.Prn
278
+ && l.driverIndex >= 0)
279
+ .map((l) => l.driverIndex));
280
+ const allDriversHavePrimary = drivers.every((_, driverIndex) => vehlinks.some((l) => l.priority === DriverPriorityTypes.Prn && l.driverIndex === driverIndex));
281
+ const canRepeatPrimary = vehicles.length > drivers.length && allDriversHavePrimary;
268
282
  const primaryOptions = drivers
269
- .map((driver, driverIndex) => ({ name: driver.firstName, value: driverIndex }));
270
- const isDuplicatePrimary = !isTwoByTwo
271
- && isPrimaryAnswered
272
- && drivers.length >= vehicles.length
273
- && vehlinks.some((l) => l.vehicleIndex !== vehicleIndex
274
- && l.priority === DriverPriorityTypes.Prn
275
- && l.driverIndex === selectedPrimary?.driverIndex);
276
- return (jsx(SelectFormBox, { title: `Who is the principal driver of the ${year} ${make} ${model}?`, onChange: handlePrimaryDriverChange(vehicleIndex), options: primaryOptions, defaultValue: isPrimaryAnswered ? selectedPrimary.driverIndex : '', name: `vehlink-${vehicleIndex}`, placeholder: "Select from the list", autoSelectIfValueIsOutOfOptions: false, error: (!isPrimaryAnswered && inValidation) || isDuplicatePrimary, errorMessage: isDuplicatePrimary
277
- ? 'This driver is already the primary driver of another vehicle. Each vehicle should have a different primary driver.'
278
- : '' }, `vehlink-${vehicleIndex}`));
279
- }), drivers.length > vehicles.length && vehicles.length > 1
283
+ .map((driver, driverIndex) => ({ name: driver.firstName, value: driverIndex }))
284
+ .filter(({ value }) => canRepeatPrimary
285
+ || !previousPrimaryDriverIndices.has(value));
286
+ return (jsx(SelectFormBox, { title: `Who is the principal driver of the ${year} ${make} ${model}?`, onChange: handlePrimaryDriverChange(vehicleIndex), options: primaryOptions, defaultValue: isPrimaryAnswered ? selectedPrimary.driverIndex : '', name: `vehlink-${vehicleIndex}`, placeholder: "Select from the list", autoSelectIfValueIsOutOfOptions: false, error: !isPrimaryAnswered && inValidation }, `vehlink-${vehicleIndex}`));
287
+ }), shouldAskOccasional
280
288
  && unassignedDrivers.map(({ driver, index: driverIndex }) => {
281
289
  const selectedVehicle = occVehlinks.find((l) => l.driverIndex === driverIndex);
282
290
  const vehicleOptions = vehicles.map((vehicle, vehicleIndex) => ({
@@ -1760,7 +1768,7 @@ you had insurance. If this is correct, please continue with the form.`);
1760
1768
  const firstInsuredMinDate = listedYear && listedMonth
1761
1769
  ? addDaysToDate(`${listedYear}-${listedMonth}-01`, birthDay ? +birthDay + 1 : 1)
1762
1770
  : getMinDate(birthDate, firstLicenceAge);
1763
- const twentyYearsAgo = getMinDateByYears(getFormattedDate('', 'yyyy-MM-dd'), 20);
1771
+ const twentyYearsAgo = subYearsFromDate('', 20);
1764
1772
  let lastPolicyEndMinDate = twentyYearsAgo;
1765
1773
  if (firstInsuredMinDate && compareDates(firstInsuredMinDate, twentyYearsAgo) > 0) {
1766
1774
  lastPolicyEndMinDate = firstInsuredMinDate;