debian-mirror-gitlab/app/assets/javascripts/profile/account/components/update_username.vue

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

146 lines
3.9 KiB
Vue
Raw Normal View History

2018-05-09 12:01:36 +05:30
<script>
2023-03-04 22:38:38 +05:30
import { GlButton, GlModal, GlModalDirective } from '@gitlab/ui';
2021-03-11 19:13:27 +05:30
import { escape } from 'lodash';
2023-03-04 22:38:38 +05:30
import SafeHtml from '~/vue_shared/directives/safe_html';
2022-11-25 23:54:43 +05:30
import { createAlert, VARIANT_INFO } from '~/flash';
2018-05-09 12:01:36 +05:30
import axios from '~/lib/utils/axios_utils';
2021-12-11 22:18:48 +05:30
import { __, s__, sprintf } from '~/locale';
2018-05-09 12:01:36 +05:30
export default {
components: {
2021-01-29 00:20:46 +05:30
GlModal,
2021-01-03 14:25:43 +05:30
GlButton,
2018-05-09 12:01:36 +05:30
},
2021-01-29 00:20:46 +05:30
directives: {
GlModalDirective,
SafeHtml,
},
2018-05-09 12:01:36 +05:30
props: {
actionUrl: {
type: String,
required: true,
},
rootUrl: {
type: String,
required: true,
},
initialUsername: {
type: String,
required: true,
},
},
data() {
return {
isRequestPending: false,
username: this.initialUsername,
newUsername: this.initialUsername,
};
},
computed: {
path() {
return sprintf(s__('Profiles|Current path: %{path}'), {
path: `${this.rootUrl}${this.username}`,
});
},
modalText() {
return sprintf(
s__(`Profiles|
You are going to change the username %{currentUsernameBold} to %{newUsernameBold}.
Profile and projects will be redirected to the %{newUsername} namespace but this redirect will expire once the %{currentUsername} namespace is registered by another user or group.
Please update your Git repository remotes as soon as possible.`),
{
2020-05-24 23:13:21 +05:30
currentUsernameBold: `<strong>${escape(this.username)}</strong>`,
newUsernameBold: `<strong>${escape(this.newUsername)}</strong>`,
currentUsername: escape(this.username),
newUsername: escape(this.newUsername),
2018-05-09 12:01:36 +05:30
},
false,
);
},
2021-01-29 00:20:46 +05:30
primaryProps() {
return {
2021-12-11 22:18:48 +05:30
text: __('Update username'),
2021-01-29 00:20:46 +05:30
attributes: [
2022-07-23 23:45:48 +05:30
{ variant: 'confirm' },
2021-01-29 00:20:46 +05:30
{ category: 'primary' },
{ disabled: this.isRequestPending },
],
};
},
cancelProps() {
return {
2021-12-11 22:18:48 +05:30
text: __('Cancel'),
2021-01-29 00:20:46 +05:30
};
},
2018-05-09 12:01:36 +05:30
},
methods: {
onConfirm() {
this.isRequestPending = true;
const username = this.newUsername;
const putData = {
user: {
username,
},
};
return axios
.put(this.actionUrl, putData)
2021-03-08 18:12:59 +05:30
.then((result) => {
2022-11-25 23:54:43 +05:30
createAlert({ message: result.data.message, variant: VARIANT_INFO });
2018-05-09 12:01:36 +05:30
this.username = username;
this.isRequestPending = false;
})
2021-03-08 18:12:59 +05:30
.catch((error) => {
2022-11-25 23:54:43 +05:30
createAlert({
2021-09-04 01:27:46 +05:30
message:
error?.response?.data?.message ||
2021-04-17 20:07:23 +05:30
s__('Profiles|An error occurred while updating your username, please try again.'),
2021-09-04 01:27:46 +05:30
});
2018-05-09 12:01:36 +05:30
this.isRequestPending = false;
throw error;
});
},
},
modalId: 'username-change-confirmation-modal',
inputId: 'username-change-input',
buttonText: s__('Profiles|Update username'),
};
</script>
<template>
<div>
<div class="form-group">
<label :for="$options.inputId">{{ s__('Profiles|Path') }}</label>
<div class="input-group">
2018-11-08 19:23:39 +05:30
<div class="input-group-prepend">
2019-02-15 15:39:39 +05:30
<div class="input-group-text">{{ rootUrl }}</div>
2018-11-08 19:23:39 +05:30
</div>
2018-05-09 12:01:36 +05:30
<input
:id="$options.inputId"
v-model="newUsername"
:disabled="isRequestPending"
2018-11-08 19:23:39 +05:30
class="form-control"
required="required"
2018-05-09 12:01:36 +05:30
/>
</div>
2019-02-15 15:39:39 +05:30
<p class="form-text text-muted">{{ path }}</p>
2018-05-09 12:01:36 +05:30
</div>
2021-01-03 14:25:43 +05:30
<gl-button
2021-01-29 00:20:46 +05:30
v-gl-modal-directive="$options.modalId"
2021-04-17 20:07:23 +05:30
:disabled="newUsername === username"
:loading="isRequestPending"
2022-07-23 23:45:48 +05:30
variant="confirm"
2021-01-29 00:20:46 +05:30
data-testid="username-change-confirmation-modal"
>{{ $options.buttonText }}</gl-button
2018-05-09 12:01:36 +05:30
>
<gl-modal
2021-01-29 00:20:46 +05:30
:modal-id="$options.modalId"
:title="s__('Profiles|Change username') + '?'"
:action-primary="primaryProps"
:action-cancel="cancelProps"
@primary="onConfirm"
2018-05-09 12:01:36 +05:30
>
2021-01-29 00:20:46 +05:30
<span v-safe-html="modalText"></span>
2018-05-09 12:01:36 +05:30
</gl-modal>
</div>
</template>