Compare commits
2
Commits
c44ecfc14b
...
338dc20126
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
338dc20126 | ||
|
|
6880b74b60 |
No files matched your search
@@ -13,11 +13,13 @@ from ..schemas import (
|
|||||||
GenerateMapPreviewResponse,
|
GenerateMapPreviewResponse,
|
||||||
InvitationConfigResponse,
|
InvitationConfigResponse,
|
||||||
InvitationConfigUpdate,
|
InvitationConfigUpdate,
|
||||||
|
RSVPAdminItem,
|
||||||
RSVPListResponse,
|
RSVPListResponse,
|
||||||
|
RSVPUpdate,
|
||||||
)
|
)
|
||||||
from ..services.config import get_config, seed_default_config, update_config
|
from ..services.config import get_config, seed_default_config, update_config
|
||||||
from ..services.map_preview import generate_map_preview_image, resolve_google_maps_coordinates
|
from ..services.map_preview import generate_map_preview_image, resolve_google_maps_coordinates
|
||||||
from ..services.rsvp import get_rsvps
|
from ..services.rsvp import delete_rsvp, get_rsvps, update_rsvp
|
||||||
|
|
||||||
router = APIRouter(tags=["Admin"])
|
router = APIRouter(tags=["Admin"])
|
||||||
|
|
||||||
@@ -82,6 +84,67 @@ def list_rsvps(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@router.delete(
|
||||||
|
"/rsvps/{rsvp_id}",
|
||||||
|
status_code=status.HTTP_204_NO_CONTENT,
|
||||||
|
summary="Eliminar confirmación de asistencia",
|
||||||
|
description="Elimina permanentemente un registro de RSVP por su identificador.",
|
||||||
|
responses={
|
||||||
|
204: {"description": "Registro eliminado con éxito."},
|
||||||
|
404: {"description": "Registro no encontrado."},
|
||||||
|
**ADMIN_401,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
def delete_rsvp_endpoint(
|
||||||
|
rsvp_id: int,
|
||||||
|
admin: AdminDep,
|
||||||
|
db: DbDep,
|
||||||
|
):
|
||||||
|
deleted = delete_rsvp(db, rsvp_id)
|
||||||
|
if not deleted:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=status.HTTP_404_NOT_FOUND,
|
||||||
|
detail=f"No se encontró el registro con ID {rsvp_id}",
|
||||||
|
)
|
||||||
|
return Response(status_code=status.HTTP_204_NO_CONTENT)
|
||||||
|
|
||||||
|
|
||||||
|
@router.patch(
|
||||||
|
"/rsvps/{rsvp_id}",
|
||||||
|
response_model=RSVPAdminItem,
|
||||||
|
summary="Editar una confirmación de asistencia",
|
||||||
|
description="Actualiza el nombre, teléfono o correo de un asistente confirmado.",
|
||||||
|
responses={
|
||||||
|
200: {"model": RSVPAdminItem, "description": "Registro actualizado exitosamente."},
|
||||||
|
400: {"description": "Error de validación en los campos proporcionados."},
|
||||||
|
404: {"description": "Registro no encontrado."},
|
||||||
|
409: {"description": "El número de teléfono ya está registrado por otro asistente."},
|
||||||
|
**ADMIN_401,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
def update_rsvp_endpoint(
|
||||||
|
rsvp_id: int,
|
||||||
|
payload: RSVPUpdate,
|
||||||
|
admin: AdminDep,
|
||||||
|
db: DbDep,
|
||||||
|
):
|
||||||
|
status_res, updated = update_rsvp(db, rsvp_id, payload)
|
||||||
|
|
||||||
|
if status_res == "NOT_FOUND":
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=status.HTTP_404_NOT_FOUND,
|
||||||
|
detail=f"No se encontró el registro con ID {rsvp_id}",
|
||||||
|
)
|
||||||
|
if status_res == "DUPLICATE":
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=status.HTTP_409_CONFLICT,
|
||||||
|
detail="El número de teléfono ya está registrado para otro asistente.",
|
||||||
|
)
|
||||||
|
assert updated is not None
|
||||||
|
return updated
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@router.get(
|
@router.get(
|
||||||
"/export",
|
"/export",
|
||||||
summary="Exportar confirmaciones en formato CSV",
|
summary="Exportar confirmaciones en formato CSV",
|
||||||
|
|||||||
@@ -6,6 +6,24 @@ from zoneinfo import ZoneInfo, ZoneInfoNotFoundError
|
|||||||
from pydantic import BaseModel, ConfigDict, Field, field_validator
|
from pydantic import BaseModel, ConfigDict, Field, field_validator
|
||||||
|
|
||||||
|
|
||||||
|
def normalize_phone(raw: str) -> str:
|
||||||
|
"""Normalize Colombian mobile numbers.
|
||||||
|
|
||||||
|
Rules:
|
||||||
|
1. Strip all non-digit characters.
|
||||||
|
2. If starts with '57' and has 12 digits, strip '57'.
|
||||||
|
3. Must be exactly 10 digits and start with '3'.
|
||||||
|
"""
|
||||||
|
digits = re.sub(r"\D", "", raw)
|
||||||
|
if digits.startswith("57") and len(digits) == 12:
|
||||||
|
digits = digits[2:]
|
||||||
|
|
||||||
|
if len(digits) != 10 or not digits.startswith("3"):
|
||||||
|
raise ValueError("Formato de teléfono inválido")
|
||||||
|
|
||||||
|
return digits
|
||||||
|
|
||||||
|
|
||||||
class RSVPCreate(BaseModel):
|
class RSVPCreate(BaseModel):
|
||||||
name: str = Field(
|
name: str = Field(
|
||||||
...,
|
...,
|
||||||
@@ -36,6 +54,11 @@ class RSVPCreate(BaseModel):
|
|||||||
raise ValueError("El nombre no puede estar vacío.")
|
raise ValueError("El nombre no puede estar vacío.")
|
||||||
return cleaned
|
return cleaned
|
||||||
|
|
||||||
|
@field_validator("phone")
|
||||||
|
@classmethod
|
||||||
|
def validate_phone(cls, v: str) -> str:
|
||||||
|
return normalize_phone(v)
|
||||||
|
|
||||||
@field_validator("email")
|
@field_validator("email")
|
||||||
@classmethod
|
@classmethod
|
||||||
def validate_email(cls, v: str | None) -> str | None:
|
def validate_email(cls, v: str | None) -> str | None:
|
||||||
@@ -50,6 +73,61 @@ class RSVPCreate(BaseModel):
|
|||||||
return cleaned.lower()
|
return cleaned.lower()
|
||||||
|
|
||||||
|
|
||||||
|
class RSVPUpdate(BaseModel):
|
||||||
|
name: str | None = Field(
|
||||||
|
default=None,
|
||||||
|
min_length=1,
|
||||||
|
max_length=100,
|
||||||
|
description="Nombre completo del invitado",
|
||||||
|
examples=["Andrés García"],
|
||||||
|
)
|
||||||
|
phone: str | None = Field(
|
||||||
|
default=None,
|
||||||
|
min_length=1,
|
||||||
|
max_length=50,
|
||||||
|
description="Número móvil en formato colombiano (10 dígitos, con o sin prefijo +57)",
|
||||||
|
examples=["+57 300 123 4567"],
|
||||||
|
)
|
||||||
|
email: str | None = Field(
|
||||||
|
default=None,
|
||||||
|
max_length=255,
|
||||||
|
description="Correo electrónico opcional para confirmación y recordatorios",
|
||||||
|
examples=["andres@example.com"],
|
||||||
|
)
|
||||||
|
|
||||||
|
@field_validator("name")
|
||||||
|
@classmethod
|
||||||
|
def normalize_name(cls, v: str | None) -> str | None:
|
||||||
|
if v is None:
|
||||||
|
return None
|
||||||
|
cleaned = " ".join(v.strip().split())
|
||||||
|
if not cleaned:
|
||||||
|
raise ValueError("El nombre no puede estar vacío.")
|
||||||
|
return cleaned
|
||||||
|
|
||||||
|
@field_validator("phone")
|
||||||
|
@classmethod
|
||||||
|
def validate_phone(cls, v: str | None) -> str | None:
|
||||||
|
if v is None:
|
||||||
|
return None
|
||||||
|
return normalize_phone(v)
|
||||||
|
|
||||||
|
@field_validator("email")
|
||||||
|
@classmethod
|
||||||
|
def validate_email(cls, v: str | None) -> str | None:
|
||||||
|
if v is None:
|
||||||
|
return None
|
||||||
|
cleaned = v.strip()
|
||||||
|
if not cleaned:
|
||||||
|
return None
|
||||||
|
email_regex = r"^[^@\s]+@[^@\s]+\.[^@\s]+$"
|
||||||
|
if not re.match(email_regex, cleaned):
|
||||||
|
raise ValueError("Formato de correo electrónico inválido")
|
||||||
|
return cleaned.lower()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class RSVPSuccessResponse(BaseModel):
|
class RSVPSuccessResponse(BaseModel):
|
||||||
result: Literal["SUCCESS"] = Field(
|
result: Literal["SUCCESS"] = Field(
|
||||||
default="SUCCESS",
|
default="SUCCESS",
|
||||||
|
|||||||
@@ -1,29 +1,9 @@
|
|||||||
import re
|
|
||||||
|
|
||||||
from sqlalchemy import or_, select
|
from sqlalchemy import or_, select
|
||||||
from sqlalchemy.exc import IntegrityError
|
from sqlalchemy.exc import IntegrityError
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
from ..models import RSVP
|
from ..models import RSVP
|
||||||
from ..schemas import RSVPCreate
|
from ..schemas import RSVPCreate, RSVPUpdate, normalize_phone
|
||||||
|
|
||||||
|
|
||||||
def normalize_phone(raw: str) -> str:
|
|
||||||
"""Normalize Colombian mobile numbers.
|
|
||||||
|
|
||||||
Rules:
|
|
||||||
1. Strip all non-digit characters.
|
|
||||||
2. If starts with '57' and has 12 digits, strip '57'.
|
|
||||||
3. Must be exactly 10 digits and start with '3'.
|
|
||||||
"""
|
|
||||||
digits = re.sub(r"\D", "", raw)
|
|
||||||
if digits.startswith("57") and len(digits) == 12:
|
|
||||||
digits = digits[2:]
|
|
||||||
|
|
||||||
if len(digits) != 10 or not digits.startswith("3"):
|
|
||||||
raise ValueError("Formato de teléfono inválido")
|
|
||||||
|
|
||||||
return digits
|
|
||||||
|
|
||||||
|
|
||||||
def create_rsvp(db: Session, rsvp_in: RSVPCreate) -> tuple[str, RSVP | None]:
|
def create_rsvp(db: Session, rsvp_in: RSVPCreate) -> tuple[str, RSVP | None]:
|
||||||
@@ -81,3 +61,57 @@ def get_rsvp_count(db: Session) -> int:
|
|||||||
"""Get total count of RSVPs."""
|
"""Get total count of RSVPs."""
|
||||||
query = select(RSVP)
|
query = select(RSVP)
|
||||||
return len(list(db.execute(query).scalars().all()))
|
return len(list(db.execute(query).scalars().all()))
|
||||||
|
|
||||||
|
|
||||||
|
def delete_rsvp(db: Session, rsvp_id: int) -> bool:
|
||||||
|
"""Delete an RSVP record by its ID. Returns True if deleted, False if not found."""
|
||||||
|
rsvp = db.execute(select(RSVP).where(RSVP.id == rsvp_id)).scalar_one_or_none()
|
||||||
|
if not rsvp:
|
||||||
|
return False
|
||||||
|
db.delete(rsvp)
|
||||||
|
db.commit()
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def update_rsvp(
|
||||||
|
db: Session,
|
||||||
|
rsvp_id: int,
|
||||||
|
update_in: RSVPUpdate,
|
||||||
|
) -> tuple[str, RSVP | None]:
|
||||||
|
"""Update an RSVP record using validated RSVPUpdate schema.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
("SUCCESS", rsvp)
|
||||||
|
("NOT_FOUND", None)
|
||||||
|
("DUPLICATE", None)
|
||||||
|
"""
|
||||||
|
rsvp = db.execute(select(RSVP).where(RSVP.id == rsvp_id)).scalar_one_or_none()
|
||||||
|
if not rsvp:
|
||||||
|
return "NOT_FOUND", None
|
||||||
|
|
||||||
|
if update_in.phone is not None:
|
||||||
|
existing = db.execute(
|
||||||
|
select(RSVP).where(RSVP.phone == update_in.phone, RSVP.id != rsvp_id)
|
||||||
|
).scalar_one_or_none()
|
||||||
|
if existing:
|
||||||
|
return "DUPLICATE", None
|
||||||
|
rsvp.phone = update_in.phone
|
||||||
|
|
||||||
|
if update_in.name is not None:
|
||||||
|
rsvp.name = update_in.name
|
||||||
|
|
||||||
|
if update_in.email is not None:
|
||||||
|
rsvp.email = update_in.email
|
||||||
|
|
||||||
|
try:
|
||||||
|
db.commit()
|
||||||
|
db.refresh(rsvp)
|
||||||
|
return "SUCCESS", rsvp
|
||||||
|
except IntegrityError:
|
||||||
|
db.rollback()
|
||||||
|
return "DUPLICATE", None
|
||||||
|
except Exception:
|
||||||
|
db.rollback()
|
||||||
|
raise
|
||||||
|
|
||||||
|
|
||||||
@@ -68,3 +68,94 @@ def test_admin_export_csv(client):
|
|||||||
lines = content.strip().split("\r\n") if "\r\n" in content else content.strip().split("\n")
|
lines = content.strip().split("\r\n") if "\r\n" in content else content.strip().split("\n")
|
||||||
assert lines[0] == "name,phone,email,created_at"
|
assert lines[0] == "name,phone,email,created_at"
|
||||||
assert "Sofia Vergara,3019998877,sofia@hollywood.com" in lines[1]
|
assert "Sofia Vergara,3019998877,sofia@hollywood.com" in lines[1]
|
||||||
|
|
||||||
|
|
||||||
|
def test_admin_delete_rsvp(client):
|
||||||
|
headers = {"Remote-User": "kiskaadee"}
|
||||||
|
|
||||||
|
# Unauthorized without header
|
||||||
|
res_unauth = client.delete("/birthday/api/admin/rsvps/1")
|
||||||
|
assert res_unauth.status_code == 401
|
||||||
|
|
||||||
|
# 404 for non-existent RSVP
|
||||||
|
res_404 = client.delete("/birthday/api/admin/rsvps/9999", headers=headers)
|
||||||
|
assert res_404.status_code == 404
|
||||||
|
|
||||||
|
# Create an RSVP
|
||||||
|
client.post(
|
||||||
|
"/birthday/api/rsvp",
|
||||||
|
json={"name": "Lucas Silva", "phone": "300 444 5566", "email": "lucas@test.com"},
|
||||||
|
)
|
||||||
|
list_res = client.get("/birthday/api/admin/rsvps", headers=headers)
|
||||||
|
assert list_res.status_code == 200
|
||||||
|
rsvps = list_res.json()["rsvps"]
|
||||||
|
assert len(rsvps) == 1
|
||||||
|
rsvp_id = rsvps[0]["id"]
|
||||||
|
|
||||||
|
# Delete successfully
|
||||||
|
del_res = client.delete(f"/birthday/api/admin/rsvps/{rsvp_id}", headers=headers)
|
||||||
|
assert del_res.status_code == 204
|
||||||
|
|
||||||
|
# Confirm deletion
|
||||||
|
list_after = client.get("/birthday/api/admin/rsvps", headers=headers)
|
||||||
|
assert list_after.json()["count"] == 0
|
||||||
|
|
||||||
|
|
||||||
|
def test_admin_update_rsvp(client):
|
||||||
|
headers = {"Remote-User": "kiskaadee"}
|
||||||
|
|
||||||
|
# Unauthorized without header
|
||||||
|
res_unauth = client.patch("/birthday/api/admin/rsvps/1", json={"name": "New Name"})
|
||||||
|
assert res_unauth.status_code == 401
|
||||||
|
|
||||||
|
# 404 for non-existent RSVP
|
||||||
|
res_404 = client.patch(
|
||||||
|
"/birthday/api/admin/rsvps/9999",
|
||||||
|
json={"name": "New Name"},
|
||||||
|
headers=headers,
|
||||||
|
)
|
||||||
|
assert res_404.status_code == 404
|
||||||
|
|
||||||
|
# Create two RSVPs
|
||||||
|
client.post(
|
||||||
|
"/birthday/api/rsvp",
|
||||||
|
json={"name": "Person One", "phone": "300 111 2222", "email": "one@test.com"},
|
||||||
|
)
|
||||||
|
client.post(
|
||||||
|
"/birthday/api/rsvp",
|
||||||
|
json={"name": "Person Two", "phone": "300 333 4444", "email": "two@test.com"},
|
||||||
|
)
|
||||||
|
|
||||||
|
list_res = client.get("/birthday/api/admin/rsvps", headers=headers)
|
||||||
|
rsvps = list_res.json()["rsvps"]
|
||||||
|
id_one = next(r["id"] for r in rsvps if r["name"] == "Person One")
|
||||||
|
id_two = next(r["id"] for r in rsvps if r["name"] == "Person Two")
|
||||||
|
|
||||||
|
# Update Person One with valid new name and phone
|
||||||
|
patch_res = client.patch(
|
||||||
|
f"/birthday/api/admin/rsvps/{id_one}",
|
||||||
|
json={"name": "Person One Updated", "phone": "+57 300 999 8888", "email": "newone@test.com"},
|
||||||
|
headers=headers,
|
||||||
|
)
|
||||||
|
assert patch_res.status_code == 200
|
||||||
|
updated_data = patch_res.json()
|
||||||
|
assert updated_data["name"] == "Person One Updated"
|
||||||
|
assert updated_data["phone"] == "3009998888"
|
||||||
|
assert updated_data["email"] == "newone@test.com"
|
||||||
|
|
||||||
|
# Attempt to update Person One's phone to Person Two's phone -> 409
|
||||||
|
dup_res = client.patch(
|
||||||
|
f"/birthday/api/admin/rsvps/{id_one}",
|
||||||
|
json={"phone": "300 333 4444"},
|
||||||
|
headers=headers,
|
||||||
|
)
|
||||||
|
assert dup_res.status_code == 409
|
||||||
|
|
||||||
|
# Validation error for invalid phone
|
||||||
|
val_res = client.patch(
|
||||||
|
f"/birthday/api/admin/rsvps/{id_one}",
|
||||||
|
json={"phone": "12345"},
|
||||||
|
headers=headers,
|
||||||
|
)
|
||||||
|
assert val_res.status_code in (400, 422)
|
||||||
|
|
||||||
@@ -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) => {
|
||||||
|
if (editingId !== row.id) {
|
||||||
e.currentTarget.style.backgroundColor = "rgba(255, 255, 255, 0.04)";
|
e.currentTarget.style.backgroundColor = "rgba(255, 255, 255, 0.04)";
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
onMouseLeave={(e) => {
|
onMouseLeave={(e) => {
|
||||||
|
if (editingId !== row.id) {
|
||||||
e.currentTarget.style.backgroundColor = "transparent";
|
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,30 +138,59 @@ 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}>
|
|
||||||
|
{/* 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}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* 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
|
VOLVER AL FORMULARIO
|
||||||
</Button>
|
</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