thm-p3-configurator 0.0.129 → 0.0.131

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.
@@ -25,7 +25,7 @@ var _FormulaContext = require("./__context__/FormulaContext");
25
25
  var _OrderSessionContext = require("./__context__/OrderSessionContext");
26
26
  var _cookiebot = require("./__helpers__/cookiebot");
27
27
  var _queryClient = _interopRequireDefault(require("./__helpers__/queryClient"));
28
- var _TEST_ONLY_INTERNAL_ROUTES = _interopRequireDefault(require("./__pages__/internal/__TEST_ONLY_INTERNAL_ROUTES"));
28
+ var _index = _interopRequireDefault(require("./__pages__/index"));
29
29
  var _Experiments = _interopRequireDefault(require("./__services__/Experiments"));
30
30
  var _mainExternal = _interopRequireDefault(require("./__style__/main-external.scss"));
31
31
  var _main = _interopRequireDefault(require("./__style__/main.scss"));
@@ -59,7 +59,7 @@ function _interopRequireWildcard(e, r) {
59
59
  }
60
60
  return n.default = e, t && t.set(e, n), n;
61
61
  }
62
- // import Routes from './__pages__/index';
62
+ // import TEST_ONLY_INTERNAL_ROUTES from './__pages__/internal/__TEST_ONLY_INTERNAL_ROUTES';
63
63
 
64
64
  _reactGtmModule.default.initialize({
65
65
  gtmId: APP_CONFIG.googleTagManagerId || 'GTM-TC67SZ4'
@@ -76,6 +76,6 @@ const App = () => {
76
76
  defaultCountry: APP_CONFIG.country
77
77
  }, /*#__PURE__*/_react.default.createElement(_OrderSessionContext.OrderSessionController, null, /*#__PURE__*/_react.default.createElement(_reactQuery.QueryClientProvider, {
78
78
  client: _queryClient.default
79
- }, /*#__PURE__*/_react.default.createElement(_reactRouterDom.BrowserRouter, null, /*#__PURE__*/_react.default.createElement(_reactHotLoader.AppContainer, null, /*#__PURE__*/_react.default.createElement(_ActiveMarkerContext.ActiveMarkerProvider, null, /*#__PURE__*/_react.default.createElement(_StyleWrapper.default, null, !APP_CONFIG.internal && /*#__PURE__*/_react.default.createElement(_Navbar.default, null), APP_CONFIG.internal && /*#__PURE__*/_react.default.createElement(_InternalBranchSelectorModal.default, null), APP_CONFIG.nodeEnv === 'development' && APP_CONFIG.internal === true && /*#__PURE__*/_react.default.createElement(_TEST_ONLY_INTERNAL_ROUTES.default, null))))))))));
79
+ }, /*#__PURE__*/_react.default.createElement(_reactRouterDom.BrowserRouter, null, /*#__PURE__*/_react.default.createElement(_reactHotLoader.AppContainer, null, /*#__PURE__*/_react.default.createElement(_ActiveMarkerContext.ActiveMarkerProvider, null, /*#__PURE__*/_react.default.createElement(_StyleWrapper.default, null, !APP_CONFIG.internal && /*#__PURE__*/_react.default.createElement(_Navbar.default, null), APP_CONFIG.internal && /*#__PURE__*/_react.default.createElement(_InternalBranchSelectorModal.default, null), /*#__PURE__*/_react.default.createElement(_index.default, null))))))))));
80
80
  };
81
81
  var _default = exports.default = App;
@@ -110,6 +110,13 @@ const QuestionsForm = _ref => {
110
110
  executionAnswer2: '',
111
111
  durationAnswer: ''
112
112
  });
