@mychoice/mychoice-sdk-store 2.2.11 → 2.2.14

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/cjs/index.js CHANGED
@@ -455,6 +455,11 @@ const limitedWaiverOfDepreciationInitialState = {
455
455
  coverage: true,
456
456
  limit: 1,
457
457
  };
458
+ const vehicleAccidentBenefitsInitialState = {
459
+ baseCoverage: 'minimum_required',
460
+ additionalCoverages: [],
461
+ abAcknowledged: false,
462
+ };
458
463
  const vehicleItemInitialState = {
459
464
  year: '',
460
465
  make: '',
@@ -477,6 +482,7 @@ const vehicleItemInitialState = {
477
482
  lossofuse: { ...vehicleLossOfUseInitialState },
478
483
  liabilityfordamage: { ...vehicleLiabilityForDamageInitialState },
479
484
  limitedwaiverofdepreciation: { ...limitedWaiverOfDepreciationInitialState },
485
+ accidentbenefits: { ...vehicleAccidentBenefitsInitialState },
480
486
  postalCode: '',
481
487
  locationIndex: '',
482
488
  city: '',
@@ -532,6 +538,10 @@ exports.StoreFormCarVehicleActionTypes = void 0;
532
538
  StoreFormCarVehicleActionTypes["FormCarLossOfUseCoverageSelect"] = "FormCarLossOfUseCoverageSelect";
533
539
  StoreFormCarVehicleActionTypes["FormCarLiabilityForDamageCoverageSelect"] = "FormCarLiabilityForDamageCoverageSelect";
534
540
  StoreFormCarVehicleActionTypes["FormCarLimitedWaiverOfDepreciationCoverageSelect"] = "FormCarLimitedWaiverOfDepreciationCoverageSelect";
541
+ StoreFormCarVehicleActionTypes["FormCarAccidentBenefitsBaseCoverageSelect"] = "FormCarAccidentBenefitsBaseCoverageSelect";
542
+ StoreFormCarVehicleActionTypes["FormCarAccidentBenefitsAdditionalCoveragesSet"] = "FormCarAccidentBenefitsAdditionalCoveragesSet";
543
+ StoreFormCarVehicleActionTypes["FormCarAccidentBenefitsAdditionalCoverageRemove"] = "FormCarAccidentBenefitsAdditionalCoverageRemove";
544
+ StoreFormCarVehicleActionTypes["FormCarAccidentBenefitsAcknowledge"] = "FormCarAccidentBenefitsAcknowledge";
535
545
  })(exports.StoreFormCarVehicleActionTypes || (exports.StoreFormCarVehicleActionTypes = {}));
536
546
 
