Welcome to mirror list, hosted at ThFree Co, Russian Federation.

change_url.vue « components « general « settings « organizations « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8b65947ab2f74136fc139f1d7f5eeb882a909393 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<script>
import { GlFormFields, GlButton, GlForm, GlCard } from '@gitlab/ui';
import { s__ } from '~/locale';
import { visitUrlWithAlerts, joinPaths } from '~/lib/utils/url_utility';
import { createAlert } from '~/alert';
import OrganizationUrlField from '~/organizations/shared/components/organization_url_field.vue';
import { FORM_FIELD_PATH, FORM_FIELD_PATH_VALIDATORS } from '~/organizations/shared/constants';
import { convertToGraphQLId } from '~/graphql_shared/utils';
import { TYPE_ORGANIZATION } from '~/graphql_shared/constants';
import FormErrorsAlert from '~/vue_shared/components/form/errors_alert.vue';
import organizationUpdateMutation from '../graphql/mutations/organization_update.mutation.graphql';

export default {
  name: 'OrganizationSettings',
  components: { OrganizationUrlField, GlFormFields, GlButton, GlForm, GlCard, FormErrorsAlert },
  inject: ['organization'],
  i18n: {
    cardHeaderTitle: s__('Organization|Change organization URL'),
    cardHeaderDescription: s__(
      "Organization|Changing an organization's URL can have unintended side effects.",
    ),
    submitButtonText: s__('Organization|Change organization URL'),
    errorMessage: s__(
      'Organization|An error occurred changing your organization URL. Please try again.',
    ),
    successAlertMessage: s__('Organization|Organization URL successfully changed.'),
  },
  formId: 'change-organization-url-form',
  fields: {
    [FORM_FIELD_PATH]: {
      label: s__('Organization|Organization URL'),
      validators: FORM_FIELD_PATH_VALIDATORS,
      groupAttrs: {
        class: 'gl-w-full',
        labelSrOnly: true,
      },
    },
  },
  data() {
    return {
      formValues: {
        path: this.organization.path,
      },
      loading: false,
      errors: [],
    };
  },
  computed: {
    isSubmitButtonDisabled() {
      return this.formValues.path === this.organization.path;
    },
  },
  methods: {
    async onSubmit() {
      this.errors = [];
      this.loading = true;
      try {
        const {
          data: {
            organizationUpdate: { errors, organization },
          },
        } = await this.$apollo.mutate({
          mutation: organizationUpdateMutation,
          variables: {
            input: {
              id: convertToGraphQLId(TYPE_ORGANIZATION, this.organization.id),
              path: this.formValues.path,
            },
          },
        });

        if (errors.length) {
          this.errors = errors;

          return;
        }

        visitUrlWithAlerts(joinPaths(organization.webUrl, '/settings/general'), [
          {
            id: 'organization-url-successfully-changed',
            message: this.$options.i18n.successAlertMessage,
            variant: 'info',
          },
        ]);
      } catch (error) {
        createAlert({ message: this.$options.i18n.errorMessage, error, captureError: true });
      } finally {
        this.loading = false;
      }
    },
  },
};
</script>

<template>
  <div>
    <form-errors-alert v-model="errors" />
    <gl-card
      class="gl-new-card"
      header-class="gl-new-card-header gl-flex-direction-column"
      body-class="gl-new-card-body gl-px-5 gl-py-4"
    >
      <template #header>
        <div class="gl-new-card-title-wrapper">
          <h4 class="gl-new-card-title">{{ $options.i18n.cardHeaderTitle }}</h4>
        </div>
        <p class="gl-new-card-description">{{ $options.i18n.cardHeaderDescription }}</p>
      </template>
      <gl-form :id="$options.formId">
        <gl-form-fields
          v-model="formValues"
          :form-id="$options.formId"
          :fields="$options.fields"
          @submit="onSubmit"
        >
          <template #input(path)="{ id, value, validation, input, blur }">
            <organization-url-field
              :id="id"
              :value="value"
              :validation="validation"
              @input="input"
              @blur="blur"
            />
          </template>
        </gl-form-fields>
        <div class="gl-display-flex gl-gap-3">
          <gl-button
            type="submit"
            variant="danger"
            class="js-no-auto-disable"
            :loading="loading"
            :disabled="isSubmitButtonDisabled"
            >{{ $options.i18n.submitButtonText }}</gl-button
          >
        </div>
      </gl-form>
    </gl-card>
  </div>
</template>