summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/environments/components/edit_environment.vue
blob: 1cd960d7cd64ca60959dcf19459bfe681b74a762 (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
<script>
import createFlash from '~/flash';
import axios from '~/lib/utils/axios_utils';
import { visitUrl } from '~/lib/utils/url_utility';
import EnvironmentForm from './environment_form.vue';

export default {
  components: {
    EnvironmentForm,
  },
  inject: ['projectEnvironmentsPath', 'updateEnvironmentPath'],
  props: {
    environment: {
      required: true,
      type: Object,
    },
  },
  data() {
    return {
      formEnvironment: {
        name: this.environment.name,
        externalUrl: this.environment.external_url,
      },
      loading: false,
    };
  },
  methods: {
    onChange(environment) {
      this.formEnvironment = environment;
    },
    onSubmit() {
      this.loading = true;
      axios
        .put(this.updateEnvironmentPath, {
          id: this.environment.id,
          name: this.formEnvironment.name,
          external_url: this.formEnvironment.externalUrl,
        })
        .then(({ data: { path } }) => visitUrl(path))
        .catch((error) => {
          const message = error.response.data.message[0];
          createFlash({ message });
          this.loading = false;
        });
    },
  },
};
</script>
<template>
  <environment-form
    :cancel-path="projectEnvironmentsPath"
    :environment="formEnvironment"
    :title="__('Edit environment')"
    :loading="loading"
    @change="onChange"
    @submit="onSubmit"
  />
</template>