537
547
  const createTab = (name, id) => ({
@@ -565,6 +575,7 @@ const createVehicleItem = (state) => ({
565
575
  comprehensive: state.items[0].comprehensive,
566
576
  collision: state.items[0].collision,
567
577
  liability: state.items[0].liability,
578
+ accidentbenefits: state.items[0].accidentbenefits,
568
579
  },
569
580
  ],
570
581
  tabs: [...state.tabs, { ...createTab('Vehicle', state.tabs.length) }],
@@ -696,6 +707,26 @@ const formCarVehicleStateReducer = (state = { ...carFormVehicleInitialState }, a
696
707
  return setLocalVehicles(action.localIndex, setCarCoverageProperty(state, 'liabilityfordamage', action.payload.coverage, action.payload.limit));
697
708
  case exports.StoreFormCarVehicleActionTypes.FormCarLimitedWaiverOfDepreciationCoverageSelect:
698
709
  return setLocalVehicles(action.localIndex, setCarCoverageProperty(state, 'limitedwaiverofdepreciation', action.payload.coverage, action.payload.limit));
710
+ case exports.StoreFormCarVehicleActionTypes.FormCarAccidentBenefitsBaseCoverageSelect:
711
+ return setLocalVehicles(action.localIndex, setItemProperty(state, 'accidentbenefits', {
712
+ ...state.items[state.activeIndex].accidentbenefits,
713
+ baseCoverage: action.payload.baseCoverage,
714
+ }));
715
+ case exports.StoreFormCarVehicleActionTypes.FormCarAccidentBenefitsAdditionalCoveragesSet:
716
+ return setLocalVehicles(action.localIndex, setItemProperty(state, 'accidentbenefits', {
717
+ ...state.items[state.activeIndex].accidentbenefits,
718
+ additionalCoverages: action.payload.additionalCoverages,
719
+ }));
720
+ case exports.StoreFormCarVehicleActionTypes.FormCarAccidentBenefitsAdditionalCoverageRemove:
721
+ return setLocalVehicles(action.localIndex, setItemProperty(state, 'accidentbenefits', {
722
+ ...state.items[state.activeIndex].accidentbenefits,
723
+ additionalCoverages: state.items[state.activeIndex].accidentbenefits.additionalCoverages.filter((coverage) => coverage !== action.payload.coverageValue),
724
+ }));
725
+ case exports.StoreFormCarVehicleActionTypes.FormCarAccidentBenefitsAcknowledge:
726
+ return setLocalVehicles(action.localIndex, setItemProperty(state, 'accidentbenefits', {
727
+ ...state.items[state.activeIndex].accidentbenefits,
728
+ abAcknowledged: true,
729
+ }));
699
730
  default:
700
731
  return state;
701
732
  }
@@ -3721,6 +3752,16 @@ const useProvince = () => {
3721
3752
  isOntarioProvince: code === OntarioCode,
3722
3753
  };
3723
3754
  };
3755
+ const useAbReform = () => {
3756
+ const { isOntarioProvince } = useProvince();
3757
+ const { discountState } = useTypedSelector((state) => state).formCarState;
3758
+ const { policyStartYear, policyStartMonth, policyStartDay, policyStart, } = discountState;
3759
+ const policyStartDate = policyStartYear && policyStartMonth && policyStartDay
3760
+ ? `${policyStartYear}-${policyStartMonth}-${policyStartDay}`
3761
+ : policyStart;
3762
+ const isAbReformActive = isOntarioProvince && policyStartDate >= '2026-07-01';
3763
+ return { isAbReformActive };
3764
+ };
3724
3765
 
3725
3766
  const useStoreFormHomeQuote = () => {
3726
3767
  const { appConfigState } = useStoreAppConfig();
@@ -5054,9 +5095,12 @@ const CarQuoteDataHandler = () => {
5054
5095
  const postal = mychoiceSdkComponents.deepClone(postalState).item;
5055
5096
  const discount = mychoiceSdkComponents.deepClone(discountState);
5056
5097
  const { policyStartYear, policyStartMonth, policyStartDay } = discountState;
5098
+ const policyStartDate = policyStartYear && policyStartMonth && policyStartDay
5099
+ ? `${policyStartYear}-${policyStartMonth}-${policyStartDay}`
5100
+ : discountState.policyStart;
5057
5101
  // dispatchQuoteState({ type: StoreFormCarQuoteActionTypes.UpdateCarCallMessage, payload: { showCallMessage: false } });
5058
5102
  if (policyStartYear && policyStartMonth && policyStartDay) {
5059
- discount.policyStart = `${policyStartYear}-${policyStartMonth}-${policyStartDay}`;
5103
+ discount.policyStart = policyStartDate;
5060
5104
  delete discount.policyStartYear;
5061
5105
  delete discount.policyStartMonth;
5062
5106
  delete discount.policyStartDay;
@@ -5073,6 +5117,13 @@ const CarQuoteDataHandler = () => {
5073
5117
  provinceName: postal.provinceName,
5074
5118
  };
5075
5119
  requestBody.quoterInfo.recalculate = isRecalc;
5120
+ const isAbReformEligible = requestBody.provinceCode === 'ON' && policyStartDate >= '2026-07-01';
5121
+ // Flag if any Accident Benefits buy-ups are selected (Ontario only)
5122
+ if (isRecalc && isAbReformEligible) {
5123
+ const hasAbChanges = vehicles.some((v) => v.accidentbenefits?.baseCoverage !== 'minimum_required'
5124
+ || v.accidentbenefits?.additionalCoverages?.length > 0);
5125
+ requestBody.quoterInfo.accidentBenefitsChanged = hasAbChanges;
5126
+ }
5076
5127
  delete requestBody.isValid;
5077
5128
  delete requestBody.inValidation;
5078
5129
  if (hasToBeConfirmed !== undefined) {
@@ -5282,7 +5333,20 @@ const CarQuoteDataHandler = () => {
5282
5333
  vehicle.comprehensive.coverage = false;
5283
5334
  vehicle.comprehensive.deductible = 1000;
5284
5335
  }
5285
- return vehicle;
5336
+ const { accidentbenefits, ...vehiclePayload } = vehicle;
5337
+ const transformedVehicle = { ...vehiclePayload };
5338
+ if (accidentbenefits) {
5339
+ const { baseCoverage, additionalCoverages } = accidentbenefits;
5340
+ if (isAbReformEligible
5341
+ && (baseCoverage !== 'minimum_required' || additionalCoverages.length > 0)) {
5342
+ transformedVehicle.accidentBenefits = {
5343
+ baseCoverage,
5344
+ additionalCoverages,
5345
+ };
5346
+ }
5347
+ }
5348
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
5349
+ return transformedVehicle;
5286
5350
  });
5287
5351
  requestBody.vehlinks = localVehlinks;
5288
5352
  return {
@@ -5863,6 +5927,7 @@ const useValidationVehicle = () => {
5863
5927
  const { inValidation: vehicleFormIsInValidation = false, isValid: vehicleFormIsValid = false, } = vehicleState;
5864
5928
  const { appConfigState } = useStoreAppConfig();
5865
5929
  const { dispatchAppModalState } = useStoreAppModal();
5930
+ const { isAbReformActive } = useAbReform();
5866
5931
  const navigate = reactRouterDom.useNavigate();
5867
5932
  const vehicleFormValidate = (isRedirect = true) => {
5868
5933
  let formIsValid = false;
@@ -5893,6 +5958,13 @@ const useValidationVehicle = () => {
5893
5958
  return item;
5894
5959
  });
5895
5960
  });
5961
+ if (isAbReformActive) {
5962
+ vehicleState.items.forEach((item) => {
5963
+ if (!item.accidentbenefits.abAcknowledged) {
5964
+ errors.push('abAcknowledged');
5965
+ }
5966
+ });
5967
+ }
5896
5968
  if (!errors.length) {
5897
5969
  dispatchVehicleState({
5898
5970
  type: exports.StoreFormCarVehicleActionTypes.FormCarVehicleValidateSet,
@@ -5905,12 +5977,15 @@ const useValidationVehicle = () => {
5905
5977
  formIsValid = true;
5906
5978
  }
5907
5979
  else {
5908
- const element = document.getElementsByName(errors[0])[0];
5980
+ const element = document.getElementsByName(errors[0])[0] ?? document.getElementById(errors[0]);
5909
5981
  element?.scrollIntoView({ block: 'center', behavior: 'smooth' });
5982
+ const hasOnlyAbError = errors.every((e) => e === 'abAcknowledged');
5910
5983
  dispatchAppModalState({
5911
5984
  type: exports.StoreConfigAppModalActionTypes.AppModalMessageModal,
5912
5985
  payload: {
5913
- title: 'Please enter missing values of required fields',
5986
+ title: hasOnlyAbError
5987
+ ? 'Please review the Accident Benefits section'
5988
+ : 'Please enter missing values of required fields',
5914
5989
  },
5915
5990
  });
5916
5991
  dispatchVehicleState({
@@ -6924,6 +6999,9 @@ const useAutofillCarForm = (options) => {
6924
6999
  const { dispatchDriverCancellationState } = useStoreFormCarDriverCancellation();
6925
7000
  const { dispatchDriverAccidentState } = useStoreFormCarDriverAccident();
6926
7001
  const { dispatchDriverTicketState } = useStoreFormCarDriverTicket();
7002
+ const { dispatchDriverBaseState } = useStoreFormCarDriverBase();
7003
+ const { dispatchDiscountState } = useStoreFormCarDiscount();
7004
+ const { dispatchQuoteState } = useStoreFormCarQuote();
6927
7005
  const { getVehicleMake } = useHandlerCarMake();
6928
7006
  const { getVehicleModel } = useHandlerCarModel();
6929
7007
  const { dispatchAppModalState } = useStoreAppModal();
@@ -6941,6 +7019,13 @@ const useAutofillCarForm = (options) => {
6941
7019
  }
6942
7020
  // Parse the autofill data
6943
7021
  const autofillData = parseAutofillParam(autofillParam);
7022
+ // Clear all existing car form state before applying autofill data
7023
+ dispatchPostalState({ type: exports.StoreFormCarPostalActionTypes.FormCarPostalClear });
7024
+ dispatchVehicleState({ type: exports.StoreFormCarVehicleActionTypes.FormCarVehicleClear });
7025
+ dispatchConfigState({ type: exports.StoreFormCarConfigActionTypes.FormCarConfigClear, payload: { province: '' } });
7026
+ dispatchDriverBaseState({ type: exports.StoreFormCarDriverBaseActionTypes.FormCarDriverClear });
7027
+ dispatchDiscountState({ type: exports.StoreFormCarDiscountActionTypes.FormCarDiscountClear });
7028
+ dispatchQuoteState({ type: exports.StoreFormCarQuoteActionTypes.FormCarQuoteClear });
6944
7029
  // Dispatch postal state
6945
7030
  const postalData = mapToPostalState(autofillData);
6946
7031
  dispatchPostalState({
@@ -7248,6 +7333,9 @@ const useAutofillCarForm = (options) => {
7248
7333
  dispatchDriverCancellationState,
7249
7334
  dispatchDriverAccidentState,
7250
7335
  dispatchDriverTicketState,
7336
+ dispatchDriverBaseState,
7337
+ dispatchDiscountState,
7338
+ dispatchQuoteState,
7251
7339
  dispatchAppModalState,
7252
7340
  getVehicleMake,
7253
7341
  getVehicleModel,
@@ -7261,6 +7349,7 @@ const useAutofillLifeForm = (options) => {
7261
7349
  const { dispatchPostalState } = useStoreFormLifePostal();
7262
7350
  const { dispatchCoverageState } = useStoreFormLifeCoverage();
7263
7351
  const { dispatchApplicantState } = useStoreFormLifeApplicant();
7352
+ const { dispatchQuoteState } = useStoreFormLifeQuote();
7264
7353
  const { dispatchAppModalState } = useStoreAppModal();
7265
7354
  const autofillProcessedRef = react.useRef(false);
7266
7355
  react.useEffect(() => {
@@ -7276,6 +7365,11 @@ const useAutofillLifeForm = (options) => {
7276
7365
  }
7277
7366
  // Parse the autofill data
7278
7367
  const autofillData = parseLifeAutofillParam(autofillParam);
7368
+ // Clear all existing life form state before applying autofill data
7369
+ dispatchPostalState({ type: exports.StoreFormLifePostalActionTypes.FormLifePostalClear });
7370
+ dispatchCoverageState({ type: exports.StoreFormLifeCoverageActionTypes.FormLifeCoverageClear });
7371
+ dispatchApplicantState({ type: exports.StoreFormLifeApplicantActionTypes.FormLifeApplicantClear });
7372
+ dispatchQuoteState({ type: exports.StoreFormLifeQuoteActionTypes.FormLifeQuoteClear });
7279
7373
  // Map and dispatch postal state
7280
7374
  const postalData = mapToLifePostalState(autofillData);
7281
7375
  dispatchPostalState({
@@ -7426,7 +7520,7 @@ const useAutofillLifeForm = (options) => {
7426
7520
  // Silently fail - let the app continue with normal flow
7427
7521
  console.error('Life autofill initialization error:', error);
7428
7522
  }
7429
- }, [dispatchPostalState, dispatchCoverageState, dispatchApplicantState, dispatchAppModalState]);
7523
+ }, [dispatchPostalState, dispatchCoverageState, dispatchApplicantState, dispatchQuoteState, dispatchAppModalState]);
7430
7524
  };
7431
7525
 
7432
7526
  exports.CarQuoteDataHandler = CarQuoteDataHandler;
@@ -7459,6 +7553,7 @@ exports.parseAutofillParam = parseAutofillParam;
7459
7553
  exports.parseLifeAutofillParam = parseLifeAutofillParam;
7460
7554
  exports.reducers = reducers;
7461
7555
  exports.token = default_1;
7556
+ exports.useAbReform = useAbReform;
7462
7557
  exports.useAutofillCarForm = useAutofillCarForm;
7463
7558
  exports.useAutofillLifeForm = useAutofillLifeForm;
7464
7559
  exports.useHandlerAuth = useHandlerAuth;