@mychoice/mychoice-sdk-store 2.1.27 → 2.1.36
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 +81 -48
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +81 -48
- package/dist/esm/index.js.map +1 -1
- package/package.json +2 -2
package/dist/cjs/index.js
CHANGED
|
@@ -523,7 +523,7 @@ const removeVehicleItem = (state, vehicleIndex) => {
|
|
|
523
523
|
if (r !== vehicleIndex) {
|
|
524
524
|
newItems.push(state.items[r]);
|
|
525
525
|
newTabs.push({
|
|
526
|
-
name: state.items[r].make || `Vehicle ${
|
|
526
|
+
name: state.items[r].make || `Vehicle ${newItems.length}`,
|
|
527
527
|
index: newItems.length - 1,
|
|
528
528
|
});
|
|
529
529
|
}
|
|
@@ -531,7 +531,9 @@ const removeVehicleItem = (state, vehicleIndex) => {
|
|
|
531
531
|
return {
|
|
532
532
|
items: newItems,
|
|
533
533
|
tabs: newTabs,
|
|
534
|
-
activeIndex: state.activeIndex >
|
|
534
|
+
activeIndex: state.activeIndex > newItems.length - 1
|
|
535
|
+
? newItems.length - 1
|
|
536
|
+
: state.activeIndex,
|
|
535
537
|
};
|
|
536
538
|
};
|
|
537
539
|
const createVehicleItem = (state) => ({
|
|
@@ -542,7 +544,7 @@ const createVehicleItem = (state) => ({
|
|
|
542
544
|
comprehensive: state.items[0].comprehensive,
|
|
543
545
|
collision: state.items[0].collision,
|
|
544
546
|
liability: state.items[0].liability,
|
|
545
|
-
}
|
|
547
|
+
},
|
|
546
548
|
],
|
|
547
549
|
tabs: [...state.tabs, { ...createTab('Vehicle', state.tabs.length) }],
|
|
548
550
|
activeIndex: state.tabs.length,
|
|
@@ -578,26 +580,16 @@ const setItemProperty = (state, name, value) => {
|
|
|
578
580
|
return newState;
|
|
579
581
|
};
|
|
580
582
|
const setCarCoverageProperty = (state, name, coverage, value) => {
|
|
581
|
-
const newState = mychoiceSdkComponents.deepClone(state);
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
return newItem;
|
|
586
|
-
});
|
|
583
|
+
const newState = JSON.parse(JSON.stringify(mychoiceSdkComponents.deepClone(state)));
|
|
584
|
+
const vehicleIndex = state.activeIndex;
|
|
585
|
+
const newItem = newState.items[vehicleIndex];
|
|
586
|
+
newItem[name].coverage = coverage;
|
|
587
587
|
if (coverage) {
|
|
588
588
|
if (name === mychoiceSdkComponents.CoverageTypes.Liability) {
|
|
589
|
-
|
|
590
|
-
const newItem = item;
|
|
591
|
-
newItem[name].limit = Number(value);
|
|
592
|
-
return newItem;
|
|
593
|
-
});
|
|
589
|
+
newItem[name].limit = Number(value);
|
|
594
590
|
}
|
|
595
591
|
else {
|
|
596
|
-
|
|
597
|
-
const newItem = item;
|
|
598
|
-
newItem[name].deductible = Number(value);
|
|
599
|
-
return newItem;
|
|
600
|
-
});
|
|
592
|
+
newItem[name].deductible = Number(value);
|
|
601
593
|
}
|
|
602
594
|
}
|
|
603
595
|
return newState;
|
|
@@ -660,7 +652,6 @@ const formCarVehicleStateReducer = (state = { ...carFormVehicleInitialState }, a
|
|
|
660
652
|
return setLocalVehicles(action.localIndex, setItemProperty(state, 'distanceBusiness', action.payload.distanceBusiness));
|
|
661
653
|
case exports.StoreFormCarVehicleActionTypes.FormCarYearlyDistanceSelect:
|
|
662
654
|
return setLocalVehicles(action.localIndex, setItemProperty(state, 'distanceYearly', action.payload.distanceYearly));
|
|
663
|
-
// coverage
|
|
664
655
|
case exports.StoreFormCarVehicleActionTypes.FormCarComprehensiveCoverageSelect:
|
|
665
656
|
return setLocalVehicles(action.localIndex, setCarCoverageProperty(state, 'comprehensive', action.payload.coverage, action.payload.deductible));
|
|
666
657
|
case exports.StoreFormCarVehicleActionTypes.FormCarCollisionCoverageSelect:
|
|
@@ -668,7 +659,9 @@ const formCarVehicleStateReducer = (state = { ...carFormVehicleInitialState }, a
|
|
|
668
659
|
case exports.StoreFormCarVehicleActionTypes.FormCarLiabilityCoverageSelect:
|
|
669
660
|
return setLocalVehicles(action.localIndex, setCarCoverageProperty(state, 'liability', action.payload.coverage, action.payload.limit));
|
|
670
661
|
case exports.StoreFormCarVehicleActionTypes.FormCarVehicleClear:
|
|
671
|
-
return setLocalVehicles(action.localIndex, {
|
|
662
|
+
return setLocalVehicles(action.localIndex, {
|
|
663
|
+
...carFormVehicleInitialState,
|
|
664
|
+
});
|
|
672
665
|
default:
|
|
673
666
|
return state;
|
|
674
667
|
}
|
|
@@ -4365,7 +4358,9 @@ const useHandlerPostal = (insuranceType) => {
|
|
|
4365
4358
|
const { dwellingState, dispatchDwellingState } = useStoreFormHomeDwelling();
|
|
4366
4359
|
const { dispatchConfigState: dispatchCarConfigState } = useStoreFormCarConfig();
|
|
4367
4360
|
const { dispatchAppModalState } = useStoreAppModal();
|
|
4368
|
-
const [requestState, setRequestState] = react.useReducer(dataHandlerReducer, {
|
|
4361
|
+
const [requestState, setRequestState] = react.useReducer(dataHandlerReducer, {
|
|
4362
|
+
...initialHandlerRequestState,
|
|
4363
|
+
});
|
|
4369
4364
|
const { cancelToken } = useCancelToken();
|
|
4370
4365
|
const { status, successMessage, responseData, errorMessage, isFirstRequest, responseError, } = requestState;
|
|
4371
4366
|
const getPostal = async (postalCode) => {
|
|
@@ -4388,8 +4383,13 @@ const useHandlerPostal = (insuranceType) => {
|
|
|
4388
4383
|
type: exports.StoreFormCarConfigActionTypes.FormCarConfigSet,
|
|
4389
4384
|
payload: { province: response.data.provinceCode },
|
|
4390
4385
|
});
|
|
4391
|
-
dispatchAppModalState({
|
|
4392
|
-
|
|
4386
|
+
dispatchAppModalState({
|
|
4387
|
+
type: exports.StoreConfigAppModalActionTypes.AppModalClose,
|
|
4388
|
+
});
|
|
4389
|
+
setRequestState({
|
|
4390
|
+
type: DataHandlerActionTypes.SetSuccess,
|
|
4391
|
+
payload: response.data,
|
|
4392
|
+
});
|
|
4393
4393
|
return { errorMessage: '' };
|
|
4394
4394
|
}
|
|
4395
4395
|
setRequestState({
|
|
@@ -4404,7 +4404,9 @@ const useHandlerPostal = (insuranceType) => {
|
|
|
4404
4404
|
});
|
|
4405
4405
|
return { errorMessage: 'Postal Code Is Not Supported' };
|
|
4406
4406
|
}
|
|
4407
|
-
if (insuranceType === mychoiceSdkComponents.InsuranceTypes.Home ||
|
|
4407
|
+
if (insuranceType === mychoiceSdkComponents.InsuranceTypes.Home ||
|
|
4408
|
+
insuranceType === mychoiceSdkComponents.InsuranceTypes.Condo ||
|
|
4409
|
+
insuranceType === mychoiceSdkComponents.InsuranceTypes.Tenant) {
|
|
4408
4410
|
const response = await httpRequest({
|
|
4409
4411
|
url: `${mychoiceSdkComponents.API_FORM_HOME.GET_POSTAL}?postal_code=${postalCode}`,
|
|
4410
4412
|
method: mychoiceSdkComponents.RequestTypes.Get,
|
|
@@ -4417,13 +4419,20 @@ const useHandlerPostal = (insuranceType) => {
|
|
|
4417
4419
|
type: exports.StoreFormHomePostalActionTypes.FormHomePostalSet,
|
|
4418
4420
|
payload: { ...response.data },
|
|
4419
4421
|
});
|
|
4420
|
-
dispatchAppModalState({
|
|
4421
|
-
|
|
4422
|
+
dispatchAppModalState({
|
|
4423
|
+
type: exports.StoreConfigAppModalActionTypes.AppModalClose,
|
|
4424
|
+
});
|
|
4425
|
+
setRequestState({
|
|
4426
|
+
type: DataHandlerActionTypes.SetSuccess,
|
|
4427
|
+
payload: response.data,
|
|
4428
|
+
});
|
|
4422
4429
|
return { errorMessage: '', data: response.data };
|
|
4423
4430
|
}
|
|
4424
4431
|
dispatchHomePostalState({
|
|
4425
4432
|
type: exports.StoreFormHomePostalActionTypes.FormHomePostalErrorMessageSet,
|
|
4426
|
-
payload: {
|
|
4433
|
+
payload: {
|
|
4434
|
+
errorMessage: 'Something went wrong! Please try again.',
|
|
4435
|
+
},
|
|
4427
4436
|
});
|
|
4428
4437
|
return { errorMessage: 'Something went wrong! Please try again.' };
|
|
4429
4438
|
}
|
|
@@ -4431,7 +4440,10 @@ const useHandlerPostal = (insuranceType) => {
|
|
|
4431
4440
|
type: exports.StoreFormHomePostalActionTypes.FormHomePostalErrorMessageSet,
|
|
4432
4441
|
payload: { errorMessage: 'Postal Code Is Not Supported' },
|
|
4433
4442
|
});
|
|
4434
|
-
return {
|
|
4443
|
+
return {
|
|
4444
|
+
errorMessage: 'Postal Code Is Not Supported',
|
|
4445
|
+
data: response.data,
|
|
4446
|
+
};
|
|
4435
4447
|
}
|
|
4436
4448
|
// if (insuranceType === InsuranceTypes.Life) {
|
|
4437
4449
|
// const response = await httpRequest({
|
|
@@ -4470,14 +4482,18 @@ const useHandlerPostal = (insuranceType) => {
|
|
|
4470
4482
|
if (insuranceType === mychoiceSdkComponents.InsuranceTypes.Home) {
|
|
4471
4483
|
dispatchHomePostalState({
|
|
4472
4484
|
type: exports.StoreFormHomePostalActionTypes.FormHomePostalErrorMessageSet,
|
|
4473
|
-
payload: {
|
|
4485
|
+
payload: {
|
|
4486
|
+
errorMessage: requestError.response?.data?.postalCode[0],
|
|
4487
|
+
},
|
|
4474
4488
|
});
|
|
4475
4489
|
}
|
|
4476
4490
|
setRequestState({
|
|
4477
4491
|
type: DataHandlerActionTypes.SetError,
|
|
4478
4492
|
payload: requestError.response?.data?.postalCode[0],
|
|
4479
4493
|
});
|
|
4480
|
-
return {
|
|
4494
|
+
return {
|
|
4495
|
+
errorMessage: requestError.response?.data?.postalCode[0],
|
|
4496
|
+
};
|
|
4481
4497
|
}
|
|
4482
4498
|
};
|
|
4483
4499
|
const getPlaceByAddress = async (streetAddress, city, postalCode, province) => {
|
|
@@ -4488,16 +4504,18 @@ const useHandlerPostal = (insuranceType) => {
|
|
|
4488
4504
|
url: `${mychoiceSdkComponents.API_FORM_HOME.GET_PLACE}`,
|
|
4489
4505
|
method: mychoiceSdkComponents.RequestTypes.Post,
|
|
4490
4506
|
data: {
|
|
4491
|
-
streetAddress,
|
|
4507
|
+
streetAddress,
|
|
4508
|
+
city,
|
|
4509
|
+
postalCode,
|
|
4510
|
+
province,
|
|
4492
4511
|
},
|
|
4493
4512
|
withoutToken: true,
|
|
4494
4513
|
cancelToken,
|
|
4495
4514
|
});
|
|
4496
|
-
console.log('dwelling', response?.data);
|
|
4497
4515
|
const { auxiliaryHeating, basementFinishPercent: dataBasementFinishPercent, buildingStructure: dataBuildingStructure, builtDate: dataBuiltDate, exteriorFinish: dataExteriorFinish, garageType: dataGarageType, livingArea: dataLivingArea, primaryHeating, replacementCost: dataReplacementCost, storeysCount: dataStoreysCount, roofType: dataRoofType, poolType: dataPoolType, bathroomsCount: dataBathroomsCount, } = response.data;
|
|
4498
4516
|
const { basementFinishPercent, buildingStructure, builtYear, exteriorFinish, garageType, livingArea, heatings, replacementCost, storeysCount, roofReplacedYear, roofType, poolType, bathroomsCount, } = getDwellingInitialState(mychoiceSdkComponents.getInsuranceType());
|
|
4499
4517
|
let roofYear = roofReplacedYear;
|
|
4500
|
-
if (dataBuiltDate &&
|
|
4518
|
+
if (dataBuiltDate && Number(dataBuiltDate) > Number(roofReplacedYear)) {
|
|
4501
4519
|
roofYear = dataBuiltDate;
|
|
4502
4520
|
}
|
|
4503
4521
|
const dwellingInfoUpdatedState = {
|
|
@@ -4507,7 +4525,10 @@ const useHandlerPostal = (insuranceType) => {
|
|
|
4507
4525
|
exteriorFinish: dataExteriorFinish || exteriorFinish,
|
|
4508
4526
|
garageType: dataGarageType || garageType,
|
|
4509
4527
|
livingArea: dataLivingArea || livingArea,
|
|
4510
|
-
heatings: [
|
|
4528
|
+
heatings: [
|
|
4529
|
+
{ type: primaryHeating || heatings[0].type },
|
|
4530
|
+
{ type: auxiliaryHeating || heatings[1].type },
|
|
4531
|
+
],
|
|
4511
4532
|
replacementCost: dataReplacementCost || replacementCost,
|
|
4512
4533
|
storeysCount: +dataStoreysCount || storeysCount,
|
|
4513
4534
|
roofReplacedYear: roofYear,
|
|
@@ -4518,7 +4539,11 @@ const useHandlerPostal = (insuranceType) => {
|
|
|
4518
4539
|
if (!response.data.primaryHeating) {
|
|
4519
4540
|
dispatchDwellingState({
|
|
4520
4541
|
type: exports.StoreFormHomeDwellingActionTypes.FormHomeDwellingSet,
|
|
4521
|
-
payload: {
|
|
4542
|
+
payload: {
|
|
4543
|
+
...dwellingState,
|
|
4544
|
+
...dwellingInfoUpdatedState,
|
|
4545
|
+
isCompleted: false,
|
|
4546
|
+
},
|
|
4522
4547
|
});
|
|
4523
4548
|
}
|
|
4524
4549
|
else {
|
|
@@ -4527,7 +4552,10 @@ const useHandlerPostal = (insuranceType) => {
|
|
|
4527
4552
|
payload: { ...dwellingState, ...dwellingInfoUpdatedState },
|
|
4528
4553
|
});
|
|
4529
4554
|
}
|
|
4530
|
-
setRequestState({
|
|
4555
|
+
setRequestState({
|
|
4556
|
+
type: DataHandlerActionTypes.SetSuccess,
|
|
4557
|
+
payload: response.data,
|
|
4558
|
+
});
|
|
4531
4559
|
}
|
|
4532
4560
|
}
|
|
4533
4561
|
catch (error) {
|
|
@@ -5968,8 +5996,8 @@ const useValidationAddress = () => {
|
|
|
5968
5996
|
const { dispatchAppLoaderState } = useStoreAppLoader();
|
|
5969
5997
|
const { postalState, dispatchPostalState } = useStoreFormHomePostal();
|
|
5970
5998
|
const { getPlaceByAddress } = useHandlerPostal(mychoiceSdkComponents.InsuranceTypes.Home);
|
|
5971
|
-
const { inValidation = false, isValid = false, item: { streetAddress, city, postalCode, provinceCode
|
|
5972
|
-
const { appConfigState: { localIndex, insuranceType } } = useStoreAppConfig();
|
|
5999
|
+
const { inValidation = false, isValid = false, item: { streetAddress, city, postalCode, provinceCode }, } = postalState;
|
|
6000
|
+
const { appConfigState: { localIndex, insuranceType }, } = useStoreAppConfig();
|
|
5973
6001
|
const { dispatchAppModalState } = useStoreAppModal();
|
|
5974
6002
|
const navigate = reactRouterDom.useNavigate();
|
|
5975
6003
|
const isHomeOwner = insuranceType === mychoiceSdkComponents.InsuranceTypes.Home;
|
|
@@ -5982,9 +6010,7 @@ const useValidationAddress = () => {
|
|
|
5982
6010
|
'postalCode',
|
|
5983
6011
|
'provinceCode',
|
|
5984
6012
|
];
|
|
5985
|
-
const dwellingKeys = [
|
|
5986
|
-
'type',
|
|
5987
|
-
];
|
|
6013
|
+
const dwellingKeys = ['type'];
|
|
5988
6014
|
const errors = [];
|
|
5989
6015
|
dispatchPostalState({
|
|
5990
6016
|
type: exports.StoreFormHomePostalActionTypes.FormHomePostalValidate,
|
|
@@ -5996,10 +6022,12 @@ const useValidationAddress = () => {
|
|
|
5996
6022
|
}
|
|
5997
6023
|
});
|
|
5998
6024
|
Object.keys(postalState.item).forEach((key) => {
|
|
5999
|
-
if (postalKeys.includes(key) &&
|
|
6025
|
+
if (postalKeys.includes(key) &&
|
|
6026
|
+
!postalState.item[key] &&
|
|
6027
|
+
key !== 'errorMessage') {
|
|
6000
6028
|
errors.push(key);
|
|
6001
6029
|
}
|
|
6002
|
-
if (
|
|
6030
|
+
if (key === 'errorMessage' && postalState.item[key]) {
|
|
6003
6031
|
errors.push(key);
|
|
6004
6032
|
}
|
|
6005
6033
|
});
|
|
@@ -6022,10 +6050,11 @@ const useValidationAddress = () => {
|
|
|
6022
6050
|
payload: { isValid: true },
|
|
6023
6051
|
});
|
|
6024
6052
|
formIsValid = true;
|
|
6025
|
-
dispatchAppLoaderState({
|
|
6053
|
+
dispatchAppLoaderState({
|
|
6054
|
+
type: exports.StoreConfigAppLoaderActionTypes.AppLoaderClose,
|
|
6055
|
+
});
|
|
6026
6056
|
}
|
|
6027
6057
|
catch (e) {
|
|
6028
|
-
console.log('dwelling get error:', e);
|
|
6029
6058
|
dispatchPostalState({
|
|
6030
6059
|
type: exports.StoreFormHomePostalActionTypes.FormHomePostalValidate,
|
|
6031
6060
|
payload: { inValidation: false },
|
|
@@ -6035,7 +6064,9 @@ const useValidationAddress = () => {
|
|
|
6035
6064
|
payload: { isValid: true },
|
|
6036
6065
|
});
|
|
6037
6066
|
formIsValid = true;
|
|
6038
|
-
dispatchAppLoaderState({
|
|
6067
|
+
dispatchAppLoaderState({
|
|
6068
|
+
type: exports.StoreConfigAppLoaderActionTypes.AppLoaderClose,
|
|
6069
|
+
});
|
|
6039
6070
|
}
|
|
6040
6071
|
}
|
|
6041
6072
|
else {
|
|
@@ -6048,7 +6079,9 @@ const useValidationAddress = () => {
|
|
|
6048
6079
|
payload: { isValid: true },
|
|
6049
6080
|
});
|
|
6050
6081
|
formIsValid = true;
|
|
6051
|
-
dispatchAppLoaderState({
|
|
6082
|
+
dispatchAppLoaderState({
|
|
6083
|
+
type: exports.StoreConfigAppLoaderActionTypes.AppLoaderClose,
|
|
6084
|
+
});
|
|
6052
6085
|
}
|
|
6053
6086
|
}
|
|
6054
6087
|
else {
|