From 0c47bf916c097828b5e902eaa0efdd5ada247f52 Mon Sep 17 00:00:00 2001 From: Julien Froidefond Date: Mon, 22 Dec 2025 08:56:37 +0100 Subject: [PATCH] Refactor management components to remove loading state: Eliminate unused loading state and related conditional rendering from ChallengeManagement, EventManagement, FeedbackManagement, HouseManagement, and UserManagement components, simplifying the code and improving readability. --- components/admin/ChallengeManagement.tsx | 9 +-------- components/admin/EventManagement.tsx | 7 +------ components/admin/FeedbackManagement.tsx | 11 +---------- components/admin/HouseManagement.tsx | 7 +------ components/admin/UserManagement.tsx | 7 +------ components/ui/Button.tsx | 2 +- 6 files changed, 6 insertions(+), 37 deletions(-) diff --git a/components/admin/ChallengeManagement.tsx b/components/admin/ChallengeManagement.tsx index b758cc3..a59cf46 100644 --- a/components/admin/ChallengeManagement.tsx +++ b/components/admin/ChallengeManagement.tsx @@ -1,6 +1,6 @@ "use client"; -import { useEffect, useState, useTransition } from "react"; +import { useState, useTransition } from "react"; import { validateChallenge, rejectChallenge, @@ -48,7 +48,6 @@ interface ChallengeManagementProps { export default function ChallengeManagement({ initialChallenges }: ChallengeManagementProps) { const [challenges, setChallenges] = useState(initialChallenges); - const [loading, setLoading] = useState(false); const [selectedChallenge, setSelectedChallenge] = useState( null ); @@ -260,12 +259,6 @@ export default function ChallengeManagement({ initialChallenges }: ChallengeMana }); }; - if (loading) { - return ( -
Chargement...
- ); - } - if (challenges.length === 0) { return
Aucun défi
; } diff --git a/components/admin/EventManagement.tsx b/components/admin/EventManagement.tsx index 1ba9889..6dfe03c 100644 --- a/components/admin/EventManagement.tsx +++ b/components/admin/EventManagement.tsx @@ -1,6 +1,6 @@ "use client"; -import { useState, useEffect, useTransition } from "react"; +import { useState, useTransition } from "react"; import { calculateEventStatus } from "@/lib/eventStatus"; import { createEvent, updateEvent, deleteEvent } from "@/actions/admin/events"; import { @@ -98,7 +98,6 @@ interface EventManagementProps { export default function EventManagement({ initialEvents }: EventManagementProps) { const [events, setEvents] = useState(initialEvents); - const [loading, setLoading] = useState(false); const [editingEvent, setEditingEvent] = useState(null); const [isCreating, setIsCreating] = useState(false); const [saving, setSaving] = useState(false); @@ -304,10 +303,6 @@ export default function EventManagement({ initialEvents }: EventManagementProps) }); }; - if (loading) { - return
Chargement...
; - } - return (
diff --git a/components/admin/FeedbackManagement.tsx b/components/admin/FeedbackManagement.tsx index 1be909f..416ce22 100644 --- a/components/admin/FeedbackManagement.tsx +++ b/components/admin/FeedbackManagement.tsx @@ -1,6 +1,6 @@ "use client"; -import { useState, useEffect } from "react"; +import { useState } from "react"; import { addFeedbackBonusPoints, markFeedbackAsRead, @@ -49,7 +49,6 @@ export default function FeedbackManagement({ }: FeedbackManagementProps) { const [feedbacks, setFeedbacks] = useState(initialFeedbacks); const [statistics, setStatistics] = useState(initialStatistics); - const [loading, setLoading] = useState(false); const [error, setError] = useState(""); const [selectedEvent, setSelectedEvent] = useState(null); const [addingPoints, setAddingPoints] = useState>( @@ -161,14 +160,6 @@ export default function FeedbackManagement({ ); }); - if (loading) { - return ( -
-

Chargement...

-
- ); - } - return (
{/* Statistiques par événement */} diff --git a/components/admin/HouseManagement.tsx b/components/admin/HouseManagement.tsx index c0ad810..cffaa81 100644 --- a/components/admin/HouseManagement.tsx +++ b/components/admin/HouseManagement.tsx @@ -1,6 +1,6 @@ "use client"; -import { useState, useEffect, useTransition } from "react"; +import { useState, useTransition } from "react"; import { Input, Textarea, @@ -77,7 +77,6 @@ interface HouseManagementProps { export default function HouseManagement({ initialHouses }: HouseManagementProps) { const [houses, setHouses] = useState(initialHouses); - const [loading, setLoading] = useState(false); const [editingHouse, setEditingHouse] = useState(null); const [saving, setSaving] = useState(false); const [deletingHouseId, setDeletingHouseId] = useState(null); @@ -216,10 +215,6 @@ export default function HouseManagement({ initialHouses }: HouseManagementProps) return num.toLocaleString("en-US"); }; - if (loading) { - return
Chargement...
; - } - return (
diff --git a/components/admin/UserManagement.tsx b/components/admin/UserManagement.tsx index 612ad26..1d36a3e 100644 --- a/components/admin/UserManagement.tsx +++ b/components/admin/UserManagement.tsx @@ -1,6 +1,6 @@ "use client"; -import { useState, useEffect, useTransition } from "react"; +import { useState, useTransition } from "react"; import { Avatar, Input, @@ -43,7 +43,6 @@ interface UserManagementProps { export default function UserManagement({ initialUsers }: UserManagementProps) { const [users, setUsers] = useState(initialUsers); - const [loading, setLoading] = useState(false); const [editingUser, setEditingUser] = useState(null); const [saving, setSaving] = useState(false); const [deletingUserId, setDeletingUserId] = useState(null); @@ -183,10 +182,6 @@ export default function UserManagement({ initialUsers }: UserManagementProps) { ? Math.max(0, currentEditingUserData.xp + editingUser.xpDelta) : 0; - if (loading) { - return
Chargement...
; - } - return (
{users.length === 0 ? ( diff --git a/components/ui/Button.tsx b/components/ui/Button.tsx index 70269b3..0b1a357 100644 --- a/components/ui/Button.tsx +++ b/components/ui/Button.tsx @@ -1,6 +1,6 @@ "use client"; -import { ButtonHTMLAttributes, ReactNode, ElementType, AnchorHTMLAttributes } from "react"; +import { ButtonHTMLAttributes, ReactNode, ElementType } from "react"; import Link from "next/link"; type ButtonProps = ButtonHTMLAttributes & {