import { blob } from "https://esm.town/v/std/blob?v=11";
import { email } from "https://esm.town/v/std/email?v=9";
import { html } from "https://esm.town/v/stevekrouse/html?v=5";
export const renderFormAndSaveData = async (
req: Request,
): Promise<Response> => {
if (req.method !== "POST") {
return new Response("method not allowed", { status: 405 });
}
const events = (await blob.getJSON("events")) ?? {};
const formData = await req.formData();
const id = formData.get("id");
const name = formData.get("name");
const plusOnes = formData.get("plus_ones");
let event = events[id] ?? {};
await email({
text: `${name} rsvp'd to ${id}. plus ones: ${plusOnes}`,
subject: `new rsvp to ${id}`,
});
const rsvps = event.rsvps ?? [];
event = {
...event,
rsvps,
};
events[id] = event;
await blob.setJSON(
"events",
events,
);
return new Response("thanks! you're signed up!");
};