feat: add session editing functionality with modal in WorkshopTabs component and enhance session revalidation
This commit is contained in:
@@ -70,6 +70,46 @@ export async function updateSessionCollaborator(sessionId: string, collaborator:
|
||||
}
|
||||
}
|
||||
|
||||
export async function updateSwotSession(
|
||||
sessionId: string,
|
||||
data: { title?: string; collaborator?: string }
|
||||
) {
|
||||
const session = await auth();
|
||||
if (!session?.user?.id) {
|
||||
return { success: false, error: 'Non autorisé' };
|
||||
}
|
||||
|
||||
if (data.title !== undefined && !data.title.trim()) {
|
||||
return { success: false, error: 'Le titre ne peut pas être vide' };
|
||||
}
|
||||
|
||||
if (data.collaborator !== undefined && !data.collaborator.trim()) {
|
||||
return { success: false, error: 'Le nom du collaborateur ne peut pas être vide' };
|
||||
}
|
||||
|
||||
try {
|
||||
const updateData: { title?: string; collaborator?: string } = {};
|
||||
if (data.title) updateData.title = data.title.trim();
|
||||
if (data.collaborator) updateData.collaborator = data.collaborator.trim();
|
||||
|
||||
const result = await sessionsService.updateSession(sessionId, session.user.id, updateData);
|
||||
|
||||
if (result.count === 0) {
|
||||
return { success: false, error: 'Session non trouvée ou non autorisé' };
|
||||
}
|
||||
|
||||
// Emit event for real-time sync
|
||||
await sessionsService.createSessionEvent(sessionId, session.user.id, 'SESSION_UPDATED', updateData);
|
||||
|
||||
revalidatePath(`/sessions/${sessionId}`);
|
||||
revalidatePath('/sessions');
|
||||
return { success: true };
|
||||
} catch (error) {
|
||||
console.error('Error updating session:', error);
|
||||
return { success: false, error: 'Erreur lors de la mise à jour' };
|
||||
}
|
||||
}
|
||||
|
||||
export async function deleteSwotSession(sessionId: string) {
|
||||
const session = await auth();
|
||||
if (!session?.user?.id) {
|
||||
|
||||
Reference in New Issue
Block a user