Skip to content

Commit ca9b46b

Browse files
committed
Added form submission page
1 parent bef48ab commit ca9b46b

File tree

4 files changed

+97
-1
lines changed

4 files changed

+97
-1
lines changed

_assets/css/main.css

+38
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,44 @@ table#professional-experience tr + tr td {
190190
padding-top: 0.75rem;
191191
}
192192

193+
/* spinner used while waiting for fetch, see https://loading.io/css/ */
194+
195+
.lds-dual-ring {
196+
color: #961c1c;
197+
}
198+
199+
.lds-dual-ring,
200+
.lds-dual-ring:after {
201+
box-sizing: border-box;
202+
}
203+
204+
.lds-dual-ring {
205+
display: inline-block;
206+
width: 80px;
207+
height: 80px;
208+
}
209+
210+
.lds-dual-ring:after {
211+
content: " ";
212+
display: block;
213+
width: 64px;
214+
height: 64px;
215+
margin: 8px;
216+
border-radius: 50%;
217+
border: 6.4px solid currentColor;
218+
border-color: currentColor transparent currentColor transparent;
219+
animation: lds-dual-ring 1.2s linear infinite;
220+
}
221+
222+
@keyframes lds-dual-ring {
223+
0% {
224+
transform: rotate(0deg);
225+
}
226+
100% {
227+
transform: rotate(360deg);
228+
}
229+
}
230+
193231
/* footer */
194232

195233
#main {

functions/secure/api/form.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export async function onRequest(context) {
1616
return row;
1717
});
1818

19-
return Response.json(submissionsQuery.results);
19+
return Response.json(submissionsQuery.results);
2020
}
2121

2222
// TODO: this is bad practice, consider replacing (see https://www.reddit.com/r/learnjavascript/comments/qgtut6/comment/hi8jg6w/)

secure/form-submissions.md

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
layout: default
3+
title: Form Submissions
4+
---
5+
6+
This table shows form submissions over the last 30 days:
7+
<div id="form-submissions"><div class="lds-dual-ring"></div></div>
8+
9+
<script>
10+
fetch("/secure/api/form", {
11+
method: "GET",
12+
headers: {
13+
"accept": "application/json",
14+
"content-type": "application/json",
15+
},
16+
})
17+
.then(res => res.json())
18+
.then(submissions => {
19+
const table = document.createElement("table");
20+
const thead = table.createTHead();
21+
const headings = thead.insertRow();
22+
[
23+
"Submission ID",
24+
"Form ID",
25+
"Submitted",
26+
"Spam Reasons",
27+
"IP Address",
28+
"ASN",
29+
].formEach(heading => headings.insertCell().innerHTML = heading)
30+
const tbody = table.createTBody();
31+
submissions.forEach(row => {
32+
const tr = table.insertRow();
33+
34+
const tdSubmissionId = tr.insertCell();
35+
tdSubmissionId.innerHTML = row.submission_id;
36+
37+
const tdFormId = tr.insertCell();
38+
tdFormId.innerHTML = row.form_id;
39+
40+
const tdSubmitted = tr.insertCell();
41+
tdSubmitted.innerHTML = row.submitted_ts;
42+
43+
const tdSpamReasons = tr.insertCell();
44+
tdSpamReasons.innerHTML = row.spam_reasons;
45+
46+
const tdIpAddress = tr.insertCell();
47+
tdIpAddress.innerHTML = `${getFlagEmoji(row.country)} <a href="https://cleantalk.org/blacklists/${row.ip}">${row.ip}</a>`;
48+
49+
const tdAsn = tr.insertCell();
50+
tdAsn.innerHTML = `<a href="https://bgp.tools/as/${row.asn}">AS${row.asn}</a>`;
51+
});
52+
document.getElementById("form-submissions").innerHTML = table.outerHTML;
53+
});
54+
55+
// https://www.bqst.fr/country-code-to-flag-emoji/
56+
const getFlagEmoji = countryCode=>String.fromCodePoint(...[...countryCode.toUpperCase()].map(x=>0x1f1a5+x.charCodeAt()));
57+
</script>

secure/index.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ layout: default
33
title: "Secure area: index"
44
---
55

6+
- [(Contact) form submissions](form-submissions)
67
- [Token generator (for urgent contact form)](token-generator)

0 commit comments

Comments
 (0)