@mychoice/mychoice-sdk-store 2.0.1 → 2.1.0

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.
@@ -2,4 +2,5 @@ import { DataHandlerRequestState } from '../shared';
2
2
  export type UseHandlerQuoteInterface = DataHandlerRequestState & {
3
3
  postRequestQuoteOnliaUrl: (isLoader: boolean, redirectUrl: string) => void;
4
4
  postRequestQuote: (isRecalc: boolean) => void;
5
+ postPerformLeadsAction?: () => void;
5
6
  };
package/dist/cjs/index.js CHANGED
@@ -2022,6 +2022,7 @@ exports.StoreFormCarQuoteActionTypes = void 0;
2022
2022
  StoreFormCarQuoteActionTypes["FormCarQuoteGetLocal"] = "FormCarQuoteGetLocal";
2023
2023
  StoreFormCarQuoteActionTypes["FormCarQuoteClear"] = "FormCarQuoteClear";
2024
2024
  StoreFormCarQuoteActionTypes["UpdateCarCallMessage"] = "UpdateCarCallMessage";
2025
+ StoreFormCarQuoteActionTypes["FormCarQuoteConfirmStepSet"] = "FormCarQuoteConfirmStepSet";
2025
2026
  })(exports.StoreFormCarQuoteActionTypes || (exports.StoreFormCarQuoteActionTypes = {}));
2026
2027
 
2027
2028
  const setQuoteStateProperty$2 = (state, name, value) => {
@@ -2048,6 +2049,8 @@ const formCarQuoteStateReducer = (state = { ...formCarQuoteInitialState }, actio
2048
2049
  return setLocalQuotes$2(action.localIndex, setQuoteStateProperty$2(state, 'items', action.payload.items));
2049
2050
  case exports.StoreFormCarQuoteActionTypes.FormCarQuoteRequestDateSet:
2050
2051
  return setLocalQuotes$2(action.localIndex, setQuoteStateProperty$2(state, 'requestDate', action.payload.requestDate));
2052
+ case exports.StoreFormCarQuoteActionTypes.FormCarQuoteConfirmStepSet:
2053
+ return setLocalQuotes$2(action.localIndex, setQuoteStateProperty$2(state, 'quoteConfirm', action.payload.quoteConfirm));
2051
2054
  case exports.StoreFormCarQuoteActionTypes.FormCarQuoteGetLocal:
2052
2055
  return {
2053
2056
  ...getLocalQuotes$2(action.localIndex),
@@ -5204,6 +5207,12 @@ const CarQuoteDataHandler = () => {
5204
5207
  type: exports.StoreFormCarQuoteActionTypes.FormCarQuotesSet,
5205
5208
  payload: { items: response.data },
5206
5209
  });
5210
+ if (discountState.quoterInfo.initial) {
5211
+ dispatchQuoteState({
5212
+ type: exports.StoreFormCarQuoteActionTypes.FormCarQuoteConfirmStepSet,
5213
+ payload: { quoteConfirm: !!response.data?.[0]?.confirmQuote },
5214
+ });
5215
+ }
5207
5216
  setRequestState({
5208
5217
  type: DataHandlerActionTypes.SetSuccess,
5209
5218
  });
@@ -5222,6 +5231,37 @@ const CarQuoteDataHandler = () => {
5222
5231
  }
5223
5232
  }
5224
5233
  };
5234
+ const postPerformLeadsAction = async () => {
5235
+ const { firstName, lastName, phone } = discountState.quoterInfo;
5236
+ const requestBody = {
5237
+ quote_id: quoteState.items[0].id,
5238
+ first_name: firstName,
5239
+ last_name: lastName,
5240
+ phone,
5241
+ };
5242
+ openLoader('Please wait while we are finalizing your quote.');
5243
+ try {
5244
+ await httpRequest({
5245
+ url: mychoiceSdkComponents.API_FORM_CAR.POST_SEND_LEADS,
5246
+ method: mychoiceSdkComponents.RequestTypes.Post,
5247
+ data: requestBody,
5248
+ withoutToken: true,
5249
+ cancelToken,
5250
+ });
5251
+ }
5252
+ catch (error) {
5253
+ setRequestState({
5254
+ type: DataHandlerActionTypes.SetError,
5255
+ payload: 'Axios request error',
5256
+ });
5257
+ }
5258
+ // As precaution always reveal all quotes even if lead endpoint failed
5259
+ dispatchQuoteState({
5260
+ type: exports.StoreFormCarQuoteActionTypes.FormCarQuoteConfirmStepSet,
5261
+ payload: { quoteConfirm: false },
5262
+ });
5263
+ dispatchAppLoaderState({ type: exports.StoreConfigAppLoaderActionTypes.AppLoaderClose });
5264
+ };
5225
5265
  return ({
5226
5266
  status,
5227
5267
  successMessage,
@@ -5231,6 +5271,7 @@ const CarQuoteDataHandler = () => {
5231
5271
  responseError,
5232
5272
  postRequestQuoteOnliaUrl,
5233
5273
  postRequestQuote,
5274
+ postPerformLeadsAction,
5234
5275
  });
5235
5276
  };
5236
5277