857d863c6f
deploy / deploy (push) Successful in 3s
The API already returns specific, honest messages (e.g. 'this course isn't open for signups yet' for an inactive course) — the frontend was discarding them and always showing a generic 'something went wrong'.
53 lines
2.0 KiB
HTML
53 lines
2.0 KiB
HTML
{{ define "main" }}
|
|
<h1 style="font-size:2rem; margin-bottom:0.5rem;">{{ .Title }}</h1>
|
|
{{ with .Params.pitch }}<div style="font-size:1.05rem; opacity:0.9;">{{ . | markdownify }}</div>{{ end }}
|
|
{{ .Content }}
|
|
|
|
<form id="enroll-form" style="margin-top:2rem; max-width:24rem;">
|
|
<label for="email">Email</label>
|
|
<input type="email" id="email" name="email" required autocomplete="email" placeholder="you@example.com">
|
|
|
|
<div class="field-honeypot" aria-hidden="true">
|
|
<label for="website">Leave this field empty</label>
|
|
<input type="text" id="website" name="website" tabindex="-1" autocomplete="off">
|
|
</div>
|
|
|
|
<button type="submit" class="btn">Send me day one</button>
|
|
</form>
|
|
<p id="enroll-status" role="status" style="margin-top:1rem;"></p>
|
|
|
|
<script>
|
|
(function () {
|
|
var form = document.getElementById("enroll-form");
|
|
var status = document.getElementById("enroll-status");
|
|
var slug = {{ .Params.eec_slug }};
|
|
form.addEventListener("submit", function (e) {
|
|
e.preventDefault();
|
|
if (form.website.value) return; // honeypot
|
|
var submitBtn = form.querySelector("button[type=submit]");
|
|
submitBtn.disabled = true;
|
|
status.textContent = "Signing you up…";
|
|
fetch("{{ .Site.Params.eec_base_url }}/courses/" + slug + "/enroll", {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({ email: form.email.value })
|
|
}).then(function (res) {
|
|
if (res.ok) {
|
|
form.reset();
|
|
form.hidden = true;
|
|
status.textContent = "Check your inbox — day one is on its way.";
|
|
return;
|
|
}
|
|
return res.text().then(function (msg) {
|
|
submitBtn.disabled = false;
|
|
status.textContent = msg || "Something went wrong. Try again in a moment.";
|
|
});
|
|
}).catch(function () {
|
|
submitBtn.disabled = false;
|
|
status.textContent = "Something went wrong. Try again in a moment.";
|
|
});
|
|
});
|
|
})();
|
|
</script>
|
|
{{ end }}
|