Skip to content

Commit 61803ea

Browse files
get chat box id got it
1 parent 9a886fa commit 61803ea

File tree

2 files changed

+65
-17
lines changed

2 files changed

+65
-17
lines changed

src/component/connection/connection-common-layout.js

+31-17
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
WithDrawConnectionRequestButton,
1111
} from "../common/buttons";
1212
import { successMessage } from "../common/desktop-notification";
13+
import { getChatBoxId } from "../messaging-section/helper/api_call";
1314
import { connectionSpecificOperations } from "./helper/api_call";
1415

1516
const ConnectionCollectionItem = ({
@@ -31,7 +32,7 @@ const ConnectionCollectionItem = ({
3132
<ButtonCollectionPrediction
3233
darkMode={darkMode}
3334
connectionType={connectionType}
34-
userId={user.id}
35+
partnerUserId={user.id}
3536
setCollectiveIds={setCollectiveIds}
3637
/>
3738
</div>
@@ -42,30 +43,30 @@ const ConnectionCollectionItem = ({
4243
const ButtonCollectionPrediction = ({
4344
connectionType,
4445
darkMode,
45-
userId,
46+
partnerUserId,
4647
setCollectiveIds,
4748
}) => {
4849
if (connectionType === ConnectionType.AlreadyConnected) {
4950
return (
5051
<ConnectedUsersButtonCollection
5152
darkMode={darkMode}
52-
userId={userId}
53+
partnerUserId={partnerUserId}
5354
setCollectiveIds={setCollectiveIds}
5455
/>
5556
);
5657
} else if (connectionType === ConnectionType.RequestReceived) {
5758
return (
5859
<ReceivedInvitationButtonsCollection
5960
darkMode={darkMode}
60-
userId={userId}
61+
partnerUserId={partnerUserId}
6162
setCollectiveIds={setCollectiveIds}
6263
/>
6364
);
6465
} else if (connectionType === ConnectionType.RequestSent) {
6566
return (
6667
<SentRequestButtonCollection
6768
darkMode={darkMode}
68-
userId={userId}
69+
partnerUserId={partnerUserId}
6970
setCollectiveIds={setCollectiveIds}
7071
/>
7172
);
@@ -111,18 +112,28 @@ const ConnectionTile = ({ user }) => {
111112

112113
const ConnectedUsersButtonCollection = ({
113114
darkMode,
114-
userId,
115+
partnerUserId,
115116
setCollectiveIds,
116117
}) => {
117118
// ** NOTE: Message Button Will be redirect to the specific chat..
118119
// ** We will do it after implement chat feature.
119120

121+
const onMessageButtonClick = () => {
122+
getChatBoxId(partnerUserId)
123+
.then((data) => {
124+
console.log("Chat Box Id is: ", data);
125+
})
126+
.catch((e) => {
127+
console.log("Error in get chat box id: ", e);
128+
});
129+
};
130+
120131
return (
121132
<div className="md:flex items-center sm:ml-5 text-sm md:text-md 2xl:text-lg md:tracking-wider">
122133
<MessageButton
123134
darkMode={darkMode}
124135
customClassName={"connection-screens-common-button-layout mx-3 md:mx-0"}
125-
onClickOperation={() => {}}
136+
onClickOperation={onMessageButtonClick}
126137
/>
127138

128139
<RemoveConnectionButton
@@ -131,9 +142,9 @@ const ConnectedUsersButtonCollection = ({
131142
"connection-screens-common-button-layout mt-3 md:mt-0 mx-3 md:ml-5"
132143
}
133144
onClickOperation={() => {
134-
connectionSpecificOperations(userId, "removeConnections");
145+
connectionSpecificOperations(partnerUserId, "removeConnections");
135146
successMessage("😔 Connection Removed", 2000);
136-
setCollectiveIds((prev) => [...prev, userId]);
147+
setCollectiveIds((prev) => [...prev, partnerUserId]);
137148
}}
138149
/>
139150
</div>
@@ -142,7 +153,7 @@ const ConnectedUsersButtonCollection = ({
142153

143154
const ReceivedInvitationButtonsCollection = ({
144155
darkMode,
145-
userId,
156+
partnerUserId,
146157
setCollectiveIds,
147158
}) => {
148159
return (
@@ -151,9 +162,12 @@ const ReceivedInvitationButtonsCollection = ({
151162
darkMode={darkMode}
152163
customClassName={"connection-screens-common-button-layout mx-3"}
153164
onClickOperation={() => {
154-
connectionSpecificOperations(userId, "acceptConnectionRequest");
165+
connectionSpecificOperations(
166+
partnerUserId,
167+
"acceptConnectionRequest"
168+
);
155169
successMessage("🥳 Connection request accepted", 2000);
156-
setCollectiveIds((prev) => [...prev, userId]);
170+
setCollectiveIds((prev) => [...prev, partnerUserId]);
157171
}}
158172
/>
159173

@@ -164,11 +178,11 @@ const ReceivedInvitationButtonsCollection = ({
164178
}
165179
onClickOperation={() => {
166180
connectionSpecificOperations(
167-
userId,
181+
partnerUserId,
168182
"removeIncomingConnectionRequest"
169183
);
170184
successMessage("😏 Incoming Connection Request Removed", 2000);
171-
setCollectiveIds((prev) => [...prev, userId]);
185+
setCollectiveIds((prev) => [...prev, partnerUserId]);
172186
}}
173187
/>
174188
</div>
@@ -177,7 +191,7 @@ const ReceivedInvitationButtonsCollection = ({
177191

178192
const SentRequestButtonCollection = ({
179193
darkMode,
180-
userId,
194+
partnerUserId,
181195
setCollectiveIds,
182196
}) => {
183197
return (
@@ -188,9 +202,9 @@ const SentRequestButtonCollection = ({
188202
"ml-3 md:mr-5 connection-screens-common-button-layout text-sm md:text-md 2xl:text-lg md:tracking-wider"
189203
}
190204
onClickOperation={() => {
191-
connectionSpecificOperations(userId, "withDrawSentRequest");
205+
connectionSpecificOperations(partnerUserId, "withDrawSentRequest");
192206
successMessage("😏 Outgoing Connection Request Removed", 2000);
193-
setCollectiveIds((prev) => [...prev, userId]);
207+
setCollectiveIds((prev) => [...prev, partnerUserId]);
194208
}}
195209
/>
196210
</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { API } from "../../common/backend";
2+
import { getDataFromLocalStorage } from "../../common/local-storage-management";
3+
4+
import { errorMessage } from "../../common/desktop-notification";
5+
6+
export const getChatBoxId = async (partnerId) => {
7+
const { user, token } = getDataFromLocalStorage();
8+
9+
const res = await fetch(`${API}/messaging/getChatBoxId/${user}`, {
10+
method: "POST",
11+
headers: {
12+
"Content-Type": "application/json",
13+
Authorization: `Bearer ${token}`,
14+
},
15+
body: JSON.stringify({
16+
partnerId,
17+
}),
18+
});
19+
20+
const data = await res.json();
21+
22+
if (data.code !== 200) {
23+
errorMessage(data.message);
24+
return;
25+
}
26+
27+
return data.chatBoxId;
28+
};
29+
30+
31+
// TODO: Do it //
32+
export const getAllChatConnections = async () => {
33+
34+
}

0 commit comments

Comments
 (0)