abmp-npm 2.0.44 → 2.0.45

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 CHANGED
@@ -68,6 +68,20 @@ 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
+
71
85
  async function updateSiteMapS3() {
72
86
  try {
73
87
  return await taskManager().schedule({
@@ -85,4 +99,5 @@ module.exports = {
85
99
  scheduleDailyPullTask,
86
100
  updateSiteMapS3,
87
101
  scheduleCreateContactsFromMembersTask,
102
+ scheduleFixPrimaryAddressForMembersTask,
88
103
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "abmp-npm",
3
- "version": "2.0.44",
3
+ "version": "2.0.45",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "check-cycles": "madge --circular .",
@@ -1,6 +1,8 @@
1
+ const { location: wixLocationFrontend } = require('@wix/site-location');
2
+ const { local } = require('@wix/site-storage');
1
3
  const { window: wixWindow, rendering } = require('@wix/site-window');
2
4
 
3
- const { LIGHTBOX_NAMES } = require('../public/consts');
5
+ const { LIGHTBOX_NAMES, PAGES_PATHS } = require('../public/consts');
4
6
  const { checkAndLogin } = require('../public/sso-auth-methods');
5
7
 
6
8
  async function loadingPageOnReady(authenticateSSOToken) {
@@ -8,9 +10,16 @@ async function loadingPageOnReady(authenticateSSOToken) {
8
10
  //This calls needs to triggered on client side, otherwise PAC API will return 401 error
9
11
  if (renderingEnv === 'browser') {
10
12
  //Need to pass authenticateSSOToken to checkAndLogin so it will run as a web method not a public one.
11
- await checkAndLogin(authenticateSSOToken).catch(error => {
12
- wixWindow.openLightbox(LIGHTBOX_NAMES.LOGIN_ERROR_ALERT);
13
+ await checkAndLogin(authenticateSSOToken).catch(async error => {
13
14
  console.error(`Something went wrong while logging in: ${error}`);
15
+ // If we already have a session (memberId), redirect to form instead of showing error.
16
+ const storedMemberId = await local.getItem('memberId');
17
+ if (storedMemberId) {
18
+ const redirectTo = `${PAGES_PATHS.MEMBERS_FORM}?token=${encodeURIComponent(storedMemberId)}`;
19
+ await wixLocationFrontend.to(`/${redirectTo}`);
20
+ return;
21
+ }
22
+ wixWindow.openLightbox(LIGHTBOX_NAMES.LOGIN_ERROR_ALERT);
14
23
  });
15
24
  }
16
25
  }
@@ -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