feat(frontend): add RSVP inline editing, deletion, and direct map preview
This commit is contained in:
1 parent
6880b74b60
commit
338dc20126
7 files changed
+670
-29
No files matched your search
@@ -1,5 +1,10 @@
|
|||||||
import { useCallback, useEffect, useState } from "react";
|
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 { Button } from "../components/Button";
|
||||||
import { Spinner } from "../components/Spinner";
|
import { Spinner } from "../components/Spinner";
|
||||||
import type { RSVPAdminItem } from "../types/config";
|
import type { RSVPAdminItem } from "../types/config";
|
||||||
@@ -9,6 +14,14 @@ export function RsvpTable() {
|
|||||||
const [count, setCount] = useState<number>(0);
|
const [count, setCount] = useState<number>(0);
|
||||||
const [search, setSearch] = useState<string>("");
|
const [search, setSearch] = useState<string>("");
|
||||||
const [loading, setLoading] = useState<boolean>(true);
|
const [loading, setLoading] = useState<boolean>(true);
|
||||||
|
const [deletingId, setDeletingId] = useState<number | null>(null);
|
||||||
|
const [editingId, setEditingId] = useState<number | null>(null);
|
||||||
|
const [editForm, setEditForm] = useState<{ name: string; phone: string; email: string }>({
|
||||||
|
name: "",
|
||||||
|
phone: "",
|
||||||
|
email: "",
|
||||||
|
});
|
||||||
|
const [savingId, setSavingId] = useState<number | null>(null);
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
|
||||||
const loadData = useCallback(async (searchTerm = "") => {
|
const loadData = useCallback(async (searchTerm = "") => {
|
||||||
@@ -52,6 +65,71 @@ export function RsvpTable() {
|
|||||||
return phone;
|
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 (
|
return (
|
||||||
<div>
|
<div>
|
||||||
{/* Top action bar: Count, Search, Export */}
|
{/* Top action bar: Count, Search, Export */}
|
||||||
@@ -164,19 +242,20 @@ export function RsvpTable() {
|
|||||||
<th style={{ padding: "0.9rem 1.2rem" }}>Teléfono</th>
|
<th style={{ padding: "0.9rem 1.2rem" }}>Teléfono</th>
|
||||||
<th style={{ padding: "0.9rem 1.2rem" }}>Correo</th>
|
<th style={{ padding: "0.9rem 1.2rem" }}>Correo</th>
|
||||||
<th style={{ padding: "0.9rem 1.2rem" }}>Fecha de Registro</th>
|
<th style={{ padding: "0.9rem 1.2rem" }}>Fecha de Registro</th>
|
||||||
|
<th style={{ padding: "0.9rem 1.2rem", textAlign: "right" }}>Acciones</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{loading ? (
|
{loading ? (
|
||||||
<tr>
|
<tr>
|
||||||
<td colSpan={4} style={{ padding: "3rem", textAlign: "center" }}>
|
<td colSpan={5} style={{ padding: "3rem", textAlign: "center" }}>
|
||||||
<Spinner size={28} />
|
<Spinner size={28} />
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
) : rsvps.length === 0 ? (
|
) : rsvps.length === 0 ? (
|
||||||
<tr>
|
<tr>
|
||||||
<td
|
<td
|
||||||
colSpan={4}
|
colSpan={5}
|
||||||
style={{
|
style={{
|
||||||
padding: "3rem",
|
padding: "3rem",
|
||||||
textAlign: "center",
|
textAlign: "center",
|
||||||
@@ -194,36 +273,116 @@ export function RsvpTable() {
|
|||||||
key={row.id}
|
key={row.id}
|
||||||
style={{
|
style={{
|
||||||
borderBottom: "1px solid rgba(255, 255, 255, 0.06)",
|
borderBottom: "1px solid rgba(255, 255, 255, 0.06)",
|
||||||
|
backgroundColor:
|
||||||
|
editingId === row.id
|
||||||
|
? "rgba(212, 168, 67, 0.08)"
|
||||||
|
: "transparent",
|
||||||
transition: "background-color 0.15s ease",
|
transition: "background-color 0.15s ease",
|
||||||
}}
|
}}
|
||||||
onMouseEnter={(e) => {
|
onMouseEnter={(e) => {
|
||||||
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) => {
|
onMouseLeave={(e) => {
|
||||||
e.currentTarget.style.backgroundColor = "transparent";
|
if (editingId !== row.id) {
|
||||||
|
e.currentTarget.style.backgroundColor = "transparent";
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<td
|
<td
|
||||||
style={{
|
style={{
|
||||||
padding: "0.9rem 1.2rem",
|
padding: editingId === row.id ? "0.5rem 0.8rem" : "0.9rem 1.2rem",
|
||||||
fontWeight: 500,
|
fontWeight: 500,
|
||||||
color: "#ffffff",
|
color: "#ffffff",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{row.name}
|
{editingId === row.id ? (
|
||||||
</td>
|
<input
|
||||||
<td
|
type="text"
|
||||||
style={{ padding: "0.9rem 1.2rem", color: "var(--color-gold-light)" }}
|
value={editForm.name}
|
||||||
>
|
onChange={(e) =>
|
||||||
{formatPhone(row.phone)}
|
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
|
||||||
|
)}
|
||||||
</td>
|
</td>
|
||||||
<td
|
<td
|
||||||
style={{
|
style={{
|
||||||
padding: "0.9rem 1.2rem",
|
padding: editingId === row.id ? "0.5rem 0.8rem" : "0.9rem 1.2rem",
|
||||||
|
color: "var(--color-gold-light)",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{editingId === row.id ? (
|
||||||
|
<input
|
||||||
|
type="tel"
|
||||||
|
value={editForm.phone}
|
||||||
|
onChange={(e) =>
|
||||||
|
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)
|
||||||
|
)}
|
||||||
|
</td>
|
||||||
|
<td
|
||||||
|
style={{
|
||||||
|
padding: editingId === row.id ? "0.5rem 0.8rem" : "0.9rem 1.2rem",
|
||||||
color: "rgba(255, 255, 255, 0.7)",
|
color: "rgba(255, 255, 255, 0.7)",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{row.email || "—"}
|
{editingId === row.id ? (
|
||||||
|
<input
|
||||||
|
type="email"
|
||||||
|
value={editForm.email}
|
||||||
|
onChange={(e) =>
|
||||||
|
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 || "—"
|
||||||
|
)}
|
||||||
</td>
|
</td>
|
||||||
<td
|
<td
|
||||||
style={{
|
style={{
|
||||||
@@ -234,6 +393,212 @@ export function RsvpTable() {
|
|||||||
>
|
>
|
||||||
{formatDate(row.created_at)}
|
{formatDate(row.created_at)}
|
||||||
</td>
|
</td>
|
||||||
|
<td style={{ padding: "0.9rem 1.2rem", textAlign: "right", whiteSpace: "nowrap" }}>
|
||||||
|
{editingId === row.id ? (
|
||||||
|
<div style={{ display: "inline-flex", alignItems: "center", gap: "0.4rem" }}>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
disabled={savingId === row.id}
|
||||||
|
onClick={() => handleSaveEdit(row.id)}
|
||||||
|
style={{
|
||||||
|
background: "rgba(76, 175, 80, 0.15)",
|
||||||
|
border: "1px solid rgba(76, 175, 80, 0.4)",
|
||||||
|
borderRadius: "4px",
|
||||||
|
color: "#81c784",
|
||||||
|
padding: "0.45rem 0.65rem",
|
||||||
|
cursor: savingId === row.id ? "not-allowed" : "pointer",
|
||||||
|
display: "inline-flex",
|
||||||
|
alignItems: "center",
|
||||||
|
justifyContent: "center",
|
||||||
|
transition: "all 0.15s ease",
|
||||||
|
outline: "none",
|
||||||
|
}}
|
||||||
|
onMouseEnter={(e) => {
|
||||||
|
if (savingId !== row.id) {
|
||||||
|
e.currentTarget.style.backgroundColor = "rgba(76, 175, 80, 0.3)";
|
||||||
|
e.currentTarget.style.borderColor = "#81c784";
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
onMouseLeave={(e) => {
|
||||||
|
e.currentTarget.style.backgroundColor = "rgba(76, 175, 80, 0.15)";
|
||||||
|
e.currentTarget.style.borderColor = "rgba(76, 175, 80, 0.4)";
|
||||||
|
}}
|
||||||
|
title="Guardar cambios"
|
||||||
|
aria-label="Guardar cambios"
|
||||||
|
>
|
||||||
|
{savingId === row.id ? (
|
||||||
|
<Spinner size={14} />
|
||||||
|
) : (
|
||||||
|
<svg
|
||||||
|
width="15"
|
||||||
|
height="15"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
fill="none"
|
||||||
|
stroke="currentColor"
|
||||||
|
strokeWidth="2.5"
|
||||||
|
strokeLinecap="round"
|
||||||
|
strokeLinejoin="round"
|
||||||
|
role="img"
|
||||||
|
aria-label="Guardar"
|
||||||
|
>
|
||||||
|
<polyline points="20 6 9 17 4 12" />
|
||||||
|
</svg>
|
||||||
|
)}
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
disabled={savingId === row.id}
|
||||||
|
onClick={cancelEditing}
|
||||||
|
style={{
|
||||||
|
background: "rgba(255, 255, 255, 0.08)",
|
||||||
|
border: "1px solid rgba(255, 255, 255, 0.2)",
|
||||||
|
borderRadius: "4px",
|
||||||
|
color: "rgba(255, 255, 255, 0.7)",
|
||||||
|
padding: "0.45rem 0.65rem",
|
||||||
|
cursor: savingId === row.id ? "not-allowed" : "pointer",
|
||||||
|
display: "inline-flex",
|
||||||
|
alignItems: "center",
|
||||||
|
justifyContent: "center",
|
||||||
|
transition: "all 0.15s ease",
|
||||||
|
outline: "none",
|
||||||
|
}}
|
||||||
|
onMouseEnter={(e) => {
|
||||||
|
if (savingId !== row.id) {
|
||||||
|
e.currentTarget.style.backgroundColor = "rgba(255, 255, 255, 0.18)";
|
||||||
|
e.currentTarget.style.color = "#ffffff";
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
onMouseLeave={(e) => {
|
||||||
|
e.currentTarget.style.backgroundColor = "rgba(255, 255, 255, 0.08)";
|
||||||
|
e.currentTarget.style.color = "rgba(255, 255, 255, 0.7)";
|
||||||
|
}}
|
||||||
|
title="Cancelar edición"
|
||||||
|
aria-label="Cancelar edición"
|
||||||
|
>
|
||||||
|
<svg
|
||||||
|
width="15"
|
||||||
|
height="15"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
fill="none"
|
||||||
|
stroke="currentColor"
|
||||||
|
strokeWidth="2.5"
|
||||||
|
strokeLinecap="round"
|
||||||
|
strokeLinejoin="round"
|
||||||
|
role="img"
|
||||||
|
aria-label="Cancelar"
|
||||||
|
>
|
||||||
|
<line x1="18" y1="6" x2="6" y2="18" />
|
||||||
|
<line x1="6" y1="6" x2="18" y2="18" />
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div style={{ display: "inline-flex", alignItems: "center", gap: "0.4rem" }}>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
disabled={deletingId === row.id || editingId !== null}
|
||||||
|
onClick={() => startEditing(row)}
|
||||||
|
style={{
|
||||||
|
background: "rgba(212, 168, 67, 0.1)",
|
||||||
|
border: "1px solid rgba(212, 168, 67, 0.35)",
|
||||||
|
borderRadius: "4px",
|
||||||
|
color: "var(--color-gold)",
|
||||||
|
padding: "0.45rem 0.65rem",
|
||||||
|
cursor:
|
||||||
|
deletingId === row.id || editingId !== null ? "not-allowed" : "pointer",
|
||||||
|
display: "inline-flex",
|
||||||
|
alignItems: "center",
|
||||||
|
justifyContent: "center",
|
||||||
|
transition: "all 0.15s ease",
|
||||||
|
outline: "none",
|
||||||
|
opacity: editingId !== null && editingId !== row.id ? 0.35 : 1,
|
||||||
|
}}
|
||||||
|
onMouseEnter={(e) => {
|
||||||
|
if (deletingId !== row.id && editingId === null) {
|
||||||
|
e.currentTarget.style.backgroundColor = "rgba(212, 168, 67, 0.25)";
|
||||||
|
e.currentTarget.style.borderColor = "var(--color-gold-light)";
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
onMouseLeave={(e) => {
|
||||||
|
e.currentTarget.style.backgroundColor = "rgba(212, 168, 67, 0.1)";
|
||||||
|
e.currentTarget.style.borderColor = "rgba(212, 168, 67, 0.35)";
|
||||||
|
}}
|
||||||
|
title={`Editar confirmación de ${row.name}`}
|
||||||
|
aria-label={`Editar confirmación de ${row.name}`}
|
||||||
|
>
|
||||||
|
<svg
|
||||||
|
width="15"
|
||||||
|
height="15"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
fill="none"
|
||||||
|
stroke="currentColor"
|
||||||
|
strokeWidth="2"
|
||||||
|
strokeLinecap="round"
|
||||||
|
strokeLinejoin="round"
|
||||||
|
role="img"
|
||||||
|
aria-label="Editar"
|
||||||
|
>
|
||||||
|
<path d="M12 20h9" />
|
||||||
|
<path d="M16.5 3.5a2.121 2.121 0 0 1 3 3L7 19l-4 1 1-4L16.5 3.5z" />
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
disabled={deletingId === row.id || editingId !== null}
|
||||||
|
onClick={() => handleDelete(row.id, row.name)}
|
||||||
|
style={{
|
||||||
|
background: "rgba(255, 82, 82, 0.1)",
|
||||||
|
border: "1px solid rgba(255, 82, 82, 0.35)",
|
||||||
|
borderRadius: "4px",
|
||||||
|
color: "#ff5252",
|
||||||
|
padding: "0.45rem 0.65rem",
|
||||||
|
cursor:
|
||||||
|
deletingId === row.id || editingId !== null ? "not-allowed" : "pointer",
|
||||||
|
display: "inline-flex",
|
||||||
|
alignItems: "center",
|
||||||
|
justifyContent: "center",
|
||||||
|
transition: "all 0.15s ease",
|
||||||
|
outline: "none",
|
||||||
|
opacity: editingId !== null && editingId !== row.id ? 0.35 : 1,
|
||||||
|
}}
|
||||||
|
onMouseEnter={(e) => {
|
||||||
|
if (deletingId !== row.id && editingId === null) {
|
||||||
|
e.currentTarget.style.backgroundColor = "rgba(255, 82, 82, 0.25)";
|
||||||
|
e.currentTarget.style.borderColor = "#ff5252";
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
onMouseLeave={(e) => {
|
||||||
|
e.currentTarget.style.backgroundColor = "rgba(255, 82, 82, 0.1)";
|
||||||
|
e.currentTarget.style.borderColor = "rgba(255, 82, 82, 0.35)";
|
||||||
|
}}
|
||||||
|
title={`Eliminar confirmación de ${row.name}`}
|
||||||
|
aria-label={`Eliminar confirmación de ${row.name}`}
|
||||||
|
>
|
||||||
|
{deletingId === row.id ? (
|
||||||
|
<Spinner size={14} />
|
||||||
|
) : (
|
||||||
|
<svg
|
||||||
|
width="15"
|
||||||
|
height="15"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
fill="none"
|
||||||
|
stroke="currentColor"
|
||||||
|
strokeWidth="2"
|
||||||
|
strokeLinecap="round"
|
||||||
|
strokeLinejoin="round"
|
||||||
|
role="img"
|
||||||
|
aria-label="Eliminar"
|
||||||
|
>
|
||||||
|
<polyline points="3 6 5 6 21 6" />
|
||||||
|
<path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2" />
|
||||||
|
<line x1="10" y1="11" x2="10" y2="17" />
|
||||||
|
<line x1="14" y1="11" x2="14" y2="17" />
|
||||||
|
</svg>
|
||||||
|
)}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
))
|
))
|
||||||
)}
|
)}
|
||||||
@@ -241,5 +606,6 @@ export function RsvpTable() {
|
|||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,10 @@
|
|||||||
import type {
|
import type {
|
||||||
InvitationConfig,
|
InvitationConfig,
|
||||||
RSVPApiResult,
|
RSVPApiResult,
|
||||||
|
RSVPAdminItem,
|
||||||
RSVPListResponse,
|
RSVPListResponse,
|
||||||
RSVPRequest,
|
RSVPRequest,
|
||||||
|
RSVPUpdateRequest,
|
||||||
} from "../types/config";
|
} from "../types/config";
|
||||||
|
|
||||||
const BASE_API = "/birthday/api";
|
const BASE_API = "/birthday/api";
|
||||||
@@ -117,3 +119,42 @@ export async function regenerateMapPreview(
|
|||||||
}
|
}
|
||||||
return res.json();
|
return res.json();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function deleteAdminRsvp(rsvpId: number): Promise<void> {
|
||||||
|
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<RSVPAdminItem> {
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { useRef } from "react";
|
import { useRef, useState } from "react";
|
||||||
import { Button } from "../components/Button";
|
import { Button } from "../components/Button";
|
||||||
import { Spinner } from "../components/Spinner";
|
import { Spinner } from "../components/Spinner";
|
||||||
import { useConfig } from "../hooks/useConfig";
|
import { useConfig } from "../hooks/useConfig";
|
||||||
@@ -11,6 +11,7 @@ import { RsvpResult } from "./RsvpResult";
|
|||||||
export function Invitation() {
|
export function Invitation() {
|
||||||
const { config, status, error, reload } = useConfig();
|
const { config, status, error, reload } = useConfig();
|
||||||
const rsvpForm = useRsvpForm();
|
const rsvpForm = useRsvpForm();
|
||||||
|
const [showDetailsOnly, setShowDetailsOnly] = useState(false);
|
||||||
const rsvpSectionRef = useRef<HTMLDivElement | null>(null);
|
const rsvpSectionRef = useRef<HTMLDivElement | null>(null);
|
||||||
|
|
||||||
function scrollToRsvp() {
|
function scrollToRsvp() {
|
||||||
@@ -112,7 +113,17 @@ export function Invitation() {
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{/* Section 1: Invitation Hero */}
|
{/* Section 1: Invitation Hero */}
|
||||||
<InvitationHero config={config} onCtaClick={scrollToRsvp} />
|
<InvitationHero
|
||||||
|
config={config}
|
||||||
|
onCtaClick={() => {
|
||||||
|
setShowDetailsOnly(false);
|
||||||
|
scrollToRsvp();
|
||||||
|
}}
|
||||||
|
onShowDetailsClick={() => {
|
||||||
|
setShowDetailsOnly(true);
|
||||||
|
scrollToRsvp();
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
{/* Section 2: RSVP / Confirmation Flow */}
|
{/* Section 2: RSVP / Confirmation Flow */}
|
||||||
<div
|
<div
|
||||||
@@ -129,7 +140,16 @@ export function Invitation() {
|
|||||||
position: "relative",
|
position: "relative",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{rsvpForm.formState === "idle" || rsvpForm.formState === "submitting" ? (
|
{showDetailsOnly ? (
|
||||||
|
<RsvpResult
|
||||||
|
formState="idle"
|
||||||
|
confirmedName=""
|
||||||
|
config={config}
|
||||||
|
onRetry={() => setShowDetailsOnly(false)}
|
||||||
|
isDetailsOnly={true}
|
||||||
|
onBackToForm={() => setShowDetailsOnly(false)}
|
||||||
|
/>
|
||||||
|
) : rsvpForm.formState === "idle" || rsvpForm.formState === "submitting" ? (
|
||||||
<RsvpForm
|
<RsvpForm
|
||||||
config={config}
|
config={config}
|
||||||
name={rsvpForm.name}
|
name={rsvpForm.name}
|
||||||
@@ -141,6 +161,7 @@ export function Invitation() {
|
|||||||
formState={rsvpForm.formState}
|
formState={rsvpForm.formState}
|
||||||
errors={rsvpForm.errors}
|
errors={rsvpForm.errors}
|
||||||
onSubmit={rsvpForm.submit}
|
onSubmit={rsvpForm.submit}
|
||||||
|
onShowDetails={() => setShowDetailsOnly(true)}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<RsvpResult
|
<RsvpResult
|
||||||
|
|||||||
@@ -4,9 +4,14 @@ import { RsvpCta } from "./RsvpCta";
|
|||||||
interface InvitationHeroProps {
|
interface InvitationHeroProps {
|
||||||
config: InvitationConfig;
|
config: InvitationConfig;
|
||||||
onCtaClick: () => void;
|
onCtaClick: () => 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
|
// Parse date into Month, Day, and Day of Week
|
||||||
const [year, monthNum, dayNum] = config.event_date.split("-").map(Number);
|
const [year, monthNum, dayNum] = config.event_date.split("-").map(Number);
|
||||||
const dateObj = new Date(year, (monthNum || 1) - 1, dayNum || 1);
|
const dateObj = new Date(year, (monthNum || 1) - 1, dayNum || 1);
|
||||||
@@ -167,8 +172,46 @@ export function InvitationHero({ config, onCtaClick }: InvitationHeroProps) {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* 4. RSVP Call to action */}
|
{/* 4. RSVP Call to action */}
|
||||||
<div style={{ marginBottom: "1rem" }}>
|
<div
|
||||||
|
style={{
|
||||||
|
marginBottom: "1rem",
|
||||||
|
display: "flex",
|
||||||
|
flexDirection: "column",
|
||||||
|
alignItems: "center",
|
||||||
|
gap: "0.8rem",
|
||||||
|
}}
|
||||||
|
>
|
||||||
<RsvpCta label={config.rsvp_cta} onClick={onCtaClick} />
|
<RsvpCta label={config.rsvp_cta} onClick={onCtaClick} />
|
||||||
|
{onShowDetailsClick && (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={onShowDetailsClick}
|
||||||
|
style={{
|
||||||
|
background: "none",
|
||||||
|
border: "none",
|
||||||
|
color: "var(--color-text-muted)",
|
||||||
|
fontSize: "0.74rem",
|
||||||
|
letterSpacing: "0.14em",
|
||||||
|
textTransform: "uppercase",
|
||||||
|
cursor: "pointer",
|
||||||
|
padding: "0.3rem 0.6rem",
|
||||||
|
textDecoration: "underline",
|
||||||
|
textUnderlineOffset: "3px",
|
||||||
|
opacity: 0.8,
|
||||||
|
transition: "opacity 0.2s ease, color 0.2s ease",
|
||||||
|
}}
|
||||||
|
onMouseEnter={(e) => {
|
||||||
|
e.currentTarget.style.opacity = "1";
|
||||||
|
e.currentTarget.style.color = "var(--color-gold)";
|
||||||
|
}}
|
||||||
|
onMouseLeave={(e) => {
|
||||||
|
e.currentTarget.style.opacity = "0.8";
|
||||||
|
e.currentTarget.style.color = "var(--color-text-muted)";
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
¿Ya confirmaste? Ver ubicación y mapa
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ interface RsvpFormProps {
|
|||||||
formState: RsvpFormState;
|
formState: RsvpFormState;
|
||||||
errors: FormErrors;
|
errors: FormErrors;
|
||||||
onSubmit: () => void;
|
onSubmit: () => void;
|
||||||
|
onShowDetails?: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function RsvpForm({
|
export function RsvpForm({
|
||||||
@@ -29,6 +30,7 @@ export function RsvpForm({
|
|||||||
formState,
|
formState,
|
||||||
errors,
|
errors,
|
||||||
onSubmit,
|
onSubmit,
|
||||||
|
onShowDetails,
|
||||||
}: RsvpFormProps) {
|
}: RsvpFormProps) {
|
||||||
const isSubmitting = formState === "submitting";
|
const isSubmitting = formState === "submitting";
|
||||||
|
|
||||||
@@ -107,6 +109,40 @@ export function RsvpForm({
|
|||||||
config.submit_label || "TE VEO AHÍ"
|
config.submit_label || "TE VEO AHÍ"
|
||||||
)}
|
)}
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
|
{onShowDetails && (
|
||||||
|
<div style={{ marginTop: "1.4rem" }}>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={onShowDetails}
|
||||||
|
style={{
|
||||||
|
background: "none",
|
||||||
|
border: "none",
|
||||||
|
color: "var(--color-gold)",
|
||||||
|
fontSize: "0.78rem",
|
||||||
|
letterSpacing: "0.14em",
|
||||||
|
textTransform: "uppercase",
|
||||||
|
cursor: "pointer",
|
||||||
|
padding: "0.4rem 0.8rem",
|
||||||
|
borderRadius: "4px",
|
||||||
|
textDecoration: "underline",
|
||||||
|
textUnderlineOffset: "4px",
|
||||||
|
opacity: 0.85,
|
||||||
|
transition: "opacity 0.2s ease, color 0.2s ease",
|
||||||
|
}}
|
||||||
|
onMouseEnter={(e) => {
|
||||||
|
e.currentTarget.style.opacity = "1";
|
||||||
|
e.currentTarget.style.color = "var(--color-gold-light)";
|
||||||
|
}}
|
||||||
|
onMouseLeave={(e) => {
|
||||||
|
e.currentTarget.style.opacity = "0.85";
|
||||||
|
e.currentTarget.style.color = "var(--color-gold)";
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
¿Ya confirmaste? Ver ubicación y mapa ↓
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ interface RsvpResultProps {
|
|||||||
confirmedName: string;
|
confirmedName: string;
|
||||||
config: InvitationConfig;
|
config: InvitationConfig;
|
||||||
onRetry: () => void;
|
onRetry: () => void;
|
||||||
|
isDetailsOnly?: boolean;
|
||||||
|
onBackToForm?: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function RsvpResult({
|
export function RsvpResult({
|
||||||
@@ -18,6 +20,8 @@ export function RsvpResult({
|
|||||||
confirmedName,
|
confirmedName,
|
||||||
config,
|
config,
|
||||||
onRetry,
|
onRetry,
|
||||||
|
isDetailsOnly = false,
|
||||||
|
onBackToForm,
|
||||||
}: RsvpResultProps) {
|
}: RsvpResultProps) {
|
||||||
const countdown = useCountdown(
|
const countdown = useCountdown(
|
||||||
config.event_date,
|
config.event_date,
|
||||||
@@ -25,14 +29,108 @@ export function RsvpResult({
|
|||||||
config.event_timezone,
|
config.event_timezone,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (isDetailsOnly) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
width: "100%",
|
||||||
|
maxWidth: "440px",
|
||||||
|
margin: "0 auto",
|
||||||
|
padding: "1.5rem 1.5rem 3.5rem 1.5rem",
|
||||||
|
textAlign: "center",
|
||||||
|
}}
|
||||||
|
aria-live="polite"
|
||||||
|
>
|
||||||
|
<h3
|
||||||
|
style={{
|
||||||
|
fontFamily: "var(--font-display)",
|
||||||
|
fontSize: "clamp(2.8rem, 9vw, 3.6rem)",
|
||||||
|
fontWeight: 400,
|
||||||
|
color: "var(--color-gold-light)",
|
||||||
|
lineHeight: 1.15,
|
||||||
|
marginBottom: "0.4rem",
|
||||||
|
textShadow: "0 2px 20px rgba(212, 168, 67, 0.4)",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Ubicación del Evento
|
||||||
|
</h3>
|
||||||
|
|
||||||
|
<p
|
||||||
|
style={{
|
||||||
|
fontSize: "0.85rem",
|
||||||
|
fontWeight: 600,
|
||||||
|
letterSpacing: "0.18em",
|
||||||
|
color: "var(--color-gold)",
|
||||||
|
textTransform: "uppercase",
|
||||||
|
marginBottom: "1.5rem",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{config.address_name}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
{/* Live Countdown */}
|
||||||
|
<Countdown
|
||||||
|
days={countdown.days}
|
||||||
|
hours={countdown.hours}
|
||||||
|
minutes={countdown.minutes}
|
||||||
|
seconds={countdown.seconds}
|
||||||
|
state={countdown.state}
|
||||||
|
label={config.countdown_label}
|
||||||
|
inProgressLabel={config.countdown_in_progress}
|
||||||
|
finishedLabel={config.countdown_finished}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* Decorative divider dot */}
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: "flex",
|
||||||
|
justifyContent: "center",
|
||||||
|
gap: "0.4rem",
|
||||||
|
margin: "1.5rem 0",
|
||||||
|
color: "var(--color-gold)",
|
||||||
|
opacity: 0.5,
|
||||||
|
fontSize: "1.2rem",
|
||||||
|
}}
|
||||||
|
aria-hidden="true"
|
||||||
|
>
|
||||||
|
<span>·</span>
|
||||||
|
<span>·</span>
|
||||||
|
<span>·</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Circular Map Preview and Venue Logistics */}
|
||||||
|
<MapPreview
|
||||||
|
previewUrl={config.map_preview_url}
|
||||||
|
mapUrl={config.map_url}
|
||||||
|
venueName={config.address_name}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<VenueInfo venueName={config.address_name} addressLines={config.address_lines} />
|
||||||
|
|
||||||
|
{onBackToForm && (
|
||||||
|
<div style={{ marginTop: "2.5rem" }}>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
onClick={onBackToForm}
|
||||||
|
style={{ fontSize: "0.75rem", padding: "0.6rem 1.4rem" }}
|
||||||
|
>
|
||||||
|
« VOLVER AL FORMULARIO DE ASISTENCIA
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (formState === "duplicate") {
|
if (formState === "duplicate") {
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
width: "100%",
|
width: "100%",
|
||||||
maxWidth: "420px",
|
maxWidth: "440px",
|
||||||
margin: "0 auto",
|
margin: "0 auto",
|
||||||
padding: "2.5rem 1.5rem",
|
padding: "1.5rem 1.5rem 3.5rem 1.5rem",
|
||||||
textAlign: "center",
|
textAlign: "center",
|
||||||
}}
|
}}
|
||||||
role="alert"
|
role="alert"
|
||||||
@@ -40,29 +138,58 @@ export function RsvpResult({
|
|||||||
<h3
|
<h3
|
||||||
style={{
|
style={{
|
||||||
fontFamily: "var(--font-display)",
|
fontFamily: "var(--font-display)",
|
||||||
fontSize: "3.2rem",
|
fontSize: "clamp(2.8rem, 9vw, 3.6rem)",
|
||||||
fontWeight: 400,
|
fontWeight: 400,
|
||||||
color: "var(--color-gold-light)",
|
color: "var(--color-gold-light)",
|
||||||
marginBottom: "1rem",
|
marginBottom: "0.8rem",
|
||||||
textShadow: "0 2px 14px rgba(212, 168, 67, 0.3)",
|
textShadow: "0 2px 14px rgba(212, 168, 67, 0.3)",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
¡Ups!
|
¡Ya estás registrado!
|
||||||
</h3>
|
</h3>
|
||||||
<p
|
<p
|
||||||
style={{
|
style={{
|
||||||
fontSize: "0.92rem",
|
fontSize: "0.92rem",
|
||||||
lineHeight: 1.7,
|
lineHeight: 1.7,
|
||||||
color: "var(--color-text-muted)",
|
color: "var(--color-text-muted)",
|
||||||
marginBottom: "2rem",
|
marginBottom: "1.8rem",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{config.msg_duplicate ||
|
{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!"}
|
||||||
</p>
|
</p>
|
||||||
<Button variant="outline" onClick={onRetry}>
|
|
||||||
VOLVER AL FORMULARIO
|
{/* Live Countdown */}
|
||||||
</Button>
|
<Countdown
|
||||||
|
days={countdown.days}
|
||||||
|
hours={countdown.hours}
|
||||||
|
minutes={countdown.minutes}
|
||||||
|
seconds={countdown.seconds}
|
||||||
|
state={countdown.state}
|
||||||
|
label={config.countdown_label}
|
||||||
|
inProgressLabel={config.countdown_in_progress}
|
||||||
|
finishedLabel={config.countdown_finished}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* Circular Map Preview and Venue Logistics */}
|
||||||
|
<MapPreview
|
||||||
|
previewUrl={config.map_preview_url}
|
||||||
|
mapUrl={config.map_url}
|
||||||
|
venueName={config.address_name}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<VenueInfo venueName={config.address_name} addressLines={config.address_lines} />
|
||||||
|
|
||||||
|
<div style={{ marginTop: "2rem" }}>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
onClick={onRetry}
|
||||||
|
style={{ fontSize: "0.75rem", padding: "0.6rem 1.4rem" }}
|
||||||
|
>
|
||||||
|
VOLVER AL FORMULARIO
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,13 @@ export interface RSVPRequest {
|
|||||||
email?: string | null;
|
email?: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface RSVPUpdateRequest {
|
||||||
|
name?: string;
|
||||||
|
phone?: string;
|
||||||
|
email?: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
export type RSVPApiResult =
|
export type RSVPApiResult =
|
||||||
| { result: "SUCCESS"; name: string }
|
| { result: "SUCCESS"; name: string }
|
||||||
| { result: "DUPLICATE" }
|
| { result: "DUPLICATE" }
|
||||||
|
|||||||
Reference in new issue
Block a user