revert updated api
This commit is contained in:
2026-05-22 12:27:12 +00:00
parent e0be2c501f
commit c86768e391
17 changed files with 41 additions and 867 deletions

View File

@ -11,7 +11,6 @@ export async function clientsPage() {
<div class="page-header">
<h1>Clients</h1>
<div class="actions">
<button class="btn btn-sm" id="exportAllBtn">Download all client data</button>
<button class="btn btn-primary" id="showCreateFormBtn">+ Create Client</button>
</div>
</div>
@ -19,8 +18,6 @@ export async function clientsPage() {
<div id="clientsContent"><div class="spinner"></div></div>
`;
document.getElementById('exportAllBtn').addEventListener('click', () => downloadClientExport('clients/export_all'));
document.getElementById('showCreateFormBtn').addEventListener('click', () => {
const wrapper = document.getElementById('createClientWrapper');
if (wrapper.style.display === 'none') {
@ -84,35 +81,6 @@ function renderClients() {
container.querySelectorAll('.delete-client-btn').forEach(btn => {
btn.addEventListener('click', () => deleteClient(btn.dataset.code));
});
container.querySelectorAll('.download-client-btn').forEach(btn => {
btn.addEventListener('click', () => downloadClientExport(`clients/export?clientCode=${encodeURIComponent(btn.dataset.code)}`));
});
}
async function downloadClientExport(endpoint) {
try {
const token = localStorage.getItem('qdb_token');
const res = await fetch(`../api/${endpoint}`, {
headers: { Authorization: `Bearer ${token}` },
});
if (!res.ok) {
const err = await res.json().catch(() => ({ error: { message: 'Download failed' } }));
throw new Error(err.error?.message || err.error || 'Download failed');
}
const blob = await res.blob();
const disposition = res.headers.get('Content-Disposition') || '';
const match = disposition.match(/filename="([^"]+)"/);
const filename = match ? match[1] : 'client_export.csv';
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = filename;
a.click();
URL.revokeObjectURL(url);
showToast('Download started', 'success');
} catch (e) {
showToast(e.message, 'error');
}
}
function clientRowHTML(c) {
@ -125,7 +93,6 @@ function clientRowHTML(c) {
<td><strong>${esc(c.clientCode)}</strong></td>
<td>${coach}</td>
<td>
<button class="btn btn-sm download-client-btn" data-code="${esc(c.clientCode)}">Download</button>
<button class="btn btn-sm btn-danger delete-client-btn" data-code="${esc(c.clientCode)}">Delete</button>
</td>
</tr>`;