@mychoice/mychoice-sdk-store 2.2.10 → 2.2.12

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.
@@ -1,3 +1,4 @@
1
1
  export * from './types';
2
2
  export * from './utils';
3
3
  export * from './useAutofillCarForm';
4
+ export * from './useAutofillLifeForm';
@@ -74,3 +74,29 @@ export interface MappedAutofillData {
74
74
  postalData: any;
75
75
  configData: any;
76
76
  }
77
+ export interface LifeAutofillQuoterInfo {
78
+ phone: number;
79
+ last_name: string;
80
+ first_name: string;
81
+ utm_source: string | null;
82
+ recalculate: boolean;
83
+ utm_campaign: string | null;
84
+ }
85
+ export interface LifeAutofillData {
86
+ Sex: string;
87
+ uuid: string;
88
+ City: string;
89
+ State: string;
90
+ Health: string;
91
+ Smoker: string;
92
+ Birthday: string;
93
+ ModeUsed: string;
94
+ email_to: string;
95
+ BirthYear: string;
96
+ BirthMonth: string;
97
+ FaceAmount: number;
98
+ IsUsaQuote: boolean;
99
+ PostalCode: string;
100
+ NewCategory: string;
101
+ quoter_info: LifeAutofillQuoterInfo;
102
+ }
@@ -0,0 +1,8 @@
1
+ interface AutofillOptions {
2
+ onComplete?: () => void;
3
+ }
4
+ /**
5
+ * Hook to initialize life insurance form with autofill data from query parameter
6
+ */
7
+ export declare const useAutofillLifeForm: (options?: AutofillOptions) => void;
8
+ export {};
@@ -92,3 +92,51 @@ export declare const mapToDriverState: (autofillData: AutofillData) => {
92
92
  export declare const mapToConfigState: (autofillData: AutofillData) => {
93
93
  province: string;
94
94
  };
95
+ /**
96
+ * Parse URL-encoded JSON from query parameter for life insurance
97
+ */
98
+ export declare const parseLifeAutofillParam: (urlEncodedJson: string) => any;
99
+ /**
100
+ * Get province code from state number
101
+ */
102
+ export declare const getProvinceCodeFromState: (stateNumber: string) => string;
103
+ /**
104
+ * Map life autofill data to coverage state format
105
+ */
106
+ export declare const mapToLifeCoverageState: (autofillData: any) => {
107
+ province: string;
108
+ type: any;
109
+ coverage: string;
110
+ postalCode: any;
111
+ city: any;
112
+ };
113
+ /**
114
+ * Map life autofill data to applicant state format
115
+ */
116
+ export declare const mapToLifeApplicantState: (autofillData: any) => {
117
+ birthYear: any;
118
+ birthMonth: any;
119
+ birthDay: any;
120
+ gender: any;
121
+ smoker: boolean;
122
+ emailTo: {
123
+ email: any;
124
+ };
125
+ quoterInfo: {
126
+ firstName: any;
127
+ lastName: any;
128
+ phone: string;
129
+ utmSource: any;
130
+ utmCampaign: any;
131
+ };
132
+ };
133
+ /**
134
+ * Map life autofill data to postal state format
135
+ */
136
+ export declare const mapToLifePostalState: (autofillData: any) => {
137
+ postalCode: any;
138
+ provinceCode: string;
139
+ provinceName: string;
140
+ city: any;
141
+ locationIndex: string;
142
+ };
package/dist/cjs/index.js CHANGED
@@ -6832,6 +6832,83 @@ const mapToConfigState = (autofillData) => {
6832
6832
  province: autofillData.province_code || '',
6833
6833
  };
6834
6834
  };
