@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/esm/index.js
CHANGED
|
@@ -514,7 +514,7 @@ const removeVehicleItem = (state, vehicleIndex) => {
|
|
|
514
514
|
if (r !== vehicleIndex) {
|
|
515
515
|
newItems.push(state.items[r]);
|
|
516
516
|
newTabs.push({
|
|
517
|
-
name: state.items[r].make || `Vehicle ${
|
|
517
|
+
name: state.items[r].make || `Vehicle ${newItems.length}`,
|
|
518
518
|
index: newItems.length - 1,
|
|
519
519
|
});
|
|
520
520
|
}
|
|
@@ -522,7 +522,9 @@ const removeVehicleItem = (state, vehicleIndex) => {
|
|
|
522
522
|
return {
|
|
523
523
|
items: newItems,
|
|
524
524
|
tabs: newTabs,
|
|
525
|
-
activeIndex: state.activeIndex >
|
|
525
|
+
activeIndex: state.activeIndex > newItems.length - 1
|
|
526
|
+
? newItems.length - 1
|
|
527
|
+
: state.activeIndex,
|
|
526
528
|
};
|
|
527
529
|
};
|
|
528
530
|
const createVehicleItem = (state) => ({
|
|
@@ -533,7 +535,7 @@ const createVehicleItem = (state) => ({
|
|
|
533
535
|
comprehensive: state.items[0].comprehensive,
|
|
534
536
|
collision: state.items[0].collision,
|
|
535
537
|
liability: state.items[0].liability,
|
|
536
|
-
}
|
|
538
|
+
},
|
|
537
539
|
],
|
|
538
540
|
tabs: [...state.tabs, { ...createTab('Vehicle', state.tabs.length) }],
|
|
539
541
|
activeIndex: state.tabs.length,
|
|
@@ -569,26 +571,16 @@ const setItemProperty = (state, name, value) => {
|
|
|
569
571
|
return newState;
|
|
570
572
|
};
|
|
571
573
|
const setCarCoverageProperty = (state, name, coverage, value) => {
|
|
572
|
-
const newState = deepClone(state);
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
return newItem;
|
|
577
|
-
});
|
|
574
|
+
const newState = JSON.parse(JSON.stringify(deepClone(state)));
|
|
575
|
+
const vehicleIndex = state.activeIndex;
|
|
576
|
+
const newItem = newState.items[vehicleIndex];
|
|
577
|
+
newItem[name].coverage = coverage;
|
|
578
578
|
if (coverage) {
|
|
579
579
|
if (name === CoverageTypes.Liability) {
|
|
580
|
-
|
|
581
|
-
const newItem = item;
|
|
582
|
-
newItem[name].limit = Number(value);
|
|
583
|
-
return newItem;
|
|
584
|
-
});
|
|
580
|
+
newItem[name].limit = Number(value);
|
|
585
581
|
}
|
|
586
582
|
else {
|
|
587
|
-
|
|
588
|
-
const newItem = item;
|
|
589
|
-
newItem[name].deductible = Number(value);
|
|
590
|
-
return newItem;
|
|
591
|
-
});
|
|
583
|
+
newItem[name].deductible = Number(value);
|
|
592
584
|
}
|
|
593
585
|
}
|
|
594
586
|
return newState;
|
|
@@ -651,7 +643,6 @@ const formCarVehicleStateReducer = (state = { ...carFormVehicleInitialState }, a
|
|
|
651
643
|
return setLocalVehicles(action.localIndex, setItemProperty(state, 'distanceBusiness', action.payload.distanceBusiness));
|
|
652
644
|
case StoreFormCarVehicleActionTypes.FormCarYearlyDistanceSelect:
|
|
653
645
|
return setLocalVehicles(action.localIndex, setItemProperty(state, 'distanceYearly', action.payload.distanceYearly));
|
|
654
|
-
// coverage
|
|
655
646
|
case StoreFormCarVehicleActionTypes.FormCarComprehensiveCoverageSelect:
|
|
656
647
|
return setLocalVehicles(action.localIndex, setCarCoverageProperty(state, 'comprehensive', action.payload.coverage, action.payload.deductible));
|
|
657
648
|
case StoreFormCarVehicleActionTypes.FormCarCollisionCoverageSelect:
|
|
@@ -659,7 +650,9 @@ const formCarVehicleStateReducer = (state = { ...carFormVehicleInitialState }, a
|
|
|
659
650
|
case StoreFormCarVehicleActionTypes.FormCarLiabilityCoverageSelect:
|
|
660
651
|
return setLocalVehicles(action.localIndex, setCarCoverageProperty(state, 'liability', action.payload.coverage, action.payload.limit));
|
|
661
652
|
case StoreFormCarVehicleActionTypes.FormCarVehicleClear:
|
|
662
|
-
return setLocalVehicles(action.localIndex, {
|
|
653
|
+
return setLocalVehicles(action.localIndex, {
|
|
654
|
+
...carFormVehicleInitialState,
|
|
655
|
+
});
|
|
663
656
|
default:
|
|
664
657
|
return state;
|
|
665
658
|
}
|
|
@@ -4356,7 +4349,9 @@ const useHandlerPostal = (insuranceType) => {
|
|
|
4356
4349
|
const { dwellingState, dispatchDwellingState } = useStoreFormHomeDwelling();
|
|
4357
4350
|
const { dispatchConfigState: dispatchCarConfigState } = useStoreFormCarConfig();
|
|
4358
4351
|
const { dispatchAppModalState } = useStoreAppModal();
|
|
4359
|
-
const [requestState, setRequestState] = useReducer(dataHandlerReducer, {
|
|
4352
|
+
const [requestState, setRequestState] = useReducer(dataHandlerReducer, {
|
|
4353
|
+
...initialHandlerRequestState,
|
|
4354
|
+
});
|
|
4360
4355
|
const { cancelToken } = useCancelToken();
|
|
4361
4356
|
const { status, successMessage, responseData, errorMessage, isFirstRequest, responseError, } = requestState;
|
|
4362
4357
|
const getPostal = async (postalCode) => {
|
|
@@ -4379,8 +4374,13 @@ const useHandlerPostal = (insuranceType) => {
|
|
|
4379
4374
|
type: StoreFormCarConfigActionTypes.FormCarConfigSet,
|
|
4380
4375
|
payload: { province: response.data.provinceCode },
|
|
4381
4376
|
});
|
|
4382
|
-
dispatchAppModalState({
|
|
4383
|
-
|
|
4377
|
+
dispatchAppModalState({
|
|
4378
|
+
type: StoreConfigAppModalActionTypes.AppModalClose,
|
|
4379
|
+
});
|
|
4380
|
+
setRequestState({
|
|
4381
|
+
type: DataHandlerActionTypes.SetSuccess,
|
|
4382
|
+
payload: response.data,
|
|
4383
|
+
});
|
|
4384
4384
|
return { errorMessage: '' };
|
|
4385
4385
|
}
|
|
4386
4386
|
setRequestState({
|
|
@@ -4395,7 +4395,9 @@ const useHandlerPostal = (insuranceType) => {
|
|
|
4395
4395
|
});
|
|
4396
4396
|
return { errorMessage: 'Postal Code Is Not Supported' };
|
|
4397
4397
|
}
|
|
4398
|
-
if (insuranceType === InsuranceTypes.Home ||
|
|
4398
|
+
if (insuranceType === InsuranceTypes.Home ||
|
|
4399
|
+
insuranceType === InsuranceTypes.Condo ||
|
|
4400
|
+
insuranceType === InsuranceTypes.Tenant) {
|
|
4399
4401
|
const response = await httpRequest({
|
|
4400
4402
|
url: `${API_FORM_HOME.GET_POSTAL}?postal_code=${postalCode}`,
|
|
4401
4403
|
method: RequestTypes.Get,
|
|
@@ -4408,13 +4410,20 @@ const useHandlerPostal = (insuranceType) => {
|
|
|
4408
4410
|
type: StoreFormHomePostalActionTypes.FormHomePostalSet,
|
|
4409
4411
|
payload: { ...response.data },
|
|
4410
4412
|
});
|
|
4411
|
-
dispatchAppModalState({
|
|
4412
|
-
|
|
4413
|
+
dispatchAppModalState({
|
|
4414
|
+
type: StoreConfigAppModalActionTypes.AppModalClose,
|
|
4415
|
+
});
|
|
4416
|
+
setRequestState({
|
|
4417
|
+
type: DataHandlerActionTypes.SetSuccess,
|
|
4418
|
+
payload: response.data,
|
|
4419
|
+
});
|
|
4413
4420
|
return { errorMessage: '', data: response.data };
|
|
4414
4421
|
}
|
|
4415
4422
|
dispatchHomePostalState({
|
|
4416
4423
|
type: StoreFormHomePostalActionTypes.FormHomePostalErrorMessageSet,
|
|
4417
|
-
payload: {
|
|
4424
|
+
payload: {
|
|
4425
|
+
errorMessage: 'Something went wrong! Please try again.',
|
|
4426
|
+
},
|
|
4418
4427
|
});
|
|
4419
4428
|
return { errorMessage: 'Something went wrong! Please try again.' };
|
|
4420
4429
|
}
|
|
@@ -4422,7 +4431,10 @@ const useHandlerPostal = (insuranceType) => {
|
|
|
4422
4431
|
type: StoreFormHomePostalActionTypes.FormHomePostalErrorMessageSet,
|
|
4423
4432
|
payload: { errorMessage: 'Postal Code Is Not Supported' },
|
|
4424
4433
|
});
|
|
4425
|
-
return {
|
|
4434
|
+
return {
|
|
4435
|
+
errorMessage: 'Postal Code Is Not Supported',
|
|
4436
|
+
data: response.data,
|
|
4437
|
+
};
|
|
4426
4438
|
}
|
|
4427
4439
|
// if (insuranceType === InsuranceTypes.Life) {
|
|
4428
4440
|
// const response = await httpRequest({
|
|
@@ -4461,14 +4473,18 @@ const useHandlerPostal = (insuranceType) => {
|
|
|
4461
4473
|
if (insuranceType === InsuranceTypes.Home) {
|
|
4462
4474
|
dispatchHomePostalState({
|
|
4463
4475
|
type: StoreFormHomePostalActionTypes.FormHomePostalErrorMessageSet,
|
|
4464
|
-
payload: {
|
|
4476
|
+
payload: {
|
|
4477
|
+
errorMessage: requestError.response?.data?.postalCode[0],
|
|
4478
|
+
},
|
|
4465
4479
|
});
|
|
4466
4480
|
}
|
|
4467
4481
|
setRequestState({
|
|
4468
4482
|
type: DataHandlerActionTypes.SetError,
|
|
4469
4483
|
payload: requestError.response?.data?.postalCode[0],
|
|
4470
4484
|
});
|
|
4471
|
-
return {
|
|
4485
|
+
return {
|
|
4486
|
+
errorMessage: requestError.response?.data?.postalCode[0],
|
|
4487
|
+
};
|
|
4472
4488
|
}
|
|
4473
4489
|
};
|
|
4474
4490
|
const getPlaceByAddress = async (streetAddress, city, postalCode, province) => {
|
|
@@ -4479,16 +4495,18 @@ const useHandlerPostal = (insuranceType) => {
|
|
|
4479
4495
|
url: `${API_FORM_HOME.GET_PLACE}`,
|
|
4480
4496
|
method: RequestTypes.Post,
|
|
4481
4497
|
data: {
|
|
4482
|
-
streetAddress,
|
|
4498
|
+
streetAddress,
|
|
4499
|
+
city,
|
|
4500
|
+
postalCode,
|
|
4501
|
+
province,
|
|
4483
4502
|
},
|
|
4484
4503
|
withoutToken: true,
|
|
4485
4504
|
cancelToken,
|
|
4486
4505
|
});
|
|
4487
|
-
console.log('dwelling', response?.data);
|
|
4488
4506
|
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;
|
|
4489
4507
|
const { basementFinishPercent, buildingStructure, builtYear, exteriorFinish, garageType, livingArea, heatings, replacementCost, storeysCount, roofReplacedYear, roofType, poolType, bathroomsCount, } = getDwellingInitialState(getInsuranceType$2());
|
|
4490
4508
|
let roofYear = roofReplacedYear;
|
|
4491
|
-
if (dataBuiltDate &&
|
|
4509
|
+
if (dataBuiltDate && Number(dataBuiltDate) > Number(roofReplacedYear)) {
|
|
4492
4510
|
roofYear = dataBuiltDate;
|
|
4493
4511
|
}
|
|
4494
4512
|
const dwellingInfoUpdatedState = {
|
|
@@ -4498,7 +4516,10 @@ const useHandlerPostal = (insuranceType) => {
|
|
|
4498
4516
|
exteriorFinish: dataExteriorFinish || exteriorFinish,
|
|
4499
4517
|
garageType: dataGarageType || garageType,
|
|
4500
4518
|
livingArea: dataLivingArea || livingArea,
|
|
4501
|
-
heatings: [
|
|
4519
|
+
heatings: [
|
|
4520
|
+
{ type: primaryHeating || heatings[0].type },
|
|
4521
|
+
{ type: auxiliaryHeating || heatings[1].type },
|
|
4522
|
+
],
|
|
4502
4523
|
replacementCost: dataReplacementCost || replacementCost,
|
|
4503
4524
|
storeysCount: +dataStoreysCount || storeysCount,
|
|
4504
4525
|
roofReplacedYear: roofYear,
|
|
@@ -4509,7 +4530,11 @@ const useHandlerPostal = (insuranceType) => {
|
|
|
4509
4530
|
if (!response.data.primaryHeating) {
|
|
4510
4531
|
dispatchDwellingState({
|
|
4511
4532
|
type: StoreFormHomeDwellingActionTypes.FormHomeDwellingSet,
|
|
4512
|
-
payload: {
|
|
4533
|
+
payload: {
|
|
4534
|
+
...dwellingState,
|
|
4535
|
+
...dwellingInfoUpdatedState,
|
|
4536
|
+
isCompleted: false,
|
|
4537
|
+
},
|
|
4513
4538
|
});
|
|
4514
4539
|
}
|
|
4515
4540
|
else {
|
|
@@ -4518,7 +4543,10 @@ const useHandlerPostal = (insuranceType) => {
|
|
|
4518
4543
|
payload: { ...dwellingState, ...dwellingInfoUpdatedState },
|
|
4519
4544
|
});
|
|
4520
4545
|
}
|
|
4521
|
-
setRequestState({
|
|
4546
|
+
setRequestState({
|
|
4547
|
+
type: DataHandlerActionTypes.SetSuccess,
|
|
4548
|
+
payload: response.data,
|
|
4549
|
+
});
|
|
4522
4550
|
}
|
|
4523
4551
|
}
|
|
4524
4552
|
catch (error) {
|
|
@@ -5959,8 +5987,8 @@ const useValidationAddress = () => {
|
|
|
5959
5987
|
const { dispatchAppLoaderState } = useStoreAppLoader();
|
|
5960
5988
|
const { postalState, dispatchPostalState } = useStoreFormHomePostal();
|
|
5961
5989
|
const { getPlaceByAddress } = useHandlerPostal(InsuranceTypes.Home);
|
|
5962
|
-
const { inValidation = false, isValid = false, item: { streetAddress, city, postalCode, provinceCode
|
|
5963
|
-
const { appConfigState: { localIndex, insuranceType } } = useStoreAppConfig();
|
|
5990
|
+
const { inValidation = false, isValid = false, item: { streetAddress, city, postalCode, provinceCode }, } = postalState;
|
|
5991
|
+
const { appConfigState: { localIndex, insuranceType }, } = useStoreAppConfig();
|
|
5964
5992
|
const { dispatchAppModalState } = useStoreAppModal();
|
|
5965
5993
|
const navigate = useNavigate();
|
|
5966
5994
|
const isHomeOwner = insuranceType === InsuranceTypes.Home;
|
|
@@ -5973,9 +6001,7 @@ const useValidationAddress = () => {
|
|
|
5973
6001
|
'postalCode',
|
|
5974
6002
|
'provinceCode',
|
|
5975
6003
|
];
|
|
5976
|
-
const dwellingKeys = [
|
|
5977
|
-
'type',
|
|
5978
|
-
];
|
|
6004
|
+
const dwellingKeys = ['type'];
|
|
5979
6005
|
const errors = [];
|
|
5980
6006
|
dispatchPostalState({
|
|
5981
6007
|
type: StoreFormHomePostalActionTypes.FormHomePostalValidate,
|
|
@@ -5987,10 +6013,12 @@ const useValidationAddress = () => {
|
|
|
5987
6013
|
}
|
|
5988
6014
|
});
|
|
5989
6015
|
Object.keys(postalState.item).forEach((key) => {
|
|
5990
|
-
if (postalKeys.includes(key) &&
|
|
6016
|
+
if (postalKeys.includes(key) &&
|
|
6017
|
+
!postalState.item[key] &&
|
|
6018
|
+
key !== 'errorMessage') {
|
|
5991
6019
|
errors.push(key);
|
|
5992
6020
|
}
|
|
5993
|
-
if (
|
|
6021
|
+
if (key === 'errorMessage' && postalState.item[key]) {
|
|
5994
6022
|
errors.push(key);
|
|
5995
6023
|
}
|
|
5996
6024
|
});
|
|
@@ -6013,10 +6041,11 @@ const useValidationAddress = () => {
|
|
|
6013
6041
|
payload: { isValid: true },
|
|
6014
6042
|
});
|
|
6015
6043
|
formIsValid = true;
|
|
6016
|
-
dispatchAppLoaderState({
|
|
6044
|
+
dispatchAppLoaderState({
|
|
6045
|
+
type: StoreConfigAppLoaderActionTypes.AppLoaderClose,
|
|
6046
|
+
});
|
|
6017
6047
|
}
|
|
6018
6048
|
catch (e) {
|
|
6019
|
-
console.log('dwelling get error:', e);
|
|
6020
6049
|
dispatchPostalState({
|
|
6021
6050
|
type: StoreFormHomePostalActionTypes.FormHomePostalValidate,
|
|
6022
6051
|
payload: { inValidation: false },
|
|
@@ -6026,7 +6055,9 @@ const useValidationAddress = () => {
|
|
|
6026
6055
|
payload: { isValid: true },
|
|
6027
6056
|
});
|
|
6028
6057
|
formIsValid = true;
|
|
6029
|
-
dispatchAppLoaderState({
|
|
6058
|
+
dispatchAppLoaderState({
|
|
6059
|
+
type: StoreConfigAppLoaderActionTypes.AppLoaderClose,
|
|
6060
|
+
});
|
|
6030
6061
|
}
|
|
6031
6062
|
}
|
|
6032
6063
|
else {
|
|
@@ -6039,7 +6070,9 @@ const useValidationAddress = () => {
|
|
|
6039
6070
|
payload: { isValid: true },
|
|
6040
6071
|
});
|
|
6041
6072
|
formIsValid = true;
|
|
6042
|
-
dispatchAppLoaderState({
|
|
6073
|
+
dispatchAppLoaderState({
|
|
6074
|
+
type: StoreConfigAppLoaderActionTypes.AppLoaderClose,
|
|
6075
|
+
});
|
|
6043
6076
|
}
|
|
6044
6077
|
}
|
|
6045
6078
|
else {
|