create_form #48

Merged
esteban merged 42 commits from create_form into main 2026-07-28 11:50:56 +00:00
2 changed files with 37 additions and 0 deletions
Showing only changes of commit 7f146a3cf9 - Show all commits

View File

@ -1,5 +1,6 @@
import type { APIRoute } from "astro";
import { appendRegistrationToSheet } from "../lib/googleSheets";
import { sendEmail } from "../lib/email";
export const prerender = false;
const COLUMNS = [
@ -75,8 +76,14 @@ export const POST: APIRoute = async ({ request }) => {
const result = await appendRegistrationToSheet(row);
await sendEmail({
nombres: formData.nombre,
apellidos: formData.apellido,
}, formData.correo, "CENTRO_DEL_REINO_PAZ_Y_JUSTICIA_POSTULACION");
return Response.json(result);
} catch (error) {
console.error("Error en /api/formulario/send:", error);
return Response.json(
{
success: false,

View File

@ -0,0 +1,30 @@
type TypeEmailData = "CENTRO_DEL_REINO_PAZ_Y_JUSTICIA_INFO" | "CENTRO_DEL_REINO_PAZ_Y_JUSTICIA_POSTULACION";
export async function sendEmail(data: object, to: string, type: TypeEmailData) {
const emailApiKey = import.meta.env.EMAIL_API_KEY;
const dataFinal = {
...data,
email: to,
senderName: "Centro del Reino de Paz y Justicia",
};
const emailResponse = await fetch("https://flows2.carpa.com/webhook/email/send", {
method: "POST",
headers: {
"Content-Type": "application/json",
"x-api-key": emailApiKey!,
},
body: JSON.stringify({
type: type,
data: dataFinal,
}),
});
const responseBody = await emailResponse.text();
if (!emailResponse.ok) {
console.error(`Error enviando correo (status ${emailResponse.status}): ${responseBody}`);
throw new Error(`Error en servicio de correo: ${emailResponse.status}`);
}
}