From 7aa9d6dd6b926137c700e167dbb72dc7379b446b Mon Sep 17 00:00:00 2001 From: Julien Froidefond Date: Tue, 30 Sep 2025 22:20:57 +0200 Subject: [PATCH] fix: streamline error handling and clean up unused imports - Simplified error handling in `LoginPage` by removing the error parameter in the catch block. - Removed unused import of `cn` in `KeyboardShortcutsModal` to clean up the code. - Updated `UserPreferencesContext` to only destructure `status` from `useSession`, improving clarity. - Refactored multiple methods in `UserPreferencesService` to eliminate unnecessary variable assignments, enhancing performance. - Added ESLint directive to suppress unused variable warning for `NextAuth` import in type definitions. --- src/app/login/page.tsx | 2 +- src/components/ui/KeyboardShortcutsModal.tsx | 1 - src/contexts/UserPreferencesContext.tsx | 2 +- src/services/core/user-preferences.ts | 20 ++++++++++---------- src/types/next-auth.d.ts | 3 ++- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/app/login/page.tsx b/src/app/login/page.tsx index ab2bc25..34ee37f 100644 --- a/src/app/login/page.tsx +++ b/src/app/login/page.tsx @@ -37,7 +37,7 @@ export default function LoginPage() { router.push('/') } } - } catch (error) { + } catch { setError('Une erreur est survenue') } finally { setIsLoading(false) diff --git a/src/components/ui/KeyboardShortcutsModal.tsx b/src/components/ui/KeyboardShortcutsModal.tsx index 5b9d2f0..b5d51b5 100644 --- a/src/components/ui/KeyboardShortcutsModal.tsx +++ b/src/components/ui/KeyboardShortcutsModal.tsx @@ -1,7 +1,6 @@ 'use client'; import { Modal } from './Modal'; -import { cn } from '@/lib/utils'; interface KeyboardShortcut { keys: string[]; diff --git a/src/contexts/UserPreferencesContext.tsx b/src/contexts/UserPreferencesContext.tsx index 1b0dc1f..eda5506 100644 --- a/src/contexts/UserPreferencesContext.tsx +++ b/src/contexts/UserPreferencesContext.tsx @@ -78,7 +78,7 @@ export function UserPreferencesProvider({ children, initialPreferences }: UserPr const [preferences, setPreferences] = useState(initialPreferences || defaultPreferences); const [isPending, startTransition] = useTransition(); const { theme, toggleTheme: themeToggleTheme, setTheme: themeSetTheme } = useTheme(); - const { data: session, status } = useSession(); + const { status } = useSession(); // Fonction pour charger les préférences côté client const loadUserPreferences = useCallback(async () => { diff --git a/src/services/core/user-preferences.ts b/src/services/core/user-preferences.ts index bbcf737..b464987 100644 --- a/src/services/core/user-preferences.ts +++ b/src/services/core/user-preferences.ts @@ -106,7 +106,7 @@ class UserPreferencesService { */ async saveKanbanFilters(userId: string, filters: KanbanFilters): Promise { try { - const userPrefs = await this.getOrCreateUserPreferences(userId); + await this.getOrCreateUserPreferences(userId); await prisma.userPreferences.update({ where: { userId }, data: { kanbanFilters: filters } @@ -138,7 +138,7 @@ class UserPreferencesService { */ async saveViewPreferences(userId: string, preferences: ViewPreferences): Promise { try { - const userPrefs = await this.getOrCreateUserPreferences(userId); + await this.getOrCreateUserPreferences(userId); await prisma.userPreferences.update({ where: { userId }, data: { viewPreferences: preferences } @@ -176,7 +176,7 @@ class UserPreferencesService { */ async saveColumnVisibility(userId: string, visibility: ColumnVisibility): Promise { try { - const userPrefs = await this.getOrCreateUserPreferences(userId); + await this.getOrCreateUserPreferences(userId); await prisma.userPreferences.update({ where: { userId }, data: { columnVisibility: visibility }, @@ -230,7 +230,7 @@ class UserPreferencesService { */ async saveJiraConfig(userId: string, config: JiraConfig): Promise { try { - const userPrefs = await this.getOrCreateUserPreferences(userId); + await this.getOrCreateUserPreferences(userId); await prisma.userPreferences.update({ where: { userId }, data: { jiraConfig: config as any } // eslint-disable-line @typescript-eslint/no-explicit-any @@ -278,7 +278,7 @@ class UserPreferencesService { */ async saveTfsConfig(userId: string, config: TfsConfig): Promise { try { - const userPrefs = await this.getOrCreateUserPreferences(userId); + await this.getOrCreateUserPreferences(userId); await prisma.userPreferences.update({ where: { userId }, data: { tfsConfig: config as any }, // eslint-disable-line @typescript-eslint/no-explicit-any @@ -322,7 +322,7 @@ class UserPreferencesService { tfsSyncInterval: 'hourly' | 'daily' | 'weekly' ): Promise { try { - const userPrefs = await this.getOrCreateUserPreferences(userId); + await this.getOrCreateUserPreferences(userId); await prisma.$executeRaw` UPDATE user_preferences SET tfsAutoSync = ${tfsAutoSync}, tfsSyncInterval = ${tfsSyncInterval} @@ -345,7 +345,7 @@ class UserPreferencesService { tfsSyncInterval: 'hourly' | 'daily' | 'weekly'; }> { try { - const userPrefs = await this.getOrCreateUserPreferences(userId); + await this.getOrCreateUserPreferences(userId); const result = await prisma.$queryRaw< Array<{ tfsAutoSync: number; tfsSyncInterval: string }> >` @@ -388,7 +388,7 @@ class UserPreferencesService { jiraSyncInterval: 'hourly' | 'daily' | 'weekly' ): Promise { try { - const userPrefs = await this.getOrCreateUserPreferences(userId); + await this.getOrCreateUserPreferences(userId); // Utiliser une requête SQL brute temporairement pour éviter les problèmes de types await prisma.$executeRaw` UPDATE user_preferences @@ -512,9 +512,9 @@ class UserPreferencesService { */ async resetAllPreferences(userId: string): Promise { try { - const userPrefs = await this.getOrCreateUserPreferences(userId); + await this.getOrCreateUserPreferences(userId); await prisma.userPreferences.update({ - where: { userId: userPrefs.userId }, + where: { userId }, data: { kanbanFilters: DEFAULT_PREFERENCES.kanbanFilters, viewPreferences: DEFAULT_PREFERENCES.viewPreferences, diff --git a/src/types/next-auth.d.ts b/src/types/next-auth.d.ts index 636bdea..cdf6fbd 100644 --- a/src/types/next-auth.d.ts +++ b/src/types/next-auth.d.ts @@ -1,4 +1,5 @@ -import NextAuth from "next-auth" +// eslint-disable-next-line @typescript-eslint/no-unused-vars +import type NextAuth from "next-auth" declare module "next-auth" { interface Session {