@mychoice/mychoice-sdk-modules 2.2.29 → 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/cjs/index.js +42 -34
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +43 -35
- package/dist/esm/index.js.map +1 -1
- package/package.json +3 -3
package/dist/cjs/index.js
CHANGED
|
@@ -218,8 +218,8 @@ const BlockVehLinks = () => {
|
|
|
218
218
|
const { vehicleState: { items: vehicles } } = mychoiceSdkStore.useStoreFormCarVehicle();
|
|
219
219
|
const { driverState: { items: drivers } } = mychoiceSdkStore.useStoreFormCarDriverBase();
|
|
220
220
|
const { discountState: { vehlinks, occVehlinks, inValidation }, dispatchDiscountState } = mychoiceSdkStore.useStoreFormCarDiscount();
|
|
221
|
-
|
|
222
|
-
const
|
|
221
|
+
const equalCounts = drivers.length === vehicles.length;
|
|
222
|
+
const askedVehicleCount = equalCounts ? vehicles.length - 1 : vehicles.length;
|
|
223
223
|
const assignPrimary = (driverIndex, vehicleIndex) => {
|
|
224
224
|
dispatchDiscountState({
|
|
225
225
|
type: mychoiceSdkStore.StoreFormCarDiscountActionTypes.FormCarDiscountVehlinkSelect,
|
|
@@ -227,31 +227,31 @@ const BlockVehLinks = () => {
|
|
|
227
227
|
});
|
|
228
228
|
};
|
|
229
229
|
React.useEffect(() => {
|
|
230
|
-
if (!
|
|
230
|
+
if (!equalCounts || drivers.length <= 1)
|
|
231
231
|
return;
|
|
232
|
-
const
|
|
233
|
-
|
|
232
|
+
const primaryOf = (vehicleIndex) => vehlinks.find((l) => l.vehicleIndex === vehicleIndex && l.priority === mychoiceSdkComponents.DriverPriorityTypes.Prn)?.driverIndex ?? -1;
|
|
233
|
+
const askedDrivers = new Set();
|
|
234
|
+
for (let vehicleIndex = 0; vehicleIndex < askedVehicleCount; vehicleIndex += 1) {
|
|
235
|
+
const po = primaryOf(vehicleIndex);
|
|
236
|
+
if (po < 0)
|
|
237
|
+
return;
|
|
238
|
+
askedDrivers.add(po);
|
|
239
|
+
}
|
|
240
|
+
if (askedDrivers.size !== askedVehicleCount)
|
|
234
241
|
return;
|
|
235
|
-
const
|
|
236
|
-
if (
|
|
242
|
+
const remainingDriver = drivers.findIndex((_, driverIndex) => !askedDrivers.has(driverIndex));
|
|
243
|
+
if (remainingDriver < 0)
|
|
237
244
|
return;
|
|
238
|
-
const
|
|
239
|
-
if (
|
|
245
|
+
const lastVehicleIndex = vehicles.length - 1;
|
|
246
|
+
if (primaryOf(lastVehicleIndex) === remainingDriver)
|
|
240
247
|
return;
|
|
241
|
-
assignPrimary(
|
|
242
|
-
}, [
|
|
248
|
+
assignPrimary(remainingDriver, lastVehicleIndex);
|
|
249
|
+
}, [equalCounts, askedVehicleCount, vehlinks, drivers, vehicles]);
|
|
243
250
|
if (drivers.length <= 1) {
|
|
244
251
|
return null;
|
|
245
252
|
}
|
|
246
253
|
const handlePrimaryDriverChange = (vehicleIndex) => ({ value }) => {
|
|
247
|
-
|
|
248
|
-
assignPrimary(driverIndex, vehicleIndex);
|
|
249
|
-
if (isTwoByTwo && vehicleIndex === 0) {
|
|
250
|
-
const otherDriverIndex = drivers.findIndex((_, index) => index !== driverIndex);
|
|
251
|
-
if (otherDriverIndex >= 0) {
|
|
252
|
-
assignPrimary(otherDriverIndex, 1);
|
|
253
|
-
}
|
|
254
|
-
}
|
|
254
|
+
assignPrimary(value === '' ? -1 : Number(value), vehicleIndex);
|
|
255
255
|
};
|
|
256
256
|
const handleOccDriverChange = (driverIndex) => ({ value }) => {
|
|
257
257
|
dispatchDiscountState({
|
|
@@ -269,24 +269,32 @@ const BlockVehLinks = () => {
|
|
|
269
269
|
const unassignedDrivers = drivers
|
|
270
270
|
.map((driver, index) => ({ driver, index }))
|
|
271
271
|
.filter(({ index }) => !primaryDriverIndices.includes(index));
|
|
272
|
-
const vehiclesToAsk =
|
|
272
|
+
const vehiclesToAsk = vehicles.slice(0, askedVehicleCount);
|
|
273
|
+
const primaryQuestionsAnswered = vehiclesToAsk.every((_vehicle, vehicleIndex) => vehlinks.some((l) => l.vehicleIndex === vehicleIndex
|
|
274
|
+
&& l.priority === mychoiceSdkComponents.DriverPriorityTypes.Prn
|
|
275
|
+
&& l.driverIndex >= 0));
|
|
276
|
+
const primaryQuestionsAreUnique = new Set(primaryDriverIndices).size >= vehicles.length;
|
|
277
|
+
const shouldAskOccasional = drivers.length > vehicles.length
|
|
278
|
+
&& vehicles.length > 1
|
|
279
|
+
&& primaryQuestionsAnswered
|
|
280
|
+
&& primaryQuestionsAreUnique;
|
|
273
281
|
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.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) => {
|
|
274
282
|
const { year, make, model } = vehicle;
|
|
275
283
|
const selectedPrimary = vehlinks.find((l) => l.vehicleIndex === vehicleIndex && l.priority === mychoiceSdkComponents.DriverPriorityTypes.Prn);
|
|
276
284
|
const isPrimaryAnswered = selectedPrimary !== undefined && selectedPrimary.driverIndex >= 0;
|
|
277
|
-
|
|
285
|
+
const previousPrimaryDriverIndices = new Set(vehlinks
|
|
286
|
+
.filter((l) => l.vehicleIndex < vehicleIndex
|
|
287
|
+
&& l.priority === mychoiceSdkComponents.DriverPriorityTypes.Prn
|
|
288
|
+
&& l.driverIndex >= 0)
|
|
289
|
+
.map((l) => l.driverIndex));
|
|
290
|
+
const allDriversHavePrimary = drivers.every((_, driverIndex) => vehlinks.some((l) => l.priority === mychoiceSdkComponents.DriverPriorityTypes.Prn && l.driverIndex === driverIndex));
|
|
291
|
+
const canRepeatPrimary = vehicles.length > drivers.length && allDriversHavePrimary;
|
|
278
292
|
const primaryOptions = drivers
|
|
279
|
-
.map((driver, driverIndex) => ({ name: driver.firstName, value: driverIndex }))
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
&& l.priority === mychoiceSdkComponents.DriverPriorityTypes.Prn
|
|
285
|
-
&& l.driverIndex === selectedPrimary?.driverIndex);
|
|
286
|
-
return (jsxRuntime.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
|
|
287
|
-
? 'This driver is already the primary driver of another vehicle. Each vehicle should have a different primary driver.'
|
|
288
|
-
: '' }, `vehlink-${vehicleIndex}`));
|
|
289
|
-
}), drivers.length > vehicles.length && vehicles.length > 1
|
|
293
|
+
.map((driver, driverIndex) => ({ name: driver.firstName, value: driverIndex }))
|
|
294
|
+
.filter(({ value }) => canRepeatPrimary
|
|
295
|
+
|| !previousPrimaryDriverIndices.has(value));
|
|
296
|
+
return (jsxRuntime.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}`));
|
|
297
|
+
}), shouldAskOccasional
|
|
290
298
|
&& unassignedDrivers.map(({ driver, index: driverIndex }) => {
|
|
291
299
|
const selectedVehicle = occVehlinks.find((l) => l.driverIndex === driverIndex);
|
|
292
300
|
const vehicleOptions = vehicles.map((vehicle, vehicleIndex) => ({
|
|
@@ -1582,7 +1590,7 @@ const SectionDriverLicence = () => {
|
|
|
1582
1590
|
};
|
|
1583
1591
|
const g2MaxDate = getMax60Date(q1Date);
|
|
1584
1592
|
const gMaxDate = getMax60Date(q1Date);
|
|
1585
|
-
return (jsxRuntime.jsxs("div", { className: `form-section ${mychoiceCls}`, children: [jsxRuntime.jsx(DateSelectFormBox, { name: "firstLicenceDate", dateNames: ['firstLicenceYear', 'firstLicenceMonth'], onDateChange: handleLicenceDateChange(q1SlotType), defaultValue: getDefaultLicenceDate(q1SlotType), title: `When did ${driverName} first receive their drivers license in Canada?`, description: "Select the year and month in which you received your first license to drive an automobile in Canada. This would include a beginners, intermediate or full license.", errorMessage: q1Error, error: driverState.inValidation, minDate: q1MinDate, maxDate: today, disabled: !birthDate }), q1Date && (jsxRuntime.jsx(SelectFormBox, { options: isOnlyG ? ontarioOnlyGOptions : ontarioFirstClassOptions, name: "firstLicenceClass", onChange: handleLicenceTypeChange, defaultValue: getSelectedOption(isOnlyG ? ontarioOnlyGOptions : ontarioFirstClassOptions, firstClass), title: "What class of license was it?", placeholder: "Select from the list", description: "Drivers licensed in Ontario under the graduated licensing program would select G1 Beginner. If the driver was licensed outside Ontario or granted an exception for having driving experience from another jurisdiction then select the license class they first received. Select class G Full or equivalent if the driver was licensed in Ontario before 1994 or was licensed in another province. G equivalent classes in Canada are class 5.", autoSelectIfValueIsOutOfOptions: false })), firstClass === mychoiceSdkComponents.DriverLicenceTypes.G1 && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [showDtcG1Only && (jsxRuntime.jsx(SwitchButtonBox, { items: mychoiceSdkComponents.yesNoOptions, onChange: handleTrainingChange, name: "passedDriverTraining", defaultValue: getSelectedOption(mychoiceSdkComponents.yesNoOptions, passedDriverTraining), title: `Has ${driverName} completed a gov't approved drivers education course within the past
|
|
1593
|
+
return (jsxRuntime.jsxs("div", { className: `form-section ${mychoiceCls}`, children: [jsxRuntime.jsx(DateSelectFormBox, { name: "firstLicenceDate", dateNames: ['firstLicenceYear', 'firstLicenceMonth'], onDateChange: handleLicenceDateChange(q1SlotType), defaultValue: getDefaultLicenceDate(q1SlotType), title: `When did ${driverName} first receive their drivers license in Canada?`, description: "Select the year and month in which you received your first license to drive an automobile in Canada. This would include a beginners, intermediate or full license.", errorMessage: q1Error, error: driverState.inValidation, minDate: q1MinDate, maxDate: today, disabled: !birthDate }), q1Date && (jsxRuntime.jsx(SelectFormBox, { options: isOnlyG ? ontarioOnlyGOptions : ontarioFirstClassOptions, name: "firstLicenceClass", onChange: handleLicenceTypeChange, defaultValue: getSelectedOption(isOnlyG ? ontarioOnlyGOptions : ontarioFirstClassOptions, firstClass), title: "What class of license was it?", placeholder: "Select from the list", description: "Drivers licensed in Ontario under the graduated licensing program would select G1 Beginner. If the driver was licensed outside Ontario or granted an exception for having driving experience from another jurisdiction then select the license class they first received. Select class G Full or equivalent if the driver was licensed in Ontario before 1994 or was licensed in another province. G equivalent classes in Canada are class 5.", autoSelectIfValueIsOutOfOptions: false })), firstClass === mychoiceSdkComponents.DriverLicenceTypes.G1 && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [showDtcG1Only && (jsxRuntime.jsx(SwitchButtonBox, { items: mychoiceSdkComponents.yesNoOptions, onChange: handleTrainingChange, name: "passedDriverTraining", defaultValue: getSelectedOption(mychoiceSdkComponents.yesNoOptions, passedDriverTraining), title: `Has ${driverName} completed a gov't approved drivers education course within the past 3 years?` })), jsxRuntime.jsx(SwitchButtonBox, { items: mychoiceSdkComponents.yesNoOptions, onChange: handleReceivedG2Change, name: "receivedG2", defaultValue: getSelectedOption(mychoiceSdkComponents.yesNoOptions, receivedG2), title: `Did ${driverName} receive a G2 license?` }), showG2Date && (jsxRuntime.jsx(DateSelectFormBox, { name: "g2LicenceDate", dateNames: ['g2LicenceYear', 'g2LicenceMonth'], onDateChange: handleLicenceDateChange(mychoiceSdkComponents.DriverLicenceTypes.G2), defaultValue: getDefaultLicenceDate(mychoiceSdkComponents.DriverLicenceTypes.G2), title: `When did ${driverName} receive this G2 license?`, errorMessage: g2Error, error: driverState.inValidation, minDate: g2MinDate, maxDate: g2MaxDate })), showGQuestionAfterG1 && (jsxRuntime.jsx(SwitchButtonBox, { items: mychoiceSdkComponents.yesNoOptions, onChange: handleReceivedGChange, name: "receivedG", defaultValue: getSelectedOption(mychoiceSdkComponents.yesNoOptions, receivedG), title: `Did ${driverName} receive a G license?` })), showGDateAfterG1 && (jsxRuntime.jsx(DateSelectFormBox, { name: "gLicenceDate", dateNames: ['gLicenceYear', 'gLicenceMonth'], onDateChange: handleLicenceDateChange(mychoiceSdkComponents.DriverLicenceTypes.G), defaultValue: getDefaultLicenceDate(mychoiceSdkComponents.DriverLicenceTypes.G), title: `When did ${driverName} receive this G license?`, errorMessage: gError, error: driverState.inValidation, minDate: gMinDate, maxDate: gMaxDate }))] })), firstClass === mychoiceSdkComponents.DriverLicenceTypes.G2 && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [showDtcG2Only && (jsxRuntime.jsx(SwitchButtonBox, { items: mychoiceSdkComponents.yesNoOptions, onChange: handleTrainingChange, name: "passedDriverTraining", defaultValue: getSelectedOption(mychoiceSdkComponents.yesNoOptions, passedDriverTraining), title: `Has ${driverName} completed a gov't approved drivers education course within the past 3 years?` })), jsxRuntime.jsx(SwitchButtonBox, { items: mychoiceSdkComponents.yesNoOptions, onChange: handleReceivedGChange, name: "receivedG", defaultValue: getSelectedOption(mychoiceSdkComponents.yesNoOptions, receivedG), title: `Did ${driverName} receive a G license?` }), showGDateAfterG2 && (jsxRuntime.jsx(DateSelectFormBox, { name: "gLicenceDate", dateNames: ['gLicenceYear', 'gLicenceMonth'], onDateChange: handleLicenceDateChange(mychoiceSdkComponents.DriverLicenceTypes.G), defaultValue: getDefaultLicenceDate(mychoiceSdkComponents.DriverLicenceTypes.G), title: `When did ${driverName} receive this G license?`, errorMessage: gError, error: driverState.inValidation, minDate: gMinDate, maxDate: gMaxDate }))] })), firstClass === mychoiceSdkComponents.DriverLicenceTypes.G && !isOnlyG && showDtcGFull && (jsxRuntime.jsx(SwitchButtonBox, { items: mychoiceSdkComponents.yesNoOptions, onChange: handleTrainingChange, name: "passedDriverTraining", defaultValue: getSelectedOption(mychoiceSdkComponents.yesNoOptions, passedDriverTraining), title: `Has ${driverName} completed a gov't approved drivers education course within the past 3 years?` })), isOnlyG && showDtcGFull && (jsxRuntime.jsx(SwitchButtonBox, { items: mychoiceSdkComponents.yesNoOptions, onChange: handleTrainingChange, name: "passedDriverTraining", defaultValue: getSelectedOption(mychoiceSdkComponents.yesNoOptions, passedDriverTraining), title: `Has ${driverName} completed a gov't approved drivers education course within the past 3 years?` })), jsxRuntime.jsx(SwitchButtonBox, { items: mychoiceSdkComponents.yesNoOptions, onChange: handlePreviousLicenceChange, name: "previousLicence", defaultValue: getSelectedOption(mychoiceSdkComponents.yesNoOptions, previousLicence), title: `Has ${driverName} ever had a full license anywhere else in Canada or USA?`, description: "If you have driving experience outside Canada or the United States, it may lower your premium. Your insurer may require proof of insurance in these other locations or some proof of driving experience from the country you indicate (like a copy of a previous driver's licence)." })] }));
|
|
1586
1594
|
}
|
|
1587
1595
|
return (jsxRuntime.jsxs("div", { className: `form-section ${mychoiceCls}`, children: [jsxRuntime.jsx(InputFormBox, { name: "firstLicenceAge", title: getLicenceAgeTitle(), onChange: handleLicenceAgeChange, type: mychoiceSdkComponents.InputTypes.Number, defaultValue: firstLicenceAge, description: configState.toolTip.licenceAge, hintMessage: birthDate
|
|
1588
1596
|
? `${driverName} was licenced in ${Number(birthYear) + Number(firstLicenceAge)} - ${Number(birthYear) + Number(firstLicenceAge) + 1}`
|
|
@@ -1770,7 +1778,7 @@ you had insurance. If this is correct, please continue with the form.`);
|
|
|
1770
1778
|
const firstInsuredMinDate = listedYear && listedMonth
|
|
1771
1779
|
? mychoiceSdkComponents.addDaysToDate(`${listedYear}-${listedMonth}-01`, birthDay ? +birthDay + 1 : 1)
|
|
1772
1780
|
: mychoiceSdkComponents.getMinDate(birthDate, firstLicenceAge);
|
|
1773
|
-
const twentyYearsAgo = mychoiceSdkComponents.
|
|
1781
|
+
const twentyYearsAgo = mychoiceSdkComponents.subYearsFromDate('', 20);
|
|
1774
1782
|
let lastPolicyEndMinDate = twentyYearsAgo;
|
|
1775
1783
|
if (firstInsuredMinDate && mychoiceSdkComponents.compareDates(firstInsuredMinDate, twentyYearsAgo) > 0) {
|
|
1776
1784
|
lastPolicyEndMinDate = firstInsuredMinDate;
|