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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
<script>
import { GlDisclosureDropdown, GlModal } from '@gitlab/ui';
import axios from '~/lib/utils/axios_utils';
import { __, sprintf } from '~/locale';
import { redirectTo, refreshCurrentPage } from '~/lib/utils/url_utility'; // eslint-disable-line import/no-deprecated
import { createAlert, VARIANT_SUCCESS } from '~/alert';
import { ACTIONS_I18N } from '../constants';
const modalActionButtonAttributes = {
block: {
text: __('OK'),
attributes: {
variant: 'confirm',
},
},
removeUserAndReport: {
text: __('OK'),
attributes: {
variant: 'danger',
},
},
secondary: {
text: __('Cancel'),
attributes: {
variant: 'default',
},
},
};
const BLOCK_ACTION = 'block';
const REMOVE_USER_AND_REPORT_ACTION = 'removeUserAndReport';
export default {
name: 'AbuseReportActions',
components: {
GlDisclosureDropdown,
GlModal,
},
modalId: 'abuse-report-row-action-confirm-modal',
modalActionButtonAttributes,
i18n: ACTIONS_I18N,
props: {
report: {
type: Object,
required: true,
},
},
data() {
return {
userBlocked: this.report.userBlocked,
confirmModalShown: false,
actionToConfirm: 'block',
};
},
computed: {
blockUserButtonText() {
const { alreadyBlocked, blockUser } = this.$options.i18n;
return this.userBlocked ? alreadyBlocked : blockUser;
},
removeUserAndReportConfirmText() {
return sprintf(this.$options.i18n.removeUserAndReportConfirm, {
user: this.report.reportedUser.name,
});
},
modalData() {
return {
[BLOCK_ACTION]: {
action: this.blockUser,
confirmText: this.$options.i18n.blockUserConfirm,
},
[REMOVE_USER_AND_REPORT_ACTION]: {
action: this.removeUserAndReport,
confirmText: this.removeUserAndReportConfirmText,
},
};
},
reportActionsDropdownItems() {
return [
{
text: this.$options.i18n.removeUserAndReport,
action: () => {
this.showConfirmModal(REMOVE_USER_AND_REPORT_ACTION);
},
extraAttrs: { class: 'gl-text-red-500!' },
},
{
text: this.blockUserButtonText,
action: () => {
this.showConfirmModal(BLOCK_ACTION);
},
extraAttrs: {
disabled: this.userBlocked,
'data-testid': 'block-user-button',
},
},
{
text: this.$options.i18n.removeReport,
action: () => {
this.removeReport();
},
},
];
},
},
methods: {
showConfirmModal(action) {
this.confirmModalShown = true;
this.actionToConfirm = action;
},
blockUser() {
axios
.put(this.report.blockUserPath)
.then(this.handleBlockUserResponse)
.catch(this.handleError);
},
removeUserAndReport() {
axios
.delete(this.report.removeUserAndReportPath)
.then(this.handleRemoveReportResponse)
.catch(this.handleError);
},
removeReport() {
axios
.delete(this.report.removeReportPath)
.then(this.handleRemoveReportResponse)
.catch(this.handleError);
},
handleRemoveReportResponse() {
// eslint-disable-next-line import/no-deprecated
if (this.report.redirectPath) redirectTo(this.report.redirectPath);
else refreshCurrentPage();
},
handleBlockUserResponse({ data }) {
const message = data?.error || data?.notice;
const alertOptions = data?.notice ? { variant: VARIANT_SUCCESS } : {};
if (message) {
createAlert({ message, ...alertOptions });
}
if (!data?.error) {
this.userBlocked = true;
}
},
handleError(error) {
createAlert({
message: __('Something went wrong. Please try again.'),
captureError: true,
error,
});
},
},
};
</script>
<template>
<div>
<gl-disclosure-dropdown
:toggle-text="$options.i18n.actionsToggleText"
text-sr-only
icon="ellipsis_v"
category="tertiary"
no-caret
placement="right"
:items="reportActionsDropdownItems"
/>
<gl-modal
v-model="confirmModalShown"
:modal-id="$options.modalId"
:title="modalData[actionToConfirm].confirmText"
size="sm"
:action-primary="$options.modalActionButtonAttributes[actionToConfirm]"
:action-secondary="$options.modalActionButtonAttributes.secondary"
@primary="modalData[actionToConfirm].action"
/>
</div>
</template>
|