diff --git a/modules/user_accounts/.gitignore b/modules/user_accounts/.gitignore index 0683785912..1034f44c2f 100644 --- a/modules/user_accounts/.gitignore +++ b/modules/user_accounts/.gitignore @@ -1,2 +1,2 @@ js/* -!js/edit_user_helper.js +!js/edit_user_helper.js \ No newline at end of file diff --git a/modules/user_accounts/js/rejectUser.js b/modules/user_accounts/js/rejectUser.js deleted file mode 100644 index fdc3eeff68..0000000000 --- a/modules/user_accounts/js/rejectUser.js +++ /dev/null @@ -1,17 +0,0 @@ -$(document).ready(function() { - $("#btn_reject").click(function() { - const userID = document.getElementById("UserID").value; - const baseurl = loris.BaseURL; - - $.ajax(baseurl + '/user_accounts/ajax/rejectUser.php', { - type:'POST', - data: {identifier: userID}, - success: function(data, textStatus){ - location.href = baseurl+'/user_accounts/'; - }, - error: function(jqXHR, textStatus, errorThrown){ - alert(jqXHR.responseText); - } - }); - }); -}); diff --git a/modules/user_accounts/jsx/rejectUser.js b/modules/user_accounts/jsx/rejectUser.js new file mode 100644 index 0000000000..667e195f68 --- /dev/null +++ b/modules/user_accounts/jsx/rejectUser.js @@ -0,0 +1,46 @@ +import swal from 'sweetalert2'; + +window.addEventListener('load', () => { + const btn = document.getElementById('btn_reject'); + + if (!btn) return; + + btn.addEventListener('click', () => { + const userID = document.getElementById('UserID').value; + const baseurl = loris.BaseURL; + + swal.fire({ + title: 'Are you sure?', + text: `Do you really want to reject user "${userID}"?\n` + + 'This action cannot be undone.', + icon: 'warning', + showCancelButton: true, + confirmButtonText: 'Yes, reject user!', + cancelButtonText: 'Cancel', + }).then((result) => { + if (result.isConfirmed) { + fetch(`${baseurl}/user_accounts/ajax/rejectUser.php`, { + method: 'POST', + credentials: 'same-origin', + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + }, + body: new URLSearchParams({ + identifier: userID, + }), + }) + .then((resp) => { + if (!resp.ok) { + return resp.text().then((text) => { + throw new Error(text); + }); + } + window.location.href = `${baseurl}/user_accounts/`; + }) + .catch((error) => { + swal.fire('Error', error.message, 'error'); + }); + } + }); + }); +}); diff --git a/webpack.config.ts b/webpack.config.ts index fe047a1b29..ca1dfa1ad1 100644 --- a/webpack.config.ts +++ b/webpack.config.ts @@ -60,7 +60,7 @@ let lorisModules: { [x: string]: string[] } = { instrument_manager: ['instrumentManagerIndex'], survey_accounts: ['surveyAccountsIndex'], mri_violations: ['mriViolationsIndex'], - user_accounts: ['userAccountsIndex'], + user_accounts: ['userAccountsIndex', 'rejectUser'], examiner: ['examinerIndex'], help_editor: ['help_editor', 'helpEditorForm'], brainbrowser: ['Brainbrowser'],