-
Notifications
You must be signed in to change notification settings - Fork 83
/
Copy pathreport.js
42 lines (36 loc) · 1.26 KB
/
report.js
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
let reportData;
function initReportControls() {
const form = document.getElementById('reportForm');
const reportCustomReason = document.getElementById('reportCustomReason');
/** @type {HTMLSelectElement} */
const reportReasonSelect = document.getElementById('reportReasonSelect');
reportReasonSelect.addEventListener('input', function () {
const cannedValue = !!this.value;
reportCustomReason.classList.toggle('hidden', cannedValue);
form.customReason.toggleAttribute('required', !cannedValue);
});
form.addEventListener('submit', async function () {
const reason = this.reason.value || this.customReason.value;
await apiJsonPost('report', {
uuid: reportData?.uuid,
original_msg: reportData?.msg,
reason,
msg_id: reportData?.msgId,
}).then(
resp => { if (!resp.ok) throw new Error(resp.statusText); },
err => console.error(err),
);
this.reset();
closeModal();
});
}
/**
* @param {*} [props]
*/
function openReportForm(props) {
reportData = props;
const form = document.getElementById('reportForm');
form.reset();
form.reason.dispatchEvent(new Event('input'));
openModal('reportModal');
}