113
+
114
+ // Store initial options in state
115
+ const [initialOptions, setInitialOptions] = (0, _react.useState)({
116
+ execution1: [],
117
+ execution2: [],
118
+ duration: []
119
+ });
113
120
  const [{
114
121
  licensePlate,
115
122
  model,
@@ -128,6 +135,34 @@ const QuestionsForm = _ref => {
128
135
  formula = singleOrderFormulaCode;
129
136
  }
130
137
  const history = (0, _reactRouter.useHistory)();
138
+
139
+ // Create a modified version of execution answers for the query
140
+ // Only include both execution answers if both are provided
141
+ const createQueryParams = () => {
142
+ const hasMultipleExecutionQuestions = initialOptions.execution1.length > 0 && initialOptions.execution2.length > 0;
143
+
144
+ // If we have multiple execution questions, only include answers if both are provided
145
+ if (hasMultipleExecutionQuestions && (!executionAnswer1 || !executionAnswer2)) {
146
+ return {
147
+ licensePlate: initialLicensePlate !== null && initialLicensePlate !== void 0 ? initialLicensePlate : licensePlate,
148
+ model,
149
+ formula,
150
+ discountCode,
151
+ durationAnswer: durationAnswer
152
+ };
153
+ }
154
+
155
+ // Otherwise include all available answers
156
+ return {
157
+ licensePlate: initialLicensePlate !== null && initialLicensePlate !== void 0 ? initialLicensePlate : licensePlate,
158
+ model,
159
+ formula,
160
+ discountCode,
161
+ executionAnswer1,
162
+ executionAnswer2,
163
+ durationAnswer: durationAnswer
164
+ };
165
+ };
131
166
  const {
132
167
  isLoadingQuestions,
133
168
  execution1AnswerOptions,
@@ -135,25 +170,70 @@ const QuestionsForm = _ref => {
135
170
  durationAnswer: durationAnswerPrefilled,
136
171
  questionsError,
137
172
  durationQuestion
138
- } = (0, _queries.useQuestionsQuery)({
173
+ } = (0, _queries.useQuestionsQuery)(createQueryParams());
174
+
175
+ // Store initial options when they first arrive
176
+ (0, _react.useEffect)(() => {
177
+ if (!initialOptions.execution1.length && execution1AnswerOptions !== null && execution1AnswerOptions !== void 0 && execution1AnswerOptions.length) {
178
+ setInitialOptions(prev => _objectSpread(_objectSpread({}, prev), {}, {
179
+ execution1: execution1AnswerOptions
180
+ }));
181
+ // Only update context on initial load
182
+ dispatch({
183
+ type: _OrderSessionContext.orderSessionActions.SET_EXECUTION1_OPTIONS,
184
+ payload: {
185
+ options: execution1AnswerOptions
186
+ }
187
+ });
188
+ }
189
+ }, [execution1AnswerOptions]);
190
+ (0, _react.useEffect)(() => {
191
+ if (!initialOptions.execution2.length && execution2AnswerOptions !== null && execution2AnswerOptions !== void 0 && execution2AnswerOptions.length) {
192
+ setInitialOptions(prev => _objectSpread(_objectSpread({}, prev), {}, {
193
+ execution2: execution2AnswerOptions
194
+ }));
195
+ // Only update context on initial load
196
+ dispatch({
197
+ type: _OrderSessionContext.orderSessionActions.SET_EXECUTION2_OPTIONS,
198
+ payload: {
199
+ options: execution2AnswerOptions
200
+ }
201
+ });
202
+ }
203
+ }, [execution2AnswerOptions]);
204
+ (0, _react.useEffect)(() => {
205
+ if (!initialOptions.duration.length && durationQuestion !== null && durationQuestion !== void 0 && durationQuestion.length) {
206
+ setInitialOptions(prev => _objectSpread(_objectSpread({}, prev), {}, {
207
+ duration: durationQuestion
208
+ }));
209
+ dispatch({
210
+ type: _OrderSessionContext.orderSessionActions.SET_DURATION_OPTIONS,
211
+ payload: {
212
+ options: durationQuestion
213
+ }
214
+ });
215
+ }
216
+ }, [durationQuestion]);
217
+
218
+ // Only prefetch products when all required answers are provided
219
+ const hasMultipleExecutionQuestions = initialOptions.execution1.length > 0 && initialOptions.execution2.length > 0;
220
+ const shouldPrefetchProducts = !hasMultipleExecutionQuestions || executionAnswer1 && executionAnswer2;
221
+ (0, _queries.useProductsQuery)(shouldPrefetchProducts ? {
139
222
  licensePlate: initialLicensePlate !== null && initialLicensePlate !== void 0 ? initialLicensePlate : licensePlate,
140
223
  model,
141
- formula,
142
- discountCode,
143
224
  executionAnswer1,
144
225
  executionAnswer2,
145
- durationAnswer: durationAnswer
146
- });
147
- (0, _queries.useProductsQuery)({
226
+ durationAnswer,
227
+ formula,
228
+ discountCode,
229
+ priceCalculationDate
230
+ } : {
148
231
  licensePlate: initialLicensePlate !== null && initialLicensePlate !== void 0 ? initialLicensePlate : licensePlate,
149
232
  model,
150
- executionAnswer1,
151
- executionAnswer2,
152
- durationAnswer,
153
233
  formula,
154
234
  discountCode,
155
235
  priceCalculationDate
156
- }); // Prefetch
236
+ });
157
237
 
158
238
  /**
159
239
  * @description This hook pre-fills the duration answer, only if it comes pre-filled from the API, and it's not set manually by the user.
@@ -294,26 +374,26 @@ const QuestionsForm = _ref => {
294
374
  };
295
375
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("p", null, "We hebben nog een aantal vragen (max 4) voordat we de juiste trekhaak voor jouw auto kunnen adviseren."), /*#__PURE__*/_react.default.createElement("div", {
296
376
  className: (0, _helpers__.withStyle)('my-2')
297
- }, (durationOptions === null || durationOptions === void 0 ? void 0 : durationOptions.length) > 0 && /*#__PURE__*/_react.default.createElement(_RadioInput.default, {
377
+ }, initialOptions.duration.length > 0 && /*#__PURE__*/_react.default.createElement(_RadioInput.default, {
298
378
  name: "questions-duration",
299
379
  label: "Selecteer uw uitvoering",
300
380
  onChange: handleDurationChange,
301
381
  initialValue: isFilter ? filterAnswers.durationAnswer : durationAnswer,
302
- options: durationOptions,
382
+ options: initialOptions.duration,
303
383
  isRequired: true
304
- }), (execution1Options === null || execution1Options === void 0 ? void 0 : execution1Options.length) > 0 && /*#__PURE__*/_react.default.createElement(_RadioInput.default, {
384
+ }), initialOptions.execution1.length > 0 && /*#__PURE__*/_react.default.createElement(_RadioInput.default, {
305
385
  name: "questions-1",
306
386
  label: "Selecteer uw uitvoering",
307
387
  onChange: handleExecution1Change,
308
388
  initialValue: isFilter ? filterAnswers.executionAnswer1 : executionAnswer1,
309
- options: execution1Options,
389
+ options: initialOptions.execution1,
310
390
  isRequired: true
311
- }), (execution2Options === null || execution2Options === void 0 ? void 0 : execution2Options.length) > 0 && /*#__PURE__*/_react.default.createElement(_RadioInput.default, {
391
+ }), initialOptions.execution2.length > 0 && /*#__PURE__*/_react.default.createElement(_RadioInput.default, {
312
392
  name: "questions-2",
313
393
  label: "Selecteer uw uitvoering",
314
394
  onChange: handleExecution2Change,
315
395
  initialValue: isFilter ? filterAnswers.executionAnswer2 : executionAnswer2,
316
- options: execution2Options,
396
+ options: initialOptions.execution2,
317
397
  isRequired: true
318
398
  })), /*#__PURE__*/_react.default.createElement("div", {
319
399
  className: (0, _helpers__.withStyle)('row align-items-center justify-content-end mt-2')
@@ -331,20 +411,29 @@ const QuestionsForm = _ref => {
331
411
  }, /*#__PURE__*/_react.default.createElement("div", {
332
412
  className: (0, _helpers__.withStyle)('d-grid gap-2')
333
413
  }, /*#__PURE__*/_react.default.createElement(_PrimaryButton.default, {
334
- isDisabled: isFilter ? execution1AnswerOptions.length && !filterAnswers.executionAnswer1 || execution2AnswerOptions.length && !filterAnswers.executionAnswer2 || durationQuestion.length && !filterAnswers.durationAnswer : execution1AnswerOptions.length && !executionAnswer1 || execution2AnswerOptions.length && !executionAnswer2 || durationQuestion.length && !durationAnswer,
335
- onClick: () => onSubmit(isFilter ? {
336
- type: 'licensePlate',
337
- value: {
338
- licensePlate: initialLicensePlate,
339
- executionAnswer1: filterAnswers.executionAnswer1,
340
- executionAnswer2: filterAnswers.executionAnswer2,
341
- durationAnswer: filterAnswers.durationAnswer
414
+ isDisabled: isFilter ? initialOptions.execution1.length && !filterAnswers.executionAnswer1 || initialOptions.execution2.length && !filterAnswers.executionAnswer2 || initialOptions.duration.length && !filterAnswers.durationAnswer || hasMultipleExecutionQuestions && (!filterAnswers.executionAnswer1 || !filterAnswers.executionAnswer2) : initialOptions.execution1.length && !executionAnswer1 || initialOptions.execution2.length && !executionAnswer2 || initialOptions.duration.length && !durationAnswer || hasMultipleExecutionQuestions && (!executionAnswer1 || !executionAnswer2),
415
+ onClick: () => {
416
+ // Don't proceed if both are required but not provided
417
+ if (hasMultipleExecutionQuestions && (!executionAnswer1 || !executionAnswer2) && !isFilter) {
418
+ return;
342
419
  }
343
- } : {
344
- executionAnswer1,
345
- executionAnswer2,
346
- durationAnswer
347
- }),
420
+ if (isFilter && hasMultipleExecutionQuestions && (!filterAnswers.executionAnswer1 || !filterAnswers.executionAnswer2)) {
421
+ return;
422
+ }
423
+ onSubmit(isFilter ? {
424
+ type: 'licensePlate',
425
+ value: {
426
+ licensePlate: initialLicensePlate,
427
+ executionAnswer1: filterAnswers.executionAnswer1,
428
+ executionAnswer2: filterAnswers.executionAnswer2,
429
+ durationAnswer: filterAnswers.durationAnswer
430
+ }
431
+ } : {
432
+ executionAnswer1,
433
+ executionAnswer2,
434
+ durationAnswer
435
+ });
436
+ },
348
437
  label: isFilter ? 'Filter' : 'Bekijk de mogelijkheden'
349
438
  })))));
350
439
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "thm-p3-configurator",
3
- "version": "0.0.129",
3
+ "version": "0.0.131",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "author": "EnoRm.",