@mychoice/mychoice-sdk-modules 2.1.36 → 2.1.37

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
@@ -958,36 +958,35 @@ const SectionDriverInsurancePolicy = () => {
958
958
  const { configState } = mychoiceSdkStore.useStoreFormCarConfig();
959
959
  const { driverState, dispatchDriverInsuranceState } = mychoiceSdkStore.useStoreFormCarDriverInsurance();
960
960
  const { discountState, dispatchDiscountState } = mychoiceSdkStore.useStoreFormCarDiscount();
961
- const { quoteState: { isRequested } } = mychoiceSdkStore.useStoreFormCarQuote();
961
+ const { quoteState: { isRequested }, } = mychoiceSdkStore.useStoreFormCarQuote();
962
962
  const { listed, listedMonth = '', listedYear = '', insured, insuredDate = '', firstName, birthYear, birthMonth, birthDay, licenceInfo: { firstLicenceAge, licenceType, gLicenceYear, gLicenceMonth, g1LicenceYear, g1LicenceMonth, }, } = driverState.items[driverState.activeIndex];
963
963
  const { policyStartYear, policyStartMonth, policyStartDay } = discountState;
964
964
  const driverNameDefault = `Driver ${driverState.activeIndex + 1}`;
965
- const birthDate = birthYear && birthMonth && birthDay ? `${birthYear}-${birthMonth}-${birthDay}` : '';
966
- const { appConfigState: { appType } } = mychoiceSdkStore.useStoreAppConfig();
965
+ const birthDate = birthYear && birthMonth && birthDay
966
+ ? `${birthYear}-${birthMonth}-${birthDay}`
967
+ : '';
968
+ const { appConfigState: { appType }, } = mychoiceSdkStore.useStoreAppConfig();
967
969
  const mychoiceCls = appType === mychoiceSdkComponents.AppTypes.MyChoice ? 'mychoice' : '';
968
970
  const getPeriodOptions = (year, month) => {
969
- const options = [{ value: '', name: 'Date Period', disabled: true }];
971
+ const options = [
972
+ { value: '', name: 'Date Period', disabled: true },
973
+ ];
970
974
  if (year && month) {
971
- const listedDate = mychoiceSdkComponents.addDaysToDate(`${year}-${month}-01`, birthDay ? +birthDay + 1 : 1);
972
- const yearPeriod = mychoiceSdkComponents.getDifferenceInYears('', listedDate) || 0;
973
- for (let y = yearPeriod; y >= 0; y -= 1) {
974
- switch (true) {
975
- case y === 0:
976
- options.push({
977
- value: mychoiceSdkComponents.subMonthsFromDate('', 10),
978
- name: 'Less than 1 Year',
979
- });
980
- break;
981
- case y === 1:
982
- options.push({ value: mychoiceSdkComponents.addYearsToDate(listedDate, y), name: '1 Year' });
983
- break;
984
- default:
985
- options.push({
986
- value: mychoiceSdkComponents.addYearsToDate(listedDate, y),
987
- name: `${y} Years`,
988
- });
989
- }
975
+ const todayDate = new Date();
976
+ const month = String(todayDate.getMonth() + 1).padStart(2, '0');
977
+ const day = String(todayDate.getDate()).padStart(2, '0');
978
+ const yearsInPast = todayDate.getFullYear() - parseInt(year);
979
+ for (let i = yearsInPast; i > 0; i--) {
980
+ const pastDate = `${todayDate.getFullYear() - i}-${month}-${day}`;
981
+ options.push({
982
+ value: pastDate,
983
+ name: `${i} ${i === 1 ? 'Year' : 'Years'}`,
984
+ });
990
985
  }
986
+ options.push({
987
+ value: `${todayDate.getFullYear() - 1}-${month}-${day}`,
988
+ name: 'Less than 1 Year',
989
+ });
991
990
  }
992
991
  return options;
993
992
  };
@@ -1027,7 +1026,9 @@ you had insurance. If this is correct, please continue with the form.`);
1027
1026
  }
1028
1027
  };
1029
1028
  if (birthDate) {
1030
- const defaultMinDate = birthDate && firstLicenceAge ? mychoiceSdkComponents.addYearsToDate(birthDate, +firstLicenceAge) : '';
1029
+ const defaultMinDate = birthDate && firstLicenceAge
1030
+ ? mychoiceSdkComponents.addYearsToDate(birthDate, +firstLicenceAge)
1031
+ : '';
1031
1032
  const isOnlyG = mychoiceSdkComponents.checkDateIsSpecial(defaultMinDate, configState.minDates.g.specialDate);
1032
1033
  if (isOnlyG) {
1033
1034
  setMessage(gLicenceYear, gLicenceMonth);
@@ -1046,7 +1047,16 @@ you had insurance. If this is correct, please continue with the form.`);
1046
1047
  else {
1047
1048
  setHintMessage('');
1048
1049
  }
1049
- }, [listedYear, listedMonth, g1LicenceYear, g1LicenceMonth, firstLicenceAge, birthDate, gLicenceYear, gLicenceMonth]);
1050
+ }, [
1051
+ listedYear,
1052
+ listedMonth,
1053
+ g1LicenceYear,
1054
+ g1LicenceMonth,
1055
+ firstLicenceAge,
1056
+ birthDate,
1057
+ gLicenceYear,
1058
+ gLicenceMonth,
1059
+ ]);
1050
1060
  const handleInsuredChange = ({ value }) => {
1051
1061
  dispatchDriverInsuranceState({
1052
1062
  type: mychoiceSdkStore.StoreFormCarDriverInsuranceActionTypes.FormCarDriverInsuredSelect,
@@ -1099,12 +1109,11 @@ you had insurance. If this is correct, please continue with the form.`);
1099
1109
  });
1100
1110
  }
1101
1111
  };
1102
- return (jsxRuntime.jsxs("div", { className: `form-section ${mychoiceCls}`, children: [jsxRuntime.jsxs("div", { className: "box-container", children: [jsxRuntime.jsx(DateSelectFormBox, { name: "listedYear", dateNames: ['listedYear', 'listedMonth'], onDateChange: handleListedDateChange, defaultValue: defaultListedDate, disabled: !listed, title: `When was ${firstName || driverNameDefault} first listed as a driver on a Canadian or US insurance policy?`, description: "The selection indicates what year the main driver was first listed on a Canadian or US insurance policy. If you do not remember your age, it is acceptable to provide a best estimate for the purposes of the policy or quote.", errorMessage: listed ? getDateErrorMessage(['01', listedMonth, listedYear], driverState.inValidation) : '', error: driverState.inValidation, hintMessage: hintMessage, minDate: mychoiceSdkComponents.getMinDate(birthDate, firstLicenceAge) }), jsxRuntime.jsx(mychoiceSdkComponents.CheckboxForm, { name: "listed", label: "Never listed on an insurance policy", onChange: handleListedChange, defaultValue: !listed })] }), listed
1103
- && (jsxRuntime.jsxs("div", { className: "box-container", children: [jsxRuntime.jsx(SelectFormBox, { name: "insuredDate", onChange: handleInsuredPeriodChange, options: getPeriodOptions(listedYear, listedMonth), defaultValue: insuredDate, disabled: !insured, title: `How long has ${firstName || driverNameDefault} been with their current insurance provider?`, description: "It is common for insurers to provide loyalty rewards or discounts for valued customers. Loyalty is a positive trait in the industry, and most insurance companies will want to provide some incentive for continued customer relationships through tangible policy rewards.", errorMessage: insured ? getErrorMessage(insuredDate, driverState.inValidation) : '', error: !insuredDate && driverState.inValidation }), jsxRuntime.jsx(mychoiceSdkComponents.CheckboxForm, { name: "insured", label: "Not currently insured", onChange: handleInsuredChange, defaultValue: !insured })] })), jsxRuntime.jsx(DateSelectFormBox, { name: "policyStart", dateNames: ['policyStartYear', 'policyStartMonth', 'policyStartDay'], onDateChange: handlePolicyStartDateChange, defaultValue: defaultPolicyStartDate, title: "What is the ideal start date for your new insurance policy?", description: "Select your preferred date for the beginning of your new insurance policy.For instance, you may set the start date for the day that your current insurance expires to ensure that you\u2019re continuously covered. Alternatively, select today's date for a quote or new policy.", errorMessage: getDateErrorMessage([
1104
- policyStartDay || '',
1105
- policyStartMonth || '',
1106
- policyStartYear || '',
1107
- ], driverState.inValidation), error: driverState.inValidation, minDate: mychoiceSdkComponents.addDaysToDate('', 1), maxDate: mychoiceSdkComponents.addDaysToDate('', 60), isDay: true })] }));
1112
+ return (jsxRuntime.jsxs("div", { className: `form-section ${mychoiceCls}`, children: [jsxRuntime.jsxs("div", { className: "box-container", children: [jsxRuntime.jsx(DateSelectFormBox, { name: "listedYear", dateNames: ['listedYear', 'listedMonth'], onDateChange: handleListedDateChange, defaultValue: defaultListedDate, disabled: !listed, title: `When was ${firstName || driverNameDefault} first listed as a driver on a Canadian or US insurance policy?`, description: "The selection indicates what year the main driver was first listed on a Canadian or US insurance policy. If you do not remember your age, it is acceptable to provide a best estimate for the purposes of the policy or quote.", errorMessage: listed
1113
+ ? getDateErrorMessage(['01', listedMonth, listedYear], driverState.inValidation)
1114
+ : '', error: driverState.inValidation, hintMessage: hintMessage, minDate: mychoiceSdkComponents.getMinDate(birthDate, firstLicenceAge) }), jsxRuntime.jsx(mychoiceSdkComponents.CheckboxForm, { name: "listed", label: "Never listed on an insurance policy", onChange: handleListedChange, defaultValue: !listed })] }), listed && (jsxRuntime.jsxs("div", { className: "box-container", children: [jsxRuntime.jsx(SelectFormBox, { name: "insuredDate", onChange: handleInsuredPeriodChange, options: getPeriodOptions(listedYear, listedMonth), defaultValue: insuredDate, disabled: !insured, title: `How long has ${firstName || driverNameDefault} been with their current insurance provider?`, description: "It is common for insurers to provide loyalty rewards or discounts for valued customers. Loyalty is a positive trait in the industry, and most insurance companies will want to provide some incentive for continued customer relationships through tangible policy rewards.", errorMessage: insured
1115
+ ? getErrorMessage(insuredDate, driverState.inValidation)
1116
+ : '', error: !insuredDate && driverState.inValidation }), jsxRuntime.jsx(mychoiceSdkComponents.CheckboxForm, { name: "insured", label: "Not currently insured", onChange: handleInsuredChange, defaultValue: !insured })] })), jsxRuntime.jsx(DateSelectFormBox, { name: "policyStart", dateNames: ['policyStartYear', 'policyStartMonth', 'policyStartDay'], onDateChange: handlePolicyStartDateChange, defaultValue: defaultPolicyStartDate, title: "What is the ideal start date for your new insurance policy?", description: "Select your preferred date for the beginning of your new insurance policy.For instance, you may set the start date for the day that your current insurance expires to ensure that you\u2019re continuously covered. Alternatively, select today's date for a quote or new policy.", errorMessage: getDateErrorMessage([policyStartDay || '', policyStartMonth || '', policyStartYear || ''], driverState.inValidation), error: driverState.inValidation, minDate: mychoiceSdkComponents.addDaysToDate('', 1), maxDate: mychoiceSdkComponents.addDaysToDate('', 60), isDay: true })] }));
1108
1117
  };
1109
1118
 
1110
1119
  const SectionDriverCancellation = () => {