Recurring Visit Button

This commit is contained in:
jessikitty committed 2026-09-30 23:01:32 +10:00
1 parent 215c38849b
commit 1b1d950d71
4 files changed
+156 -1

No files matched your search

+31
View File
@@ -185,6 +185,11 @@ async function loadOnsite() {
<td class="actions">
<button class="ghost" data-badge="${v.id}">Badge</button>
<button class="ghost" data-print="${v.id}">Print</button>
${
v.visitorType !== 'frequent' && v.phone
? `<button class="ghost" data-make-regular="${v.id}" title="Save them with a PIN so they can sign in themselves next time">Make regular</button>`
: ''
}
<button class="ghost" data-signout="${v.id}">Sign out</button>
</td>
</tr>`
@@ -202,6 +207,32 @@ async function loadOnsite() {
$$('[data-badge]').forEach((btn) =>
btn.addEventListener('click', () => window.open(`/admin/api/badge/${btn.dataset.badge}`, '_blank'))
);
$$('[data-make-regular]').forEach((btn) =>
btn.addEventListener('click', async () => {
const row = btn.closest('tr');
const name = row?.querySelector('strong')?.textContent?.trim() || 'this visitor';
openModal(
`Save ${esc(name)} as a regular visitor?`,
`<p class="hint">Their name, mobile number and check details are taken from this visit, a
PIN is issued, and their sign in photo is kept on file. Next time they enter their mobile
number and PIN, pick who they are seeing, and the badge prints — no form, no camera.</p>
<p class="hint">This visit stays in the log as a guest visit.</p>`,
async () => {
btn.disabled = true;
try {
const saved = await api(`/visits/${btn.dataset.makeRegular}/make-regular`, { method: 'POST' });
loadOnsite();
showPin(saved.pin, saved.id);
} catch (err) {
toast(err.message, true);
} finally {
btn.disabled = false;
}
},
{ saveLabel: 'Save and issue a PIN' }
);
})
);
$$('[data-print]').forEach((btn) =>
btn.addEventListener('click', async () => {
btn.disabled = true;