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 1c0d63b633..0000000000 --- a/modules/user_accounts/js/rejectUser.js +++ /dev/null @@ -1,29 +0,0 @@ -$(document).ready(function() { - $("#btn_reject").click(function() { - const userID = document.getElementById("UserID").value; - const baseurl = loris.BaseURL; - const lorisFetch = window.lorisFetch || fetch; - - lorisFetch(baseurl + '/user_accounts/ajax/rejectUser.php', { - method: 'POST', - headers: { - 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', - }, - body: new URLSearchParams({identifier: userID}), - credentials: 'same-origin', - }) - .then((response) => { - if (!response.ok) { - return response.text().then((text) => { - let error = new Error('request_failed'); - error.lorisMessage = text; - throw error; - }); - } - location.href = baseurl + '/user_accounts/'; - }) - .catch((error) => { - alert(error.lorisMessage || ''); - }); - }); -}); diff --git a/modules/user_accounts/jsx/rejectUser.js b/modules/user_accounts/jsx/rejectUser.js new file mode 100644 index 0000000000..9bdd571ccc --- /dev/null +++ b/modules/user_accounts/jsx/rejectUser.js @@ -0,0 +1,47 @@ +import swal from 'sweetalert2'; + +window.addEventListener('load', () => { + const btn = document.getElementById('btn_reject'); + + if (!btn) return; + + btn.addEventListener('click', () => { + const pathParts = window.location.pathname.split('/'); + const userID = pathParts[pathParts.length - 1]; + 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.', + type: 'warning', + showCancelButton: true, + confirmButtonText: 'Yes, reject user!', + cancelButtonText: 'Cancel', + }).then((result) => { + if (result.value) { + 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 60d715aa1d..54b98fcaba 100644 --- a/webpack.config.ts +++ b/webpack.config.ts @@ -65,7 +65,7 @@ const lorisModules: Record = { 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'],