mod-build 4.0.60-beta.5 → 4.0.60-beta.9

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/CHANGELOG.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  ## 4.0.60
4
4
 
5
- - Adding VWO variation ID to the body tag as an attribute `data-vwo-test-id`
5
+ - Applying merging of default trade questions and default form config on all the `steps` objects found.
6
6
 
7
7
  ## 4.0.59
8
8
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mod-build",
3
- "version": "4.0.60-beta.5",
3
+ "version": "4.0.60-beta.9",
4
4
  "description": "Share components for S3 sites.",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -10,12 +10,6 @@
10
10
  n: variationName
11
11
  }
12
12
  }
13
- if (variationId != 1 && window.addVwoTestAttribute) {
14
- // Control is assigned variation ID 1 - variations receive incremented IDs starting from 2
15
- const adjustedVariationId = variationId - 1;
16
- const vwoTestAttrValue = `${experimentId}-${adjustedVariationId}`;
17
- document.body.setAttribute('data-vwo-test', vwoTestAttrValue);
18
- }
19
13
  }
20
14
  }]);
21
15
 
@@ -3,6 +3,174 @@ import merge from 'lodash.merge';
3
3
  import axios from 'axios';
4
4
  import { defaultSettings } from '../src/data/config.js';
5
5
 
6
+ function mergeDefaultTradeQuestionsConfigOnSteps(config, steps) {
7
+ console.log('helllooow!!')
8
+ if (!config || typeof config !== 'object') return;
9
+
10
+ if (config.steps && typeof config.steps === 'object' && config.steps.items) {
11
+ mergeDefaultTradeQuestionsConfig(config, steps);
12
+ }
13
+
14
+ for (const key in config) {
15
+ if (config.hasOwnProperty(key)) {
16
+ const value = config[key];
17
+ if (typeof value === 'object' && value !== null) {
18
+ mergeDefaultTradeQuestionsConfigOnSteps(value, steps);
19
+ }
20
+ }
21
+ }
22
+ }
23
+
24
+ function mergeDefaultTradeQuestionsConfig(config, steps) {
25
+ if (!config || !config.steps || !config.steps.items || !Array.isArray(config.steps.items)) {
26
+ return;
27
+ }
28
+
29
+ config.steps.items.forEach((item) => {
30
+ const stepName = item.attributes.data['step-name'];
31
+ if (steps[stepName]) {
32
+ if (!item.stepContent) {
33
+ item.stepContent = {};
34
+ }
35
+
36
+ if (!item.stepContent.fields) {
37
+ item.stepContent.fields = [];
38
+ }
39
+ const defaultStepFields = steps[stepName].fields;
40
+ let defaultStepOptions = [];
41
+ let defaultQuestionLegend = {};
42
+ defaultStepFields.forEach((defaultField) => {
43
+ defaultStepOptions = defaultField.options;
44
+ defaultQuestionLegend = defaultField.legend;
45
+ });
46
+
47
+ item.stepContent.fields.forEach((field) => {
48
+ if (field.legend) {
49
+ field.legend = merge(defaultQuestionLegend, field.legend);
50
+ } else {
51
+ field.legend = defaultQuestionLegend;
52
+ }
53
+
54
+ if (field && field.remove) {
55
+ if (field.remove.includes('all')) {
56
+ defaultStepOptions = [];
57
+ } else {
58
+ defaultStepOptions = defaultStepOptions.filter((_, i) => !field.remove.includes(i));
59
+ }
60
+ }
61
+
62
+ if (field.fieldType === 'radio') {
63
+ if (!field.errorMessage) {
64
+ field.errorMessage = 'Professionals need this info to generate a quote.';
65
+ }
66
+
67
+ if (field.options && Array.isArray(field.options) && field.options.length) {
68
+ field.options.forEach((option) => {
69
+ if (typeof option.update === 'number') {
70
+ if (option.attributes && option.attributes.checked === false) {
71
+ delete option.attributes.checked;
72
+ delete defaultStepOptions[option.update].attributes.checked;
73
+ }
74
+ merge(defaultStepOptions[option.update], option);
75
+ } else {
76
+ if (typeof option.insertAt === 'number') {
77
+ defaultStepOptions.splice(option.insertAt, 0, option);
78
+ } else {
79
+ defaultStepOptions.push(option);
80
+ }
81
+ }
82
+ });
83
+ }
84
+ field.options = defaultStepOptions;
85
+ } else {
86
+ if (field && Array.isArray(field) && field.length) {
87
+ if (typeof field.update === 'number') {
88
+ merge(defaultStepFields[field.update], field);
89
+ } else {
90
+ if (typeof field.insertAt === 'number') {
91
+ defaultStepFields.splice(field.insertAt, 0, field);
92
+ } else {
93
+ defaultStepFields.push(field);
94
+ }
95
+ }
96
+ }
97
+
98
+ field = defaultStepFields;
99
+ }
100
+ });
101
+
102
+ // extra question block
103
+ if (item.stepContent.extraQuestionBlock) {
104
+ if (!item.stepContent.extraQuestionBlock.fields) {
105
+ item.stepContent.extraQuestionBlock.fields = [];
106
+ }
107
+
108
+ const defaultExtraQuestionFields = steps[stepName].extraQuestionBlock.fields;
109
+ let defaultExtraQuestionOptions = [];
110
+ let defaultExtraQuestionLegend = {};
111
+ defaultExtraQuestionFields.forEach((defaultExtraQuestionField) => {
112
+ defaultExtraQuestionOptions = defaultExtraQuestionField.options;
113
+ defaultExtraQuestionLegend = defaultExtraQuestionField.legend;
114
+ });
115
+ item.stepContent.extraQuestionBlock.fields.forEach((field) => {
116
+
117
+ if (field.legend) {
118
+ field.legend = merge(defaultExtraQuestionLegend, field.legend);
119
+ } else {
120
+ field.legend = defaultExtraQuestionLegend;
121
+ }
122
+
123
+ if (field && field.remove) {
124
+ if (field.remove.includes('all')) {
125
+ defaultExtraQuestionOptions = [];
126
+ } else {
127
+ defaultExtraQuestionOptions = defaultExtraQuestionOptions.filter((_, i) => !field.remove.includes(i));
128
+ }
129
+ }
130
+
131
+ if (field.fieldType === 'radio') {
132
+ if (!field.errorMessage) {
133
+ field.errorMessage = 'Professionals need this info to generate a quote.';
134
+ }
135
+
136
+ if (field.options && Array.isArray(field.options) && field.options.length) {
137
+ field.options.forEach((option, optionIndex) => {
138
+ if (typeof option.update === 'number') {
139
+ if (option.attributes && option.attributes.checked === false) {
140
+ delete option.attributes.checked;
141
+ delete defaultStepOptions[option.update].attributes.checked;
142
+ }
143
+ merge(defaultExtraQuestionOptions[option.update], option);
144
+ } else {
145
+ if (typeof option.insertAt === 'number') {
146
+ defaultExtraQuestionOptions.splice(option.insertAt, 0, option);
147
+ } else {
148
+ defaultExtraQuestionOptions.push(option);
149
+ }
150
+ }
151
+ });
152
+ }
153
+ field.options = defaultExtraQuestionOptions;
154
+ } else {
155
+ if (field && Array.isArray(field) && field.length) {
156
+ if (typeof field.update === 'number') {
157
+ merge(defaultExtraQuestionFields[field.update], field);
158
+ } else {
159
+ if (typeof field.insertAt === 'number') {
160
+ defaultExtraQuestionFields.splice(field.insertAt, 0, field);
161
+ } else {
162
+ defaultExtraQuestionFields.push(field);
163
+ }
164
+ }
165
+ }
166
+ field = defaultExtraQuestionFields;
167
+ }
168
+ });
169
+ }
170
+ }
171
+ });
172
+ }
173
+
6
174
  export default async function(config) {
7
175
  if (config.useStepsConfig) {
8
176
  console.log('Starting get-default-trade-questions...');
@@ -35,149 +203,7 @@ export default async function(config) {
35
203
  steps.OwnHome = commonQuestions.OwnHome;
36
204
  steps.BuyTimeframe = commonQuestions.BuyTimeframe;
37
205
 
38
- config.steps.items.forEach((item) => {
39
- const stepName = item.attributes.data['step-name'];
40
- if (steps[stepName]) {
41
- if (!item.stepContent) {
42
- item.stepContent = {};
43
- }
44
-
45
- if (!item.stepContent.fields) {
46
- item.stepContent.fields = [];
47
- }
48
- const defaultStepFields = steps[stepName].fields;
49
- let defaultStepOptions = [];
50
- let defaultQuestionLegend = {};
51
- defaultStepFields.forEach((defaultField) => {
52
- defaultStepOptions = defaultField.options;
53
- defaultQuestionLegend = defaultField.legend;
54
- });
55
-
56
- item.stepContent.fields.forEach((field) => {
57
- if (field.legend) {
58
- field.legend = merge(defaultQuestionLegend, field.legend);
59
- } else {
60
- field.legend = defaultQuestionLegend;
61
- }
62
-
63
- if (field && field.remove) {
64
- if (field.remove.includes('all')) {
65
- defaultStepOptions = [];
66
- } else {
67
- defaultStepOptions = defaultStepOptions.filter((_, i) => !field.remove.includes(i));
68
- }
69
- }
70
-
71
- if (field.fieldType === 'radio') {
72
- if (!field.errorMessage) {
73
- field.errorMessage = 'Professionals need this info to generate a quote.';
74
- }
75
-
76
- if (field.options && Array.isArray(field.options) && field.options.length) {
77
- field.options.forEach((option) => {
78
- if (typeof option.update === 'number') {
79
- if (option.attributes && option.attributes.checked === false) {
80
- delete option.attributes.checked;
81
- delete defaultStepOptions[option.update].attributes.checked;
82
- }
83
- merge(defaultStepOptions[option.update], option);
84
- } else {
85
- if (typeof option.insertAt === 'number') {
86
- defaultStepOptions.splice(option.insertAt, 0, option);
87
- } else {
88
- defaultStepOptions.push(option);
89
- }
90
- }
91
- });
92
- }
93
- field.options = defaultStepOptions;
94
- } else {
95
- if (field && Array.isArray(field) && field.length) {
96
- if (typeof field.update === 'number') {
97
- merge(defaultStepFields[field.update], field);
98
- } else {
99
- if (typeof field.insertAt === 'number') {
100
- defaultStepFields.splice(field.insertAt, 0, field);
101
- } else {
102
- defaultStepFields.push(field);
103
- }
104
- }
105
- }
106
-
107
- field = defaultStepFields;
108
- }
109
- });
110
-
111
- // extra question block
112
- if (item.stepContent.extraQuestionBlock) {
113
- if (!item.stepContent.extraQuestionBlock.fields) {
114
- item.stepContent.extraQuestionBlock.fields = [];
115
- }
116
-
117
- const defaultExtraQuestionFields = steps[stepName].extraQuestionBlock.fields;
118
- let defaultExtraQuestionOptions = [];
119
- let defaultExtraQuestionLegend = {};
120
- defaultExtraQuestionFields.forEach((defaultExtraQuestionField) => {
121
- defaultExtraQuestionOptions = defaultExtraQuestionField.options;
122
- defaultExtraQuestionLegend = defaultExtraQuestionField.legend;
123
- });
124
- item.stepContent.extraQuestionBlock.fields.forEach((field) => {
125
-
126
- if (field.legend) {
127
- field.legend = merge(defaultExtraQuestionLegend, field.legend);
128
- } else {
129
- field.legend = defaultExtraQuestionLegend;
130
- }
131
-
132
- if (field && field.remove) {
133
- if (field.remove.includes('all')) {
134
- defaultExtraQuestionOptions = [];
135
- } else {
136
- defaultExtraQuestionOptions = defaultExtraQuestionOptions.filter((_, i) => !field.remove.includes(i));
137
- }
138
- }
139
-
140
- if (field.fieldType === 'radio') {
141
- if (!field.errorMessage) {
142
- field.errorMessage = 'Professionals need this info to generate a quote.';
143
- }
144
-
145
- if (field.options && Array.isArray(field.options) && field.options.length) {
146
- field.options.forEach((option, optionIndex) => {
147
- if (typeof option.update === 'number') {
148
- if (option.attributes && option.attributes.checked === false) {
149
- delete option.attributes.checked;
150
- delete defaultStepOptions[option.update].attributes.checked;
151
- }
152
- merge(defaultExtraQuestionOptions[option.update], option);
153
- } else {
154
- if (typeof option.insertAt === 'number') {
155
- defaultExtraQuestionOptions.splice(option.insertAt, 0, option);
156
- } else {
157
- defaultExtraQuestionOptions.push(option);
158
- }
159
- }
160
- });
161
- }
162
- field.options = defaultExtraQuestionOptions;
163
- } else {
164
- if (field && Array.isArray(field) && field.length) {
165
- if (typeof field.update === 'number') {
166
- merge(defaultExtraQuestionFields[field.update], field);
167
- } else {
168
- if (typeof field.insertAt === 'number') {
169
- defaultExtraQuestionFields.splice(field.insertAt, 0, field);
170
- } else {
171
- defaultExtraQuestionFields.push(field);
172
- }
173
- }
174
- }
175
- field = defaultExtraQuestionFields;
176
- }
177
- });
178
- }
179
- }
180
- });
206
+ mergeDefaultTradeQuestionsConfigOnSteps(config, steps);
181
207
  resolve();
182
208
  })
183
209
  .catch(error => {
@@ -15,7 +15,24 @@ responseInterceptor(axiosInstance);
15
15
  responseInterceptor(tcpaAxiosInstance);
16
16
  responseInterceptor(consentCaptureAxiosInstance);
17
17
 
18
- function mergeDefaultFormFieldConfig(defaultConfig, config) {
18
+ async function mergeDefaultFormFieldConfigOnSteps(defaultConfig, data, parentConfig) {
19
+ if (!data || typeof data !== 'object') return;
20
+
21
+ if (data.steps && typeof data.steps === 'object') {
22
+ data.steps = await mergeDefaultFormFieldConfig(defaultConfig, data, parentConfig);
23
+ }
24
+
25
+ for (const key in data) {
26
+ if (data.hasOwnProperty(key)) {
27
+ const value = data[key];
28
+ if (typeof value === 'object' && value !== null) {
29
+ await mergeDefaultFormFieldConfigOnSteps(defaultConfig, value, parentConfig);
30
+ }
31
+ }
32
+ }
33
+ }
34
+
35
+ function mergeDefaultFormFieldConfig(defaultConfig, config, parentConfig) {
19
36
  const { steps } = config;
20
37
 
21
38
  if (!steps.items) {
@@ -23,7 +40,7 @@ function mergeDefaultFormFieldConfig(defaultConfig, config) {
23
40
  return steps;
24
41
  }
25
42
 
26
- if (config.useAccessibleConfig) {
43
+ if (parentConfig.useAccessibleConfig) {
27
44
  steps.items.forEach(item => {
28
45
  if (item.stepContent.fields) {
29
46
  item.stepContent.fields = item.stepContent.fields.map(field => {
@@ -60,9 +77,7 @@ const getDefaultFormFieldConfig = async (config, folder = 'accessible-components
60
77
  throw new Error(`${resp.status}: Error while fetching ${folder}/defaultFormFieldConfig.json`);
61
78
  }
62
79
  const defaultConfig = resp.data;
63
- if (config.steps) {
64
- config.steps = await mergeDefaultFormFieldConfig(defaultConfig, config);
65
- }
80
+ mergeDefaultFormFieldConfigOnSteps(defaultConfig, config, config);
66
81
  resolve();
67
82
  }).catch(error => {
68
83
  console.error(error);