summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/pages/milestones/shared/components/promote_milestone_modal.vue
blob: a79ef07f1c557d46e8c0f233e3db3ad3e2b1c2c5 (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
<script>
import axios from '~/lib/utils/axios_utils';
import createFlash from '~/flash';
import GlModal from '~/vue_shared/components/gl_modal.vue';
import { s__, sprintf } from '~/locale';
import { visitUrl } from '~/lib/utils/url_utility';
import eventHub from '../event_hub';

export default {
  components: {
    GlModal,
  },
  props: {
    milestoneTitle: {
      type: String,
      required: true,
    },
    url: {
      type: String,
      required: true,
    },
    groupName: {
      type: String,
      required: true,
    },
  },
  computed: {
    title() {
      return sprintf(s__('Milestones|Promote %{milestoneTitle} to group milestone?'), {
        milestoneTitle: this.milestoneTitle,
      });
    },
    text() {
      return sprintf(
        s__(`Milestones|Promoting %{milestoneTitle} will make it available for all projects inside %{groupName}.
        Existing project milestones with the same title will be merged.
        This action cannot be reversed.`),
        { milestoneTitle: this.milestoneTitle, groupName: this.groupName },
      );
    },
  },
  methods: {
    onSubmit() {
      eventHub.$emit('promoteMilestoneModal.requestStarted', this.url);
      return axios
        .post(this.url, { params: { format: 'json' } })
        .then(response => {
          eventHub.$emit('promoteMilestoneModal.requestFinished', {
            milestoneUrl: this.url,
            successful: true,
          });
          visitUrl(response.data.url);
        })
        .catch(error => {
          eventHub.$emit('promoteMilestoneModal.requestFinished', {
            milestoneUrl: this.url,
            successful: false,
          });
          createFlash(error);
        });
    },
  },
};
</script>
<template>
  <gl-modal
    id="promote-milestone-modal"
    :footer-primary-button-text="s__('Milestones|Promote Milestone')"
    footer-primary-button-variant="warning"
    @submit="onSubmit"
  >
    <template slot="title">
      {{ title }}
    </template>
    {{ text }}
  </gl-modal>
</template>