mirror of
https://github.com/Retrospring/retrospring.git
synced 2024-11-20 12:19:52 +01:00
Merge pull request #662 from Retrospring/feature/request-js-user
Refactor user TS functionality to use `@rails/request.js`
This commit is contained in:
commit
5baafdc38d
1 changed files with 15 additions and 14 deletions
|
@ -1,4 +1,4 @@
|
||||||
import Rails from '@rails/ujs';
|
import { post } from '@rails/request.js';
|
||||||
import { showNotification, showErrorNotification } from 'utilities/notifications';
|
import { showNotification, showErrorNotification } from 'utilities/notifications';
|
||||||
import I18n from 'retrospring/i18n';
|
import I18n from 'retrospring/i18n';
|
||||||
|
|
||||||
|
@ -30,22 +30,24 @@ export function userActionHandler(event: Event): void {
|
||||||
}
|
}
|
||||||
let success = false;
|
let success = false;
|
||||||
|
|
||||||
Rails.ajax({
|
post(targetURL, {
|
||||||
url: targetURL,
|
body: {
|
||||||
type: 'POST',
|
|
||||||
data: new URLSearchParams({
|
|
||||||
screen_name: target,
|
screen_name: target,
|
||||||
type: relationshipType,
|
type: relationshipType,
|
||||||
}).toString(),
|
},
|
||||||
success: (data) => {
|
contentType: 'application/json'
|
||||||
|
})
|
||||||
|
.then(async response => {
|
||||||
|
const data = await response.json;
|
||||||
|
|
||||||
success = data.success;
|
success = data.success;
|
||||||
showNotification(data.message, data.success);
|
showNotification(data.message, data.success);
|
||||||
},
|
})
|
||||||
error: (data, status, xhr) => {
|
.catch(err => {
|
||||||
console.log(data, status, xhr);
|
console.log(err);
|
||||||
showErrorNotification(I18n.translate('frontend.error.message'));
|
showErrorNotification(I18n.translate('frontend.error.message'));
|
||||||
},
|
})
|
||||||
complete: () => {
|
.finally(() => {
|
||||||
if (!success) return;
|
if (!success) return;
|
||||||
|
|
||||||
switch (action) {
|
switch (action) {
|
||||||
|
@ -76,7 +78,6 @@ export function userActionHandler(event: Event): void {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue