debian-mirror-gitlab/app/assets/javascripts/admin/users/components/modals/delete_user_modal.vue

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

141 lines
3.7 KiB
Vue
Raw Normal View History

2018-03-17 18:26:18 +05:30
<script>
2020-11-24 15:15:51 +05:30
import { GlModal, GlButton, GlFormInput, GlSprintf } from '@gitlab/ui';
2018-12-13 13:39:08 +05:30
import { s__, sprintf } from '~/locale';
2021-11-18 22:05:49 +05:30
import UserDeletionObstaclesList from '~/vue_shared/components/user_deletion_obstacles/user_deletion_obstacles_list.vue';
2022-06-21 17:19:12 +05:30
import eventHub, { EVENT_OPEN_DELETE_USER_MODAL } from './delete_user_modal_event_hub';
2018-03-17 18:26:18 +05:30
2018-12-13 13:39:08 +05:30
export default {
components: {
2019-12-21 20:55:43 +05:30
GlModal,
2020-10-24 23:57:45 +05:30
GlButton,
2019-12-21 20:55:43 +05:30
GlFormInput,
2020-11-24 15:15:51 +05:30
GlSprintf,
2021-11-18 22:05:49 +05:30
UserDeletionObstaclesList,
2018-12-13 13:39:08 +05:30
},
props: {
csrfToken: {
type: String,
2019-12-21 20:55:43 +05:30
required: true,
2018-12-13 13:39:08 +05:30
},
},
data() {
return {
enteredUsername: '',
2022-06-21 17:19:12 +05:30
username: '',
blockPath: '',
deletePath: '',
userDeletionObstacles: [],
i18n: {
title: '',
primaryButtonLabel: '',
messageBody: '',
},
2018-12-13 13:39:08 +05:30
};
},
computed: {
2022-01-26 12:08:38 +05:30
trimmedUsername() {
return this.username.trim();
},
2019-12-21 20:55:43 +05:30
modalTitle() {
2022-06-21 17:19:12 +05:30
return sprintf(this.i18n.title, { username: this.trimmedUsername }, false);
2018-12-13 13:39:08 +05:30
},
canSubmit() {
2022-06-21 17:19:12 +05:30
return this.enteredUsername && this.enteredUsername === this.trimmedUsername;
2018-12-13 13:39:08 +05:30
},
2022-06-21 17:19:12 +05:30
secondaryButtonLabel() {
return s__('AdminUsers|Block user');
2021-06-08 01:23:25 +05:30
},
2018-12-13 13:39:08 +05:30
},
2022-06-21 17:19:12 +05:30
mounted() {
eventHub.$on(EVENT_OPEN_DELETE_USER_MODAL, this.onOpenEvent);
},
destroyed() {
eventHub.$off(EVENT_OPEN_DELETE_USER_MODAL, this.onOpenEvent);
},
2018-12-13 13:39:08 +05:30
methods: {
2022-06-21 17:19:12 +05:30
onOpenEvent({ username, blockPath, deletePath, userDeletionObstacles, i18n }) {
this.username = username;
this.blockPath = blockPath;
this.deletePath = deletePath;
this.userDeletionObstacles = userDeletionObstacles;
this.i18n = i18n;
this.openModal();
},
openModal() {
2019-12-21 20:55:43 +05:30
this.$refs.modal.show();
},
2022-06-21 17:19:12 +05:30
onSubmit() {
this.$refs.form.submit();
this.enteredUsername = '';
},
2018-12-13 13:39:08 +05:30
onCancel() {
this.enteredUsername = '';
2019-12-21 20:55:43 +05:30
this.$refs.modal.hide();
2018-12-13 13:39:08 +05:30
},
onSecondaryAction() {
const { form } = this.$refs;
2022-06-21 17:19:12 +05:30
form.action = this.blockPath;
2018-12-13 13:39:08 +05:30
this.$refs.method.value = 'put';
form.submit();
},
},
};
2018-03-17 18:26:18 +05:30
</script>
<template>
2019-12-21 20:55:43 +05:30
<gl-modal ref="modal" modal-id="delete-user-modal" :title="modalTitle" kind="danger">
2021-03-11 19:13:27 +05:30
<p>
2022-06-21 17:19:12 +05:30
<gl-sprintf :message="i18n.messageBody">
2021-03-11 19:13:27 +05:30
<template #username>
2022-06-21 17:19:12 +05:30
<strong data-testid="message-username">{{ trimmedUsername }}</strong>
2021-03-11 19:13:27 +05:30
</template>
2022-06-21 17:19:12 +05:30
<template #strong="{ content }">
<strong>{{ content }}</strong>
2021-03-11 19:13:27 +05:30
</template>
</gl-sprintf>
</p>
2020-11-24 15:15:51 +05:30
2021-11-18 22:05:49 +05:30
<user-deletion-obstacles-list
2022-06-21 17:19:12 +05:30
v-if="userDeletionObstacles.length"
:obstacles="userDeletionObstacles"
2022-01-26 12:08:38 +05:30
:user-name="trimmedUsername"
2021-11-18 22:05:49 +05:30
/>
2021-06-08 01:23:25 +05:30
2021-03-11 19:13:27 +05:30
<p>
<gl-sprintf :message="s__('AdminUsers|To confirm, type %{username}')">
<template #username>
2022-06-21 17:19:12 +05:30
<code data-testid="confirm-username" class="gl-white-space-pre-wrap">{{
trimmedUsername
}}</code>
2021-03-11 19:13:27 +05:30
</template>
</gl-sprintf>
</p>
2020-11-24 15:15:51 +05:30
2022-06-21 17:19:12 +05:30
<form ref="form" :action="deletePath" method="post" @submit.prevent>
2021-03-11 19:13:27 +05:30
<input ref="method" type="hidden" name="_method" value="delete" />
<input :value="csrfToken" type="hidden" name="authenticity_token" />
<gl-form-input
v-model="enteredUsername"
autofocus
type="text"
name="username"
autocomplete="off"
/>
</form>
2022-06-21 17:19:12 +05:30
2020-05-24 23:13:21 +05:30
<template #modal-footer>
2021-12-11 22:18:48 +05:30
<gl-button @click="onCancel">{{ __('Cancel') }}</gl-button>
2020-10-24 23:57:45 +05:30
<gl-button
:disabled="!canSubmit"
2021-04-29 21:17:54 +05:30
category="secondary"
variant="danger"
2020-10-24 23:57:45 +05:30
@click="onSecondaryAction"
>
2022-06-21 17:19:12 +05:30
{{ secondaryButtonLabel }}
2020-10-24 23:57:45 +05:30
</gl-button>
<gl-button :disabled="!canSubmit" category="primary" variant="danger" @click="onSubmit">{{
2022-06-21 17:19:12 +05:30
i18n.primaryButtonLabel
2020-10-24 23:57:45 +05:30
}}</gl-button>
2018-03-17 18:26:18 +05:30
</template>
2019-12-21 20:55:43 +05:30
</gl-modal>
2018-03-17 18:26:18 +05:30
</template>