6835
+ // Life insurance autofill utilities
6836
+ // State number to province code mapping (reverse of stateMapper in LifeQuoteDataHandler)
6837
+ const STATE_TO_PROVINCE_CODE_MAP = {
6838
+ '1': 'AB',
6839
+ '2': 'BC',
6840
+ '3': 'MB',
6841
+ '4': 'NB',
6842
+ '5': 'NF',
6843
+ '6': 'NS',
6844
+ '7': 'NT',
6845
+ '9': 'ON',
6846
+ '10': 'PE',
6847
+ '11': 'QC',
6848
+ '12': 'SK',
6849
+ '13': 'YT',
6850
+ };
6851
+ /**
6852
+ * Parse URL-encoded JSON from query parameter for life insurance
6853
+ */
6854
+ const parseLifeAutofillParam = (urlEncodedJson) => {
6855
+ const decoded = decodeURIComponent(urlEncodedJson);
6856
+ return JSON.parse(decoded);
6857
+ };
6858
+ /**
6859
+ * Get province code from state number
6860
+ */
6861
+ const getProvinceCodeFromState = (stateNumber) => {
6862
+ return STATE_TO_PROVINCE_CODE_MAP[stateNumber] || '';
6863
+ };
6864
+ /**
6865
+ * Map life autofill data to coverage state format
6866
+ */
6867
+ const mapToLifeCoverageState = (autofillData) => {
6868
+ const provinceCode = getProvinceCodeFromState(autofillData.State || '');
6869
+ return {
6870
+ province: provinceCode,
6871
+ type: autofillData.NewCategory || '',
6872
+ coverage: String(autofillData.FaceAmount || ''),
6873
+ postalCode: autofillData.PostalCode || '',
6874
+ city: autofillData.City || '',
6875
+ };
6876
+ };
6877
+ /**
6878
+ * Map life autofill data to applicant state format
6879
+ */
6880
+ const mapToLifeApplicantState = (autofillData) => {
6881
+ return {
6882
+ birthYear: autofillData.BirthYear || '',
6883
+ birthMonth: autofillData.BirthMonth || '',
6884
+ birthDay: autofillData.Birthday || '',
6885
+ gender: autofillData.Sex || 'M',
6886
+ smoker: autofillData.Smoker === 'Y',
6887
+ emailTo: {
6888
+ email: autofillData.email_to || '',
6889
+ },
6890
+ quoterInfo: {
6891
+ firstName: autofillData.quoter_info?.first_name || '',
6892
+ lastName: autofillData.quoter_info?.last_name || '',
6893
+ phone: autofillData.quoter_info?.phone ? String(autofillData.quoter_info.phone) : '',
6894
+ utmSource: autofillData.quoter_info?.utm_source || '',
6895
+ utmCampaign: autofillData.quoter_info?.utm_campaign || '',
6896
+ },
6897
+ };
6898
+ };
6899
+ /**
6900
+ * Map life autofill data to postal state format
6901
+ */
6902
+ const mapToLifePostalState = (autofillData) => {
6903
+ const provinceCode = getProvinceCodeFromState(autofillData.State || '');
6904
+ return {
6905
+ postalCode: autofillData.PostalCode || '',
6906
+ provinceCode,
6907
+ provinceName: getProvinceName(provinceCode),
6908
+ city: autofillData.City || '',
6909
+ locationIndex: '',
6910
+ };
6911
+ };
6835
6912
 
