debian-mirror-gitlab/app/assets/javascripts/vue_shared/components/remove_member_modal.vue

117 lines
3.1 KiB
Vue
Raw Normal View History

2020-07-28 23:09:34 +05:30
<script>
import { GlFormCheckbox, GlModal } from '@gitlab/ui';
2021-04-29 21:17:54 +05:30
import * as Sentry from '@sentry/browser';
2020-07-28 23:09:34 +05:30
import { parseBoolean } from '~/lib/utils/common_utils';
import csrf from '~/lib/utils/csrf';
2021-04-29 21:17:54 +05:30
import { s__, __ } from '~/locale';
import OncallSchedulesList from '~/vue_shared/components/oncall_schedules_list.vue';
2020-07-28 23:09:34 +05:30
export default {
actionCancel: {
text: __('Cancel'),
},
csrf,
components: {
GlFormCheckbox,
GlModal,
2021-04-29 21:17:54 +05:30
OncallSchedulesList,
2020-07-28 23:09:34 +05:30
},
data() {
return {
modalData: {},
};
},
computed: {
isAccessRequest() {
return parseBoolean(this.modalData.isAccessRequest);
},
2021-04-29 21:17:54 +05:30
isInvite() {
return parseBoolean(this.modalData.isInvite);
},
isGroupMember() {
return this.modalData.memberType === 'GroupMember';
},
2020-07-28 23:09:34 +05:30
actionText() {
2021-04-29 21:17:54 +05:30
if (this.isAccessRequest) {
return __('Deny access request');
} else if (this.isInvite) {
return s__('Member|Revoke invite');
}
return __('Remove member');
2020-07-28 23:09:34 +05:30
},
actionPrimary() {
return {
text: this.actionText,
attributes: {
variant: 'danger',
},
};
},
2021-04-29 21:17:54 +05:30
showUnassignIssuablesCheckbox() {
return !this.isAccessRequest && !this.isInvite;
},
isPartOfOncallSchedules() {
return !this.isAccessRequest && this.oncallSchedules.schedules?.length;
},
oncallSchedules() {
try {
2021-06-08 01:23:25 +05:30
return JSON.parse(this.modalData.oncallSchedules);
2021-04-29 21:17:54 +05:30
} catch (e) {
Sentry.captureException(e);
}
2021-06-08 01:23:25 +05:30
return {};
2021-04-29 21:17:54 +05:30
},
2020-07-28 23:09:34 +05:30
},
mounted() {
document.addEventListener('click', this.handleClick);
},
beforeDestroy() {
document.removeEventListener('click', this.handleClick);
},
methods: {
handleClick(event) {
const removeButton = event.target.closest('.js-remove-member-button');
if (removeButton) {
this.modalData = removeButton.dataset;
this.$refs.modal.show();
}
},
submitForm() {
this.$refs.form.submit();
},
},
};
</script>
<template>
<gl-modal
ref="modal"
modal-id="remove-member-modal"
:action-cancel="$options.actionCancel"
:action-primary="actionPrimary"
:title="actionText"
data-qa-selector="remove_member_modal_content"
@primary="submitForm"
>
<form ref="form" :action="modalData.memberPath" method="post">
<p data-testid="modal-message">{{ modalData.message }}</p>
2021-04-29 21:17:54 +05:30
<oncall-schedules-list
v-if="isPartOfOncallSchedules"
:schedules="oncallSchedules.schedules"
:user-name="oncallSchedules.name"
/>
2020-07-28 23:09:34 +05:30
<input ref="method" type="hidden" name="_method" value="delete" />
<input :value="$options.csrf.token" type="hidden" name="authenticity_token" />
2021-04-29 21:17:54 +05:30
<gl-form-checkbox v-if="isGroupMember" name="remove_sub_memberships">
{{ __('Also remove direct user membership from subgroups and projects') }}
</gl-form-checkbox>
<gl-form-checkbox v-if="showUnassignIssuablesCheckbox" name="unassign_issuables">
2020-07-28 23:09:34 +05:30
{{ __('Also unassign this user from related issues and merge requests') }}
</gl-form-checkbox>
</form>
</gl-modal>
</template>