Skip to content

Commit dd01e43

Browse files
committed
dummy
1 parent ddc960c commit dd01e43

12 files changed

Lines changed: 171 additions & 13 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"account": {
3+
"id": "5516600d8cb0f28a922c95138413c97c",
4+
"name": "Vinodraj.j@gmail.com's Account"
5+
}
6+
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

assets/js/site.js

Lines changed: 62 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,51 @@ function resolveApiEndpoint(form) {
9999
return new URL(action, envBase.endsWith("/") ? envBase : `${envBase}/`).toString();
100100
}
101101

102+
function formActionPath(form) {
103+
const action = String(form.getAttribute("action") || "").trim();
104+
return action.replace(/^https?:\/\/[^/]+/i, "");
105+
}
106+
107+
function buildApiPayload(form, fd) {
108+
const actionPath = formActionPath(form);
109+
110+
if (actionPath === "/api/small-group") {
111+
return {
112+
name: String(fd.get("name") || "").trim(),
113+
area: String(fd.get("area") || "").trim(),
114+
phone: String(fd.get("phone") || "").trim(),
115+
message: String(fd.get("message") || "").trim()
116+
};
117+
}
118+
119+
if (actionPath === "/api/volunteer") {
120+
return {
121+
name: String(fd.get("name") || "").trim(),
122+
email: String(fd.get("email") || "").trim(),
123+
ministry: String(fd.get("ministry") || "").trim(),
124+
message: String(fd.get("message") || "").trim()
125+
};
126+
}
127+
128+
return {
129+
name: String(fd.get("name") || "").trim(),
130+
email: String(fd.get("email") || "").trim(),
131+
subject: String(fd.get("subject") || "").trim(),
132+
message: String(fd.get("message") || "").trim()
133+
};
134+
}
135+
136+
function successMessageForForm(form) {
137+
const actionPath = formActionPath(form);
138+
if (actionPath === "/api/small-group") {
139+
return "Thank you. Your small group registration has been received.";
140+
}
141+
if (actionPath === "/api/volunteer") {
142+
return "Thank you. Your volunteer signup has been received.";
143+
}
144+
return "Thank you. Your message has been sent.";
145+
}
146+
102147
function initEmailApiForms() {
103148
bySelAll("form[data-email-submit]").forEach((form) => {
104149
form.addEventListener("submit", async (e) => {
@@ -112,12 +157,7 @@ function initEmailApiForms() {
112157
}
113158

114159
const fd = new FormData(form);
115-
const payload = {
116-
name: String(fd.get("name") || "").trim(),
117-
email: String(fd.get("email") || "").trim(),
118-
subject: String(fd.get("subject") || "").trim(),
119-
message: String(fd.get("message") || "").trim()
120-
};
160+
const payload = buildApiPayload(form, fd);
121161

122162
try {
123163
const res = await fetch(resolveApiEndpoint(form), {
@@ -129,12 +169,24 @@ function initEmailApiForms() {
129169
body: JSON.stringify(payload)
130170
});
131171

132-
if (!res.ok) throw new Error("Failed to submit message.");
172+
if (!res.ok) {
173+
let apiError = "Failed to submit form.";
174+
try {
175+
const data = await res.json();
176+
if (data && typeof data.error === "string" && data.error) {
177+
apiError = data.error;
178+
}
179+
} catch (_jsonErr) {
180+
// Keep fallback API error message when response body is not JSON.
181+
}
182+
throw new Error(apiError);
183+
}
133184

134-
setFormMessage(form, "Thank you. Your message has been sent.");
185+
setFormMessage(form, successMessageForForm(form));
135186
form.reset();
136-
} catch (_err) {
137-
setFormMessage(form, "Unable to send right now. Please try again shortly.");
187+
} catch (err) {
188+
const msg = err && err.message ? err.message : "Unable to send right now. Please try again shortly.";
189+
setFormMessage(form, msg);
138190
} finally {
139191
if (submitBtn) {
140192
submitBtn.disabled = false;

contact.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ <h3>Message Us</h3>
8181
<div class="grid grid-2">
8282
<article class="card">
8383
<h3>Small Group Registration</h3>
84-
<form data-generic-form>
84+
<form data-generic-form data-email-submit data-api-dev="http://127.0.0.1:8787" data-api-prod="https://api.ziongospelministry.org" action="/api/small-group" method="POST">
8585
<div class="form-grid">
8686
<label>Name<input name="name" required></label>
8787
<label>Preferred Area<input name="area"></label>
@@ -95,7 +95,7 @@ <h3>Small Group Registration</h3>
9595

9696
<article class="card" id="volunteer">
9797
<h3>Volunteer Signup</h3>
98-
<form data-generic-form>
98+
<form data-generic-form data-email-submit data-api-dev="http://127.0.0.1:8787" data-api-prod="https://api.ziongospelministry.org" action="/api/volunteer" method="POST">
9999
<div class="form-grid">
100100
<label>Name<input name="name" required></label>
101101
<label>Email<input type="email" name="email" required></label>

0 commit comments

Comments
 (0)