@pushwoosh/smart-components-kit 1.3.25 → 1.3.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.
@@ -4,6 +4,7 @@ import { Columns, Horizontal, Vertical } from '@pushwoosh/kit-helpers';
4
4
  import { CloseIcon, EmailIcon, MobileIcon, PushIcon, SmsIcon, WhatsappIcon } from '@pushwoosh/kit-icons';
5
5
  import { H1, H3 } from '@pushwoosh/kit-typography';
6
6
  import { Card } from './components/Card';
7
+ import { useCanSendMessages } from './hooks';
7
8
  import { useLang } from './polyglot';
8
9
  import { CloseButtonWrap } from './styled';
9
10
  export function CampaignsConfigurationDrawer(props) {
@@ -15,6 +16,10 @@ export function CampaignsConfigurationDrawer(props) {
15
16
  onClose
16
17
  } = props;
17
18
  const lang = useLang();
19
+ const {
20
+ canSendMessages,
21
+ isResolved
22
+ } = useCanSendMessages(applicationCode);
18
23
  return _jsxs(Drawer, {
19
24
  size: "medium",
20
25
  isOpen: isOpen,
@@ -38,7 +43,7 @@ export function CampaignsConfigurationDrawer(props) {
38
43
  }), _jsx(DrawerBody, {
39
44
  children: _jsxs(Vertical, {
40
45
  "$gap": "32px",
41
- children: [_jsxs(Horizontal, {
46
+ children: [isResolved && canSendMessages && _jsxs(Horizontal, {
42
47
  "$gap": "6px",
43
48
  children: [_jsx(Card, {
44
49
  title: lang({
@@ -0,0 +1,7 @@
1
+ type UseCanSendMessages = {
2
+ readonly canSendMessages: boolean;
3
+ /** False until the application answers, so "not loaded yet" is not read as "not allowed". */
4
+ readonly isResolved: boolean;
5
+ };
6
+ export declare function useCanSendMessages(applicationCode: string): UseCanSendMessages;
7
+ export {};
@@ -0,0 +1,28 @@
1
+ import { useAsync } from '@pushwoosh/kit-helpers';
2
+ import { useSPAContext } from '@pushwoosh/spa-context';
3
+ // The flag covers both the account-wide SendPush ACE and the per-application Send one,
4
+ // so the application response answers "may this user send here" on its own.
5
+ export function useCanSendMessages(applicationCode) {
6
+ const {
7
+ rpcGateway
8
+ } = useSPAContext();
9
+ const state = useAsync(async () => {
10
+ if (!applicationCode) {
11
+ return false;
12
+ }
13
+ try {
14
+ const {
15
+ application
16
+ } = await rpcGateway.applications.Get({
17
+ code: applicationCode
18
+ });
19
+ return Boolean(application?.permissions?.canSendMessages);
20
+ } catch {
21
+ return false;
22
+ }
23
+ }, [applicationCode, rpcGateway]);
24
+ return {
25
+ canSendMessages: state.value ?? false,
26
+ isResolved: !state.loading
27
+ };
28
+ }
@@ -1,4 +1,5 @@
1
1
  import { type FC } from 'react';
2
+ import { type LanguageAudience } from './platforms';
2
3
  type LanguageItem = {
3
4
  code: string;
4
5
  name: string;
@@ -9,6 +10,7 @@ type LanguagesSelectProps = {
9
10
  langs: string[];
10
11
  onChange: (languages: string[]) => void;
11
12
  systemLanguage?: string;
13
+ audience?: LanguageAudience;
12
14
  };
13
15
  export declare const LanguagesSelectForm: FC<LanguagesSelectProps>;
14
16
  export {};
@@ -1,15 +1,27 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useMemo, useState } from 'react';
3
3
  import { Checkbox, SearchInput } from '@pushwoosh/dumb-components';
4
+ import { Color } from '@pushwoosh/kit-constants';
4
5
  import { Columns, Horizontal, Vertical } from '@pushwoosh/kit-helpers';
6
+ import { Text } from '@pushwoosh/kit-typography';
5
7
  import { useLang } from './polyglot';
6
8
  import { ActionButton } from './styled';
7
9
  import { fetchLastSelection, useGetLangName } from './utils';
10
+ const AUDIENCE_HINT_MESSAGE = {
11
+ email: 'SMART.LANGUAGES_SELECTOR.AUDIENCE_HINT.EMAIL',
12
+ sms: 'SMART.LANGUAGES_SELECTOR.AUDIENCE_HINT.SMS',
13
+ line: 'SMART.LANGUAGES_SELECTOR.AUDIENCE_HINT.LINE',
14
+ whatsApp: 'SMART.LANGUAGES_SELECTOR.AUDIENCE_HINT.WHATSAPP',
15
+ push: 'SMART.LANGUAGES_SELECTOR.AUDIENCE_HINT.PUSH',
16
+ inApp: 'SMART.LANGUAGES_SELECTOR.AUDIENCE_HINT.IN_APP',
17
+ all: 'SMART.LANGUAGES_SELECTOR.AUDIENCE_HINT.ALL'
18
+ };
8
19
  export const LanguagesSelectForm = ({
9
20
  allLanguageItems,
10
21
  langs,
11
22
  onChange,
12
- systemLanguage = 'en'
23
+ systemLanguage = 'en',
24
+ audience = 'all'
13
25
  }) => {
14
26
  const lang = useLang();
15
27
  const getLangName = useGetLangName(systemLanguage);
@@ -27,7 +39,13 @@ export const LanguagesSelectForm = ({
27
39
  }, [allLanguageItems, search, showAllLanguages, langs]);
28
40
  return _jsxs(Vertical, {
29
41
  "$gap": 8,
30
- children: [_jsx(SearchInput, {
42
+ children: [_jsx(Text, {
43
+ "$variant": "footnote",
44
+ "$color": Color.LOCKED,
45
+ children: lang({
46
+ message: AUDIENCE_HINT_MESSAGE[audience]
47
+ })
48
+ }), _jsx(SearchInput, {
31
49
  value: search,
32
50
  onChange: e => setSearch(e.target.value),
33
51
  "$onClear": () => setSearch(''),
@@ -4,6 +4,7 @@ import { Horizontal, useAsync } from '@pushwoosh/kit-helpers';
4
4
  import { useSPAContext } from '@pushwoosh/spa-context';
5
5
  import { langCodes } from './constants';
6
6
  import { LanguagesSelectForm } from './LanguagesSelectForm';
7
+ import { resolveLanguageAudience } from './platforms';
7
8
  import { canonicalizeLangCode, useGetLangName } from './utils';
8
9
  export const LanguagesSelectFormLoader = ({
9
10
  application,
@@ -49,6 +50,7 @@ export const LanguagesSelectFormLoader = ({
49
50
  allLanguageItems: langAsync.value,
50
51
  langs: value,
51
52
  onChange: onChange,
52
- systemLanguage: systemLanguage
53
+ systemLanguage: systemLanguage,
54
+ audience: resolveLanguageAudience(platforms)
53
55
  });
54
56
  };
@@ -11,3 +11,5 @@ export declare const LANGUAGE_PLATFORMS: {
11
11
  push: AllPlatforms[];
12
12
  inApp: (AllPlatforms.IOS | AllPlatforms.Blackberry | AllPlatforms.Android | AllPlatforms.Asha | AllPlatforms.WindowsPhone | AllPlatforms.Bada | AllPlatforms.OSX | AllPlatforms.Windows | AllPlatforms.Amazon | AllPlatforms.Safari | AllPlatforms.Chrome | AllPlatforms.Firefox | AllPlatforms.IE | AllPlatforms.Email | AllPlatforms.FBMessenger | AllPlatforms.BaiduAndroid | AllPlatforms.HuaweiAndroid | AllPlatforms.SMS | AllPlatforms.Xiaomi | AllPlatforms.Web | AllPlatforms.WhatsApp | AllPlatforms.Line | AllPlatforms.KakaoTalk | AllPlatforms.Telegram | AllPlatforms.Viber)[];
13
13
  };
14
+ export type LanguageAudience = keyof typeof LANGUAGE_PLATFORMS | 'all';
15
+ export declare function resolveLanguageAudience(platforms?: AllPlatforms[]): LanguageAudience;
@@ -11,4 +11,14 @@ export const LANGUAGE_PLATFORMS = {
11
11
  whatsApp: [AllPlatforms.WhatsApp],
12
12
  push: PUSH_PLATFORMS,
13
13
  inApp: PUSH_PLATFORMS.filter(platform => platform !== AllPlatforms.AppleWallet && platform !== AllPlatforms.GoogleWallet)
14
- };
14
+ };
15
+ export function resolveLanguageAudience(platforms) {
16
+ if (!platforms?.length) {
17
+ return 'all';
18
+ }
19
+ const key = Object.keys(LANGUAGE_PLATFORMS).find(name => {
20
+ const preset = LANGUAGE_PLATFORMS[name];
21
+ return preset.length === platforms.length && preset.every(platform => platforms.includes(platform));
22
+ });
23
+ return key ?? 'all';
24
+ }
@@ -8,6 +8,13 @@ export const messages = {
8
8
  'SMART.LANGUAGES_SELECTOR.ACTION.REUSE_LAST': 'reuse last selection',
9
9
  'SMART.LANGUAGES_SELECTOR.ACTION.SHOW_ALL': 'Show all languages',
10
10
  'SMART.LANGUAGES_SELECTOR.ACTION.SHOW_WITH_SUBSCRIBERS': 'Show only languages with subscribers',
11
+ 'SMART.LANGUAGES_SELECTOR.AUDIENCE_HINT.EMAIL': 'Numbers are email contacts whose Language tag holds this value.',
12
+ 'SMART.LANGUAGES_SELECTOR.AUDIENCE_HINT.SMS': 'Numbers are SMS contacts whose Language tag holds this value.',
13
+ 'SMART.LANGUAGES_SELECTOR.AUDIENCE_HINT.LINE': 'Numbers are LINE contacts whose Language tag holds this value.',
14
+ 'SMART.LANGUAGES_SELECTOR.AUDIENCE_HINT.WHATSAPP': 'Numbers are WhatsApp contacts whose Language tag holds this value.',
15
+ 'SMART.LANGUAGES_SELECTOR.AUDIENCE_HINT.PUSH': 'Numbers are push devices whose Language tag holds this value.',
16
+ 'SMART.LANGUAGES_SELECTOR.AUDIENCE_HINT.IN_APP': 'Numbers are devices whose Language tag holds this value.',
17
+ 'SMART.LANGUAGES_SELECTOR.AUDIENCE_HINT.ALL': 'Numbers are devices and contacts of every channel whose Language tag holds this value.',
11
18
  'SMART.LANGUAGES_SELECTOR.CHECKBOX_LABEL': '{{name}} ({{subscribers}})',
12
19
  'SMART.LANGUAGES_SELECTOR.CHOOSE_LANGUAGES': 'Choose languages…'
13
20
  };
@@ -8,6 +8,13 @@ export const messages = {
8
8
  'SMART.LANGUAGES_SELECTOR.ACTION.REUSE_LAST': 'повторить прошлый выбор',
9
9
  'SMART.LANGUAGES_SELECTOR.ACTION.SHOW_ALL': 'Показать все языки',
10
10
  'SMART.LANGUAGES_SELECTOR.ACTION.SHOW_WITH_SUBSCRIBERS': 'Только языки с подписчиками',
11
+ 'SMART.LANGUAGES_SELECTOR.AUDIENCE_HINT.EMAIL': 'Числа — email-контакты, у которых тег Language равен этому значению.',
12
+ 'SMART.LANGUAGES_SELECTOR.AUDIENCE_HINT.SMS': 'Числа — SMS-контакты, у которых тег Language равен этому значению.',
13
+ 'SMART.LANGUAGES_SELECTOR.AUDIENCE_HINT.LINE': 'Числа — контакты LINE, у которых тег Language равен этому значению.',
14
+ 'SMART.LANGUAGES_SELECTOR.AUDIENCE_HINT.WHATSAPP': 'Числа — контакты WhatsApp, у которых тег Language равен этому значению.',
15
+ 'SMART.LANGUAGES_SELECTOR.AUDIENCE_HINT.PUSH': 'Числа — push-устройства, у которых тег Language равен этому значению.',
16
+ 'SMART.LANGUAGES_SELECTOR.AUDIENCE_HINT.IN_APP': 'Числа — устройства, у которых тег Language равен этому значению.',
17
+ 'SMART.LANGUAGES_SELECTOR.AUDIENCE_HINT.ALL': 'Числа — устройства и контакты всех каналов, у которых тег Language равен этому значению.',
11
18
  'SMART.LANGUAGES_SELECTOR.CHECKBOX_LABEL': '{{name}} ({{subscribers}})',
12
19
  'SMART.LANGUAGES_SELECTOR.CHOOSE_LANGUAGES': 'Выбрать языки…'
13
20
  };
@@ -9,6 +9,13 @@ export type LanguagesSelectorMessages = {
9
9
  'SMART.LANGUAGES_SELECTOR.ACTION.REUSE_LAST': NoParams;
10
10
  'SMART.LANGUAGES_SELECTOR.ACTION.SHOW_ALL': NoParams;
11
11
  'SMART.LANGUAGES_SELECTOR.ACTION.SHOW_WITH_SUBSCRIBERS': NoParams;
12
+ 'SMART.LANGUAGES_SELECTOR.AUDIENCE_HINT.EMAIL': NoParams;
13
+ 'SMART.LANGUAGES_SELECTOR.AUDIENCE_HINT.SMS': NoParams;
14
+ 'SMART.LANGUAGES_SELECTOR.AUDIENCE_HINT.LINE': NoParams;
15
+ 'SMART.LANGUAGES_SELECTOR.AUDIENCE_HINT.WHATSAPP': NoParams;
16
+ 'SMART.LANGUAGES_SELECTOR.AUDIENCE_HINT.PUSH': NoParams;
17
+ 'SMART.LANGUAGES_SELECTOR.AUDIENCE_HINT.IN_APP': NoParams;
18
+ 'SMART.LANGUAGES_SELECTOR.AUDIENCE_HINT.ALL': NoParams;
12
19
  'SMART.LANGUAGES_SELECTOR.CHECKBOX_LABEL': {
13
20
  name: string;
14
21
  subscribers: number;
package/package.json CHANGED
@@ -55,5 +55,5 @@
55
55
  "react": "^16.14.0 || ^18.0.0",
56
56
  "react-dom": "^16.14.0 || ^18.0.0"
57
57
  },
58
- "version": "1.3.25"
58
+ "version": "1.3.27"
59
59
  }