Skip to content

Commit 2d41978

Browse files
author
Sravan S
authored
feat: Notification channel (#397)
### Notification Channel A notification channel is a new group channel dedicated to receiving one way marketing and transactional messages.To allow users to view messages sent through Sendbird Message Builder with the correct rendering, you need to implement the notification channel view using <NotificationChannel> Overview: * Provide new module `NotificationChannel` * NotificationChannel `import NotificationChannel from '@sendbird/uikit-react/NotificationChannel'` props: * channelUrl: string; * children?: React.ReactElement; // To customize Query * messageListParams?: MessageListParams; // Sets last seen externally * lastSeen?: number; // handles Actions sepcified in Message Templates * handleWebAction?(event: React.SyntheticEvent, action: Action, message: BaseMessage): null; * handleCustomAction?(event: React.SyntheticEvent, action: Action, message: BaseMessage): null; * handlePredefinedAction?(event: React.SyntheticEvent, action: Action, message: BaseMessage): null; // UI overrides * isLoading?: boolean; * renderPlaceholderLoader?: () => React.ReactElement; * renderPlaceholderInvalid?: () => React.ReactElement; * renderPlaceholderEmpty?: () => React.ReactElement; * renderHeader?: () => React.ReactElement; * renderMessageHeader?: ({ message }) => React.ReactElement; * renderMessage?: ({ message }) => React.ReactElement; ``` example: export const NotificationChannelComponenet = () => ( <Sendbird appId={appId} userId={userId} accessToken={accessToken} > <div style={{ height: '960px', width: '360px' }}> <NotificationChannel channelUrl={`SENDBIRD_NOTIFICATION_CHANNEL_NOTIFICATION_${userId}`} renderPlaceholderLoader={() => <MyBrandLogo />}; handleCustomAction={(event, action, message) => { ... implement custom action }} /> </div> </Sendbird> ); ``` * Submodules: * Context `import { NotficationChannelProvider useNotficationChannelContext } from '@sendbird/uikit-react/NotificationChannel/context'` Handles business logic of Notification Channel * NotificationChannelUI `import NotificationChannelUI from '@sendbird/uikit-react/NotificationChannel/components/NotificationChannelUI'` UI wrapper of Notification Channel * NotificationMessageWrap `import NotificationMessageWrap from '@sendbird/uikit-react/NotificationChannel/components/NotificationMessageWrap'` * NotificationList `import NotificationList from '@sendbird/uikit-react/NotificationChannel/components/NotificationList'` * External modules: Unlike some of our other releases we decide to release some components into seperate packages to enahnce reusability with other platforms/projects * MessageTemplateParser('@sendbird/react-message-template') * MessageTemplate `import { createMessageTemplate } from '@sendbird/react-message-template'` * Parser `import { createParser } from '@sendbird/react-message-template'` * Renderer `import { createRenderer } from '@sendbird/react-message-template'` * MessageTemplateParser('@sendbird/react-message-template') * Context `import { MessageProvider, useMessageContext } from '@sendbird/react-uikit-message-template-view';` * MessageTemplateView `import { MessageTemplateView } from '@sendbird/react-uikit-message-template-view';`
1 parent 73759d9 commit 2d41978

37 files changed

+1701
-31
lines changed

exports.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,13 @@ export default {
103103
'Thread/components/ThreadListItem': 'src/smart-components/Thread/components/ThreadList/ThreadListItem.tsx',
104104
'Thread/components/ThreadMessageInput': 'src/smart-components/Thread/components/ThreadMessageInput/index.tsx',
105105

106+
// NotificationChannel
107+
NotificationChannel: 'src/smart-components/NotificationChannel/index.tsx',
108+
'NotificationChannel/context': 'src/smart-components/NotificationChannel/context/NotificationChannelProvider.tsx',
109+
'NotificationChannel/components/NotificationChannelUI': 'src/smart-components/NotificationChannel/components/NotificationChannelUI/index.tsx',
110+
'NotificationChannel/components/NotificationMessageWrap': 'src/smart-components/NotificationChannel/components/NotificationMessageWrap/index.tsx',
111+
'NotificationChannel/components/NotificationList': 'src/smart-components/NotificationChannel/components/NotificationList/index.tsx',
112+
106113
// CreateChannel
107114
CreateChannel: 'src/smart-components/CreateChannel/index.tsx',
108115
'CreateChannel/context': 'src/smart-components/CreateChannel/context/CreateChannelProvider.tsx',

package-lock.json

Lines changed: 41 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@
4949
"react-dom": "^16.8.6 || ^17.0.0 || ^18.0.0"
5050
},
5151
"dependencies": {
52-
"@sendbird/chat": "^4.2.3",
52+
"@sendbird/chat": "^4.2.4",
53+
"@sendbird/react-uikit-message-template-view": "^0.0.1-alpha.10",
54+
"@sendbird/uikit-message-template": "^0.0.1-alpha.8",
5355
"css-vars-ponyfill": "^2.3.2",
5456
"date-fns": "^2.16.1",
5557
"prop-types": "^15.7.2"

rollup.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ module.exports = ({
4242
'@sendbird/chat/groupChannel',
4343
'@sendbird/chat/openChannel',
4444
'@sendbird/chat/message',
45+
'@sendbird/react-uikit-message-template-view',
46+
'@sendbird/uikit-message-template',
4547
'react-dom/server',
4648
'prop-types',
4749
'react',

scripts/index_d_ts

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -902,6 +902,79 @@ declare module "SendbirdUIKitGlobal" {
902902
onCloseClick?: () => void;
903903
}
904904

905+
/**
906+
* NotificationChannel
907+
*/
908+
export enum ActionType {
909+
Web = "web",
910+
Custom = "custom",
911+
UIKit = "uikit"
912+
}
913+
914+
export interface Action {
915+
type: ActionType;
916+
data: string;
917+
customData?: string;
918+
}
919+
920+
export type NotficationChannelStateInterface = {
921+
uiState: 'loading' | 'initialized' | 'invalid';
922+
allMessages: BaseMessage[];
923+
currentNotificationChannel: GroupChannel;
924+
hasMore: boolean;
925+
messageListParams?: MessageListParams;
926+
lastSeen?: number;
927+
showDeleteModal: boolean;
928+
messageToDelete?: BaseMessage;
929+
}
930+
931+
export type NotficationChannelContextProps = {
932+
channelUrl: string;
933+
children?: React.ReactElement;
934+
messageListParams?: MessageListParams;
935+
lastSeen?: number;
936+
handleWebAction?(event: React.SyntheticEvent, action: Action, message: BaseMessage);
937+
handleCustomAction?(event: React.SyntheticEvent, action: Action, message: BaseMessage);
938+
handlePredefinedAction?(event: React.SyntheticEvent, action: Action, message: BaseMessage);
939+
};
940+
export interface NotficationChannelProviderInterface extends NotficationChannelStateInterface,
941+
NotficationChannelContextProps {
942+
notificationsDispatcher: React.Dispatch<any>;
943+
oldestMessageTimeStamp: number;
944+
scrollRef: React.RefObject<HTMLDivElement>;
945+
onFetchMore: (cb: any) => void;
946+
}
947+
export type RenderNotificationMessageProps = {
948+
message: BaseMessage;
949+
}
950+
951+
export type renderNotificationMessage = (props: RenderNotificationMessageProps) => React.ReactElement;
952+
export type renderNotificationMessageHeader = (props: RenderNotificationMessageProps) => React.ReactElement;
953+
954+
export type NotificationChannelUIProps = {
955+
isLoading?: boolean;
956+
renderPlaceholderLoader?: () => React.ReactElement;
957+
renderPlaceholderInvalid?: () => React.ReactElement;
958+
renderPlaceholderEmpty?: () => React.ReactElement;
959+
renderHeader?: () => React.ReactElement;
960+
renderMessageHeader?: renderNotificationMessageHeader;
961+
renderMessage?: renderNotificationMessage;
962+
}
963+
964+
export type NotificationListProps = {
965+
renderMessage?: renderNotificationMessage;
966+
renderMessageHeader?: renderNotificationMessageHeader;
967+
renderPlaceholderEmpty?: () => React.ReactElement;
968+
}
969+
970+
export type NotificationMessageWrapProps = {
971+
renderMessage?: renderNotificationMessage;
972+
renderMessageHeader?: renderNotificationMessageHeader;
973+
message: BaseMessage;
974+
}
975+
976+
export interface NotificationChannelProps extends NotificationChannelUIProps, NotficationChannelContextProps {}
977+
905978
/**
906979
* Thread
907980
*/
@@ -1510,6 +1583,39 @@ declare module '@sendbird/uikit-react/MessageSearch/components/MessageSearchUI'
15101583
export default MessageSearchUI;
15111584
}
15121585

1586+
/**
1587+
* NotificationChannel
1588+
*/
1589+
declare module '@sendbird/uikit-react/NotificationChannel' {
1590+
import SendbirdUIKitGlobal from 'SendbirdUIKitGlobal';
1591+
const NotificationChannel: React.FC<SendbirdUIKitGlobal.NotificationChannelProps>;
1592+
export default NotificationChannel;
1593+
}
1594+
1595+
declare module '@sendbird/uikit-react/NotificationChannel/context' {
1596+
import SendbirdUIKitGlobal from 'SendbirdUIKitGlobal';
1597+
export const useNotficationChannelContext: () => SendbirdUIKitGlobal.NotficationChannelProviderInterface;
1598+
export const NotficationChannelProvider: React.FC<SendbirdUIKitGlobal.NotficationChannelContextProps>;
1599+
}
1600+
1601+
declare module '@sendbird/uikit-react/NotificationChannel/components/NotificationChannelUI' {
1602+
import SendbirdUIKitGlobal from 'SendbirdUIKitGlobal';
1603+
const NotificationChannelUI: React.FC<SendbirdUIKitGlobal.NotificationChannelUIProps>;
1604+
export default NotificationChannelUI;
1605+
}
1606+
1607+
declare module '@sendbird/uikit-react/NotificationChannel/components/NotificationList' {
1608+
import SendbirdUIKitGlobal from 'SendbirdUIKitGlobal';
1609+
const NotificationList: React.FC<SendbirdUIKitGlobal.NotificationListProps>;
1610+
export default NotificationList;
1611+
}
1612+
1613+
declare module '@sendbird/uikit-react/NotificationChannel/components/NotificationMessageWrap' {
1614+
import SendbirdUIKitGlobal from 'SendbirdUIKitGlobal';
1615+
const NotificationMessageWrap: React.FC<SendbirdUIKitGlobal.NotificationMessageWrapProps>;
1616+
export default NotificationMessageWrap;
1617+
}
1618+
15131619
/**
15141620
* Thread
15151621
*/

scripts/package.template.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
},
2828
"dependencies": {
2929
"@sendbird/chat": "^4.1.1",
30+
"@sendbird/react-uikit-message-template-view": "^0.0.1-alpha.9",
31+
"@sendbird/uikit-message-template": "^0.0.1-alpha.8",
3032
"css-vars-ponyfill": "^2.3.2",
3133
"date-fns": "^2.16.1",
3234
"prop-types": "^15.7.2"

src/smart-components/Channel/components/ChannelHeader/channel-header.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
overflow: hidden;
3535
text-overflow: ellipsis;
3636
white-space: nowrap;
37-
max-width: 780px;
37+
max-width: calc(100vw - 600px);
3838
@include mobile() {
3939
max-width: calc(100vw - 240px);
4040
}

0 commit comments

Comments
 (0)