@pushwoosh/smart-components-kit 1.0.26 → 1.0.27

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.
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ import { type OpenActionsSummaryProps } from '../../types';
3
+ export declare const OpenActionsSummary: ({ openActions }: OpenActionsSummaryProps) => React.JSX.Element;
@@ -0,0 +1,89 @@
1
+ import React from 'react';
2
+ import { useParams, Link as ReactLink } from 'react-router-dom';
3
+ import { Link, Spinner } from '@pushwoosh/dumb-components';
4
+ import { Color, PlatformsIcons, PlatformsLabels, Tag } from '@pushwoosh/kit-constants';
5
+ import { Horizontal, useAsync, Vertical } from '@pushwoosh/kit-helpers';
6
+ import { OpenIcon, PlatformLogoIcon } from '@pushwoosh/kit-icons';
7
+ import { H4, Text } from '@pushwoosh/kit-typography';
8
+ import { LinkRow, ClickActionSection } from './styles';
9
+ import { useSPAContext } from '../../../context';
10
+ import { getSafariUrl } from '../../helpers';
11
+ export const OpenActionsSummary = ({
12
+ openActions
13
+ }) => {
14
+ var _applicationData$valu;
15
+ const {
16
+ platformsDeeplinkUrls = {},
17
+ defaultDeeplinkUrl: allPlatformsDeeplinkUrl,
18
+ webPageUrl,
19
+ safariUrlArgs,
20
+ showRichmedia
21
+ } = openActions ?? {};
22
+ const {
23
+ applicationCode
24
+ } = useParams();
25
+ const {
26
+ rpcGateway
27
+ } = useSPAContext();
28
+ const applicationData = useAsync(() => rpcGateway.applications.Get({
29
+ code: applicationCode
30
+ }), [applicationCode]);
31
+ const hasCustomPlatformsDeeplink = Object.keys(platformsDeeplinkUrls).length > 0;
32
+ const safariUrl = !hasCustomPlatformsDeeplink && getSafariUrl(((_applicationData$valu = applicationData.value) === null || _applicationData$valu === void 0 ? void 0 : _applicationData$valu.application) || null, safariUrlArgs ?? '');
33
+ const renderInfoBlock = (device, action, url = null) => React.createElement(Vertical, null, React.createElement("span", null, "For", ' ', React.createElement("strong", null, device), ' ', "subscribers:", ' ', React.createElement("strong", null, action)), url && React.createElement(LinkRow, null, React.createElement(Link, {
34
+ as: Tag.A,
35
+ rel: "noopener noreferrer",
36
+ target: "_blank",
37
+ href: url
38
+ }, url)));
39
+ const renderPlatformDeepLink = (platformKey, url, label = 'deep link') => {
40
+ const isEnumKey = typeof platformKey === 'number';
41
+ const icon = isEnumKey ? PlatformsIcons[platformKey] : null;
42
+ const labelText = isEnumKey ? PlatformsLabels[platformKey] : platformKey;
43
+ return React.createElement(ClickActionSection, {
44
+ key: platformKey
45
+ }, React.createElement(Horizontal, {
46
+ "$gap": 8,
47
+ "$justifyContent": "start",
48
+ "$alignItems": "start"
49
+ }, icon && React.createElement(PlatformLogoIcon, {
50
+ size: "small",
51
+ type: icon,
52
+ color: Color.LOCKED
53
+ }), React.createElement(Text, {
54
+ "$variant": "h4",
55
+ "$color": Color.LOCKED,
56
+ "$uppercase": true
57
+ }, labelText, ' ', label)), React.createElement(LinkRow, null, url));
58
+ };
59
+ const renderRichmedia = richmedia => {
60
+ if (richmedia.url) {
61
+ return React.createElement(Vertical, null, React.createElement(H4, null, "Show in-app banner"), React.createElement(ClickActionSection, null, React.createElement(LinkRow, null, richmedia.url)));
62
+ } else if (richmedia.code) {
63
+ return React.createElement(Horizontal, {
64
+ "$gap": 4,
65
+ "$justifyContent": "start",
66
+ "$alignItems": "center"
67
+ }, React.createElement(H4, null, "Show in-app banner:"), React.createElement(Text, null, richmedia.code), React.createElement(ReactLink, {
68
+ to: `/applications/${applicationCode}/rich-media/${richmedia.code}/edit`,
69
+ target: "_blank"
70
+ }, React.createElement(OpenIcon, {
71
+ color: Color.SOFT,
72
+ size: "small",
73
+ view: "lined"
74
+ })));
75
+ }
76
+ return null;
77
+ };
78
+ return React.createElement(Vertical, {
79
+ "$gap": 8
80
+ }, React.createElement(Text, {
81
+ "$variant": "h4",
82
+ "$uppercase": true
83
+ }, "On click actions"), React.createElement(Vertical, {
84
+ "$gap": 8
85
+ }, !openActions ? React.createElement(Spinner, {
86
+ color: Color.MAIN,
87
+ size: "medium"
88
+ }) : React.createElement(React.Fragment, null, hasCustomPlatformsDeeplink && renderInfoBlock('mobile', 'follow the Deep link'), Object.entries(platformsDeeplinkUrls).map(([platformKey, url]) => renderPlatformDeepLink(+platformKey, url)), allPlatformsDeeplinkUrl && hasCustomPlatformsDeeplink && renderPlatformDeepLink('Other platforms', allPlatformsDeeplinkUrl), allPlatformsDeeplinkUrl && !hasCustomPlatformsDeeplink && renderInfoBlock('mobile', 'follow the Deep link', allPlatformsDeeplinkUrl), !allPlatformsDeeplinkUrl && !hasCustomPlatformsDeeplink && renderInfoBlock('mobile', 'open home page in application'), webPageUrl && renderInfoBlock('web', 'open URL in browser', webPageUrl), webPageUrl && safariUrl && renderInfoBlock('Safari', 'open URL in Safari browser', safariUrl), !webPageUrl && renderInfoBlock('web', 'open home page in browser'), showRichmedia && renderRichmedia(showRichmedia))));
89
+ };
@@ -0,0 +1,2 @@
1
+ export { OpenActionsSummary } from './OpenActionsSummary';
2
+ export * from '../../types';
@@ -0,0 +1,2 @@
1
+ export { OpenActionsSummary } from './OpenActionsSummary';
2
+ export * from '../../types';
@@ -0,0 +1,57 @@
1
+ export declare const LinkRow: import("styled-components").StyledComponent<"div", any, {}, never>;
2
+ export declare const ClickActionSection: import("styled-components").StyledComponent<"div", any, {
3
+ $alignContent?: "end" | "start" | "center" | "space-between" | "space-around" | "space-evenly" | "stretch" | undefined;
4
+ $alignItems?: "end" | "start" | "center" | "stretch" | "baseline" | undefined;
5
+ $bgColor?: string | undefined;
6
+ $border?: string | ({
7
+ top?: string | undefined;
8
+ right?: string | undefined;
9
+ bottom?: string | undefined;
10
+ left?: string | undefined;
11
+ } | {
12
+ horizontal: string;
13
+ top?: string | undefined;
14
+ bottom?: string | undefined;
15
+ } | {
16
+ vertical: string;
17
+ right?: string | undefined;
18
+ left?: string | undefined;
19
+ }) | undefined;
20
+ $borderRadius?: (string | number) | undefined;
21
+ $boxShadow?: string | undefined;
22
+ $gap?: (string | number) | undefined;
23
+ $gridAutoFlow?: "row" | "column" | "dense" | "row dense" | "column dense" | undefined;
24
+ $justifyContent?: "end" | "start" | "center" | "space-between" | "space-around" | "space-evenly" | "stretch" | undefined;
25
+ $justifyItems?: "end" | "start" | "center" | "stretch" | "baseline" | undefined;
26
+ $margin?: (string | number) | ({
27
+ top?: (string | number) | undefined;
28
+ right?: (string | number) | undefined;
29
+ bottom?: (string | number) | undefined;
30
+ left?: (string | number) | undefined;
31
+ } | {
32
+ horizontal: string | number;
33
+ top?: (string | number) | undefined;
34
+ bottom?: (string | number) | undefined;
35
+ } | {
36
+ vertical: string | number;
37
+ right?: (string | number) | undefined;
38
+ left?: (string | number) | undefined;
39
+ }) | undefined;
40
+ $padding?: (string | number) | ({
41
+ top?: (string | number) | undefined;
42
+ right?: (string | number) | undefined;
43
+ bottom?: (string | number) | undefined;
44
+ left?: (string | number) | undefined;
45
+ } | {
46
+ horizontal: string | number;
47
+ top?: (string | number) | undefined;
48
+ bottom?: (string | number) | undefined;
49
+ } | {
50
+ vertical: string | number;
51
+ right?: (string | number) | undefined;
52
+ left?: (string | number) | undefined;
53
+ }) | undefined;
54
+ $placeItems?: "end" | "start" | "center" | "stretch" | undefined;
55
+ } & {
56
+ $gridAutoFlow: string;
57
+ }, "$gridAutoFlow">;
@@ -0,0 +1,11 @@
1
+ import styled from 'styled-components';
2
+ import { Color } from '@pushwoosh/kit-constants';
3
+ import { Vertical } from '@pushwoosh/kit-helpers';
4
+ export const LinkRow = styled.div.withConfig({
5
+ displayName: "LinkRow",
6
+ componentId: "sc-wfitxs-0"
7
+ })(["white-space:nowrap;text-overflow:ellipsis;overflow:hidden;"]);
8
+ export const ClickActionSection = styled(Vertical).withConfig({
9
+ displayName: "ClickActionSection",
10
+ componentId: "sc-wfitxs-1"
11
+ })(["overflow:hidden;background:", ";padding:16px;"], Color.SOFT_LIGHT);
@@ -0,0 +1,7 @@
1
+ import React from 'react';
2
+ import { type Preset } from '@pushwoosh/rpc-v2-http-api-data/presets';
3
+ type OpenActionsByPresetProps = {
4
+ pushPreset: Preset;
5
+ };
6
+ export declare const OpenActionsSummaryByPreset: ({ pushPreset }: OpenActionsByPresetProps) => React.JSX.Element;
7
+ export {};
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+ import { OpenActionsSummary } from './OpenActionsSummary';
3
+ import { usePresetOpenActions } from '../usePresetOpenActions';
4
+ export const OpenActionsSummaryByPreset = ({
5
+ pushPreset
6
+ }) => {
7
+ const openActions = usePresetOpenActions(pushPreset);
8
+ return React.createElement(OpenActionsSummary, {
9
+ openActions: openActions
10
+ });
11
+ };
@@ -0,0 +1,6 @@
1
+ import { type Application } from '@pushwoosh/rpc-v2-http-api-data/applications';
2
+ export declare const isWebLink: (url: string) => boolean;
3
+ export declare const formatDeeplink: (template: string, deeplinkParams: {
4
+ [param: string]: string;
5
+ }) => string;
6
+ export declare const getSafariUrl: (application: Application | null, safariUrlArguments: string) => string;
@@ -0,0 +1,14 @@
1
+ import { AllPlatforms } from '@pushwoosh/kit-constants';
2
+ export const isWebLink = url => {
3
+ return url.startsWith('http://') || url.startsWith('https://');
4
+ };
5
+ export const formatDeeplink = (template, deeplinkParams) => Object.keys(deeplinkParams).reduce((url, paramName) => url.replace(`{${paramName}}`, deeplinkParams[paramName]), template);
6
+ export const getSafariUrl = (application, safariUrlArguments) => {
7
+ var _application$platform, _application$properti;
8
+ if (!application) {
9
+ return '';
10
+ }
11
+ const isSafariConfigured = !!((_application$platform = application.platforms) !== null && _application$platform !== void 0 && (_application$platform = _application$platform[AllPlatforms.Safari]) !== null && _application$platform !== void 0 && _application$platform.isConfigured);
12
+ const safariUrlTemplate = ((_application$properti = application.properties) === null || _application$properti === void 0 ? void 0 : _application$properti.safari_url_template) || '';
13
+ return isSafariConfigured ? `${safariUrlTemplate}/${safariUrlArguments}` : '';
14
+ };
@@ -0,0 +1,4 @@
1
+ export { usePresetOpenActions } from './usePresetOpenActions';
2
+ export { OpenActionsSummaryByPreset } from './components/OpenActionsSummaryByPreset';
3
+ export { OpenActionsSummary } from './components/OpenActionsSummary';
4
+ export * from './types';
@@ -0,0 +1,4 @@
1
+ export { usePresetOpenActions } from './usePresetOpenActions';
2
+ export { OpenActionsSummaryByPreset } from './components/OpenActionsSummaryByPreset';
3
+ export { OpenActionsSummary } from './components/OpenActionsSummary';
4
+ export * from './types';
@@ -0,0 +1,18 @@
1
+ import { type AllPlatforms } from '@pushwoosh/kit-constants';
2
+ export type ParsedOpenActions = {
3
+ platformsDeeplinkUrls: Partial<Record<AllPlatforms, string>>;
4
+ defaultDeeplinkUrl: string | null;
5
+ webPageUrl: string | null;
6
+ showRichmedia: {
7
+ url?: string;
8
+ code?: string;
9
+ } | null;
10
+ safariUrlArgs: string | null;
11
+ };
12
+ export type OpenActionsSummaryProps = {
13
+ openActions: ParsedOpenActions | undefined;
14
+ };
15
+ export type RouterParams = {
16
+ applicationCode?: string;
17
+ groupCode?: string;
18
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import { type Preset } from '@pushwoosh/rpc-v2-http-api-data/presets';
2
+ import { type ParsedOpenActions } from './types';
3
+ export declare const usePresetOpenActions: (pushPreset: Preset | undefined) => ParsedOpenActions | undefined;
@@ -0,0 +1,91 @@
1
+ import { useCallback, useEffect, useState } from 'react';
2
+ import { useToast } from '@pushwoosh/dumb-components';
3
+ import { useSPAContext } from '../context';
4
+ import { formatDeeplink } from './helpers';
5
+ const WEB_PLATFORM_KEY = 0;
6
+ export const usePresetOpenActions = pushPreset => {
7
+ const [openActions, setOpenActions] = useState(undefined);
8
+ const {
9
+ rpcGateway
10
+ } = useSPAContext();
11
+ const {
12
+ openToast
13
+ } = useToast();
14
+ const getDeeplinkUrl = useCallback(async deeplinkCommonInfo => {
15
+ try {
16
+ const res = await rpcGateway.deeplinks.Get({
17
+ code: deeplinkCommonInfo.code
18
+ });
19
+ return formatDeeplink(res.deeplink.template || '', deeplinkCommonInfo.params);
20
+ } catch {
21
+ openToast({
22
+ title: `Error getting deeplink by code: ${deeplinkCommonInfo.code}`,
23
+ type: 'error'
24
+ });
25
+ return '';
26
+ }
27
+ }, [openToast, rpcGateway]);
28
+ const getOpenActionsByPreset = useCallback(async () => {
29
+ var _pushPreset$localized, _pushPreset$openActio;
30
+ if (!pushPreset) {
31
+ return;
32
+ }
33
+ const safariUrlArgs = ((_pushPreset$localized = pushPreset.localizedProperties.default) === null || _pushPreset$localized === void 0 || (_pushPreset$localized = _pushPreset$localized.safari) === null || _pushPreset$localized === void 0 || (_pushPreset$localized = _pushPreset$localized.urlArguments) === null || _pushPreset$localized === void 0 ? void 0 : _pushPreset$localized[0]) ?? null;
34
+ const webPageUrl = pushPreset.url;
35
+ const {
36
+ platformsDeeplinkUrls,
37
+ showRichmedia
38
+ } = await getPlatformDeeplinksByOpenActions(pushPreset, getDeeplinkUrl);
39
+ let defaultDeeplinkUrl = null;
40
+ // openAction - for common all mobile deeplink; web url is located in 'url' prop, openActions - map with mobile deeplink platform as a key (0 we should ignore)
41
+ if (((_pushPreset$openActio = pushPreset.openAction) === null || _pushPreset$openActio === void 0 || (_pushPreset$openActio = _pushPreset$openActio.kind) === null || _pushPreset$openActio === void 0 ? void 0 : _pushPreset$openActio.type) === 'deepLink') {
42
+ const deeplinkCommonInfo = pushPreset.openAction.kind.data;
43
+ defaultDeeplinkUrl = await getDeeplinkUrl(deeplinkCommonInfo);
44
+ }
45
+ // setTimeout нужен, чтобы не получать ошибку 'ResizeObserver loop completed with undelivered notifications.'
46
+ setTimeout(() => {
47
+ setOpenActions({
48
+ webPageUrl,
49
+ defaultDeeplinkUrl,
50
+ platformsDeeplinkUrls,
51
+ safariUrlArgs,
52
+ showRichmedia
53
+ });
54
+ }, 0);
55
+ }, [getDeeplinkUrl, pushPreset]);
56
+ useEffect(() => {
57
+ getOpenActionsByPreset();
58
+ }, [getOpenActionsByPreset]);
59
+ return openActions;
60
+ };
61
+ const getPlatformDeeplinksByOpenActions = async (pushPreset, getDeeplinkUrl) => {
62
+ const platformsDeeplinkUrls = {};
63
+ let showRichmedia = null;
64
+ await Promise.all(Object.entries(pushPreset.openActions).filter(([plKey]) => +plKey !== WEB_PLATFORM_KEY).map(async ([plKey, action]) => {
65
+ var _action$kind, _action$kind2, _action$kind3;
66
+ const platformKey = +plKey;
67
+ if ((action === null || action === void 0 || (_action$kind = action.kind) === null || _action$kind === void 0 ? void 0 : _action$kind.type) === 'deepLink') {
68
+ const deeplinkCommonInfo = action.kind.data;
69
+ platformsDeeplinkUrls[platformKey] = await getDeeplinkUrl(deeplinkCommonInfo);
70
+ }
71
+ if ((action === null || action === void 0 || (_action$kind2 = action.kind) === null || _action$kind2 === void 0 ? void 0 : _action$kind2.type) === 'link') {
72
+ const deeplinkCommonInfo = action.kind.data;
73
+ platformsDeeplinkUrls[platformKey] = deeplinkCommonInfo.url;
74
+ }
75
+ if ((action === null || action === void 0 || (_action$kind3 = action.kind) === null || _action$kind3 === void 0 ? void 0 : _action$kind3.type) === 'richMedia') {
76
+ if (action.kind.data.kind.type === 'url') {
77
+ showRichmedia = {
78
+ url: action.kind.data.kind.data
79
+ };
80
+ } else if (action.kind.data.kind.type === 'code') {
81
+ showRichmedia = {
82
+ code: action.kind.data.kind.data
83
+ };
84
+ }
85
+ }
86
+ }));
87
+ return {
88
+ platformsDeeplinkUrls,
89
+ showRichmedia
90
+ };
91
+ };
package/index.d.ts CHANGED
@@ -6,3 +6,4 @@ export * from './LanguagesSelector';
6
6
  export * from './RichMessageEditorSmart';
7
7
  export * from './CampaignsConfigurationDrawer';
8
8
  export * from './ExportCSV';
9
+ export * from './OpenActions';
package/index.js CHANGED
@@ -5,4 +5,5 @@ export * from './PlatformsConfigurationDrawer';
5
5
  export * from './LanguagesSelector';
6
6
  export * from './RichMessageEditorSmart';
7
7
  export * from './CampaignsConfigurationDrawer';
8
- export * from './ExportCSV';
8
+ export * from './ExportCSV';
9
+ export * from './OpenActions';
package/package.json CHANGED
@@ -21,7 +21,7 @@
21
21
  "@pushwoosh/dumb-components": "^1.1.2",
22
22
  "@pushwoosh/kit-constants": "^1.6.9",
23
23
  "@pushwoosh/kit-helpers": "^4.8.1",
24
- "@pushwoosh/kit-icons": "^2.1.2",
24
+ "@pushwoosh/kit-icons": "^2.1.6",
25
25
  "@pushwoosh/kit-typography": "^1.7.3"
26
26
  },
27
27
  "devDependencies": {
@@ -51,5 +51,5 @@
51
51
  "engines": {
52
52
  "node": ">= 18"
53
53
  },
54
- "version": "1.0.26"
54
+ "version": "1.0.27"
55
55
  }