abmp-npm 2.0.74 → 2.0.75

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "abmp-npm",
3
- "version": "2.0.74",
3
+ "version": "2.0.75",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "check-cycles": "madge --circular .",
package/pages/Home.js CHANGED
@@ -3,12 +3,17 @@ const { location: wixLocation } = require('@wix/site-location');
3
3
  const { window: wixWindow, rendering } = require('@wix/site-window');
4
4
  const { withWarmUpData } = require('psdev-utils/frontend');
5
5
 
6
- const { ADDRESS_STATUS_TYPES, DEFAULT_FILTER, DROPDOWN_OPTIONS } = require('../public/consts.js');
6
+ const {
7
+ ADDRESS_STATUS_TYPES,
8
+ DEFAULT_FILTER,
9
+ DROPDOWN_OPTIONS,
10
+ LIGHTBOX_NAMES,
11
+ } = require('../public/consts.js');
7
12
  const { createHomepageUtils } = require('../public/Utils/homePage.js');
8
13
  const {
9
14
  getMainAddress,
15
+ findMainAddress,
10
16
  formatPracticeAreasForDisplay,
11
- checkAddressIsVisible,
12
17
  isWixHostedImage,
13
18
  normalizeExternalUrl,
14
19
  } = require('../public/Utils/sharedUtils.js');
@@ -30,6 +35,24 @@ const pagination = {
30
35
  let searchResults = [];
31
36
  let isMobile = false;
32
37
 
38
+ const getDirectionsTarget = itemData => {
39
+ const addresses = Array.isArray(itemData?.addresses) ? itemData.addresses : [];
40
+ const mainAddr = findMainAddress(itemData?.addressDisplayOption, addresses);
41
+ if (!mainAddr) {
42
+ return { mainAddr: null, mapsLink: null };
43
+ }
44
+ const canShowDirections =
45
+ mainAddr.addressStatus === ADDRESS_STATUS_TYPES.FULL_ADDRESS &&
46
+ mainAddr.latitude &&
47
+ mainAddr.longitude;
48
+ return {
49
+ mainAddr,
50
+ mapsLink: canShowDirections
51
+ ? `https://maps.google.com/?q=${mainAddr.latitude},${mainAddr.longitude}`
52
+ : null,
53
+ };
54
+ };
55
+
33
56
  const homePageOnReady = async ({
34
57
  _$w,
35
58
  getCompiledFiltersOptions,
@@ -181,6 +204,16 @@ const homePageOnReady = async ({
181
204
  await updateResults('zeroTimeout');
182
205
  });
183
206
  const baseUrl = await wixLocation.baseUrl();
207
+ _$w('#showMaps').onClick(event => {
208
+ const member = searchResults.find(result => result._id === event.context.itemId);
209
+ if (!member) {
210
+ return;
211
+ }
212
+ const { mapsLink } = getDirectionsTarget(member);
213
+ if (!mapsLink) {
214
+ wixWindow.openLightbox(LIGHTBOX_NAMES.CONTACT_FOR_LOCATION, member);
215
+ }
216
+ });
184
217
  _$w('#profileRepeater').onItemReady(($item, itemData) => {
185
218
  // 1) safely default to arrays
186
219
  const addresses = Array.isArray(itemData.addresses) ? itemData.addresses : [];
@@ -225,23 +258,24 @@ const homePageOnReady = async ({
225
258
  $item('#milesAwayText').text = '';
226
259
  }
227
260
 
228
- // 7) "Show maps" button enabled only if there's a full address with valid coordinates
229
- const visible = checkAddressIsVisible(addresses);
230
- const fullAddressWithValidCoords = visible.find(
231
- addr =>
232
- addr.addressStatus === ADDRESS_STATUS_TYPES.FULL_ADDRESS &&
233
- addr.latitude &&
234
- addr.longitude
235
- );
261
+ // 7) "Show maps" button. Links to the primary address when it is a full address;
262
+ // otherwise it stays visible and the page-level onClick opens a lightbox.
263
+ const { mainAddr, mapsLink } = getDirectionsTarget(itemData);
236
264
 
237
- if (fullAddressWithValidCoords) {
265
+ if (!mainAddr) {
266
+ $item('#showMaps').hide();
267
+ } else {
238
268
  $item('#showMaps').enable();
239
269
  $item('#showMaps').show();
240
- const { latitude, longitude } = fullAddressWithValidCoords;
241
- $item('#showMaps').link = `https://maps.google.com/?q=${latitude},${longitude}`;
242
- $item('#showMaps').target = '_blank';
243
- } else {
244
- $item('#showMaps').hide();
270
+
271
+ if (mapsLink) {
272
+ $item('#showMaps').link = mapsLink;
273
+ $item('#showMaps').target = '_blank';
274
+ } else {
275
+ // Clear any link left over from a recycled repeater item, otherwise the
276
+ // button would still navigate to the previous member's address.
277
+ $item('#showMaps').link = undefined;
278
+ }
245
279
  }
246
280
 
247
281
  // 8) Phone / contact form
@@ -0,0 +1,28 @@
1
+ const { location: wixLocation } = require('@wix/site-location');
2
+ const { lightbox } = require('@wix/site-window');
3
+
4
+ const { PAGES_PATHS } = require('../public/consts.js');
5
+
6
+ /**
7
+ * Shown from the directory when a member's primary address is not a full address,
8
+ * so "Directions" cannot be offered. Sends the visitor to the member's profile
9
+ * page rather than opening the contact form.
10
+ */
11
+ async function contactForLocationOnReady({ $w: _$w }) {
12
+ const member = await lightbox.getContext();
13
+ const profilePath = member?.url;
14
+
15
+ if (!profilePath) {
16
+ _$w('#contact').hide();
17
+ return;
18
+ }
19
+
20
+ _$w('#contact').onClick(async () => {
21
+ await lightbox.close();
22
+ wixLocation.to(`/${PAGES_PATHS.PROFILE}/${profilePath}`);
23
+ });
24
+ }
25
+
26
+ module.exports = {
27
+ contactForLocationOnReady,
28
+ };
package/pages/index.js CHANGED
@@ -9,4 +9,5 @@ module.exports = {
9
9
  ...require('./deleteConfirm.js'),
10
10
  ...require('./SaveAlerts.js'),
11
11
  ...require('./LearnMore.js'),
12
+ ...require('./contactForLocation.js'),
12
13
  };
package/public/consts.js CHANGED
@@ -85,6 +85,7 @@ const LIGHTBOX_NAMES = {
85
85
  SELECT_BANNER_IMAGES: 'Select Banner Images',
86
86
  CONTACT_US: 'Contact Us',
87
87
  MAIN_ADDRESS_ERROR: 'mainAddressError',
88
+ CONTACT_FOR_LOCATION: 'contactForLocation',
88
89
  };
89
90
 
90
91
  const FREE_WEBSITE_TEXT_STATES = {