thm-p3-configurator 0.0.36 → 0.0.37

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.
@@ -171,7 +171,7 @@ const useProductsQuery = orderParameters => {
171
171
  */
172
172
  exports.useProductsQuery = useProductsQuery;
173
173
  const useQuestionsQuery = questionParams => {
174
- var _questionsQuery$error, _questionsQuery$data$, _questionsQuery$data, _questionsQuery$data$2, _questionsQuery$data2, _questionsQuery$data$3, _questionsQuery$data3;
174
+ var _questionsQuery$data, _questionsQuery$data2, _questionsQuery$data3, _questionsQuery$error, _questionsQuery$data$, _questionsQuery$data4, _questionsQuery$data$2, _questionsQuery$data5, _questionsQuery$data$3, _questionsQuery$data6;
175
175
  const {
176
176
  licensePlate,
177
177
  model
@@ -180,21 +180,27 @@ const useQuestionsQuery = questionParams => {
180
180
  const questionsQuery = (0, _reactQuery.useQuery)(['questions', questionsParamsString], {
181
181
  enabled: (licensePlate === null || licensePlate === void 0 ? void 0 : licensePlate.length) > 5 || !!(model !== null && model !== void 0 && model.length),
182
182
  queryFn: () => _orderApi.orderApi.getOrder(questionsParamsString).then(res => {
183
- var _res$data5, _res$data6, _res$data7;
183
+ var _res$data5, _res$data6, _res$data7, _res$data8, _res$data9, _res$data10;
184
184
  return {
185
- durationQuestion: (0, _helpers__.parseArrayToInputOptions)(res === null || res === void 0 || (_res$data5 = res.data) === null || _res$data5 === void 0 || (_res$data5 = _res$data5.data) === null || _res$data5 === void 0 ? void 0 : _res$data5.durationAnswerOptions),
186
- execution1AnswerOptions: (0, _helpers__.parseArrayToInputOptions)(res === null || res === void 0 || (_res$data6 = res.data) === null || _res$data6 === void 0 || (_res$data6 = _res$data6.data) === null || _res$data6 === void 0 || (_res$data6 = _res$data6.executionAnswerOptions) === null || _res$data6 === void 0 ? void 0 : _res$data6.execution1AnswerOptions),
187
- execution2AnswerOptions: (0, _helpers__.parseArrayToInputOptions)(res === null || res === void 0 || (_res$data7 = res.data) === null || _res$data7 === void 0 || (_res$data7 = _res$data7.data) === null || _res$data7 === void 0 || (_res$data7 = _res$data7.executionAnswerOptions) === null || _res$data7 === void 0 ? void 0 : _res$data7.execution2AnswerOptions)
185
+ execution1Answer: res === null || res === void 0 || (_res$data5 = res.data) === null || _res$data5 === void 0 || (_res$data5 = _res$data5.data) === null || _res$data5 === void 0 || (_res$data5 = _res$data5.answers) === null || _res$data5 === void 0 ? void 0 : _res$data5.execution1,
186
+ execution2Answer: res === null || res === void 0 || (_res$data6 = res.data) === null || _res$data6 === void 0 || (_res$data6 = _res$data6.data) === null || _res$data6 === void 0 || (_res$data6 = _res$data6.answers) === null || _res$data6 === void 0 ? void 0 : _res$data6.execution2,
187
+ durationAnswer: res === null || res === void 0 || (_res$data7 = res.data) === null || _res$data7 === void 0 || (_res$data7 = _res$data7.data) === null || _res$data7 === void 0 || (_res$data7 = _res$data7.answers) === null || _res$data7 === void 0 ? void 0 : _res$data7.duration,
188
+ durationQuestion: (0, _helpers__.parseArrayToInputOptions)(res === null || res === void 0 || (_res$data8 = res.data) === null || _res$data8 === void 0 || (_res$data8 = _res$data8.data) === null || _res$data8 === void 0 ? void 0 : _res$data8.durationAnswerOptions),
189
+ execution1AnswerOptions: (0, _helpers__.parseArrayToInputOptions)(res === null || res === void 0 || (_res$data9 = res.data) === null || _res$data9 === void 0 || (_res$data9 = _res$data9.data) === null || _res$data9 === void 0 || (_res$data9 = _res$data9.executionAnswerOptions) === null || _res$data9 === void 0 ? void 0 : _res$data9.execution1AnswerOptions),
190
+ execution2AnswerOptions: (0, _helpers__.parseArrayToInputOptions)(res === null || res === void 0 || (_res$data10 = res.data) === null || _res$data10 === void 0 || (_res$data10 = _res$data10.data) === null || _res$data10 === void 0 || (_res$data10 = _res$data10.executionAnswerOptions) === null || _res$data10 === void 0 ? void 0 : _res$data10.execution2AnswerOptions)
188
191
  };
189
192
  })
190
193
  });
191
194
  return {
192
195
  isLoadingQuestions: questionsQuery.isFetching,
193
196
  isQuestionsError: questionsQuery.isError,
197
+ execution1Answer: questionsQuery === null || questionsQuery === void 0 || (_questionsQuery$data = questionsQuery.data) === null || _questionsQuery$data === void 0 ? void 0 : _questionsQuery$data.execution1Answer,
198
+ execution2Answer: questionsQuery === null || questionsQuery === void 0 || (_questionsQuery$data2 = questionsQuery.data) === null || _questionsQuery$data2 === void 0 ? void 0 : _questionsQuery$data2.execution2Answer,
199
+ durationAnswer: questionsQuery === null || questionsQuery === void 0 || (_questionsQuery$data3 = questionsQuery.data) === null || _questionsQuery$data3 === void 0 ? void 0 : _questionsQuery$data3.durationAnswer,
194
200
  questionsError: ((_questionsQuery$error = questionsQuery.error) === null || _questionsQuery$error === void 0 || (_questionsQuery$error = _questionsQuery$error.response) === null || _questionsQuery$error === void 0 || (_questionsQuery$error = _questionsQuery$error.data) === null || _questionsQuery$error === void 0 ? void 0 : _questionsQuery$error.code) || questionsQuery.error,
195
- execution1AnswerOptions: (_questionsQuery$data$ = questionsQuery === null || questionsQuery === void 0 || (_questionsQuery$data = questionsQuery.data) === null || _questionsQuery$data === void 0 ? void 0 : _questionsQuery$data.execution1AnswerOptions) !== null && _questionsQuery$data$ !== void 0 ? _questionsQuery$data$ : [],
196
- execution2AnswerOptions: (_questionsQuery$data$2 = questionsQuery === null || questionsQuery === void 0 || (_questionsQuery$data2 = questionsQuery.data) === null || _questionsQuery$data2 === void 0 ? void 0 : _questionsQuery$data2.execution2AnswerOptions) !== null && _questionsQuery$data$2 !== void 0 ? _questionsQuery$data$2 : [],
197
- durationQuestion: (_questionsQuery$data$3 = questionsQuery === null || questionsQuery === void 0 || (_questionsQuery$data3 = questionsQuery.data) === null || _questionsQuery$data3 === void 0 ? void 0 : _questionsQuery$data3.durationQuestion) !== null && _questionsQuery$data$3 !== void 0 ? _questionsQuery$data$3 : []
201
+ execution1AnswerOptions: (_questionsQuery$data$ = questionsQuery === null || questionsQuery === void 0 || (_questionsQuery$data4 = questionsQuery.data) === null || _questionsQuery$data4 === void 0 ? void 0 : _questionsQuery$data4.execution1AnswerOptions) !== null && _questionsQuery$data$ !== void 0 ? _questionsQuery$data$ : [],
202
+ execution2AnswerOptions: (_questionsQuery$data$2 = questionsQuery === null || questionsQuery === void 0 || (_questionsQuery$data5 = questionsQuery.data) === null || _questionsQuery$data5 === void 0 ? void 0 : _questionsQuery$data5.execution2AnswerOptions) !== null && _questionsQuery$data$2 !== void 0 ? _questionsQuery$data$2 : [],
203
+ durationQuestion: (_questionsQuery$data$3 = questionsQuery === null || questionsQuery === void 0 || (_questionsQuery$data6 = questionsQuery.data) === null || _questionsQuery$data6 === void 0 ? void 0 : _questionsQuery$data6.durationQuestion) !== null && _questionsQuery$data$3 !== void 0 ? _questionsQuery$data$3 : []
198
204
  };
199
205
  };
200
206
 
@@ -175,10 +175,10 @@ const AppointmentForm = () => {
175
175
  execution1: executionAnswer1,
176
176
  execution2: executionAnswer2
177
177
  }),
178
- customer: _objectSpread(_objectSpread({}, customer), {}, {
178
+ customer: (0, _helpers__.removeNullishProps)(_objectSpread(_objectSpread({}, customer), {}, {
179
179
  firstName: (customer === null || customer === void 0 ? void 0 : customer.firstName) || '(Onbekend)',
180
180
  lastName: (customer === null || customer === void 0 ? void 0 : customer.lastName) || '(Onbekend)'
181
- }),
181
+ })),
182
182
  formula,
183
183
  branchId: selectedBranch,
184
184
  selectBoardComputerUpdate: selectedBoardComputer != null,
@@ -3,8 +3,10 @@
3
3
  require("core-js/modules/es.regexp.exec.js");
4
4
  require("core-js/modules/es.regexp.to-string.js");
5
5
  require("core-js/modules/es.string.search.js");
6
+ require("core-js/modules/es.weak-map.js");
6
7
  require("core-js/modules/web.dom-collections.iterator.js");
7
8
  require("core-js/modules/web.url-search-params.js");
9
+ require("core-js/modules/es.weak-map.js");
8
10
  Object.defineProperty(exports, "__esModule", {
9
11
  value: true
10
12
  });
@@ -14,7 +16,7 @@ require("core-js/modules/es.regexp.to-string.js");
14
16
  require("core-js/modules/es.string.search.js");
15
17
  require("core-js/modules/web.dom-collections.iterator.js");
16
18
  require("core-js/modules/web.url-search-params.js");
17
- var _react = _interopRequireDefault(require("react"));
19
+ var _react = _interopRequireWildcard(require("react"));
18
20
  var _reactRouter = require("react-router");
19
21
  var _queries = require("../__api__/queries");
20
22
  var _LinkButton = _interopRequireDefault(require("../__components__/Buttons/LinkButton"));
@@ -28,9 +30,39 @@ function _interopRequireDefault(e) {
28
30
  default: e
29
31
  };
30
32
  }
33
+ function _getRequireWildcardCache(e) {
34
+ if ("function" != typeof WeakMap) return null;
35
+ var r = new WeakMap(),
36
+ t = new WeakMap();
37
+ return (_getRequireWildcardCache = function _getRequireWildcardCache(e) {
38
+ return e ? t : r;
39
+ })(e);
40
+ }
41
+ function _interopRequireWildcard(e, r) {
42
+ if (!r && e && e.__esModule) return e;
43
+ if (null === e || "object" != typeof e && "function" != typeof e) return {
44
+ default: e
45
+ };
46
+ var t = _getRequireWildcardCache(r);
47
+ if (t && t.has(e)) return t.get(e);
48
+ var n = {
49
+ __proto__: null
50
+ },
51
+ a = Object.defineProperty && Object.getOwnPropertyDescriptor;
52
+ for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) {
53
+ var i = a ? Object.getOwnPropertyDescriptor(e, u) : null;
54
+ i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u];
55
+ }
56
+ return n.default = e, t && t.set(e, n), n;
57
+ }
31
58
  const ManualSelectionForm = _ref => {
32
59
  let {
33
- onSubmit
60
+ onSubmit,
61
+ initialValues = {
62
+ brand: null,
63
+ model: null,
64
+ buildYear: null
65
+ }
34
66
  } = _ref;
35
67
  const [{
36
68
  brand,
@@ -71,6 +103,17 @@ const ManualSelectionForm = _ref => {
71
103
  history.push("/configurator".concat(searchParams !== null && searchParams !== void 0 && searchParams.size ? "?".concat(searchParams.toString()) : '') // append search params if found
72
104
  );
73
105
  };
106
+ (0, _react.useEffect)(() => {
107
+ handleBrandChange({
108
+ value: initialValues.brand
109
+ });
110
+ handleBuildYearChange({
111
+ value: initialValues.buildYear
112
+ });
113
+ handleModelChange({
114
+ value: initialValues.model
115
+ });
116
+ }, [initialValues]);
74
117
  const handleBrandChange = brandOption => {
75
118
  dispatch({
76
119
  type: _OrderSessionContext.orderSessionActions.SET_BRAND,
@@ -106,7 +149,10 @@ const ManualSelectionForm = _ref => {
106
149
  noOptionsMessage: "Geen opties beschikbaar",
107
150
  placeholder: "Maak een keuze",
108
151
  onChange: handleBrandChange,
109
- initialValue: !brand ? null : {
152
+ initialValue: !brand ? {
153
+ value: initialValues === null || initialValues === void 0 ? void 0 : initialValues.brand,
154
+ label: initialValues === null || initialValues === void 0 ? void 0 : initialValues.brand
155
+ } : {
110
156
  value: brand,
111
157
  label: brand
112
158
  }
@@ -119,7 +165,10 @@ const ManualSelectionForm = _ref => {
119
165
  noOptionsMessage: "Geen opties beschikbaar",
120
166
  placeholder: "Maak een keuze",
121
167
  onChange: handleBuildYearChange,
122
- initialValue: !buildYear ? null : {
168
+ initialValue: !buildYear ? {
169
+ value: initialValues === null || initialValues === void 0 ? void 0 : initialValues.buildYear,
170
+ label: initialValues === null || initialValues === void 0 ? void 0 : initialValues.buildYear
171
+ } : {
123
172
  value: buildYear,
124
173
  label: buildYear
125
174
  }
@@ -132,7 +181,10 @@ const ManualSelectionForm = _ref => {
132
181
  noOptionsMessage: "Geen opties beschikbaar",
133
182
  placeholder: "Maak een keuze",
134
183
  onChange: handleModelChange,
135
- initialValue: !model ? null : {
184
+ initialValue: !model ? {
185
+ value: initialValues === null || initialValues === void 0 ? void 0 : initialValues.model,
186
+ label: initialValues === null || initialValues === void 0 ? void 0 : initialValues.model
187
+ } : {
136
188
  value: model,
137
189
  label: model
138
190
  }
@@ -71,6 +71,7 @@ const QuestionsForm = _ref => {
71
71
  isLoadingQuestions,
72
72
  execution1AnswerOptions,
73
73
  execution2AnswerOptions,
74
+ durationAnswer: durationAnswerPrefilled,
74
75
  questionsError,
75
76
  durationQuestion
76
77
  } = (0, _queries.useQuestionsQuery)({
@@ -93,6 +94,19 @@ const QuestionsForm = _ref => {
93
94
  priceCalculationDate
94
95
  }); // Prefetch
95
96
 
97
+ /**
98
+ * @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.
99
+ */
100
+ (0, _react.useEffect)(() => {
101
+ if (!durationAnswer && durationAnswerPrefilled && !(durationOptions !== null && durationOptions !== void 0 && durationOptions.length) && !(durationQuestion !== null && durationQuestion !== void 0 && durationQuestion.length)) {
102
+ dispatch({
103
+ type: _OrderSessionContext.orderSessionActions.SET_DURATION_ANSWER,
104
+ payload: {
105
+ answer: durationAnswerPrefilled
106
+ }
107
+ });
108
+ }
109
+ }, [durationOptions, durationAnswerPrefilled, durationQuestion, durationAnswer]);
96
110
  (0, _react.useEffect)(() => {
97
111
  if (durationQuestion !== null && durationQuestion !== void 0 && durationQuestion.length) {
98
112
  dispatch({
@@ -172,7 +172,7 @@ const QuotationForm = () => {
172
172
  code: discountCode
173
173
  } : null,
174
174
  formula,
175
- customer,
175
+ customer: (0, _helpers__.removeNullishProps)(customer),
176
176
  branchId: selectedBranch,
177
177
  selectBoardComputerUpdate: selectedBoardComputer != null,
178
178
  cart: (0, _product.validateCartInput)([{
@@ -32,7 +32,8 @@ const VehicleData = () => {
32
32
  executionAnswer2,
33
33
  durationAnswer,
34
34
  discountCode,
35
- priceCalculationDate
35
+ priceCalculationDate,
36
+ existingDossierId
36
37
  }] = (0, _OrderSessionContext.useOrderSession)();
37
38
  const formula = (0, _FormulaContext.useFormula)();
38
39
  const {
@@ -71,7 +72,7 @@ const VehicleData = () => {
71
72
  isDisabled: false,
72
73
  label: 'Wijzig voertuig',
73
74
  onClick: () => {
74
- history.push("/configurator".concat(licensePlate ? '' : '/manual'));
75
+ history.push("/configurator".concat(licensePlate ? '' : '/manual', "?persistSession=true"));
75
76
  },
76
77
  className: (0, _helpers__.withStyle)('license-plate__edit link-primary col-12'),
77
78
  type: "button"
@@ -202,7 +202,7 @@ const removeNullishProps = exports.removeNullishProps = function removeNullishPr
202
202
  let object = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
203
203
  return Object.fromEntries(Object.entries(object).filter(_ref3 => {
204
204
  let [key, value] = _ref3;
205
- return value != null;
205
+ return !!value;
206
206
  }));
207
207
  };
208
208
 
@@ -70,9 +70,10 @@ const getSteps = _ref => {
70
70
  const licensePlateValidator = new _LicensePlateValidator.default();
71
71
  const InternalLicensePlatePage = () => {
72
72
  const [activeStep, setActiveStep] = (0, _react.useState)(0);
73
- const [_, dispatch] = (0, _OrderSessionContext.useOrderSession)();
73
+ const [session, dispatch] = (0, _OrderSessionContext.useOrderSession)();
74
+ const originalLicensePlate = (0, _react.useRef)();
74
75
  const formula = (0, _FormulaContext.useFormula)();
75
- const [licensePlateURL, discountCode] = (0, _useSearchParam.default)(['licensePlate', 'discountCode']);
76
+ const [licensePlateURL, discountCode, persistSession] = (0, _useSearchParam.default)(['licensePlate', 'discountCode', 'persistSession']);
76
77
  const history = (0, _reactRouter.useHistory)();
77
78
  (0, _queries.useProductFieldLabels)(); // Prefetch
78
79
 
@@ -85,6 +86,11 @@ const InternalLicensePlatePage = () => {
85
86
  const handleSubmit = () => {
86
87
  history.push('/configurator/trekhaakpakket');
87
88
  };
89
+ (0, _react.useEffect)(() => {
90
+ if (!originalLicensePlate.current && session !== null && session !== void 0 && session.licensePlate) {
91
+ originalLicensePlate.current = session.licensePlate;
92
+ }
93
+ }, [session]);
88
94
  (0, _react.useEffect)(() => {
89
95
  // If no license plate was found: initialize a new order
90
96
  if (!licensePlateURL) {
@@ -109,11 +115,11 @@ const InternalLicensePlatePage = () => {
109
115
  }
110
116
  }, [discountCode]);
111
117
  const Steps = (0, _react.useMemo)(() => getSteps({
112
- initialLicensePlate: licensePlateValidator.init(licensePlateURL),
118
+ initialLicensePlate: persistSession === 'true' ? originalLicensePlate.current : licensePlateValidator.init(licensePlateURL),
113
119
  onNext: handleNext,
114
120
  onPrev: handlePrev,
115
121
  onSubmit: handleSubmit
116
- }), []);
122
+ }), [persistSession, originalLicensePlate.current]);
117
123
  return /*#__PURE__*/_react.default.createElement("div", {
118
124
  className: (0, _helpers__.withStyle)('vh-100')
119
125
  }, /*#__PURE__*/_react.default.createElement(_internal.InternalCancelDossierEdit, null), /*#__PURE__*/_react.default.createElement("section", {
@@ -55,23 +55,39 @@ const getSteps = _ref => {
55
55
  let {
56
56
  onNext,
57
57
  onPrev,
58
- onSubmit
58
+ onSubmit,
59
+ initialValues
59
60
  } = _ref;
60
61
  return [/*#__PURE__*/_react.default.createElement(_ManualSelectionForm.default, {
61
- onSubmit: onNext
62
+ onSubmit: onNext,
63
+ initialValues: initialValues
62
64
  }), /*#__PURE__*/_react.default.createElement(_QuestionsForm.default, {
63
65
  onPrev: onPrev,
64
66
  onSubmit: onSubmit
65
67
  })];
66
68
  };
67
69
  const InternalManualSelectionPage = () => {
68
- const [_, dispatch] = (0, _OrderSessionContext.useOrderSession)();
70
+ const [{
71
+ brand,
72
+ model,
73
+ buildYear
74
+ }, dispatch] = (0, _OrderSessionContext.useOrderSession)();
69
75
  const [activeStep, setActiveStep] = (0, _react.useState)(0);
76
+ const originalVehicle = (0, _react.useRef)();
70
77
  const history = (0, _reactRouter.useHistory)();
71
78
  const formula = (0, _FormulaContext.useFormula)();
72
- const [discountCode] = (0, _useSearchParam.default)(['discountCode']);
79
+ const [discountCode, persistSession] = (0, _useSearchParam.default)(['discountCode', 'persistSession']);
73
80
  (0, _queries.useProductFieldLabels)(); // Prefetch
74
81
 
82
+ (0, _react.useEffect)(() => {
83
+ if (!(originalVehicle !== null && originalVehicle !== void 0 && originalVehicle.current)) {
84
+ originalVehicle.current = {
85
+ brand,
86
+ model,
87
+ buildYear
88
+ };
89
+ }
90
+ }, [brand, model, buildYear]);
75
91
  (0, _react.useEffect)(() => {
76
92
  dispatch({
77
93
  type: _OrderSessionContext.orderSessionActions.INITIALIZE_NEW_ORDER,
@@ -100,10 +116,15 @@ const InternalManualSelectionPage = () => {
100
116
  history.push('/configurator/trekhaakpakket');
101
117
  };
102
118
  const Steps = (0, _react.useMemo)(() => getSteps({
119
+ initialValues: persistSession ? originalVehicle.current : {
120
+ brand: null,
121
+ model: null,
122
+ buildYear: null
123
+ },
103
124
  onNext: handleNext,
104
125
  onPrev: handlePrev,
105
126
  onSubmit: handleSubmit
106
- }), []);
127
+ }), [persistSession, originalVehicle.current]);
107
128
  return /*#__PURE__*/_react.default.createElement("div", {
108
129
  className: (0, _helpers__.withStyle)('vh-100')
109
130
  }, /*#__PURE__*/_react.default.createElement(_internal.InternalCancelDossierEdit, null), /*#__PURE__*/_react.default.createElement("section", {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "thm-p3-configurator",
3
- "version": "0.0.36",
3
+ "version": "0.0.37",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "author": "EnoRm.",