summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/projects/components/shared/delete_button.vue
blob: 2e46f437ace96759a97b17c5647c6e1339a9f7f4 (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
<script>
import { GlModal, GlModalDirective, GlFormInput, GlButton } from '@gitlab/ui';
import { uniqueId } from 'lodash';
import csrf from '~/lib/utils/csrf';
import { __ } from '~/locale';

export default {
  components: {
    GlModal,
    GlFormInput,
    GlButton,
  },
  directives: {
    GlModal: GlModalDirective,
  },
  props: {
    confirmPhrase: {
      type: String,
      required: true,
    },
    formPath: {
      type: String,
      required: true,
    },
  },
  data() {
    return {
      userInput: null,
      modalId: uniqueId('delete-project-modal-'),
    };
  },
  computed: {
    confirmDisabled() {
      return this.userInput !== this.confirmPhrase;
    },
    csrfToken() {
      return csrf.token;
    },
    modalActionProps() {
      return {
        primary: {
          text: __('Yes, delete project'),
          attributes: [{ variant: 'danger' }, { disabled: this.confirmDisabled }],
        },
        cancel: {
          text: __('Cancel, keep project'),
        },
      };
    },
  },
  methods: {
    submitForm() {
      this.$refs.form.submit();
    },
  },
  strings: {
    deleteProject: __('Delete project'),
    title: __('Delete project. Are you ABSOLUTELY SURE?'),
    confirmText: __('Please type the following to confirm:'),
  },
};
</script>

<template>
  <form ref="form" :action="formPath" method="post">
    <input type="hidden" name="_method" value="delete" />
    <input :value="csrfToken" type="hidden" name="authenticity_token" />

    <gl-button v-gl-modal="modalId" category="primary" variant="danger">{{
      $options.strings.deleteProject
    }}</gl-button>

    <gl-modal
      ref="removeModal"
      :modal-id="modalId"
      size="sm"
      ok-variant="danger"
      footer-class="gl-bg-gray-10 gl-p-5"
      title-class="gl-text-red-500"
      :action-primary="modalActionProps.primary"
      :action-cancel="modalActionProps.cancel"
      @ok="submitForm"
    >
      <template #modal-title>{{ $options.strings.title }}</template>
      <div>
        <slot name="modal-body"></slot>
        <p class="gl-mb-1">{{ $options.strings.confirmText }}</p>
        <p>
          <code class="gl-white-space-pre-wrap">{{ confirmPhrase }}</code>
        </p>
        <gl-form-input
          id="confirm_name_input"
          v-model="userInput"
          name="confirm_name_input"
          type="text"
        />
        <slot name="modal-footer"></slot>
      </div>
    </gl-modal>
  </form>
</template>