Dosiye y'umwimerere ikora
public/app.js
Kode n'impapuro z'ingero zikora bigumana amazina n'inyandiko by'umwimerere. Isomo n'amabwiriza ya dosiye birabisobanura mu rurimi rwawe.
document.querySelector("form").addEventListener("submit", async (e) => {
e.preventDefault();
const f = e.target,
s = document.querySelector("[role=status]"),
b = f.querySelector("button");
b.disabled = true;
try {
const r = await fetch("/.netlify/functions/mini-feedback", {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + f.elements.access.value,
},
body: JSON.stringify({ message: f.elements.message.value }),
});
if (!r.ok) throw Error();
s.textContent = "Stored by the database. Verify the matching message in your table.";
} catch {
s.textContent = "The write was not confirmed. Check the practice endpoint.";
} finally {
b.disabled = false;
}
});