summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/pages/admin/jobs/components/cancel_jobs_modal.vue
blob: 3bc785ee1b6041d6acf417873cfa6fbb3bf201e7 (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
<script>
import { GlModal } from '@gitlab/ui';
import { createAlert } from '~/alert';
import axios from '~/lib/utils/axios_utils';
import { redirectTo } from '~/lib/utils/url_utility';
import {
  CANCEL_TEXT,
  CANCEL_JOBS_FAILED_TEXT,
  CANCEL_JOBS_MODAL_TITLE,
  CANCEL_JOBS_WARNING,
  PRIMARY_ACTION_TEXT,
} from './constants';

export default {
  components: {
    GlModal,
  },
  props: {
    url: {
      type: String,
      required: true,
    },
    modalId: {
      type: String,
      required: true,
    },
  },
  methods: {
    onSubmit() {
      return axios
        .post(this.url)
        .then((response) => {
          // follow the rediect to refresh the page
          redirectTo(response.request.responseURL);
        })
        .catch((error) => {
          createAlert({
            message: CANCEL_JOBS_FAILED_TEXT,
          });
          throw error;
        });
    },
  },
  primaryAction: {
    text: PRIMARY_ACTION_TEXT,
    attributes: { variant: 'danger' },
  },
  cancelAction: {
    text: CANCEL_TEXT,
  },
  CANCEL_JOBS_WARNING,
  CANCEL_JOBS_MODAL_TITLE,
};
</script>

<template>
  <gl-modal
    :modal-id="modalId"
    :action-primary="$options.primaryAction"
    :action-cancel="$options.cancelAction"
    :title="$options.CANCEL_JOBS_MODAL_TITLE"
    @primary="onSubmit"
  >
    {{ $options.CANCEL_JOBS_WARNING }}
  </gl-modal>
</template>