6836
6913
  /**
6837
6914
  * Hook to initialize car insurance form with autofill data from query parameter
@@ -6847,6 +6924,9 @@ const useAutofillCarForm = (options) => {
6847
6924
  const { dispatchDriverCancellationState } = useStoreFormCarDriverCancellation();
6848
6925
  const { dispatchDriverAccidentState } = useStoreFormCarDriverAccident();
6849
6926
  const { dispatchDriverTicketState } = useStoreFormCarDriverTicket();
6927
+ const { dispatchDriverBaseState } = useStoreFormCarDriverBase();
6928
+ const { dispatchDiscountState } = useStoreFormCarDiscount();
6929
+ const { dispatchQuoteState } = useStoreFormCarQuote();
6850
6930
  const { getVehicleMake } = useHandlerCarMake();
6851
6931
  const { getVehicleModel } = useHandlerCarModel();
6852
6932
  const { dispatchAppModalState } = useStoreAppModal();
@@ -6864,6 +6944,13 @@ const useAutofillCarForm = (options) => {
6864
6944
  }
6865
6945
  // Parse the autofill data
6866
6946
  const autofillData = parseAutofillParam(autofillParam);
6947
+ // Clear all existing car form state before applying autofill data
6948
+ dispatchPostalState({ type: exports.StoreFormCarPostalActionTypes.FormCarPostalClear });
6949
+ dispatchVehicleState({ type: exports.StoreFormCarVehicleActionTypes.FormCarVehicleClear });
6950
+ dispatchConfigState({ type: exports.StoreFormCarConfigActionTypes.FormCarConfigClear, payload: { province: '' } });
6951
+ dispatchDriverBaseState({ type: exports.StoreFormCarDriverBaseActionTypes.FormCarDriverClear });
6952
+ dispatchDiscountState({ type: exports.StoreFormCarDiscountActionTypes.FormCarDiscountClear });
6953
+ dispatchQuoteState({ type: exports.StoreFormCarQuoteActionTypes.FormCarQuoteClear });
6867
6954
  // Dispatch postal state
6868
6955
  const postalData = mapToPostalState(autofillData);
6869
6956
  dispatchPostalState({
@@ -7171,12 +7258,196 @@ const useAutofillCarForm = (options) => {
7171
7258
  dispatchDriverCancellationState,
7172
7259
  dispatchDriverAccidentState,
7173
7260
  dispatchDriverTicketState,
7261
+ dispatchDriverBaseState,
7262
+ dispatchDiscountState,
7263
+ dispatchQuoteState,
7174
7264
  dispatchAppModalState,
7175
7265
  getVehicleMake,
7176
7266
  getVehicleModel,
7177
7267
  ]);
7178
7268
  };
7179
7269
 
7270
+ /**
7271
+ * Hook to initialize life insurance form with autofill data from query parameter
7272
+ */
7273
+ const useAutofillLifeForm = (options) => {
7274
+ const { dispatchPostalState } = useStoreFormLifePostal();
7275
+ const { dispatchCoverageState } = useStoreFormLifeCoverage();
7276
+ const { dispatchApplicantState } = useStoreFormLifeApplicant();
7277
+ const { dispatchQuoteState } = useStoreFormLifeQuote();
7278
+ const { dispatchAppModalState } = useStoreAppModal();
7279
+ const autofillProcessedRef = react.useRef(false);
7280
+ react.useEffect(() => {
7281
+ // Prevent double execution in development strict mode
7282
+ if (autofillProcessedRef.current) {
7283
+ return;
7284
+ }
7285
+ try {
7286
+ const urlParams = new URLSearchParams(window.location.search);
7287
+ const autofillParam = urlParams.get('autofill');
7288
+ if (!autofillParam) {
7289
+ return;
7290
+ }
7291
+ // Parse the autofill data
7292
+ const autofillData = parseLifeAutofillParam(autofillParam);
7293
+ // Clear all existing life form state before applying autofill data
7294
+ dispatchPostalState({ type: exports.StoreFormLifePostalActionTypes.FormLifePostalClear });
7295
+ dispatchCoverageState({ type: exports.StoreFormLifeCoverageActionTypes.FormLifeCoverageClear });
7296
+ dispatchApplicantState({ type: exports.StoreFormLifeApplicantActionTypes.FormLifeApplicantClear });
7297
+ dispatchQuoteState({ type: exports.StoreFormLifeQuoteActionTypes.FormLifeQuoteClear });
7298
+ // Map and dispatch postal state
7299
+ const postalData = mapToLifePostalState(autofillData);
7300
+ dispatchPostalState({
7301
+ type: exports.StoreFormLifePostalActionTypes.FormLifePostalSet,
7302
+ payload: postalData,
7303
+ });
7304
+ // Close the postal modal since we have postal data from autofill
7305
+ dispatchAppModalState({
7306
+ type: exports.StoreConfigAppModalActionTypes.AppModalClose,
7307
+ });
7308
+ // Map and dispatch coverage state
7309
+ const coverageData = mapToLifeCoverageState(autofillData);
7310
+ // Dispatch province
7311
+ dispatchCoverageState({
7312
+ type: exports.StoreFormLifeCoverageActionTypes.FormLifeProvinceSelect,
7313
+ payload: {
7314
+ province: coverageData.province,
7315
+ },
7316
+ });
7317
+ // Dispatch coverage type
7318
+ dispatchCoverageState({
7319
+ type: exports.StoreFormLifeCoverageActionTypes.FormLifeCoverageTypeSelect,
7320
+ payload: {
7321
+ type: coverageData.type,
7322
+ },
7323
+ });
7324
+ // Dispatch coverage amount
7325
+ dispatchCoverageState({
7326
+ type: exports.StoreFormLifeCoverageActionTypes.FormLifeCoverageSelect,
7327
+ payload: {
7328
+ coverage: coverageData.coverage,
7329
+ },
7330
+ });
7331
+ // Dispatch postal code
7332
+ dispatchCoverageState({
7333
+ type: exports.StoreFormLifeCoverageActionTypes.FormLifePostalCodeSelect,
7334
+ payload: {
7335
+ postalCode: coverageData.postalCode,
7336
+ },
7337
+ });
7338
+ // Dispatch city
7339
+ if (coverageData.city) {
7340
+ dispatchCoverageState({
7341
+ type: exports.StoreFormLifeCoverageActionTypes.FormLifeCitySelect,
7342
+ payload: {
7343
+ city: coverageData.city,
7344
+ },
7345
+ });
7346
+ }
7347
+ // Map and dispatch applicant state
7348
+ const applicantData = mapToLifeApplicantState(autofillData);
7349
+ // Dispatch birth year
7350
+ dispatchApplicantState({
7351
+ type: exports.StoreFormLifeApplicantActionTypes.FormLifeApplicantBirthYearSelect,
7352
+ payload: {
7353
+ birthYear: applicantData.birthYear,
7354
+ },
7355
+ });
7356
+ // Dispatch birth month
7357
+ dispatchApplicantState({
7358
+ type: exports.StoreFormLifeApplicantActionTypes.FormLifeApplicantBirthMonthSelect,
7359
+ payload: {
7360
+ birthMonth: applicantData.birthMonth,
7361
+ },
7362
+ });
7363
+ // Dispatch birth day
7364
+ dispatchApplicantState({
7365
+ type: exports.StoreFormLifeApplicantActionTypes.FormLifeApplicantBirthDaySelect,
7366
+ payload: {
7367
+ birthDay: applicantData.birthDay,
7368
+ },
7369
+ });
7370
+ // Dispatch gender
7371
+ dispatchApplicantState({
7372
+ type: exports.StoreFormLifeApplicantActionTypes.FormLifeApplicantGenderSelect,
7373
+ payload: {
7374
+ gender: applicantData.gender,
7375
+ },
7376
+ });
7377
+ // Dispatch smoker status
7378
+ dispatchApplicantState({
7379
+ type: exports.StoreFormLifeApplicantActionTypes.FormLifeApplicantSmokerSelect,
7380
+ payload: {
7381
+ smoker: applicantData.smoker,
7382
+ },
7383
+ });
7384
+ // Dispatch email
7385
+ if (applicantData.emailTo.email) {
7386
+ dispatchApplicantState({
7387
+ type: exports.StoreFormLifeApplicantActionTypes.FormLifeApplicantEmailSet,
7388
+ payload: {
7389
+ email: applicantData.emailTo.email,
7390
+ emailStatus: mychoiceSdkComponents.ValidationStatusTypes.Approved,
7391
+ },
7392
+ });
7393
+ }
7394
+ // Dispatch quoter info - first name
7395
+ if (applicantData.quoterInfo.firstName) {
7396
+ dispatchApplicantState({
7397
+ type: exports.StoreFormLifeApplicantActionTypes.FormLifeQuoterFirstNameSet,
7398
+ payload: {
7399
+ firstName: applicantData.quoterInfo.firstName,
7400
+ },
7401
+ });
7402
+ }
7403
+ // Dispatch quoter info - last name
7404
+ if (applicantData.quoterInfo.lastName) {
7405
+ dispatchApplicantState({
7406
+ type: exports.StoreFormLifeApplicantActionTypes.FormLifeQuoterLastNameSet,
7407
+ payload: {
7408
+ lastName: applicantData.quoterInfo.lastName,
7409
+ },
7410
+ });
7411
+ }
7412
+ // Dispatch quoter info - phone
7413
+ if (applicantData.quoterInfo.phone) {
7414
+ dispatchApplicantState({
7415
+ type: exports.StoreFormLifeApplicantActionTypes.FormLifeQuoterPhoneSet,
7416
+ payload: {
7417
+ phone: applicantData.quoterInfo.phone,
7418
+ },
7419
+ });
7420
+ }
7421
+ // Dispatch quoter info - utm source
7422
+ if (applicantData.quoterInfo.utmSource) {
7423
+ dispatchApplicantState({
7424
+ type: exports.StoreFormLifeApplicantActionTypes.FormLifeUtmSourceSet,
7425
+ payload: {
7426
+ utmSource: applicantData.quoterInfo.utmSource,
7427
+ },
7428
+ });
7429
+ }
7430
+ // Dispatch quoter info - utm campaign
7431
+ if (applicantData.quoterInfo.utmCampaign) {
7432
+ dispatchApplicantState({
7433
+ type: exports.StoreFormLifeApplicantActionTypes.FormLifeUtmCampaignSet,
7434
+ payload: {
7435
+ utmCampaign: applicantData.quoterInfo.utmCampaign,
7436
+ },
7437
+ });
7438
+ }
7439
+ autofillProcessedRef.current = true;
7440
+ if (options?.onComplete) {
7441
+ options.onComplete();
7442
+ }
7443
+ }
7444
+ catch (error) {
7445
+ // Silently fail - let the app continue with normal flow
7446
+ console.error('Life autofill initialization error:', error);
7447
+ }
7448
+ }, [dispatchPostalState, dispatchCoverageState, dispatchApplicantState, dispatchQuoteState, dispatchAppModalState]);
7449
+ };
7450
+
7180
7451
  exports.CarQuoteDataHandler = CarQuoteDataHandler;
