From 338dc20126a198286b399f67ecb616bbf3e75446 Mon Sep 17 00:00:00 2001 From: kiskaadee Date: Thu, 1 Oct 2026 13:37:26 -0500 Subject: [PATCH] feat(frontend): add RSVP inline editing, deletion, and direct map preview --- frontend/src/admin/RsvpTable.tsx | 394 ++++++++++++++++++++- frontend/src/api/client.ts | 41 +++ frontend/src/invitation/Invitation.tsx | 27 +- frontend/src/invitation/InvitationHero.tsx | 47 ++- frontend/src/invitation/RsvpForm.tsx | 36 ++ frontend/src/invitation/RsvpResult.tsx | 147 +++++++- frontend/src/types/config.ts | 7 + 7 files changed, 670 insertions(+), 29 deletions(-) diff --git a/frontend/src/admin/RsvpTable.tsx b/frontend/src/admin/RsvpTable.tsx index 501d1f1..76ddbac 100644 --- a/frontend/src/admin/RsvpTable.tsx +++ b/frontend/src/admin/RsvpTable.tsx @@ -1,5 +1,10 @@ import { useCallback, useEffect, useState } from "react"; -import { fetchAdminRsvps, getExportCsvUrl } from "../api/client"; +import { + deleteAdminRsvp, + fetchAdminRsvps, + getExportCsvUrl, + updateAdminRsvp, +} from "../api/client"; import { Button } from "../components/Button"; import { Spinner } from "../components/Spinner"; import type { RSVPAdminItem } from "../types/config"; @@ -9,6 +14,14 @@ export function RsvpTable() { const [count, setCount] = useState(0); const [search, setSearch] = useState(""); const [loading, setLoading] = useState(true); + const [deletingId, setDeletingId] = useState(null); + const [editingId, setEditingId] = useState(null); + const [editForm, setEditForm] = useState<{ name: string; phone: string; email: string }>({ + name: "", + phone: "", + email: "", + }); + const [savingId, setSavingId] = useState(null); const [error, setError] = useState(null); const loadData = useCallback(async (searchTerm = "") => { @@ -52,6 +65,71 @@ export function RsvpTable() { return phone; } + async function handleDelete(id: number, name: string) { + const confirmed = window.confirm( + `¿Estás seguro de que deseas eliminar la confirmación de "${name}"? Esta acción no se puede deshacer.`, + ); + if (!confirmed) return; + + setDeletingId(id); + setError(null); + try { + await deleteAdminRsvp(id); + setRsvps((prev) => prev.filter((r) => r.id !== id)); + setCount((prev) => Math.max(0, prev - 1)); + } catch (err) { + setError( + err instanceof Error ? err.message : "Error al eliminar el asistente.", + ); + } finally { + setDeletingId(null); + } + } + + function startEditing(row: RSVPAdminItem) { + setEditingId(row.id); + setEditForm({ + name: row.name, + phone: row.phone, + email: row.email || "", + }); + setError(null); + } + + function cancelEditing() { + setEditingId(null); + setError(null); + } + + async function handleSaveEdit(id: number) { + if (!editForm.name.trim()) { + setError("El nombre no puede estar vacío."); + return; + } + if (!editForm.phone.trim()) { + setError("El teléfono no puede estar vacío."); + return; + } + + setSavingId(id); + setError(null); + try { + const updated = await updateAdminRsvp(id, { + name: editForm.name.trim(), + phone: editForm.phone.trim(), + email: editForm.email.trim() || null, + }); + setRsvps((prev) => prev.map((r) => (r.id === id ? updated : r))); + setEditingId(null); + } catch (err) { + setError( + err instanceof Error ? err.message : "Error al actualizar el asistente.", + ); + } finally { + setSavingId(null); + } + } + return (
{/* Top action bar: Count, Search, Export */} @@ -164,19 +242,20 @@ export function RsvpTable() { Teléfono Correo Fecha de Registro + Acciones {loading ? ( - + ) : rsvps.length === 0 ? ( { - e.currentTarget.style.backgroundColor = "rgba(255, 255, 255, 0.04)"; + if (editingId !== row.id) { + e.currentTarget.style.backgroundColor = "rgba(255, 255, 255, 0.04)"; + } }} onMouseLeave={(e) => { - e.currentTarget.style.backgroundColor = "transparent"; + if (editingId !== row.id) { + e.currentTarget.style.backgroundColor = "transparent"; + } }} > - {row.name} - - - {formatPhone(row.phone)} + {editingId === row.id ? ( + + setEditForm((prev) => ({ ...prev, name: e.target.value })) + } + disabled={savingId === row.id} + placeholder="Nombre completo" + style={{ + width: "100%", + minWidth: "120px", + backgroundColor: "rgba(0, 0, 0, 0.5)", + border: "1px solid var(--color-gold)", + borderRadius: "4px", + color: "#ffffff", + padding: "0.4rem 0.6rem", + fontSize: "0.85rem", + boxSizing: "border-box", + }} + /> + ) : ( + row.name + )} + {editingId === row.id ? ( + + setEditForm((prev) => ({ ...prev, phone: e.target.value })) + } + disabled={savingId === row.id} + placeholder="300 123 4567" + style={{ + width: "100%", + minWidth: "110px", + backgroundColor: "rgba(0, 0, 0, 0.5)", + border: "1px solid var(--color-gold)", + borderRadius: "4px", + color: "var(--color-gold-light)", + padding: "0.4rem 0.6rem", + fontSize: "0.85rem", + boxSizing: "border-box", + }} + /> + ) : ( + formatPhone(row.phone) + )} + + - {row.email || "—"} + {editingId === row.id ? ( + + setEditForm((prev) => ({ ...prev, email: e.target.value })) + } + disabled={savingId === row.id} + placeholder="Opcional" + style={{ + width: "100%", + minWidth: "120px", + backgroundColor: "rgba(0, 0, 0, 0.5)", + border: "1px solid var(--color-gold)", + borderRadius: "4px", + color: "rgba(255, 255, 255, 0.9)", + padding: "0.4rem 0.6rem", + fontSize: "0.85rem", + boxSizing: "border-box", + }} + /> + ) : ( + row.email || "—" + )} {formatDate(row.created_at)} + + {editingId === row.id ? ( +
+ + +
+ ) : ( +
+ + +
+ )} + )) )} @@ -241,5 +606,6 @@ export function RsvpTable() {
+ ); } diff --git a/frontend/src/api/client.ts b/frontend/src/api/client.ts index 2adbb45..cc287db 100644 --- a/frontend/src/api/client.ts +++ b/frontend/src/api/client.ts @@ -1,8 +1,10 @@ import type { InvitationConfig, RSVPApiResult, + RSVPAdminItem, RSVPListResponse, RSVPRequest, + RSVPUpdateRequest, } from "../types/config"; const BASE_API = "/birthday/api"; @@ -117,3 +119,42 @@ export async function regenerateMapPreview( } return res.json(); } + +export async function deleteAdminRsvp(rsvpId: number): Promise { + const res = await fetch(`${BASE_API}/admin/rsvps/${rsvpId}`, { + method: "DELETE", + headers: { Accept: "application/json" }, + }); + + if (!res.ok && res.status !== 204) { + const errorJson = await res.json().catch(() => null); + const msg = errorJson?.detail || `HTTP ${res.status}`; + throw new Error(`Error al eliminar asistente: ${msg}`); + } +} + +export async function updateAdminRsvp( + rsvpId: number, + data: RSVPUpdateRequest, +): Promise { + const res = await fetch(`${BASE_API}/admin/rsvps/${rsvpId}`, { + method: "PATCH", + headers: { + "Content-Type": "application/json", + Accept: "application/json", + }, + body: JSON.stringify(data), + }); + + if (!res.ok) { + const errorJson = await res.json().catch(() => null); + const msg = + errorJson?.detail || + (errorJson?.errors + ? Object.values(errorJson.errors).join(", ") + : `HTTP ${res.status}`); + throw new Error(msg || "Error al actualizar asistente."); + } + return res.json(); +} + diff --git a/frontend/src/invitation/Invitation.tsx b/frontend/src/invitation/Invitation.tsx index 9a8f74b..0941882 100644 --- a/frontend/src/invitation/Invitation.tsx +++ b/frontend/src/invitation/Invitation.tsx @@ -1,4 +1,4 @@ -import { useRef } from "react"; +import { useRef, useState } from "react"; import { Button } from "../components/Button"; import { Spinner } from "../components/Spinner"; import { useConfig } from "../hooks/useConfig"; @@ -11,6 +11,7 @@ import { RsvpResult } from "./RsvpResult"; export function Invitation() { const { config, status, error, reload } = useConfig(); const rsvpForm = useRsvpForm(); + const [showDetailsOnly, setShowDetailsOnly] = useState(false); const rsvpSectionRef = useRef(null); function scrollToRsvp() { @@ -112,7 +113,17 @@ export function Invitation() { }} > {/* Section 1: Invitation Hero */} - + { + setShowDetailsOnly(false); + scrollToRsvp(); + }} + onShowDetailsClick={() => { + setShowDetailsOnly(true); + scrollToRsvp(); + }} + /> {/* Section 2: RSVP / Confirmation Flow */}
- {rsvpForm.formState === "idle" || rsvpForm.formState === "submitting" ? ( + {showDetailsOnly ? ( + setShowDetailsOnly(false)} + isDetailsOnly={true} + onBackToForm={() => setShowDetailsOnly(false)} + /> + ) : rsvpForm.formState === "idle" || rsvpForm.formState === "submitting" ? ( setShowDetailsOnly(true)} /> ) : ( void; + onShowDetailsClick?: () => void; } -export function InvitationHero({ config, onCtaClick }: InvitationHeroProps) { +export function InvitationHero({ + config, + onCtaClick, + onShowDetailsClick, +}: InvitationHeroProps) { // Parse date into Month, Day, and Day of Week const [year, monthNum, dayNum] = config.event_date.split("-").map(Number); const dateObj = new Date(year, (monthNum || 1) - 1, dayNum || 1); @@ -167,8 +172,46 @@ export function InvitationHero({ config, onCtaClick }: InvitationHeroProps) {
{/* 4. RSVP Call to action */} -
+
+ {onShowDetailsClick && ( + + )}
); diff --git a/frontend/src/invitation/RsvpForm.tsx b/frontend/src/invitation/RsvpForm.tsx index b540c43..6c002a2 100644 --- a/frontend/src/invitation/RsvpForm.tsx +++ b/frontend/src/invitation/RsvpForm.tsx @@ -16,6 +16,7 @@ interface RsvpFormProps { formState: RsvpFormState; errors: FormErrors; onSubmit: () => void; + onShowDetails?: () => void; } export function RsvpForm({ @@ -29,6 +30,7 @@ export function RsvpForm({ formState, errors, onSubmit, + onShowDetails, }: RsvpFormProps) { const isSubmitting = formState === "submitting"; @@ -107,6 +109,40 @@ export function RsvpForm({ config.submit_label || "TE VEO AHÍ" )} + + {onShowDetails && ( +
+ +
+ )}
); diff --git a/frontend/src/invitation/RsvpResult.tsx b/frontend/src/invitation/RsvpResult.tsx index 2b9ae8b..7f12ca8 100644 --- a/frontend/src/invitation/RsvpResult.tsx +++ b/frontend/src/invitation/RsvpResult.tsx @@ -11,6 +11,8 @@ interface RsvpResultProps { confirmedName: string; config: InvitationConfig; onRetry: () => void; + isDetailsOnly?: boolean; + onBackToForm?: () => void; } export function RsvpResult({ @@ -18,6 +20,8 @@ export function RsvpResult({ confirmedName, config, onRetry, + isDetailsOnly = false, + onBackToForm, }: RsvpResultProps) { const countdown = useCountdown( config.event_date, @@ -25,14 +29,108 @@ export function RsvpResult({ config.event_timezone, ); + if (isDetailsOnly) { + return ( +
+

+ Ubicación del Evento +

+ +

+ {config.address_name} +

+ + {/* Live Countdown */} + + + {/* Decorative divider dot */} + + + {/* Circular Map Preview and Venue Logistics */} + + + + + {onBackToForm && ( +
+ +
+ )} +
+ ); + } + if (formState === "duplicate") { return (
- ¡Ups! + ¡Ya estás registrado!

{config.msg_duplicate || - "Parece que ya tenemos tus datos registrados. Si necesitas modificar tu información, ponte en contacto con nosotros."} + "Parece que ya tenemos tus datos registrados. ¡Te esperamos!"}

- + + {/* Live Countdown */} + + + {/* Circular Map Preview and Venue Logistics */} + + + + +
+ +
); } diff --git a/frontend/src/types/config.ts b/frontend/src/types/config.ts index 522ed35..2c3f62f 100644 --- a/frontend/src/types/config.ts +++ b/frontend/src/types/config.ts @@ -30,6 +30,13 @@ export interface RSVPRequest { email?: string | null; } +export interface RSVPUpdateRequest { + name?: string; + phone?: string; + email?: string | null; +} + + export type RSVPApiResult = | { result: "SUCCESS"; name: string } | { result: "DUPLICATE" }