gitlab-org--gitlab-foss/app/assets/javascripts/namespaces/leave_by_url.js
Luke Bennett 1fb499de27
Add leave link to access_granted email
Allows users to leave a project/group
that they have been added to.
Add function to leave a namespace by url param
If the `leave` param is present on a project/group show page,
click the leave link.
2019-05-03 17:19:16 +01:00

22 lines
651 B
JavaScript

import Flash from '~/flash';
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 }),
);
}
}