feat: agregar eliminacion y Walmart Connect multipais
This commit is contained in:
+42
-3
@@ -39,7 +39,7 @@ function initials(name: string | null | undefined, email: string | null | undefi
|
||||
}
|
||||
|
||||
export default function BoardPage() {
|
||||
const { projects, loading, error, refresh } = useProjects();
|
||||
const { projects, loading, error, refresh, remove } = useProjects();
|
||||
const { user, isGerardo, logout } = useAuth();
|
||||
|
||||
const projectsTopRef = useRef<HTMLDivElement | null>(null);
|
||||
@@ -53,6 +53,7 @@ export default function BoardPage() {
|
||||
abiertos: 1,
|
||||
cerrados: 1,
|
||||
});
|
||||
const [deletingProjectId, setDeletingProjectId] = useState<string | null>(null);
|
||||
|
||||
const filtered = useMemo(() => {
|
||||
const q = query.trim().toLowerCase();
|
||||
@@ -105,6 +106,34 @@ export default function BoardPage() {
|
||||
setOpen(true);
|
||||
};
|
||||
|
||||
const deleteProject = async (project: Project) => {
|
||||
const confirmed = window.confirm(
|
||||
`¿Seguro que deseas eliminar el proyecto "${project.nombre || "Sin título"}"?\n\nEsta acción eliminará el proyecto del tablero y del Google Sheet.`,
|
||||
);
|
||||
|
||||
if (!confirmed) return;
|
||||
|
||||
setDeletingProjectId(project.id);
|
||||
|
||||
try {
|
||||
await remove(project.id);
|
||||
|
||||
if (editing?.id === project.id) {
|
||||
setOpen(false);
|
||||
setEditing(null);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error("Error eliminando proyecto:", err);
|
||||
const message =
|
||||
err instanceof Error
|
||||
? err.message
|
||||
: "No se pudo eliminar el proyecto. Revisa n8n, Supabase o permisos.";
|
||||
window.alert(message);
|
||||
} finally {
|
||||
setDeletingProjectId(null);
|
||||
}
|
||||
};
|
||||
|
||||
const displayName = user?.displayName ?? user?.email ?? "Usuario";
|
||||
const userRole = isGerardo ? "Jefe CDC" : "Usuario CDC";
|
||||
const userInitials = initials(user?.displayName, user?.email);
|
||||
@@ -256,7 +285,11 @@ export default function BoardPage() {
|
||||
) : (
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4">
|
||||
{paginatedProjects.map((p) => (
|
||||
<ProjectCard key={p.id} project={p} onClick={() => openEdit(p)} />
|
||||
<ProjectCard
|
||||
key={p.id}
|
||||
project={p}
|
||||
onClick={() => openEdit(p)}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
@@ -273,7 +306,13 @@ export default function BoardPage() {
|
||||
)}
|
||||
</main>
|
||||
|
||||
<ProjectDialog open={open} onOpenChange={setOpen} project={editing} />
|
||||
<ProjectDialog
|
||||
open={open}
|
||||
onOpenChange={setOpen}
|
||||
project={editing}
|
||||
onDelete={deleteProject}
|
||||
deleting={!!editing && deletingProjectId === editing.id}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user