@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/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
|
@@ -135,7 +135,7 @@ const SwitchButtonBox = (props) => {
|
|
|
135
135
|
}
|
|
136
136
|
return '';
|
|
137
137
|
};
|
|
138
|
-
const isAnswered = activeId
|
|
138
|
+
const isAnswered = activeId !== '' && activeId !== undefined && activeId !== null;
|
|
139
139
|
const handleClick = React.useCallback((selectedItem) => () => {
|
|
140
140
|
setActiveId(selectedItem.value);
|
|
141
141
|
if (onChange) {
|
|
@@ -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) => ({
|
|
@@ -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;
|