docbrown/app/javascript/utilities/sendFollowUser.js
Takuya N 3eee116104
Enable error tracking on sendFollowUser (#17328)
Signed-off-by: Takuya Noguchi <takninnovationresearch@gmail.com>
2022-04-18 22:13:31 -04:00

25 lines
686 B
JavaScript

export function sendFollowUser(user, successCb) {
const csrfToken = document.querySelector("meta[name='csrf-token']").content;
const formData = new FormData();
formData.append('followable_type', 'User');
formData.append('followable_id', user.id);
formData.append('verb', user.following ? 'unfollow' : 'follow');
fetch('/follows', {
method: 'POST',
headers: {
'X-CSRF-Token': csrfToken,
},
body: formData,
credentials: 'same-origin',
})
.then((response) => response.json())
.then((json) => {
successCb(json.outcome);
// json is followed or unfollowed
})
.catch((error) => {
Honeybadger.notify(error);
});
}