added functionality to archive clients
Some checks failed
PHPUnit / test (push) Has been cancelled

This commit is contained in:
2026-06-12 20:55:12 +02:00
parent 59ea2cd667
commit 5dff24a232
15 changed files with 436 additions and 48 deletions

View File

@ -1,5 +1,6 @@
import { apiGet, apiPut } from '../api.js';
import { pageHeaderHTML, showToast } from '../app.js';
import { clientTableActionsHTML, confirmAndPatchClientArchive } from '../client-archive.js';
let overview = null;
let staleClients = [];
@ -159,7 +160,7 @@ function renderInsights() {
<div class="card" style="margin-top:20px">
<h3 style="margin:0 0 8px">Needs follow-up</h3>
<p class="data-toolbar-hint" style="margin:0 0 12px">
Clients who completed at least one questionnaire, sorted by longest time since any upload activity.
Clients who completed at least one questionnaire, sorted by longest time since last activity.
</p>
<div class="filter-bar">
<input type="search" id="followupListSearch" class="filter-search"
@ -170,8 +171,8 @@ function renderInsights() {
<table class="data-table">
<thead>
<tr>
<th>Client</th><th>Counselor</th><th>Last completed</th><th>Last at</th>
<th>Last activity</th><th>Days idle</th><th>Note</th>
<th>Client</th><th>Counselor</th><th>Last questionnaire</th>
<th>Completed at</th><th>Days idle</th><th>Note</th><th></th>
</tr>
</thead>
<tbody id="followupTableBody"></tbody>
@ -196,7 +197,6 @@ function followupSearchText(c) {
c.lastQuestionnaireID,
c.note,
c.lastCompletedAt,
c.lastActivityAt,
c.daysSinceLastActivity != null ? String(c.daysSinceLastActivity) : '',
].filter(Boolean).join(' ');
}
@ -208,18 +208,23 @@ function filteredFollowupClients() {
}
function followupRowHTML(c) {
const code = esc(c.clientCode);
return `
<tr data-client="${esc(c.clientCode)}">
<td><code>${esc(c.clientCode)}</code></td>
<tr data-client="${code}">
<td><code>${code}</code></td>
<td>${esc(c.coachUsername)}</td>
<td>${esc(c.lastQuestionnaireName || '—')}</td>
<td>${esc(c.lastCompletedAt || '—')}</td>
<td>${esc(c.lastActivityAt || '—')}</td>
<td>${c.daysSinceLastActivity != null ? c.daysSinceLastActivity : '—'}</td>
<td>
<textarea class="followup-note-input" rows="2" data-client="${esc(c.clientCode)}"
<td class="followup-note-cell">
<textarea class="followup-note-input" rows="2" data-client="${code}"
placeholder="Follow-up note…">${esc(c.note || '')}</textarea>
<button type="button" class="btn btn-sm save-note-btn" data-client="${esc(c.clientCode)}">Save</button>
<div class="followup-note-actions">
<button type="button" class="btn btn-sm btn-primary save-note-btn" data-client="${code}">Save note</button>
</div>
</td>
<td class="followup-actions-cell">
${clientTableActionsHTML({ clientCode: code, archived: false, showDelete: false })}
</td>
</tr>`;
}
@ -262,6 +267,17 @@ function renderFollowupTableBody() {
saveNote(btn.dataset.client, ta);
});
});
body.querySelectorAll('.archive-client-btn').forEach(btn => {
btn.addEventListener('click', () => archiveFromFollowup(btn.dataset.code));
});
}
async function archiveFromFollowup(clientCode) {
const ok = await confirmAndPatchClientArchive(clientCode, true);
if (!ok) return;
staleClients = staleClients.filter(c => c.clientCode !== clientCode);
renderFollowupTableBody();
}
async function saveNote(clientCode, ta) {