feat(Notes): implement manual ordering for notes, add drag-and-drop functionality, and update related components for reordering
This commit is contained in:
31
src/actions/notes.ts
Normal file
31
src/actions/notes.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
'use server';
|
||||
|
||||
import { notesService } from '@/services/notes';
|
||||
import { revalidatePath } from 'next/cache';
|
||||
import { getServerSession } from 'next-auth';
|
||||
import { authOptions } from '@/lib/auth';
|
||||
|
||||
/**
|
||||
* Réordonne les notes
|
||||
*/
|
||||
export async function reorderNotes(
|
||||
noteOrders: Array<{ id: string; order: number }>
|
||||
) {
|
||||
try {
|
||||
const session = await getServerSession(authOptions);
|
||||
if (!session?.user?.id) {
|
||||
return { success: false, error: 'Non autorisé' };
|
||||
}
|
||||
|
||||
await notesService.reorderNotes(session.user.id, noteOrders);
|
||||
|
||||
revalidatePath('/notes');
|
||||
return { success: true };
|
||||
} catch (error) {
|
||||
console.error('Error reordering notes:', error);
|
||||
return {
|
||||
success: false,
|
||||
error: error instanceof Error ? error.message : 'Erreur inconnue',
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user