docbrown/app/javascript/packs/asyncUserStatusCheck.js
Joshua Wehner c91a652245
Allow trusted users to see whether a user is suspended (#20061)
* Async append user suspended status pill

* Rubocop

* Relocate JS tests, for build & coverage

* Better error-handling for this controller

* Refactor HTML to render pill outside h1

* Continuing to tweak design

* JS class prepended
2023-09-15 08:44:31 -04:00

25 lines
740 B
JavaScript

import '@utilities/document_ready';
export async function asyncUserStatusCheck() {
const indicator = ` <span data-testid="user-status" class="ml-3 c-indicator c-indicator--danger c-indicator--relaxed">Suspended</span>`;
const profile = document.querySelector('.profile-header__details');
if (profile && !profile.dataset.statusChecked) {
await window
.fetch(profile.dataset.url)
.then((res) => res.json())
.then((data) => {
profile.dataset.statusChecked = true;
const { suspended } = data;
if (suspended) {
profile.querySelector('.js-username-container').innerHTML +=
indicator;
}
});
}
}
document.ready.then(() => {
asyncUserStatusCheck();
});