@pushwoosh/smart-components-kit 1.3.26 → 1.3.28

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
+ }
@@ -2,6 +2,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { Spinner } from '@pushwoosh/dumb-components';
3
3
  import { Horizontal, useAsync } from '@pushwoosh/kit-helpers';
4
4
  import { useSPAContext } from '@pushwoosh/spa-context';
5
+ import { collectPaginatedData } from '../asyncHelpers';
5
6
  import { langCodes } from './constants';
6
7
  import { LanguagesSelectForm } from './LanguagesSelectForm';
7
8
  import { resolveLanguageAudience } from './platforms';
@@ -18,12 +19,16 @@ export const LanguagesSelectFormLoader = ({
18
19
  rpcGateway
19
20
  } = useSPAContext();
20
21
  const langAsync = useAsync(async () => {
21
- const {
22
- values
23
- } = await rpcGateway.tags.GetTagValues({
24
- application,
25
- name: 'Language',
26
- platforms
22
+ // GetTagValues caps an unpaged request at 100 values, and apps hold more languages than that
23
+ const values = await collectPaginatedData(1000, async (perPage, page) => {
24
+ const res = await rpcGateway.tags.GetTagValues({
25
+ application,
26
+ name: 'Language',
27
+ platforms,
28
+ page,
29
+ perPage
30
+ });
31
+ return res.values;
27
32
  });
28
33
  const valuesLangCodes = values.map(v => canonicalizeLangCode(v.value));
29
34
  const allLangCodes = Array.from(new Set([...valuesLangCodes, ...langCodes.map(canonicalizeLangCode)]).values());
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.26"
58
+ "version": "1.3.28"
59
59
  }