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
140
141
|
<script>
import { GlAlert, GlModal, GlFormGroup, GlFormInput, GlSprintf } from '@gitlab/ui';
import SafeHtml from '~/vue_shared/directives/safe_html';
import {
CONFIRM_DANGER_MODAL_BUTTON,
CONFIRM_DANGER_MODAL_TITLE,
CONFIRM_DANGER_PHRASE_TEXT,
CONFIRM_DANGER_WARNING,
CONFIRM_DANGER_MODAL_CANCEL,
} from './constants';
export default {
name: 'ConfirmDangerModal',
components: {
GlAlert,
GlModal,
GlFormGroup,
GlFormInput,
GlSprintf,
},
directives: {
SafeHtml,
},
inject: {
htmlConfirmationMessage: {
default: false,
},
confirmDangerMessage: {
default: '',
},
confirmButtonText: {
default: CONFIRM_DANGER_MODAL_BUTTON,
},
additionalInformation: {
default: CONFIRM_DANGER_WARNING,
},
cancelButtonText: {
default: CONFIRM_DANGER_MODAL_CANCEL,
},
},
model: {
prop: 'visible',
event: 'change',
},
props: {
visible: {
type: Boolean,
required: false,
default: null,
},
modalId: {
type: String,
required: true,
},
phrase: {
type: String,
required: true,
},
},
data() {
return { confirmationPhrase: '' };
},
computed: {
isValid() {
return Boolean(
this.confirmationPhrase.length && this.equalString(this.confirmationPhrase, this.phrase),
);
},
actionPrimary() {
return {
text: this.confirmButtonText,
attributes: {
variant: 'danger',
disabled: !this.isValid,
'data-testid': 'confirm-danger-modal-button',
},
};
},
actionCancel() {
return {
text: this.cancelButtonText,
};
},
},
methods: {
equalString(a, b) {
return a.trim().toLowerCase() === b.trim().toLowerCase();
},
},
i18n: {
CONFIRM_DANGER_MODAL_BUTTON,
CONFIRM_DANGER_MODAL_TITLE,
CONFIRM_DANGER_WARNING,
CONFIRM_DANGER_PHRASE_TEXT,
},
};
</script>
<template>
<gl-modal
ref="modal"
:visible="visible"
:modal-id="modalId"
:data-testid="modalId"
:title="$options.i18n.CONFIRM_DANGER_MODAL_TITLE"
:action-primary="actionPrimary"
:action-cancel="actionCancel"
size="sm"
@primary="$emit('confirm')"
@change="$emit('change', $event)"
>
<gl-alert
v-if="confirmDangerMessage"
variant="danger"
data-testid="confirm-danger-message"
:dismissible="false"
class="gl-mb-4"
>
<span v-if="htmlConfirmationMessage" v-safe-html="confirmDangerMessage"></span>
<span v-else>
{{ confirmDangerMessage }}
</span>
</gl-alert>
<p data-testid="confirm-danger-warning">{{ additionalInformation }}</p>
<p data-testid="confirm-danger-phrase">
<gl-sprintf :message="$options.i18n.CONFIRM_DANGER_PHRASE_TEXT">
<template #phrase_code>
<code>{{ phrase }}</code>
</template>
</gl-sprintf>
</p>
<gl-form-group :state="isValid">
<gl-form-input
id="confirm_name_input"
v-model="confirmationPhrase"
class="form-control"
data-testid="confirm-danger-field"
type="text"
/>
</gl-form-group>
</gl-modal>
</template>
|