Skip to content

Commit c607e68

Browse files
Interactive Messages
1 parent af7c3ce commit c607e68

File tree

8 files changed

+602
-9
lines changed

8 files changed

+602
-9
lines changed

src/assets/card-bubble.svg

Lines changed: 1 addition & 0 deletions
Loading

src/assets/form-bubble.svg

Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
import { CardBubbleStyle, CometChatCardBubble } from "@cometchat/uikit-shared";
2+
import { CardMessage, fontHelper } from "@cometchat/uikit-resources";
3+
import React, { useContext } from "react";
4+
import {
5+
componentDetailModalCloseIconStyle,
6+
componentDetailsModalCloseIconWrapperStyle,
7+
componentDetailsModalDescriptionStyle,
8+
componentDetailsModalHeaderStyle,
9+
componentDetailsModalStyle,
10+
componentDetailsModalTitleStyle,
11+
loadingComponentModalStyle,
12+
} from "../../style";
13+
14+
import CloseIcon from "../assets/close2x.png";
15+
import { CometChatThemeContext } from "@cometchat/chat-uikit-react";
16+
import { createComponent } from "@lit-labs/react";
17+
18+
const CardMessageBubble = createComponent({
19+
tagName: 'cometchat-card-bubble',
20+
elementClass: CometChatCardBubble,
21+
react: React
22+
});
23+
24+
const CardBubble = (props: any) => {
25+
const { activeComponent, handleCloseComponentModal, showComponentModal } =
26+
props;
27+
let showModal = false;
28+
const bubbleSlug = "card-bubble";
29+
if (showComponentModal && activeComponent === bubbleSlug) showModal = true;
30+
const { theme } = useContext(CometChatThemeContext);
31+
const themeMode = theme.palette.mode;
32+
33+
34+
function getCardMessageBubbleStyle() {
35+
const buttonStyle = {
36+
height: "40px",
37+
width: "100%",
38+
background: "transparent",
39+
border: `none`,
40+
borderRadius: "0px",
41+
buttonTextFont: fontHelper(theme.typography.subtitle2),
42+
buttonTextColor: `${theme.palette.getPrimary()}`,
43+
justifyContent: "center",
44+
};
45+
46+
return new CardBubbleStyle({
47+
background: "transparent",
48+
border: `1px solid ${theme.palette.getAccent100()}`,
49+
borderRadius: "8px",
50+
height: "fit-content",
51+
width: "300px",
52+
imageHeight: "auto",
53+
imageWidth: "100%",
54+
imageRadius: "8px",
55+
imageBackgroundColor: "transparent",
56+
descriptionFontColor: theme.palette.getAccent(),
57+
descriptionFont: fontHelper(theme.typography.subtitle2),
58+
buttonStyle: buttonStyle,
59+
dividerTintColor: theme.palette.getAccent100(),
60+
wrapperBackground: theme.palette.getBackground(),
61+
wrapperBorderRadius: "8px",
62+
wrapperPadding: "2px",
63+
disabledButtonColor: theme.palette.getAccent600(),
64+
});
65+
}
66+
67+
function getCardMessage() {
68+
const json = {
69+
id: "1978",
70+
muid: "1697641596",
71+
conversationId: "nakul_user_rohit",
72+
sender: "nakul",
73+
receiverType: "user",
74+
receiver: "rohit",
75+
category: "interactive",
76+
type: "card",
77+
data: {
78+
entities: {
79+
sender: {
80+
entity: {
81+
uid: "nakul",
82+
name: "Nakul",
83+
role: "default",
84+
status: "available",
85+
lastActiveAt: 1697636600,
86+
},
87+
entityType: "user",
88+
},
89+
receiver: {
90+
entity: {
91+
uid: "rohit",
92+
name: "Rohit",
93+
role: "default",
94+
status: "available",
95+
lastActiveAt: 1696508846,
96+
conversationId: "nakul_user_rohit",
97+
},
98+
entityType: "user",
99+
},
100+
},
101+
resource:
102+
"REACT_NATIVE-4_0_0-2d83fe8e-a47e-444c-bbbf-c5d68afc030a-1697640527366",
103+
interactionGoal: {
104+
type: "none",
105+
elementIds: [],
106+
},
107+
interactiveData: {
108+
text: "Introducing our latest product, the Super Widget 5000! With its advanced features and sleek design, this widget is sure to revolutionize the industry. Don't miss out on the opportunity to experience the future of widgets. Order yours today!",
109+
imageUrl:
110+
"https://upload.wikimedia.org/wikipedia/en/e/e1/Thomas_D._Baird_%28low-resolution%29.jpg",
111+
cardActions: [
112+
{
113+
action: {
114+
url: "https://api.example.com/register",
115+
actionType: "urlNavigation",
116+
},
117+
elementId: "submitButton1",
118+
buttonText: "Order Now",
119+
elementType: "button",
120+
disableAfterInteracted: true,
121+
},
122+
{
123+
action: {
124+
url: "https://api.example.com/register",
125+
actionType: "urlNavigation",
126+
},
127+
elementId: "submitButton2",
128+
buttonText: "Register Now",
129+
elementType: "button",
130+
disableAfterInteracted: true,
131+
},
132+
{
133+
action: {
134+
url: "https://api.example.com/register",
135+
actionType: "urlNavigation",
136+
},
137+
elementId: "submitButton3",
138+
buttonText: "Login Now",
139+
elementType: "button",
140+
disableAfterInteracted: true,
141+
},
142+
],
143+
interactableElementIds: [
144+
"submitButton1",
145+
"submitButton2",
146+
"submitButton3",
147+
],
148+
},
149+
allowSenderInteraction: true,
150+
},
151+
sentAt: 1697641596,
152+
deliveredAt: 1697641596,
153+
readAt: 1697708285,
154+
updatedAt: 1697708285,
155+
};
156+
157+
const cardMessage = CardMessage.fromJSON(json);
158+
159+
return cardMessage;
160+
}
161+
162+
return (
163+
<div style={loadingComponentModalStyle(showModal)}>
164+
<div style={componentDetailsModalStyle(themeMode)}>
165+
<div style={componentDetailsModalHeaderStyle}>
166+
<div style={componentDetailsModalTitleStyle}>Card Bubble</div>
167+
<div
168+
onClick={handleCloseComponentModal}
169+
style={componentDetailsModalCloseIconWrapperStyle}
170+
>
171+
<img
172+
style={componentDetailModalCloseIconStyle}
173+
alt="closeIcon"
174+
src={CloseIcon}
175+
/>
176+
</div>
177+
</div>
178+
<div style={componentDetailsModalDescriptionStyle}>
179+
The CometChatCardBubble component is used to display a card within a
180+
chat bubble. To learn more about this component tap here.
181+
</div>
182+
<div
183+
className="cardbubbleWrapper"
184+
style={{ margin: "0 auto", marginTop: "15px", marginBottom: "15px" }}
185+
>
186+
<CardMessageBubble
187+
message={getCardMessage()}
188+
cardBubbleStyle={getCardMessageBubbleStyle()}
189+
/>
190+
</div>
191+
</div>
192+
</div>
193+
);
194+
};
195+
export { CardBubble };

0 commit comments

Comments
 (0)