@servicetitan/notifications 31.1.0 → 31.3.0
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.
- package/dist/api/notifications.api.js +4 -3
- package/dist/api/notifications.api.js.map +1 -1
- package/dist/common.js +4 -3
- package/dist/common.js.map +1 -1
- package/dist/components/notifications.js +42 -22
- package/dist/components/notifications.js.map +1 -1
- package/dist/demo/action-button-preview.js +41 -23
- package/dist/demo/action-button-preview.js.map +1 -1
- package/dist/demo/action-button.js +4 -1
- package/dist/demo/action-button.js.map +1 -1
- package/dist/demo/basic-preview.js +9 -5
- package/dist/demo/basic-preview.js.map +1 -1
- package/dist/demo/basic.js +4 -1
- package/dist/demo/basic.js.map +1 -1
- package/dist/demo/container.js +44 -45
- package/dist/demo/container.js.map +1 -1
- package/dist/demo/duration-preview.js +23 -9
- package/dist/demo/duration-preview.js.map +1 -1
- package/dist/demo/duration.js +4 -1
- package/dist/demo/duration.js.map +1 -1
- package/dist/demo/index.js +1 -0
- package/dist/demo/index.js.map +1 -1
- package/dist/demo/multiline-message-preview.js +9 -5
- package/dist/demo/multiline-message-preview.js.map +1 -1
- package/dist/demo/multiline-message.js +4 -1
- package/dist/demo/multiline-message.js.map +1 -1
- package/dist/demo/prevent-duplicates-preview.js +9 -5
- package/dist/demo/prevent-duplicates-preview.js.map +1 -1
- package/dist/demo/prevent-duplicates.js +4 -1
- package/dist/demo/prevent-duplicates.js.map +1 -1
- package/dist/demo/progress-preview.js +9 -5
- package/dist/demo/progress-preview.js.map +1 -1
- package/dist/demo/progress.js +4 -1
- package/dist/demo/progress.js.map +1 -1
- package/dist/demo/server-custom-preview.js +5 -4
- package/dist/demo/server-custom-preview.js.map +1 -1
- package/dist/demo/server-custom.js +13 -7
- package/dist/demo/server-custom.js.map +1 -1
- package/dist/demo/server-default.js +66 -61
- package/dist/demo/server-default.js.map +1 -1
- package/dist/demo/status-variations-preview.js +35 -13
- package/dist/demo/status-variations-preview.js.map +1 -1
- package/dist/demo/status-variations.js +4 -1
- package/dist/demo/status-variations.js.map +1 -1
- package/dist/index.js +7 -6
- package/dist/index.js.map +1 -1
- package/dist/intercept.js +1 -0
- package/dist/intercept.js.map +1 -1
- package/dist/notifications-channel.js +1 -0
- package/dist/notifications-channel.js.map +1 -1
- package/dist/notifications-service.js +71 -69
- package/dist/notifications-service.js.map +1 -1
- package/dist/stores/notifications.store.js +210 -218
- package/dist/stores/notifications.store.js.map +1 -1
- package/dist/utils/date-from-string.js +2 -1
- package/dist/utils/date-from-string.js.map +1 -1
- package/dist/utils/use-compatible-navigate.js +4 -3
- package/dist/utils/use-compatible-navigate.js.map +1 -1
- package/package.json +8 -8
- package/dist/__tests__/intercept.test.js +0 -13
- package/dist/__tests__/intercept.test.js.map +0 -1
- package/dist/__tests__/notifications-service.test.js +0 -42
- package/dist/__tests__/notifications-service.test.js.map +0 -1
- package/dist/components/__tests__/notifications.test.js +0 -93
- package/dist/components/__tests__/notifications.test.js.map +0 -1
- package/dist/notifications.stories.js +0 -20
- package/dist/notifications.stories.js.map +0 -1
- package/dist/stores/__mocks__/mock-notifications-channel.js +0 -36
- package/dist/stores/__mocks__/mock-notifications-channel.js.map +0 -1
- package/dist/stores/__tests__/notifications.store.test.js +0 -367
- package/dist/stores/__tests__/notifications.store.test.js.map +0 -1
- package/dist/utils/__tests__/date-from-string.test.js +0 -45
- package/dist/utils/__tests__/date-from-string.test.js.map +0 -1
- package/dist/utils/__tests__/use-compatible-navigate.test.js +0 -27
- package/dist/utils/__tests__/use-compatible-navigate.test.js.map +0 -1
@@ -2,11 +2,15 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { Button } from '@servicetitan/anvil2';
|
3
3
|
import { useDependencies } from '@servicetitan/react-ioc';
|
4
4
|
import { NotificationsService } from '..';
|
5
|
-
export const PreventDuplicatesPreview = ()
|
5
|
+
export const PreventDuplicatesPreview = ()=>{
|
6
6
|
const [notifications] = useDependencies(NotificationsService);
|
7
|
-
const handleClick = ()
|
8
|
-
|
9
|
-
|
10
|
-
return _jsx(Button, {
|
7
|
+
const handleClick = ()=>notifications.show({
|
8
|
+
title: 'Equal notifications will be skipped.'
|
9
|
+
}, true);
|
10
|
+
return /*#__PURE__*/ _jsx(Button, {
|
11
|
+
onClick: handleClick,
|
12
|
+
children: "Show"
|
13
|
+
});
|
11
14
|
};
|
15
|
+
|
12
16
|
//# sourceMappingURL=prevent-duplicates-preview.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"sources":["../../src/demo/prevent-duplicates-preview.tsx"],"sourcesContent":["import { Button } from '@servicetitan/anvil2';\nimport { useDependencies } from '@servicetitan/react-ioc';\nimport { FC } from 'react';\n\nimport { NotificationsService } from '..';\n\nexport const PreventDuplicatesPreview: FC = () => {\n const [notifications] = useDependencies(NotificationsService);\n\n const handleClick = () =>\n notifications.show(\n {\n title: 'Equal notifications will be skipped.',\n },\n true\n );\n\n return <Button onClick={handleClick}>Show</Button>;\n};\n"],"names":["Button","useDependencies","NotificationsService","PreventDuplicatesPreview","notifications","handleClick","show","title","onClick"],"mappings":";AAAA,SAASA,MAAM,QAAQ,uBAAuB;AAC9C,SAASC,eAAe,QAAQ,0BAA0B;AAG1D,SAASC,oBAAoB,QAAQ,KAAK;AAE1C,OAAO,MAAMC,2BAA+B;IACxC,MAAM,CAACC,cAAc,GAAGH,gBAAgBC;IAExC,MAAMG,cAAc,IAChBD,cAAcE,IAAI,CACd;YACIC,OAAO;QACX,GACA;IAGR,qBAAO,KAACP;QAAOQ,SAASH;kBAAa;;AACzC,EAAE"}
|
@@ -1,5 +1,8 @@
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
2
2
|
import { Container } from './container';
|
3
3
|
import { PreventDuplicatesPreview } from './prevent-duplicates-preview';
|
4
|
-
export const PreventDuplicatesExample = ()
|
4
|
+
export const PreventDuplicatesExample = ()=>/*#__PURE__*/ _jsx(Container, {
|
5
|
+
children: ()=>/*#__PURE__*/ _jsx(PreventDuplicatesPreview, {})
|
6
|
+
});
|
7
|
+
|
5
8
|
//# sourceMappingURL=prevent-duplicates.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"sources":["../../src/demo/prevent-duplicates.tsx"],"sourcesContent":["import { FC } from 'react';\n\nimport { Container } from './container';\nimport { PreventDuplicatesPreview } from './prevent-duplicates-preview';\n\nexport const PreventDuplicatesExample: FC = () => (\n <Container>{() => <PreventDuplicatesPreview />}</Container>\n);\n"],"names":["Container","PreventDuplicatesPreview","PreventDuplicatesExample"],"mappings":";AAEA,SAASA,SAAS,QAAQ,cAAc;AACxC,SAASC,wBAAwB,QAAQ,+BAA+B;AAExE,OAAO,MAAMC,2BAA+B,kBACxC,KAACF;kBAAW,kBAAM,KAACC;OACrB"}
|
@@ -2,12 +2,16 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { Button } from '@servicetitan/anvil2';
|
3
3
|
import { useDependencies } from '@servicetitan/react-ioc';
|
4
4
|
import { NotificationsService } from '..';
|
5
|
-
export const ProgressPreview = ()
|
5
|
+
export const ProgressPreview = ()=>{
|
6
6
|
const [notifications] = useDependencies(NotificationsService);
|
7
|
-
const handleClick = ()
|
8
|
-
|
9
|
-
|
7
|
+
const handleClick = ()=>notifications.show({
|
8
|
+
title: 'This message contains progress.',
|
9
|
+
progress: 25
|
10
|
+
});
|
11
|
+
return /*#__PURE__*/ _jsx(Button, {
|
12
|
+
onClick: handleClick,
|
13
|
+
children: "Show"
|
10
14
|
});
|
11
|
-
return _jsx(Button, { onClick: handleClick, children: "Show" });
|
12
15
|
};
|
16
|
+
|
13
17
|
//# sourceMappingURL=progress-preview.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"sources":["../../src/demo/progress-preview.tsx"],"sourcesContent":["import { Button } from '@servicetitan/anvil2';\nimport { useDependencies } from '@servicetitan/react-ioc';\nimport { FC } from 'react';\n\nimport { NotificationsService } from '..';\n\nexport const ProgressPreview: FC = () => {\n const [notifications] = useDependencies(NotificationsService);\n\n const handleClick = () =>\n notifications.show({\n title: 'This message contains progress.',\n progress: 25,\n });\n\n return <Button onClick={handleClick}>Show</Button>;\n};\n"],"names":["Button","useDependencies","NotificationsService","ProgressPreview","notifications","handleClick","show","title","progress","onClick"],"mappings":";AAAA,SAASA,MAAM,QAAQ,uBAAuB;AAC9C,SAASC,eAAe,QAAQ,0BAA0B;AAG1D,SAASC,oBAAoB,QAAQ,KAAK;AAE1C,OAAO,MAAMC,kBAAsB;IAC/B,MAAM,CAACC,cAAc,GAAGH,gBAAgBC;IAExC,MAAMG,cAAc,IAChBD,cAAcE,IAAI,CAAC;YACfC,OAAO;YACPC,UAAU;QACd;IAEJ,qBAAO,KAACR;QAAOS,SAASJ;kBAAa;;AACzC,EAAE"}
|
package/dist/demo/progress.js
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
2
2
|
import { Container } from './container';
|
3
3
|
import { ProgressPreview } from './progress-preview';
|
4
|
-
export const ProgressExample = ()
|
4
|
+
export const ProgressExample = ()=>/*#__PURE__*/ _jsx(Container, {
|
5
|
+
children: ()=>/*#__PURE__*/ _jsx(ProgressPreview, {})
|
6
|
+
});
|
7
|
+
|
5
8
|
//# sourceMappingURL=progress.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"sources":["../../src/demo/progress.tsx"],"sourcesContent":["import { FC } from 'react';\n\nimport { Container } from './container';\nimport { ProgressPreview } from './progress-preview';\n\nexport const ProgressExample: FC = () => <Container>{() => <ProgressPreview />}</Container>;\n"],"names":["Container","ProgressPreview","ProgressExample"],"mappings":";AAEA,SAASA,SAAS,QAAQ,cAAc;AACxC,SAASC,eAAe,QAAQ,qBAAqB;AAErD,OAAO,MAAMC,kBAAsB,kBAAM,KAACF;kBAAW,kBAAM,KAACC;OAAgC"}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { intercept } from '../intercept';
|
2
2
|
export function setupIntercept() {
|
3
|
-
intercept('CustomServerNotification', notification
|
3
|
+
intercept('CustomServerNotification', (notification)=>{
|
4
4
|
const { username, ...payload } = notification.payload;
|
5
5
|
return {
|
6
6
|
...notification,
|
@@ -9,10 +9,11 @@ export function setupIntercept() {
|
|
9
9
|
title: `Hi ${username}!`,
|
10
10
|
action: {
|
11
11
|
label: 'Thanks!',
|
12
|
-
onClick: ()
|
13
|
-
}
|
14
|
-
}
|
12
|
+
onClick: ()=>window.alert("You're welcome!")
|
13
|
+
}
|
14
|
+
}
|
15
15
|
};
|
16
16
|
});
|
17
17
|
}
|
18
|
+
|
18
19
|
//# sourceMappingURL=server-custom-preview.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"sources":["../../src/demo/server-custom-preview.tsx"],"sourcesContent":["import { intercept } from '../intercept';\n\nexport function setupIntercept() {\n intercept<{ username: string }>('CustomServerNotification', notification => {\n const { username, ...payload } = notification.payload;\n\n return {\n ...notification,\n payload: {\n ...payload,\n title: `Hi ${username}!`,\n action: {\n label: 'Thanks!',\n onClick: () => window.alert(\"You're welcome!\"),\n },\n },\n };\n });\n}\n"],"names":["intercept","setupIntercept","notification","username","payload","title","action","label","onClick","window","alert"],"mappings":"AAAA,SAASA,SAAS,QAAQ,eAAe;AAEzC,OAAO,SAASC;IACZD,UAAgC,4BAA4BE,CAAAA;QACxD,MAAM,EAAEC,QAAQ,EAAE,GAAGC,SAAS,GAAGF,aAAaE,OAAO;QAErD,OAAO;YACH,GAAGF,YAAY;YACfE,SAAS;gBACL,GAAGA,OAAO;gBACVC,OAAO,CAAC,GAAG,EAAEF,SAAS,CAAC,CAAC;gBACxBG,QAAQ;oBACJC,OAAO;oBACPC,SAAS,IAAMC,OAAOC,KAAK,CAAC;gBAChC;YACJ;QACJ;IACJ;AACJ"}
|
@@ -4,10 +4,11 @@ import { useEffect } from 'react';
|
|
4
4
|
import { NotificationProcessStatus } from '..';
|
5
5
|
import { Container } from './container';
|
6
6
|
import { setupIntercept } from './server-custom-preview';
|
7
|
-
export const ServerCustomExample = ()
|
7
|
+
export const ServerCustomExample = ()=>{
|
8
8
|
useEffect(setupIntercept, []);
|
9
|
-
return
|
10
|
-
|
9
|
+
return /*#__PURE__*/ _jsx(Container, {
|
10
|
+
children: (publisher)=>{
|
11
|
+
const handleClick = ()=>{
|
11
12
|
const notification = {
|
12
13
|
id: Date.now(),
|
13
14
|
userId: 0,
|
@@ -19,12 +20,17 @@ export const ServerCustomExample = () => {
|
|
19
20
|
version: NotificationProcessStatus.Info,
|
20
21
|
payload: JSON.stringify({
|
21
22
|
username: 'Jane',
|
22
|
-
message: 'Your order is completed.'
|
23
|
-
})
|
23
|
+
message: 'Your order is completed.'
|
24
|
+
})
|
24
25
|
};
|
25
26
|
publisher.fire(notification);
|
26
27
|
};
|
27
|
-
return _jsx(Button, {
|
28
|
-
|
28
|
+
return /*#__PURE__*/ _jsx(Button, {
|
29
|
+
onClick: handleClick,
|
30
|
+
children: "Show"
|
31
|
+
});
|
32
|
+
}
|
33
|
+
});
|
29
34
|
};
|
35
|
+
|
30
36
|
//# sourceMappingURL=server-custom.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"sources":["../../src/demo/server-custom.tsx"],"sourcesContent":["import { Button } from '@servicetitan/anvil2';\nimport { FC, useEffect } from 'react';\n\nimport { NotificationProcessStatus } from '..';\nimport { Container } from './container';\nimport { setupIntercept } from './server-custom-preview';\n\nexport const ServerCustomExample: FC = () => {\n useEffect(setupIntercept, []);\n\n return (\n <Container>\n {publisher => {\n const handleClick = () => {\n const notification = {\n id: Date.now(),\n userId: 0,\n type: 'CustomServerNotification',\n status: NotificationProcessStatus.Info,\n isRead: false,\n createdOn: new Date(),\n modifiedOn: new Date(),\n version: NotificationProcessStatus.Info,\n payload: JSON.stringify({\n username: 'Jane',\n message: 'Your order is completed.',\n }),\n };\n\n publisher.fire(notification);\n };\n\n return <Button onClick={handleClick}>Show</Button>;\n }}\n </Container>\n );\n};\n"],"names":["Button","useEffect","NotificationProcessStatus","Container","setupIntercept","ServerCustomExample","publisher","handleClick","notification","id","Date","now","userId","type","status","Info","isRead","createdOn","modifiedOn","version","payload","JSON","stringify","username","message","fire","onClick"],"mappings":";AAAA,SAASA,MAAM,QAAQ,uBAAuB;AAC9C,SAAaC,SAAS,QAAQ,QAAQ;AAEtC,SAASC,yBAAyB,QAAQ,KAAK;AAC/C,SAASC,SAAS,QAAQ,cAAc;AACxC,SAASC,cAAc,QAAQ,0BAA0B;AAEzD,OAAO,MAAMC,sBAA0B;IACnCJ,UAAUG,gBAAgB,EAAE;IAE5B,qBACI,KAACD;kBACIG,CAAAA;YACG,MAAMC,cAAc;gBAChB,MAAMC,eAAe;oBACjBC,IAAIC,KAAKC,GAAG;oBACZC,QAAQ;oBACRC,MAAM;oBACNC,QAAQZ,0BAA0Ba,IAAI;oBACtCC,QAAQ;oBACRC,WAAW,IAAIP;oBACfQ,YAAY,IAAIR;oBAChBS,SAASjB,0BAA0Ba,IAAI;oBACvCK,SAASC,KAAKC,SAAS,CAAC;wBACpBC,UAAU;wBACVC,SAAS;oBACb;gBACJ;gBAEAlB,UAAUmB,IAAI,CAACjB;YACnB;YAEA,qBAAO,KAACR;gBAAO0B,SAASnB;0BAAa;;QACzC;;AAGZ,EAAE"}
|
@@ -2,70 +2,75 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { Button } from '@servicetitan/anvil2';
|
3
3
|
import { NotificationProcessStatus } from '..';
|
4
4
|
import { Container } from './container';
|
5
|
-
export const ServerDefaultExample = ()
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
createdOn: new Date(),
|
14
|
-
modifiedOn: new Date(),
|
15
|
-
version: NotificationProcessStatus.Info,
|
16
|
-
payload: JSON.stringify({
|
17
|
-
title: 'Server Notification',
|
18
|
-
message: 'Task was pushed into queue.',
|
19
|
-
}),
|
20
|
-
};
|
21
|
-
publisher.fire(notification);
|
22
|
-
setTimeout(() => {
|
23
|
-
let progress = 0;
|
24
|
-
notification = {
|
25
|
-
...notification,
|
26
|
-
status: NotificationProcessStatus.InProgress,
|
5
|
+
export const ServerDefaultExample = ()=>/*#__PURE__*/ _jsx(Container, {
|
6
|
+
children: (publisher)=>{
|
7
|
+
const handleClick = ()=>{
|
8
|
+
let notification = {
|
9
|
+
id: Date.now(),
|
10
|
+
userId: 0,
|
11
|
+
type: 'DefaultServerNotification',
|
12
|
+
status: NotificationProcessStatus.Info,
|
27
13
|
isRead: false,
|
14
|
+
createdOn: new Date(),
|
28
15
|
modifiedOn: new Date(),
|
29
|
-
version: NotificationProcessStatus.
|
16
|
+
version: NotificationProcessStatus.Info,
|
30
17
|
payload: JSON.stringify({
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
}),
|
18
|
+
title: 'Server Notification',
|
19
|
+
message: 'Task was pushed into queue.'
|
20
|
+
})
|
35
21
|
};
|
36
22
|
publisher.fire(notification);
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
notification
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
23
|
+
setTimeout(()=>{
|
24
|
+
let progress = 0;
|
25
|
+
notification = {
|
26
|
+
...notification,
|
27
|
+
status: NotificationProcessStatus.InProgress,
|
28
|
+
isRead: false,
|
29
|
+
modifiedOn: new Date(),
|
30
|
+
version: NotificationProcessStatus.InProgress,
|
31
|
+
payload: JSON.stringify({
|
32
|
+
...JSON.parse(notification.payload),
|
33
|
+
progress,
|
34
|
+
message: 'Task is running.'
|
35
|
+
})
|
36
|
+
};
|
37
|
+
publisher.fire(notification);
|
38
|
+
const intervalId = setInterval(()=>{
|
39
|
+
if (progress < 100) {
|
40
|
+
progress += 5;
|
41
|
+
notification = {
|
42
|
+
...notification,
|
43
|
+
modifiedOn: new Date(),
|
44
|
+
payload: JSON.stringify({
|
45
|
+
...JSON.parse(notification.payload),
|
46
|
+
progress
|
47
|
+
})
|
48
|
+
};
|
49
|
+
publisher.fire(notification);
|
50
|
+
} else {
|
51
|
+
notification = {
|
52
|
+
...notification,
|
53
|
+
status: NotificationProcessStatus.Success,
|
54
|
+
isRead: false,
|
55
|
+
modifiedOn: new Date(),
|
56
|
+
version: NotificationProcessStatus.Success,
|
57
|
+
payload: JSON.stringify({
|
58
|
+
...JSON.parse(notification.payload),
|
59
|
+
message: 'Task was successfully completed.',
|
60
|
+
progress: undefined
|
61
|
+
})
|
62
|
+
};
|
63
|
+
publisher.fire(notification);
|
64
|
+
clearInterval(intervalId);
|
65
|
+
}
|
66
|
+
}, 250);
|
67
|
+
}, 2000);
|
68
|
+
};
|
69
|
+
return /*#__PURE__*/ _jsx(Button, {
|
70
|
+
onClick: handleClick,
|
71
|
+
children: "Show"
|
72
|
+
});
|
73
|
+
}
|
74
|
+
});
|
75
|
+
|
71
76
|
//# sourceMappingURL=server-default.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"sources":["../../src/demo/server-default.tsx"],"sourcesContent":["import { Button } from '@servicetitan/anvil2';\nimport { FC } from 'react';\n\nimport { NotificationProcessStatus } from '..';\nimport { Container } from './container';\n\nexport const ServerDefaultExample: FC = () => (\n <Container>\n {publisher => {\n const handleClick = () => {\n let notification = {\n id: Date.now(),\n userId: 0,\n type: 'DefaultServerNotification',\n status: NotificationProcessStatus.Info,\n isRead: false,\n createdOn: new Date(),\n modifiedOn: new Date(),\n version: NotificationProcessStatus.Info,\n payload: JSON.stringify({\n title: 'Server Notification',\n message: 'Task was pushed into queue.',\n }),\n };\n\n publisher.fire(notification);\n\n setTimeout(() => {\n let progress = 0;\n\n notification = {\n ...notification,\n status: NotificationProcessStatus.InProgress,\n isRead: false,\n modifiedOn: new Date(),\n version: NotificationProcessStatus.InProgress,\n payload: JSON.stringify({\n ...JSON.parse(notification.payload),\n progress,\n message: 'Task is running.',\n }),\n };\n\n publisher.fire(notification);\n\n const intervalId = setInterval(() => {\n if (progress < 100) {\n progress += 5;\n\n notification = {\n ...notification,\n modifiedOn: new Date(),\n payload: JSON.stringify({\n ...JSON.parse(notification.payload),\n progress,\n }),\n };\n\n publisher.fire(notification);\n } else {\n notification = {\n ...notification,\n status: NotificationProcessStatus.Success,\n isRead: false,\n modifiedOn: new Date(),\n version: NotificationProcessStatus.Success,\n payload: JSON.stringify({\n ...JSON.parse(notification.payload),\n message: 'Task was successfully completed.',\n progress: undefined,\n }),\n };\n\n publisher.fire(notification);\n\n clearInterval(intervalId);\n }\n }, 250);\n }, 2000);\n };\n\n return <Button onClick={handleClick}>Show</Button>;\n }}\n </Container>\n);\n"],"names":["Button","NotificationProcessStatus","Container","ServerDefaultExample","publisher","handleClick","notification","id","Date","now","userId","type","status","Info","isRead","createdOn","modifiedOn","version","payload","JSON","stringify","title","message","fire","setTimeout","progress","InProgress","parse","intervalId","setInterval","Success","undefined","clearInterval","onClick"],"mappings":";AAAA,SAASA,MAAM,QAAQ,uBAAuB;AAG9C,SAASC,yBAAyB,QAAQ,KAAK;AAC/C,SAASC,SAAS,QAAQ,cAAc;AAExC,OAAO,MAAMC,uBAA2B,kBACpC,KAACD;kBACIE,CAAAA;YACG,MAAMC,cAAc;gBAChB,IAAIC,eAAe;oBACfC,IAAIC,KAAKC,GAAG;oBACZC,QAAQ;oBACRC,MAAM;oBACNC,QAAQX,0BAA0BY,IAAI;oBACtCC,QAAQ;oBACRC,WAAW,IAAIP;oBACfQ,YAAY,IAAIR;oBAChBS,SAAShB,0BAA0BY,IAAI;oBACvCK,SAASC,KAAKC,SAAS,CAAC;wBACpBC,OAAO;wBACPC,SAAS;oBACb;gBACJ;gBAEAlB,UAAUmB,IAAI,CAACjB;gBAEfkB,WAAW;oBACP,IAAIC,WAAW;oBAEfnB,eAAe;wBACX,GAAGA,YAAY;wBACfM,QAAQX,0BAA0ByB,UAAU;wBAC5CZ,QAAQ;wBACRE,YAAY,IAAIR;wBAChBS,SAAShB,0BAA0ByB,UAAU;wBAC7CR,SAASC,KAAKC,SAAS,CAAC;4BACpB,GAAGD,KAAKQ,KAAK,CAACrB,aAAaY,OAAO,CAAC;4BACnCO;4BACAH,SAAS;wBACb;oBACJ;oBAEAlB,UAAUmB,IAAI,CAACjB;oBAEf,MAAMsB,aAAaC,YAAY;wBAC3B,IAAIJ,WAAW,KAAK;4BAChBA,YAAY;4BAEZnB,eAAe;gCACX,GAAGA,YAAY;gCACfU,YAAY,IAAIR;gCAChBU,SAASC,KAAKC,SAAS,CAAC;oCACpB,GAAGD,KAAKQ,KAAK,CAACrB,aAAaY,OAAO,CAAC;oCACnCO;gCACJ;4BACJ;4BAEArB,UAAUmB,IAAI,CAACjB;wBACnB,OAAO;4BACHA,eAAe;gCACX,GAAGA,YAAY;gCACfM,QAAQX,0BAA0B6B,OAAO;gCACzChB,QAAQ;gCACRE,YAAY,IAAIR;gCAChBS,SAAShB,0BAA0B6B,OAAO;gCAC1CZ,SAASC,KAAKC,SAAS,CAAC;oCACpB,GAAGD,KAAKQ,KAAK,CAACrB,aAAaY,OAAO,CAAC;oCACnCI,SAAS;oCACTG,UAAUM;gCACd;4BACJ;4BAEA3B,UAAUmB,IAAI,CAACjB;4BAEf0B,cAAcJ;wBAClB;oBACJ,GAAG;gBACP,GAAG;YACP;YAEA,qBAAO,KAAC5B;gBAAOiC,SAAS5B;0BAAa;;QACzC;OAEN"}
|
@@ -2,20 +2,42 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Button, Flex } from '@servicetitan/anvil2';
|
3
3
|
import { useDependencies } from '@servicetitan/react-ioc';
|
4
4
|
import { NotificationsService } from '..';
|
5
|
-
export const StatusVariationsPreview = ()
|
5
|
+
export const StatusVariationsPreview = ()=>{
|
6
6
|
const [notifications] = useDependencies(NotificationsService);
|
7
|
-
const handleInfoClick = ()
|
8
|
-
|
7
|
+
const handleInfoClick = ()=>notifications.info({
|
8
|
+
title: "You've successfully clicked the 'Info' button."
|
9
|
+
});
|
10
|
+
const handleSuccessClick = ()=>notifications.success({
|
11
|
+
title: "You've successfully clicked the 'Success' button."
|
12
|
+
});
|
13
|
+
const handleWarningClick = ()=>notifications.warning({
|
14
|
+
title: "You've successfully clicked the 'Warning' button."
|
15
|
+
});
|
16
|
+
const handleErrorClick = ()=>notifications.error({
|
17
|
+
title: "You've successfully clicked the 'Error' button."
|
18
|
+
});
|
19
|
+
return /*#__PURE__*/ _jsxs(Flex, {
|
20
|
+
direction: "row",
|
21
|
+
gap: "2",
|
22
|
+
children: [
|
23
|
+
/*#__PURE__*/ _jsx(Button, {
|
24
|
+
onClick: handleInfoClick,
|
25
|
+
children: "Info"
|
26
|
+
}),
|
27
|
+
/*#__PURE__*/ _jsx(Button, {
|
28
|
+
onClick: handleSuccessClick,
|
29
|
+
children: "Success"
|
30
|
+
}),
|
31
|
+
/*#__PURE__*/ _jsx(Button, {
|
32
|
+
onClick: handleWarningClick,
|
33
|
+
children: "Warning"
|
34
|
+
}),
|
35
|
+
/*#__PURE__*/ _jsx(Button, {
|
36
|
+
onClick: handleErrorClick,
|
37
|
+
children: "Error"
|
38
|
+
})
|
39
|
+
]
|
9
40
|
});
|
10
|
-
const handleSuccessClick = () => notifications.success({
|
11
|
-
title: "You've successfully clicked the 'Success' button.",
|
12
|
-
});
|
13
|
-
const handleWarningClick = () => notifications.warning({
|
14
|
-
title: "You've successfully clicked the 'Warning' button.",
|
15
|
-
});
|
16
|
-
const handleErrorClick = () => notifications.error({
|
17
|
-
title: "You've successfully clicked the 'Error' button.",
|
18
|
-
});
|
19
|
-
return (_jsxs(Flex, { direction: "row", gap: "2", children: [_jsx(Button, { onClick: handleInfoClick, children: "Info" }), _jsx(Button, { onClick: handleSuccessClick, children: "Success" }), _jsx(Button, { onClick: handleWarningClick, children: "Warning" }), _jsx(Button, { onClick: handleErrorClick, children: "Error" })] }));
|
20
41
|
};
|
42
|
+
|
21
43
|
//# sourceMappingURL=status-variations-preview.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"sources":["../../src/demo/status-variations-preview.tsx"],"sourcesContent":["import { Button, Flex } from '@servicetitan/anvil2';\nimport { useDependencies } from '@servicetitan/react-ioc';\nimport { FC } from 'react';\n\nimport { NotificationsService } from '..';\n\nexport const StatusVariationsPreview: FC = () => {\n const [notifications] = useDependencies(NotificationsService);\n\n const handleInfoClick = () =>\n notifications.info({\n title: \"You've successfully clicked the 'Info' button.\",\n });\n\n const handleSuccessClick = () =>\n notifications.success({\n title: \"You've successfully clicked the 'Success' button.\",\n });\n\n const handleWarningClick = () =>\n notifications.warning({\n title: \"You've successfully clicked the 'Warning' button.\",\n });\n\n const handleErrorClick = () =>\n notifications.error({\n title: \"You've successfully clicked the 'Error' button.\",\n });\n\n return (\n <Flex direction=\"row\" gap=\"2\">\n <Button onClick={handleInfoClick}>Info</Button>\n <Button onClick={handleSuccessClick}>Success</Button>\n <Button onClick={handleWarningClick}>Warning</Button>\n <Button onClick={handleErrorClick}>Error</Button>\n </Flex>\n );\n};\n"],"names":["Button","Flex","useDependencies","NotificationsService","StatusVariationsPreview","notifications","handleInfoClick","info","title","handleSuccessClick","success","handleWarningClick","warning","handleErrorClick","error","direction","gap","onClick"],"mappings":";AAAA,SAASA,MAAM,EAAEC,IAAI,QAAQ,uBAAuB;AACpD,SAASC,eAAe,QAAQ,0BAA0B;AAG1D,SAASC,oBAAoB,QAAQ,KAAK;AAE1C,OAAO,MAAMC,0BAA8B;IACvC,MAAM,CAACC,cAAc,GAAGH,gBAAgBC;IAExC,MAAMG,kBAAkB,IACpBD,cAAcE,IAAI,CAAC;YACfC,OAAO;QACX;IAEJ,MAAMC,qBAAqB,IACvBJ,cAAcK,OAAO,CAAC;YAClBF,OAAO;QACX;IAEJ,MAAMG,qBAAqB,IACvBN,cAAcO,OAAO,CAAC;YAClBJ,OAAO;QACX;IAEJ,MAAMK,mBAAmB,IACrBR,cAAcS,KAAK,CAAC;YAChBN,OAAO;QACX;IAEJ,qBACI,MAACP;QAAKc,WAAU;QAAMC,KAAI;;0BACtB,KAAChB;gBAAOiB,SAASX;0BAAiB;;0BAClC,KAACN;gBAAOiB,SAASR;0BAAoB;;0BACrC,KAACT;gBAAOiB,SAASN;0BAAoB;;0BACrC,KAACX;gBAAOiB,SAASJ;0BAAkB;;;;AAG/C,EAAE"}
|
@@ -1,5 +1,8 @@
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
2
2
|
import { Container } from './container';
|
3
3
|
import { StatusVariationsPreview } from './status-variations-preview';
|
4
|
-
export const StatusVariationsExample = ()
|
4
|
+
export const StatusVariationsExample = ()=>/*#__PURE__*/ _jsx(Container, {
|
5
|
+
children: ()=>/*#__PURE__*/ _jsx(StatusVariationsPreview, {})
|
6
|
+
});
|
7
|
+
|
5
8
|
//# sourceMappingURL=status-variations.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"sources":["../../src/demo/status-variations.tsx"],"sourcesContent":["import { FC } from 'react';\n\nimport { Container } from './container';\nimport { StatusVariationsPreview } from './status-variations-preview';\n\nexport const StatusVariationsExample: FC = () => (\n <Container>{() => <StatusVariationsPreview />}</Container>\n);\n"],"names":["Container","StatusVariationsPreview","StatusVariationsExample"],"mappings":";AAEA,SAASA,SAAS,QAAQ,cAAc;AACxC,SAASC,uBAAuB,QAAQ,8BAA8B;AAEtE,OAAO,MAAMC,0BAA8B,kBACvC,KAACF;kBAAW,kBAAM,KAACC;OACrB"}
|
package/dist/index.js
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
-
export { NotificationsApi, NotificationProcessStatus, } from './api/notifications.api';
|
2
|
-
export { Notifications } from './components/notifications';
|
3
|
-
export {
|
4
|
-
export { intercept } from './intercept';
|
5
|
-
export { NOTIFICATIONS_CHANNEL_TOKEN } from './notifications-channel';
|
6
|
-
export { NotificationsService } from './notifications-service';
|
1
|
+
export { NotificationsApi, NotificationProcessStatus, DefaultServerNotificationPayload } from './api/notifications.api';
|
2
|
+
export { Notifications, NotificationsProps } from './components/notifications';
|
3
|
+
export { DefaultNotificationOptions, LinkAction, FunctionAction, Notification, Status } from './common';
|
4
|
+
export { intercept, NotificationInterceptor } from './intercept';
|
5
|
+
export { NotificationsChannel, NOTIFICATIONS_CHANNEL_TOKEN } from './notifications-channel';
|
6
|
+
export { INotificationsService, NotificationsService } from './notifications-service';
|
7
|
+
|
7
8
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export {\n NotificationsApi,\n NotificationProcessStatus,\n DefaultServerNotificationPayload,\n} from './api/notifications.api';\nexport { Notifications, NotificationsProps } from './components/notifications';\nexport {\n DefaultNotificationOptions,\n LinkAction,\n FunctionAction,\n Notification,\n Status,\n} from './common';\nexport { intercept, NotificationInterceptor } from './intercept';\nexport { NotificationsChannel, NOTIFICATIONS_CHANNEL_TOKEN } from './notifications-channel';\nexport { INotificationsService, NotificationsService } from './notifications-service';\n"],"names":["NotificationsApi","NotificationProcessStatus","DefaultServerNotificationPayload","Notifications","NotificationsProps","DefaultNotificationOptions","LinkAction","FunctionAction","Notification","Status","intercept","NotificationInterceptor","NotificationsChannel","NOTIFICATIONS_CHANNEL_TOKEN","INotificationsService","NotificationsService"],"mappings":"AAAA,SACIA,gBAAgB,EAChBC,yBAAyB,EACzBC,gCAAgC,QAC7B,0BAA0B;AACjC,SAASC,aAAa,EAAEC,kBAAkB,QAAQ,6BAA6B;AAC/E,SACIC,0BAA0B,EAC1BC,UAAU,EACVC,cAAc,EACdC,YAAY,EACZC,MAAM,QACH,WAAW;AAClB,SAASC,SAAS,EAAEC,uBAAuB,QAAQ,cAAc;AACjE,SAASC,oBAAoB,EAAEC,2BAA2B,QAAQ,0BAA0B;AAC5F,SAASC,qBAAqB,EAAEC,oBAAoB,QAAQ,0BAA0B"}
|
package/dist/intercept.js
CHANGED
package/dist/intercept.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"sources":["../src/intercept.ts"],"sourcesContent":["import { DefaultNotificationOptions, Notification } from './common';\nimport { NotificationsStore } from './stores/notifications.store';\n\nexport type NotificationInterceptor<T extends Record<keyof any, any> = {}> = (\n notification: Notification<T>,\n dismiss: () => void\n) => Notification<DefaultNotificationOptions> | undefined;\n\nexport function intercept<T extends Record<keyof any, any> = {}>(\n type: string,\n fn?: NotificationInterceptor<T>\n) {\n NotificationsStore.intercept(type, fn);\n}\n"],"names":["NotificationsStore","intercept","type","fn"],"mappings":"AACA,SAASA,kBAAkB,QAAQ,+BAA+B;AAOlE,OAAO,SAASC,UACZC,IAAY,EACZC,EAA+B;IAE/BH,mBAAmBC,SAAS,CAACC,MAAMC;AACvC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"sources":["../src/notifications-channel.ts"],"sourcesContent":["import { symbolToken } from '@servicetitan/react-ioc';\n\ntype EventCallback = (data: any, context: any) => void;\n\ninterface EventsDispatcher {\n bind(eventName: string, callback: EventCallback, context?: any): this;\n unbind(eventName?: string | null, callback?: EventCallback | null, context?: any): this;\n}\n\ninterface Publisher extends EventsDispatcher {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n global_emitter: EventsDispatcher;\n}\n\nexport type NotificationsChannel = () => Publisher;\n\nexport const NOTIFICATIONS_CHANNEL_TOKEN = symbolToken<NotificationsChannel>(\n 'NOTIFICATIONS_CHANNEL_TOKEN'\n);\n"],"names":["symbolToken","NOTIFICATIONS_CHANNEL_TOKEN"],"mappings":"AAAA,SAASA,WAAW,QAAQ,0BAA0B;AAgBtD,OAAO,MAAMC,8BAA8BD,YACvC,+BACF"}
|