2022-11-25 23:54:43 +05:30
|
|
|
import { createAlert } from '~/flash';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { initRails } from '~/lib/utils/rails_ujs';
|
2021-09-30 23:02:18 +05:30
|
|
|
import { getParameterByName } from '~/lib/utils/url_utility';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { __, sprintf } from '~/locale';
|
2019-07-31 22:56:46 +05:30
|
|
|
|
|
|
|
const PARAMETER_NAME = 'leave';
|
|
|
|
const LEAVE_LINK_SELECTOR = '.js-leave-link';
|
|
|
|
|
|
|
|
export default function leaveByUrl(namespaceType) {
|
|
|
|
if (!namespaceType) throw new Error('namespaceType not provided');
|
|
|
|
|
|
|
|
const param = getParameterByName(PARAMETER_NAME);
|
|
|
|
if (!param) return;
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
initRails();
|
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
const leaveLink = document.querySelector(LEAVE_LINK_SELECTOR);
|
|
|
|
if (leaveLink) {
|
|
|
|
leaveLink.click();
|
|
|
|
} else {
|
2022-11-25 23:54:43 +05:30
|
|
|
createAlert({
|
2021-09-30 23:02:18 +05:30
|
|
|
message: sprintf(__('You do not have permission to leave this %{namespaceType}.'), {
|
|
|
|
namespaceType,
|
|
|
|
}),
|
|
|
|
});
|
2019-07-31 22:56:46 +05:30
|
|
|
}
|
|
|
|
}
|