diff --git a/dev.db b/dev.db index dfc148a..13481d7 100644 Binary files a/dev.db and b/dev.db differ diff --git a/src/actions/session.ts b/src/actions/session.ts index d0a44d4..9108296 100644 --- a/src/actions/session.ts +++ b/src/actions/session.ts @@ -70,3 +70,24 @@ export async function updateSessionCollaborator(sessionId: string, collaborator: } } +export async function deleteSwotSession(sessionId: string) { + const session = await auth(); + if (!session?.user?.id) { + return { success: false, error: 'Non autorisé' }; + } + + try { + const result = await sessionsService.deleteSession(sessionId, session.user.id); + + if (result.count === 0) { + return { success: false, error: 'Session non trouvée ou non autorisé' }; + } + + revalidatePath('/sessions'); + return { success: true }; + } catch (error) { + console.error('Error deleting session:', error); + return { success: false, error: 'Erreur lors de la suppression' }; + } +} + diff --git a/src/app/sessions/WorkshopTabs.tsx b/src/app/sessions/WorkshopTabs.tsx index b4655d2..4742598 100644 --- a/src/app/sessions/WorkshopTabs.tsx +++ b/src/app/sessions/WorkshopTabs.tsx @@ -1,8 +1,10 @@ 'use client'; -import { useState } from 'react'; +import { useState, useTransition } from 'react'; import Link from 'next/link'; -import { Card, Badge } from '@/components/ui'; +import { Card, Badge, Button, Modal, ModalFooter } from '@/components/ui'; +import { deleteSwotSession } from '@/actions/session'; +import { deleteMotivatorSession } from '@/actions/moving-motivators'; type WorkshopType = 'all' | 'swot' | 'motivators'; @@ -172,6 +174,9 @@ function TabButton({ } function SessionCard({ session }: { session: AnySession }) { + const [showDeleteModal, setShowDeleteModal] = useState(false); + const [isPending, startTransition] = useTransition(); + const isSwot = session.workshopType === 'swot'; const href = isSwot ? `/sessions/${session.id}` : `/motivators/${session.id}`; const icon = isSwot ? '📊' : '🎯'; @@ -180,93 +185,161 @@ function SessionCard({ session }: { session: AnySession }) { : (session as MotivatorSession).participant; const accentColor = isSwot ? '#06b6d4' : '#8b5cf6'; + const handleDelete = () => { + startTransition(async () => { + const result = isSwot + ? await deleteSwotSession(session.id) + : await deleteMotivatorSession(session.id); + + if (result.success) { + setShowDeleteModal(false); + } else { + console.error('Error deleting session:', result.error); + } + }); + }; + return ( - - - {/* Accent bar */} -
+ <> +
+ + + {/* Accent bar */} +
- {/* Header: Icon + Title + Role badge */} -
- {icon} -

- {session.title} -

- {!session.isOwner && ( - - {session.role === 'EDITOR' ? '✏️' : '👁️'} - - )} -
- - {/* Participant + Owner info */} -

- 👤 {participant} - {!session.isOwner && ( - · par {session.user.name || session.user.email} - )} -

- - {/* Footer: Stats + Avatars + Date */} -
- {/* Stats */} -
- {isSwot ? ( - <> - {(session as SwotSession)._count.items} items - · - {(session as SwotSession)._count.actions} actions - - ) : ( - {(session as MotivatorSession)._count.cards}/10 - )} -
- - {/* Date */} - - {new Date(session.updatedAt).toLocaleDateString('fr-FR', { - day: 'numeric', - month: 'short', - })} - -
- - {/* Shared with */} - {session.isOwner && session.shares.length > 0 && ( -
- Partagé -
- {session.shares.slice(0, 3).map((share) => ( -
+ {icon} +

+ {session.title} +

+ {!session.isOwner && ( + - - {share.user.name?.split(' ')[0] || share.user.email.split('@')[0]} - - {share.role === 'EDITOR' ? '✏️' : '👁️'} -
- ))} - {session.shares.length > 3 && ( - - +{session.shares.length - 3} + {session.role === 'EDITOR' ? '✏️' : '👁️'} )}
-
+ + {/* Participant + Owner info */} +

+ 👤 {participant} + {!session.isOwner && ( + · par {session.user.name || session.user.email} + )} +

+ + {/* Footer: Stats + Avatars + Date */} +
+ {/* Stats */} +
+ {isSwot ? ( + <> + {(session as SwotSession)._count.items} items + · + {(session as SwotSession)._count.actions} actions + + ) : ( + {(session as MotivatorSession)._count.cards}/10 + )} +
+ + {/* Date */} + + {new Date(session.updatedAt).toLocaleDateString('fr-FR', { + day: 'numeric', + month: 'short', + })} + +
+ + {/* Shared with */} + {session.isOwner && session.shares.length > 0 && ( +
+ Partagé +
+ {session.shares.slice(0, 3).map((share) => ( +
+ + {share.user.name?.split(' ')[0] || share.user.email.split('@')[0]} + + {share.role === 'EDITOR' ? '✏️' : '👁️'} +
+ ))} + {session.shares.length > 3 && ( + + +{session.shares.length - 3} + + )} +
+
+ )} + + + + {/* Delete button - only for owner */} + {session.isOwner && ( + )} - - +
+ + {/* Delete confirmation modal */} + setShowDeleteModal(false)} + title="Supprimer l'atelier" + size="sm" + > +
+

+ Êtes-vous sûr de vouloir supprimer l'atelier "{session.title}" ? +

+

+ Cette action est irréversible. Toutes les données seront perdues. +

+ + + + +
+
+ ); }