Created
September 28, 2021 13:32
-
-
Save hieptl/f112ccfc93fcef3c4aeceac67f7ba5f5 to your computer and use it in GitHub Desktop.
index.js - Update the Match Request Status - Client Side - Tinder Clone
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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