@tap-payments/os-micro-frontend-shared 0.1.158 → 0.1.160

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.
@@ -13,25 +13,23 @@ import { jsx as _jsx } from "react/jsx-runtime";
13
13
  import Tooltip from '../../../Tooltip';
14
14
  import { ImageWrapper } from '../../../index.js';
15
15
  import { TableCell } from '../../../TableCells';
16
- import { openUrl } from '../../../../utils/index.js';
17
16
  import { ChannelTextLabel, ChannelTextWrapper, salesChannelAnimation, SalesChannelsContainer, StyledSourceCell, StyledSourceImage } from './style';
18
- import { NON_CLICKABLE_CHANNELS } from './constants';
17
+ import { openChannelUrl, transformUrl } from './utils';
19
18
  function SalesChannelCell(_a) {
20
19
  var _b;
21
20
  var { channels, isTextShown } = _a, props = __rest(_a, ["channels", "isTextShown"]);
22
21
  const salesChannels = (_b = channels === null || channels === void 0 ? void 0 : channels.filter((s) => !!s.address)) === null || _b === void 0 ? void 0 : _b.map((channel, index) => {
23
- var _a;
22
+ var _a, _b, _c;
24
23
  const sourceTooltip = channel.address;
25
24
  const channelCode = (_a = channel.code) === null || _a === void 0 ? void 0 : _a.replace(/_/g, '');
26
25
  const isLastChannel = index === (channels === null || channels === void 0 ? void 0 : channels.length) - 1;
26
+ const transformedUrl = transformUrl((_b = channel.address) !== null && _b !== void 0 ? _b : '', (_c = channel.code) !== null && _c !== void 0 ? _c : '');
27
27
  return (_jsx(Tooltip, Object.assign({ title: sourceTooltip }, { children: _jsx(ImageWrapper, Object.assign({ order: index, variants: salesChannelAnimation(index, isTextShown ? 74 : 0, isLastChannel), sx: {
28
28
  width: isTextShown ? '70px' : '36px',
29
- cursor: NON_CLICKABLE_CHANNELS.includes(channel.code) ? 'default' : 'pointer',
29
+ cursor: !transformedUrl ? 'default' : 'pointer',
30
30
  }, onClick: () => {
31
- if (NON_CLICKABLE_CHANNELS.includes(channel.code))
32
- return;
33
31
  if (channel === null || channel === void 0 ? void 0 : channel.address)
34
- openUrl(channel.address);
32
+ openChannelUrl(transformedUrl);
35
33
  } }, { children: isTextShown ? (_jsx(ChannelTextWrapper, { children: _jsx(ChannelTextLabel, { children: channelCode }) })) : (_jsx(StyledSourceImage, { src: channel.logo, alt: channelCode })) })) }), `${channel}-${index}`));
36
34
  });
37
35
  const salesChannelsCount = (salesChannels === null || salesChannels === void 0 ? void 0 : salesChannels.length) || 0;
@@ -0,0 +1,3 @@
1
+ import { SalesChannelTypes } from '../../../../types/index.js';
2
+ export declare const transformUrl: (url: string, channelCode: SalesChannelTypes) => string | null;
3
+ export declare const openChannelUrl: (url: string | null) => void;
@@ -0,0 +1,69 @@
1
+ import { SalesChannelTypes } from '../../../../types/index.js';
2
+ const needsHttpsPrefix = (url) => {
3
+ return !url.startsWith('http://') && !url.startsWith('https://');
4
+ };
5
+ const isUrl = (url) => {
6
+ return /^https?:\/\//i.test(url);
7
+ };
8
+ export const transformUrl = (url, channelCode) => {
9
+ switch (channelCode) {
10
+ case SalesChannelTypes.WEBSITE:
11
+ return url;
12
+ case SalesChannelTypes.PHYSICAL_STORE:
13
+ case SalesChannelTypes.CALL_CENTER:
14
+ return null;
15
+ case SalesChannelTypes.LINKEDIN:
16
+ case SalesChannelTypes.INSTAGRAM:
17
+ case SalesChannelTypes.TWITTER:
18
+ case SalesChannelTypes.SOCIAL_MEDIA:
19
+ return handleSocialMediaUrl(url, channelCode);
20
+ case SalesChannelTypes.IOS:
21
+ case SalesChannelTypes.ANDROID:
22
+ case SalesChannelTypes.MOBILE_APP:
23
+ return handleMobileAppUrl(url, channelCode);
24
+ default:
25
+ return url;
26
+ }
27
+ };
28
+ const handleSocialMediaUrl = (url, channelCode) => {
29
+ const lowerUrl = url.toLowerCase();
30
+ if (channelCode === SalesChannelTypes.LINKEDIN) {
31
+ if (lowerUrl.includes('linkedin.com') || lowerUrl.includes('linked.com')) {
32
+ return url;
33
+ }
34
+ return !isUrl(url) ? `https://linkedin.com/company/${url}` : null;
35
+ }
36
+ if (channelCode === SalesChannelTypes.INSTAGRAM) {
37
+ if (lowerUrl.includes('instagram.com')) {
38
+ return url;
39
+ }
40
+ return !isUrl(url) ? `https://instagram.com/${url}` : null;
41
+ }
42
+ if (channelCode === SalesChannelTypes.TWITTER) {
43
+ if (lowerUrl.includes('twitter.com') || lowerUrl.includes('x.com')) {
44
+ return url;
45
+ }
46
+ return !isUrl(url) ? `https://x.com/${url}` : null;
47
+ }
48
+ return null;
49
+ };
50
+ const handleMobileAppUrl = (url, channelCode) => {
51
+ const lowerUrl = url.toLowerCase();
52
+ if (lowerUrl.includes('apps.apple.com') && channelCode === SalesChannelTypes.IOS) {
53
+ return url;
54
+ }
55
+ if (channelCode === SalesChannelTypes.ANDROID) {
56
+ if (!isUrl(url)) {
57
+ return `https://play.google.com/store/apps/details?id=${url}`;
58
+ }
59
+ return url;
60
+ }
61
+ return null;
62
+ };
63
+ export const openChannelUrl = (url) => {
64
+ if (!url || typeof url !== 'string') {
65
+ return;
66
+ }
67
+ // Open the URL in a new tab
68
+ window.open(needsHttpsPrefix(url) ? `https://${url}` : url, '_blank', 'noopener,noreferrer');
69
+ };
@@ -0,0 +1 @@
1
+ export declare const stringToBoolean: (value: string | undefined) => boolean | undefined;
@@ -0,0 +1,7 @@
1
+ export const stringToBoolean = (value) => {
2
+ if (value === 'true')
3
+ return true;
4
+ if (value === 'false')
5
+ return false;
6
+ return undefined;
7
+ };
@@ -41,3 +41,4 @@ export * from './flag';
41
41
  export * from './encrypt';
42
42
  export * from './day';
43
43
  export * from './style';
44
+ export * from './boolean';
@@ -41,3 +41,4 @@ export * from './flag';
41
41
  export * from './encrypt';
42
42
  export * from './day';
43
43
  export * from './style';
44
+ export * from './boolean';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tap-payments/os-micro-frontend-shared",
3
3
  "description": "Shared components and utilities for Tap Payments micro frontends",
4
- "version": "0.1.158",
4
+ "version": "0.1.160",
5
5
  "testVersion": 0,
6
6
  "type": "module",
7
7
  "main": "build/index.js",
@@ -1,2 +0,0 @@
1
- import { SalesChannelTypes } from '../../../../types/index.js';
2
- export declare const NON_CLICKABLE_CHANNELS: SalesChannelTypes[];
@@ -1,2 +0,0 @@
1
- import { SalesChannelTypes } from '../../../../types/index.js';
2
- export const NON_CLICKABLE_CHANNELS = [SalesChannelTypes.CALL_CENTER, SalesChannelTypes.PHYSICAL_STORE, SalesChannelTypes.IOS];