feat: require explicit report submission
This commit is contained in:
1 parent
8519c97678
commit
3c40bff4e8
4 files changed
+41
-5
No files matched your search
+31
-1
@@ -178,7 +178,7 @@
|
||||
</div>
|
||||
</dialog>
|
||||
|
||||
<div class="result hidden" id="result"><h2>Сообщение</h2><textarea id="message" readonly></textarea></div>
|
||||
<div class="result hidden" id="result"><h2>Сообщение</h2><textarea id="message" readonly></textarea><div class="actions"><button type="button" id="sendReport" class="primary" disabled>Отправить отчёт</button></div><p class="muted hidden" id="reportStatus" aria-live="polite"></p></div>
|
||||
<div class="result hidden" id="pointsResult" aria-live="polite"><h2>Заработанные баллы</h2><div id="pointsSummary"></div></div>
|
||||
<p class="error" id="error"></p>
|
||||
</section>
|
||||
@@ -223,6 +223,9 @@
|
||||
const form = document.querySelector('#form');
|
||||
const error = document.querySelector('#error');
|
||||
const result = document.querySelector('#result');
|
||||
const sendReport = document.querySelector('#sendReport');
|
||||
const reportStatus = document.querySelector('#reportStatus');
|
||||
let preparedReportPayload = null;
|
||||
const message = document.querySelector('#message');
|
||||
const copy = document.querySelector('#copy');
|
||||
const goalCopy = document.querySelector('#goalCopy');
|
||||
@@ -429,6 +432,9 @@
|
||||
if (statusError) throw new Error(statusError);
|
||||
}
|
||||
const reportPayload = payload();
|
||||
preparedReportPayload = null;
|
||||
reportStatus.classList.add('hidden');
|
||||
reportStatus.textContent = '';
|
||||
reportPayload.attachments = mode === 'goal' ? [] : await uploadScreenshots();
|
||||
const response = await fetch('/api/calculate', { method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify(reportPayload) });
|
||||
const data = await response.json();
|
||||
@@ -443,8 +449,32 @@
|
||||
result.classList.remove('hidden');
|
||||
copy.disabled = mode === 'goal';
|
||||
goalCopy.disabled = mode !== 'goal';
|
||||
sendReport.classList.toggle('hidden', mode === 'goal');
|
||||
if (mode !== 'goal') {
|
||||
preparedReportPayload = reportPayload;
|
||||
sendReport.disabled = false;
|
||||
sendReport.textContent = 'Отправить отчёт';
|
||||
}
|
||||
} catch (err) { error.textContent = err.message; }
|
||||
});
|
||||
sendReport.addEventListener('click', async () => {
|
||||
if (!preparedReportPayload || sendReport.disabled) return;
|
||||
sendReport.disabled = true;
|
||||
sendReport.textContent = 'Отправляем…';
|
||||
try {
|
||||
const response = await fetch('/api/reports', { method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify(preparedReportPayload) });
|
||||
const data = await response.json();
|
||||
if (!response.ok) throw new Error(data.error || 'Не удалось отправить отчёт');
|
||||
preparedReportPayload = null;
|
||||
sendReport.textContent = 'Отчёт отправлен';
|
||||
reportStatus.textContent = 'Отчёт отправлен и сохранён.';
|
||||
reportStatus.classList.remove('hidden');
|
||||
} catch (err) {
|
||||
error.textContent = err.message;
|
||||
sendReport.disabled = false;
|
||||
sendReport.textContent = 'Отправить отчёт';
|
||||
}
|
||||
});
|
||||
copy.addEventListener('click', async () => { await navigator.clipboard.writeText(message.value); copy.textContent = 'Скопировано'; setTimeout(() => copy.textContent = 'Скопировать', 1500); });
|
||||
goalCopy.addEventListener('click', async () => { await navigator.clipboard.writeText(message.value); goalCopy.textContent = 'Скопировано'; setTimeout(() => goalCopy.textContent = 'Скопировать', 1500); });
|
||||
|
||||
|
||||
Reference in new issue
Block a user