Skip to content

Instantly share code, notes, and snippets.

@hieptl
Created September 28, 2021 13:32
Show Gist options
  • Save hieptl/f112ccfc93fcef3c4aeceac67f7ba5f5 to your computer and use it in GitHub Desktop.
Save hieptl/f112ccfc93fcef3c4aeceac67f7ba5f5 to your computer and use it in GitHub Desktop.
index.js - Update the Match Request Status - Client Side - Tinder Clone
window.addEventListener("DOMContentLoaded", function () {
...
const authenticatedUser = JSON.parse(localStorage.getItem("auth"));
if (authenticatedUser) {
...
const addFriend = (matchRequestFrom, matchRequestTo) => {
if (matchRequestFrom && matchRequestTo) {
const url = `https://${config.CometChatAppId}.api-${config.CometChatRegion}.cometchat.io/v3.0/users/${matchRequestTo}/friends`;
axios.post(url, { accepted: [matchRequestFrom] }, {headers: {
Accept: "application/json",
"Content-Type": "application/json",
appId: `${config.CometChatAppId}`,
apiKey: `${config.CometChatAPIKey}`,
}}).then(res => {
}).catch(error => {
});
}
};
window.acceptMatchRequest = (matchRequestId, matchRequestFrom, matchRequestTo) => {
if (matchRequestId) {
axios.post('/requests/update', {
id: matchRequestId,
status: 1
}).then(res => {
if (res) {
loadMatchRequests();
addFriend(matchRequestFrom, matchRequestTo);
}
}).catch(error => {});
}
};
...
}
...
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment