abmp-npm 10.0.49 → 10.0.50
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/backend/jobs.js +30 -0
- package/backend/tasks/address-primary-methods.js +424 -0
- package/backend/tasks/consts.js +4 -0
- package/backend/tasks/index.js +1 -0
- package/backend/tasks/tasks-configs.js +34 -0
- package/package.json +1 -1
- package/pages/LoadingPage.js +0 -1
- package/pages/personalDetails.js +24 -1
package/backend/jobs.js
CHANGED
|
@@ -68,6 +68,34 @@ async function scheduleCreateContactsFromMembersTask() {
|
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
+
async function scheduleFixPrimaryAddressForMembersTask() {
|
|
72
|
+
try {
|
|
73
|
+
console.log('scheduleFixPrimaryAddressForMembers started!');
|
|
74
|
+
return await taskManager().schedule({
|
|
75
|
+
name: TASKS_NAMES.scheduleFixPrimaryAddressForMembers,
|
|
76
|
+
data: {},
|
|
77
|
+
type: 'scheduled',
|
|
78
|
+
});
|
|
79
|
+
} catch (error) {
|
|
80
|
+
console.error(`Failed to scheduleFixPrimaryAddressForMembers: ${error.message}`);
|
|
81
|
+
throw new Error(`Failed to scheduleFixPrimaryAddressForMembers: ${error.message}`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async function scheduleFixPrimaryAddressVisibilityForMembersTask() {
|
|
86
|
+
try {
|
|
87
|
+
console.log('scheduleFixPrimaryAddressVisibilityForMembers started!');
|
|
88
|
+
return await taskManager().schedule({
|
|
89
|
+
name: TASKS_NAMES.scheduleFixPrimaryAddressVisibilityForMembers,
|
|
90
|
+
data: {},
|
|
91
|
+
type: 'scheduled',
|
|
92
|
+
});
|
|
93
|
+
} catch (error) {
|
|
94
|
+
console.error(`Failed to scheduleFixPrimaryAddressVisibilityForMembers: ${error.message}`);
|
|
95
|
+
throw new Error(`Failed to scheduleFixPrimaryAddressVisibilityForMembers: ${error.message}`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
71
99
|
async function updateSiteMapS3() {
|
|
72
100
|
try {
|
|
73
101
|
return await taskManager().schedule({
|
|
@@ -85,4 +113,6 @@ module.exports = {
|
|
|
85
113
|
scheduleDailyPullTask,
|
|
86
114
|
updateSiteMapS3,
|
|
87
115
|
scheduleCreateContactsFromMembersTask,
|
|
116
|
+
scheduleFixPrimaryAddressForMembersTask,
|
|
117
|
+
scheduleFixPrimaryAddressVisibilityForMembersTask,
|
|
88
118
|
};
|
|
@@ -0,0 +1,424 @@
|
|
|
1
|
+
const { taskManager } = require('psdev-task-manager');
|
|
2
|
+
|
|
3
|
+
const { COLLECTIONS, ADDRESS_STATUS_TYPES } = require('../../public/consts');
|
|
4
|
+
const { wixData } = require('../elevated-modules');
|
|
5
|
+
const { bulkSaveMembers, getMembersByIds } = require('../members-data-methods');
|
|
6
|
+
const { chunkArray, queryAllItems } = require('../utils');
|
|
7
|
+
|
|
8
|
+
const { TASKS_NAMES } = require('./consts');
|
|
9
|
+
|
|
10
|
+
const CHUNK_SIZE = 1000;
|
|
11
|
+
|
|
12
|
+
const getAddressKey = (address, index) =>
|
|
13
|
+
address?.key || address?.addressid || address?.addressId || `address_${index}`;
|
|
14
|
+
|
|
15
|
+
const hasPrimaryAddress = addressDisplayOption =>
|
|
16
|
+
Array.isArray(addressDisplayOption) &&
|
|
17
|
+
addressDisplayOption.some(option => option?.isMain === true);
|
|
18
|
+
|
|
19
|
+
const getPrimaryAddressKey = addressDisplayOption =>
|
|
20
|
+
Array.isArray(addressDisplayOption)
|
|
21
|
+
? addressDisplayOption.find(option => option?.isMain === true)?.key
|
|
22
|
+
: null;
|
|
23
|
+
|
|
24
|
+
const needsPrimaryAddressVisibilityFix = (address, index) => {
|
|
25
|
+
if (!address) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
const status = address?.addressStatus;
|
|
29
|
+
if (index === 0 && status === ADDRESS_STATUS_TYPES.DONT_SHOW) {
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
return !status || status === ADDRESS_STATUS_TYPES.DONT_SHOW;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Schedules tasks to fix members with multiple addresses and no primary address.
|
|
37
|
+
*/
|
|
38
|
+
async function scheduleFixPrimaryAddressForMembers() {
|
|
39
|
+
console.log('=== Scheduling Fix Primary Address Tasks ===');
|
|
40
|
+
|
|
41
|
+
try {
|
|
42
|
+
const membersQuery = await wixData
|
|
43
|
+
.query(COLLECTIONS.MEMBERS_DATA)
|
|
44
|
+
.isNotEmpty('addresses')
|
|
45
|
+
.limit(1000);
|
|
46
|
+
const members = await queryAllItems(membersQuery);
|
|
47
|
+
console.log(`Fetched ${members.length} members with addresses`);
|
|
48
|
+
|
|
49
|
+
const membersToFix = members.filter(member => {
|
|
50
|
+
const addresses = Array.isArray(member.addresses) ? member.addresses : [];
|
|
51
|
+
if (addresses.length <= 1) {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
return !hasPrimaryAddress(member.addressDisplayOption);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
const memberIds = [
|
|
58
|
+
...new Set(
|
|
59
|
+
membersToFix
|
|
60
|
+
.map(member => Number(member.memberId))
|
|
61
|
+
.filter(memberId => Number.isFinite(memberId) && memberId > 0)
|
|
62
|
+
),
|
|
63
|
+
];
|
|
64
|
+
console.log(`Members with multiple addresses and no primary: ${memberIds.length}`);
|
|
65
|
+
|
|
66
|
+
if (memberIds.length === 0) {
|
|
67
|
+
console.log('No members need primary address fixes');
|
|
68
|
+
return {
|
|
69
|
+
success: true,
|
|
70
|
+
message: 'No members need primary address fixes',
|
|
71
|
+
totalMembers: 0,
|
|
72
|
+
tasksScheduled: 0,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const chunks = chunkArray(memberIds, CHUNK_SIZE);
|
|
77
|
+
for (let i = 0; i < chunks.length; i++) {
|
|
78
|
+
const chunk = chunks[i];
|
|
79
|
+
const task = {
|
|
80
|
+
name: TASKS_NAMES.fixPrimaryAddressChunk,
|
|
81
|
+
data: {
|
|
82
|
+
memberIds: chunk,
|
|
83
|
+
chunkIndex: i,
|
|
84
|
+
totalChunks: chunks.length,
|
|
85
|
+
},
|
|
86
|
+
type: 'scheduled',
|
|
87
|
+
};
|
|
88
|
+
await taskManager().schedule(task);
|
|
89
|
+
console.log(`Scheduled task ${i + 1}/${chunks.length} (${chunk.length} members)`);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const result = {
|
|
93
|
+
success: true,
|
|
94
|
+
message: `Scheduled ${chunks.length} tasks for ${memberIds.length} members`,
|
|
95
|
+
totalMembers: memberIds.length,
|
|
96
|
+
tasksScheduled: chunks.length,
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
console.log('=== Scheduling Complete ===');
|
|
100
|
+
console.log(`Sample memberIds: ${memberIds.slice(0, 10).join(', ')}`);
|
|
101
|
+
console.log(JSON.stringify(result, null, 2));
|
|
102
|
+
|
|
103
|
+
return result;
|
|
104
|
+
} catch (error) {
|
|
105
|
+
console.error('Error scheduling primary address fix:', error);
|
|
106
|
+
throw error;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Processes a chunk of members and sets the first address as primary
|
|
112
|
+
* when a member has multiple addresses and no primary address.
|
|
113
|
+
*/
|
|
114
|
+
async function fixPrimaryAddressChunk(data) {
|
|
115
|
+
const { memberIds, chunkIndex, totalChunks } = data;
|
|
116
|
+
console.log(
|
|
117
|
+
`Processing primary address fix chunk ${chunkIndex + 1}/${totalChunks} (${memberIds.length} members)`
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
const result = {
|
|
121
|
+
successful: 0,
|
|
122
|
+
failed: 0,
|
|
123
|
+
skipped: 0,
|
|
124
|
+
errors: [],
|
|
125
|
+
skippedIds: [],
|
|
126
|
+
failedIds: [],
|
|
127
|
+
};
|
|
128
|
+
const skippedNoMultiAddress = [];
|
|
129
|
+
const skippedHasPrimary = [];
|
|
130
|
+
const updatedIds = [];
|
|
131
|
+
|
|
132
|
+
try {
|
|
133
|
+
const members = await getMembersByIds(memberIds);
|
|
134
|
+
console.log(`Loaded ${members.length} members for this chunk`);
|
|
135
|
+
const membersToUpdate = [];
|
|
136
|
+
|
|
137
|
+
members.forEach(member => {
|
|
138
|
+
const addresses = Array.isArray(member.addresses) ? member.addresses : [];
|
|
139
|
+
if (addresses.length <= 1) {
|
|
140
|
+
result.skipped++;
|
|
141
|
+
result.skippedIds.push(member.memberId);
|
|
142
|
+
if (skippedNoMultiAddress.length < 20) {
|
|
143
|
+
skippedNoMultiAddress.push(member.memberId);
|
|
144
|
+
}
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
if (hasPrimaryAddress(member.addressDisplayOption)) {
|
|
148
|
+
result.skipped++;
|
|
149
|
+
result.skippedIds.push(member.memberId);
|
|
150
|
+
if (skippedHasPrimary.length < 20) {
|
|
151
|
+
skippedHasPrimary.push(member.memberId);
|
|
152
|
+
}
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const firstKey = getAddressKey(addresses[0], 0);
|
|
157
|
+
const normalizedAddresses = addresses.map((address, index) => {
|
|
158
|
+
if (index !== 0 || address?.key) {
|
|
159
|
+
return address;
|
|
160
|
+
}
|
|
161
|
+
return { ...address, key: firstKey };
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
const updatedDisplayOptions = Array.isArray(member.addressDisplayOption)
|
|
165
|
+
? member.addressDisplayOption.map(option => ({
|
|
166
|
+
...option,
|
|
167
|
+
isMain: false,
|
|
168
|
+
}))
|
|
169
|
+
: [];
|
|
170
|
+
|
|
171
|
+
const existingOption = updatedDisplayOptions.find(option => option?.key === firstKey);
|
|
172
|
+
if (existingOption) {
|
|
173
|
+
existingOption.isMain = true;
|
|
174
|
+
} else {
|
|
175
|
+
updatedDisplayOptions.push({ key: firstKey, isMain: true });
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
membersToUpdate.push({
|
|
179
|
+
...member,
|
|
180
|
+
addresses: normalizedAddresses,
|
|
181
|
+
addressDisplayOption: updatedDisplayOptions,
|
|
182
|
+
});
|
|
183
|
+
if (updatedIds.length < 20) {
|
|
184
|
+
updatedIds.push(member.memberId);
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
if (membersToUpdate.length === 0) {
|
|
189
|
+
console.log('No members need updating in this batch');
|
|
190
|
+
return result;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
try {
|
|
194
|
+
await bulkSaveMembers(membersToUpdate);
|
|
195
|
+
result.successful += membersToUpdate.length;
|
|
196
|
+
console.log(`✅ Successfully updated ${membersToUpdate.length} members`);
|
|
197
|
+
if (updatedIds.length > 0) {
|
|
198
|
+
console.log(`Updated memberIds (sample): ${updatedIds.join(', ')}`);
|
|
199
|
+
}
|
|
200
|
+
} catch (error) {
|
|
201
|
+
console.error('❌ Error bulk saving members:', error);
|
|
202
|
+
result.failed += membersToUpdate.length;
|
|
203
|
+
result.failedIds.push(...membersToUpdate.map(member => member.memberId));
|
|
204
|
+
result.errors.push({
|
|
205
|
+
error: error.message,
|
|
206
|
+
memberCount: membersToUpdate.length,
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
if (skippedNoMultiAddress.length > 0) {
|
|
211
|
+
console.log(`Skipped (<=1 address) sample: ${skippedNoMultiAddress.join(', ')}`);
|
|
212
|
+
}
|
|
213
|
+
if (skippedHasPrimary.length > 0) {
|
|
214
|
+
console.log(`Skipped (already has primary) sample: ${skippedHasPrimary.join(', ')}`);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
return result;
|
|
218
|
+
} catch (error) {
|
|
219
|
+
console.error(`Error processing primary address fix chunk ${chunkIndex}:`, error);
|
|
220
|
+
throw error;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Schedules tasks to fix primary address visibility when missing or DONT_SHOW.
|
|
226
|
+
*/
|
|
227
|
+
async function scheduleFixPrimaryAddressVisibilityForMembers() {
|
|
228
|
+
console.log('=== Scheduling Fix Primary Address Visibility Tasks ===');
|
|
229
|
+
|
|
230
|
+
try {
|
|
231
|
+
const membersQuery = await wixData
|
|
232
|
+
.query(COLLECTIONS.MEMBERS_DATA)
|
|
233
|
+
.isNotEmpty('addresses')
|
|
234
|
+
.limit(1000);
|
|
235
|
+
const members = await queryAllItems(membersQuery);
|
|
236
|
+
console.log(`Fetched ${members.length} members with addresses`);
|
|
237
|
+
|
|
238
|
+
const membersToFix = members.filter(member => {
|
|
239
|
+
const addresses = Array.isArray(member.addresses) ? member.addresses : [];
|
|
240
|
+
if (addresses.length === 0) {
|
|
241
|
+
return false;
|
|
242
|
+
}
|
|
243
|
+
const primaryKey = getPrimaryAddressKey(member.addressDisplayOption);
|
|
244
|
+
if (!primaryKey) {
|
|
245
|
+
return false;
|
|
246
|
+
}
|
|
247
|
+
const addressIndex = addresses.findIndex(address => getAddressKey(address, 0) === primaryKey);
|
|
248
|
+
if (addressIndex === -1) {
|
|
249
|
+
return false;
|
|
250
|
+
}
|
|
251
|
+
return needsPrimaryAddressVisibilityFix(addresses[addressIndex], addressIndex);
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
const memberIds = [
|
|
255
|
+
...new Set(
|
|
256
|
+
membersToFix
|
|
257
|
+
.map(member => Number(member.memberId))
|
|
258
|
+
.filter(memberId => Number.isFinite(memberId) && memberId > 0)
|
|
259
|
+
),
|
|
260
|
+
];
|
|
261
|
+
console.log(`Members with primary address visibility issues: ${memberIds.length}`);
|
|
262
|
+
|
|
263
|
+
if (memberIds.length === 0) {
|
|
264
|
+
console.log('No members need primary address visibility fixes');
|
|
265
|
+
return {
|
|
266
|
+
success: true,
|
|
267
|
+
message: 'No members need primary address visibility fixes',
|
|
268
|
+
totalMembers: 0,
|
|
269
|
+
tasksScheduled: 0,
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
const chunks = chunkArray(memberIds, CHUNK_SIZE);
|
|
274
|
+
for (let i = 0; i < chunks.length; i++) {
|
|
275
|
+
const chunk = chunks[i];
|
|
276
|
+
const task = {
|
|
277
|
+
name: TASKS_NAMES.fixPrimaryAddressVisibilityChunk,
|
|
278
|
+
data: {
|
|
279
|
+
memberIds: chunk,
|
|
280
|
+
chunkIndex: i,
|
|
281
|
+
totalChunks: chunks.length,
|
|
282
|
+
},
|
|
283
|
+
type: 'scheduled',
|
|
284
|
+
};
|
|
285
|
+
await taskManager().schedule(task);
|
|
286
|
+
console.log(`Scheduled task ${i + 1}/${chunks.length} (${chunk.length} members)`);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
const result = {
|
|
290
|
+
success: true,
|
|
291
|
+
message: `Scheduled ${chunks.length} tasks for ${memberIds.length} members`,
|
|
292
|
+
totalMembers: memberIds.length,
|
|
293
|
+
tasksScheduled: chunks.length,
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
console.log('=== Scheduling Complete ===');
|
|
297
|
+
console.log(`Sample memberIds: ${memberIds.slice(0, 10).join(', ')}`);
|
|
298
|
+
console.log(JSON.stringify(result, null, 2));
|
|
299
|
+
|
|
300
|
+
return result;
|
|
301
|
+
} catch (error) {
|
|
302
|
+
console.error('Error scheduling primary address visibility fix:', error);
|
|
303
|
+
throw error;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* Processes a chunk of members and fixes primary address visibility when missing or DONT_SHOW.
|
|
309
|
+
*/
|
|
310
|
+
async function fixPrimaryAddressVisibilityChunk(data) {
|
|
311
|
+
const { memberIds, chunkIndex, totalChunks } = data;
|
|
312
|
+
console.log(
|
|
313
|
+
`Processing primary address visibility chunk ${chunkIndex + 1}/${totalChunks} (${memberIds.length} members)`
|
|
314
|
+
);
|
|
315
|
+
|
|
316
|
+
const result = {
|
|
317
|
+
successful: 0,
|
|
318
|
+
failed: 0,
|
|
319
|
+
skipped: 0,
|
|
320
|
+
errors: [],
|
|
321
|
+
skippedIds: [],
|
|
322
|
+
failedIds: [],
|
|
323
|
+
};
|
|
324
|
+
const skippedNoPrimary = [];
|
|
325
|
+
const skippedNoAddressMatch = [];
|
|
326
|
+
const updatedIds = [];
|
|
327
|
+
|
|
328
|
+
try {
|
|
329
|
+
const members = await getMembersByIds(memberIds);
|
|
330
|
+
console.log(`Loaded ${members.length} members for this chunk`);
|
|
331
|
+
const membersToUpdate = [];
|
|
332
|
+
|
|
333
|
+
members.forEach(member => {
|
|
334
|
+
const addresses = Array.isArray(member.addresses) ? member.addresses : [];
|
|
335
|
+
const primaryKey = getPrimaryAddressKey(member.addressDisplayOption);
|
|
336
|
+
if (!primaryKey) {
|
|
337
|
+
result.skipped++;
|
|
338
|
+
result.skippedIds.push(member.memberId);
|
|
339
|
+
if (skippedNoPrimary.length < 20) {
|
|
340
|
+
skippedNoPrimary.push(member.memberId);
|
|
341
|
+
}
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
const addressIndex = addresses.findIndex(address => getAddressKey(address, 0) === primaryKey);
|
|
346
|
+
if (addressIndex === -1) {
|
|
347
|
+
result.skipped++;
|
|
348
|
+
result.skippedIds.push(member.memberId);
|
|
349
|
+
if (skippedNoAddressMatch.length < 20) {
|
|
350
|
+
skippedNoAddressMatch.push(member.memberId);
|
|
351
|
+
}
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
const targetAddress = addresses[addressIndex];
|
|
356
|
+
if (!needsPrimaryAddressVisibilityFix(targetAddress, addressIndex)) {
|
|
357
|
+
result.skipped++;
|
|
358
|
+
result.skippedIds.push(member.memberId);
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
const updatedAddresses = addresses.map((address, index) => {
|
|
363
|
+
if (index !== addressIndex) {
|
|
364
|
+
return address;
|
|
365
|
+
}
|
|
366
|
+
return {
|
|
367
|
+
...address,
|
|
368
|
+
addressStatus: ADDRESS_STATUS_TYPES.STATE_CITY_ZIP,
|
|
369
|
+
};
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
membersToUpdate.push({
|
|
373
|
+
...member,
|
|
374
|
+
addresses: updatedAddresses,
|
|
375
|
+
});
|
|
376
|
+
if (updatedIds.length < 20) {
|
|
377
|
+
updatedIds.push(member.memberId);
|
|
378
|
+
}
|
|
379
|
+
});
|
|
380
|
+
|
|
381
|
+
if (membersToUpdate.length === 0) {
|
|
382
|
+
console.log('No members need updating in this batch');
|
|
383
|
+
return result;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
try {
|
|
387
|
+
await bulkSaveMembers(membersToUpdate);
|
|
388
|
+
result.successful += membersToUpdate.length;
|
|
389
|
+
console.log(`✅ Successfully updated ${membersToUpdate.length} members`);
|
|
390
|
+
if (updatedIds.length > 0) {
|
|
391
|
+
console.log(`Updated memberIds (sample): ${updatedIds.join(', ')}`);
|
|
392
|
+
}
|
|
393
|
+
} catch (error) {
|
|
394
|
+
console.error('❌ Error bulk saving members:', error);
|
|
395
|
+
result.failed += membersToUpdate.length;
|
|
396
|
+
result.failedIds.push(...membersToUpdate.map(member => member.memberId));
|
|
397
|
+
result.errors.push({
|
|
398
|
+
error: error.message,
|
|
399
|
+
memberCount: membersToUpdate.length,
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
if (skippedNoPrimary.length > 0) {
|
|
404
|
+
console.log(`Skipped (no primary address) sample: ${skippedNoPrimary.join(', ')}`);
|
|
405
|
+
}
|
|
406
|
+
if (skippedNoAddressMatch.length > 0) {
|
|
407
|
+
console.log(
|
|
408
|
+
`Skipped (primary address not found) sample: ${skippedNoAddressMatch.join(', ')}`
|
|
409
|
+
);
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
return result;
|
|
413
|
+
} catch (error) {
|
|
414
|
+
console.error(`Error processing primary address visibility chunk ${chunkIndex}:`, error);
|
|
415
|
+
throw error;
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
module.exports = {
|
|
420
|
+
scheduleFixPrimaryAddressForMembers,
|
|
421
|
+
fixPrimaryAddressChunk,
|
|
422
|
+
scheduleFixPrimaryAddressVisibilityForMembers,
|
|
423
|
+
fixPrimaryAddressVisibilityChunk,
|
|
424
|
+
};
|
package/backend/tasks/consts.js
CHANGED
|
@@ -18,6 +18,10 @@ const TASKS_NAMES = {
|
|
|
18
18
|
generateUrlsChunk: 'generateUrlsChunk',
|
|
19
19
|
scheduleCreateContactsFromMembers: 'scheduleCreateContactsFromMembers',
|
|
20
20
|
createContactsFromMembers: 'createContactsFromMembers',
|
|
21
|
+
scheduleFixPrimaryAddressForMembers: 'scheduleFixPrimaryAddressForMembers',
|
|
22
|
+
fixPrimaryAddressChunk: 'fixPrimaryAddressChunk',
|
|
23
|
+
scheduleFixPrimaryAddressVisibilityForMembers: 'scheduleFixPrimaryAddressVisibilityForMembers',
|
|
24
|
+
fixPrimaryAddressVisibilityChunk: 'fixPrimaryAddressVisibilityChunk',
|
|
21
25
|
};
|
|
22
26
|
|
|
23
27
|
module.exports = {
|
package/backend/tasks/index.js
CHANGED
|
@@ -4,6 +4,12 @@ const {
|
|
|
4
4
|
syncMembersDataPerAction,
|
|
5
5
|
} = require('../daily-pull/sync-to-cms-methods');
|
|
6
6
|
|
|
7
|
+
const {
|
|
8
|
+
scheduleFixPrimaryAddressForMembers,
|
|
9
|
+
fixPrimaryAddressChunk,
|
|
10
|
+
scheduleFixPrimaryAddressVisibilityForMembers,
|
|
11
|
+
fixPrimaryAddressVisibilityChunk,
|
|
12
|
+
} = require('./address-primary-methods');
|
|
7
13
|
const { TASKS_NAMES } = require('./consts');
|
|
8
14
|
const {
|
|
9
15
|
scheduleTaskForEmptyAboutYouMembers,
|
|
@@ -169,6 +175,34 @@ const TASKS = {
|
|
|
169
175
|
shouldSkipCheck: () => false,
|
|
170
176
|
estimatedDurationSec: 80,
|
|
171
177
|
},
|
|
178
|
+
[TASKS_NAMES.scheduleFixPrimaryAddressForMembers]: {
|
|
179
|
+
name: TASKS_NAMES.scheduleFixPrimaryAddressForMembers,
|
|
180
|
+
getIdentifier: () => 'SHOULD_NEVER_SKIP',
|
|
181
|
+
process: scheduleFixPrimaryAddressForMembers,
|
|
182
|
+
shouldSkipCheck: () => false,
|
|
183
|
+
estimatedDurationSec: 80,
|
|
184
|
+
},
|
|
185
|
+
[TASKS_NAMES.fixPrimaryAddressChunk]: {
|
|
186
|
+
name: TASKS_NAMES.fixPrimaryAddressChunk,
|
|
187
|
+
getIdentifier: task => task.data,
|
|
188
|
+
process: fixPrimaryAddressChunk,
|
|
189
|
+
shouldSkipCheck: () => false,
|
|
190
|
+
estimatedDurationSec: 80,
|
|
191
|
+
},
|
|
192
|
+
[TASKS_NAMES.scheduleFixPrimaryAddressVisibilityForMembers]: {
|
|
193
|
+
name: TASKS_NAMES.scheduleFixPrimaryAddressVisibilityForMembers,
|
|
194
|
+
getIdentifier: () => 'SHOULD_NEVER_SKIP',
|
|
195
|
+
process: scheduleFixPrimaryAddressVisibilityForMembers,
|
|
196
|
+
shouldSkipCheck: () => false,
|
|
197
|
+
estimatedDurationSec: 80,
|
|
198
|
+
},
|
|
199
|
+
[TASKS_NAMES.fixPrimaryAddressVisibilityChunk]: {
|
|
200
|
+
name: TASKS_NAMES.fixPrimaryAddressVisibilityChunk,
|
|
201
|
+
getIdentifier: task => task.data,
|
|
202
|
+
process: fixPrimaryAddressVisibilityChunk,
|
|
203
|
+
shouldSkipCheck: () => false,
|
|
204
|
+
estimatedDurationSec: 80,
|
|
205
|
+
},
|
|
172
206
|
};
|
|
173
207
|
|
|
174
208
|
module.exports = { TASKS };
|
package/package.json
CHANGED
package/pages/LoadingPage.js
CHANGED
|
@@ -14,7 +14,6 @@ async function loadingPageOnReady(authenticateSSOToken) {
|
|
|
14
14
|
console.error(`Something went wrong while logging in: ${error}`);
|
|
15
15
|
// If we already have a session (memberId), redirect to form instead of showing error.
|
|
16
16
|
const storedMemberId = await local.getItem('memberId');
|
|
17
|
-
console.log('storedMemberId', storedMemberId);
|
|
18
17
|
if (storedMemberId) {
|
|
19
18
|
const redirectTo = `${PAGES_PATHS.MEMBERS_FORM}?token=${encodeURIComponent(storedMemberId)}`;
|
|
20
19
|
await wixLocationFrontend.to(`/${redirectTo}`);
|
package/pages/personalDetails.js
CHANGED
|
@@ -1556,9 +1556,23 @@ async function personalDetailsOnReady({
|
|
|
1556
1556
|
_$w('#mainAddressCheckbox').checked = false;
|
|
1557
1557
|
checkbox.checked = true;
|
|
1558
1558
|
|
|
1559
|
+
// Primary address cannot be hidden: update model and repeater data so UI and save stay in sync
|
|
1559
1560
|
if (clickedItemData.address.addressStatus === ADDRESS_STATUS_TYPES.DONT_SHOW) {
|
|
1560
1561
|
updateAddressStatus(clickedItemData._id, ADDRESS_STATUS_TYPES.STATE_CITY_ZIP);
|
|
1561
1562
|
$item('#addressStatusOptions').value = ADDRESS_STATUS_TYPES.STATE_CITY_ZIP;
|
|
1563
|
+
const currentData = _$w('#addressesList').data || [];
|
|
1564
|
+
const dataWithStatusFixed = currentData.map(item =>
|
|
1565
|
+
item._id === clickedItemData._id
|
|
1566
|
+
? {
|
|
1567
|
+
...item,
|
|
1568
|
+
address: {
|
|
1569
|
+
...item.address,
|
|
1570
|
+
addressStatus: ADDRESS_STATUS_TYPES.STATE_CITY_ZIP,
|
|
1571
|
+
},
|
|
1572
|
+
}
|
|
1573
|
+
: item
|
|
1574
|
+
);
|
|
1575
|
+
_$w('#addressesList').data = dataWithStatusFixed;
|
|
1562
1576
|
}
|
|
1563
1577
|
|
|
1564
1578
|
updateMainAddressSelection(clickedItemData._id);
|
|
@@ -1567,7 +1581,7 @@ async function personalDetailsOnReady({
|
|
|
1567
1581
|
});
|
|
1568
1582
|
|
|
1569
1583
|
_$w('#addressStatusOptions').onChange(event => {
|
|
1570
|
-
const data = _$w('#addressesList').data;
|
|
1584
|
+
const data = _$w('#addressesList').data || [];
|
|
1571
1585
|
const clickedItemData = data.find(item => item._id === event.context.itemId);
|
|
1572
1586
|
const newStatus = event.target.value;
|
|
1573
1587
|
const $item = _$w.at(event.context);
|
|
@@ -1579,6 +1593,15 @@ async function personalDetailsOnReady({
|
|
|
1579
1593
|
}
|
|
1580
1594
|
|
|
1581
1595
|
updateAddressStatus(clickedItemData._id, newStatus);
|
|
1596
|
+
|
|
1597
|
+
// Keep repeater data in sync (required for new addresses not yet in itemMemberObj.addresses)
|
|
1598
|
+
const updatedData = data.map(item =>
|
|
1599
|
+
item._id === clickedItemData._id
|
|
1600
|
+
? { ...item, address: { ...item.address, addressStatus: newStatus } }
|
|
1601
|
+
: item
|
|
1602
|
+
);
|
|
1603
|
+
_$w('#addressesList').data = updatedData;
|
|
1604
|
+
|
|
1582
1605
|
checkFormChanges(FORM_SECTION_HANDLER_MAP.CONTACT_BOOKING);
|
|
1583
1606
|
});
|
|
1584
1607
|
|