@pushwoosh/smart-components-kit 1.3.26 → 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
|
+
}
|
package/package.json
CHANGED