2020-10-24 23:57:45 +05:30
|
|
|
import { deprecatedCreateFlash as Flash } from '~/flash';
|
2019-07-31 22:56:46 +05:30
|
|
|
import { __, sprintf } from '~/locale';
|
|
|
|
import { getParameterByName } from '~/lib/utils/common_utils';
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
const leaveLink = document.querySelector(LEAVE_LINK_SELECTOR);
|
|
|
|
if (leaveLink) {
|
|
|
|
leaveLink.click();
|
|
|
|
} else {
|
|
|
|
Flash(
|
|
|
|
sprintf(__('You do not have permission to leave this %{namespaceType}.'), { namespaceType }),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|