7181
7452
  exports.ClearFormDataHandler = ClearFormDataHandler;
7182
7453
  exports.HomeQuoteDataHandler = HomeQuoteDataHandler;
@@ -7192,17 +7463,23 @@ exports.formHomeReducer = formHomeReducer;
7192
7463
  exports.formLifeReducer = formLifeReducer;
7193
7464
  exports.formTenantDwellingInitialState = formTenantDwellingInitialState;
7194
7465
  exports.getDwellingInitialState = getDwellingInitialState;
7466
+ exports.getProvinceCodeFromState = getProvinceCodeFromState;
7195
7467
  exports.getProvinceName = getProvinceName;
7196
7468
  exports.globalStateReducer = globalStateReducer;
7197
7469
  exports.initHttpResponse = initHttpResponse;
7198
7470
  exports.mapToConfigState = mapToConfigState;
7199
7471
  exports.mapToDriverState = mapToDriverState;
7472
+ exports.mapToLifeApplicantState = mapToLifeApplicantState;
7473
+ exports.mapToLifeCoverageState = mapToLifeCoverageState;
7474
+ exports.mapToLifePostalState = mapToLifePostalState;
7200
7475
  exports.mapToPostalState = mapToPostalState;
7201
7476
  exports.mapToVehicleState = mapToVehicleState;
7202
7477
  exports.parseAutofillParam = parseAutofillParam;
7478
+ exports.parseLifeAutofillParam = parseLifeAutofillParam;
7203
7479
  exports.reducers = reducers;
7204
7480
  exports.token = default_1;
7205
7481
  exports.useAutofillCarForm = useAutofillCarForm;
7482
+ exports.useAutofillLifeForm = useAutofillLifeForm;
7206
7483
  exports.useHandlerAuth = useHandlerAuth;
7207
7484
  exports.useHandlerCarMake = useHandlerCarMake;
7208
7485
  exports.useHandlerCarModel = useHandlerCarModel;