Refactor challenge management functions and improve code formatting: Standardize import statements, enhance error handling messages, and apply consistent formatting across challenge validation, rejection, update, and deletion functions for better readability and maintainability.
This commit is contained in:
@@ -2,8 +2,19 @@
|
||||
|
||||
import { useEffect, useState, useTransition } from "react";
|
||||
import { useSession } from "next-auth/react";
|
||||
import { createChallenge, acceptChallenge, cancelChallenge } from "@/actions/challenges/create";
|
||||
import { Button, Card, SectionTitle, Input, Textarea, Alert } from "@/components/ui";
|
||||
import {
|
||||
createChallenge,
|
||||
acceptChallenge,
|
||||
cancelChallenge,
|
||||
} from "@/actions/challenges/create";
|
||||
import {
|
||||
Button,
|
||||
Card,
|
||||
SectionTitle,
|
||||
Input,
|
||||
Textarea,
|
||||
Alert,
|
||||
} from "@/components/ui";
|
||||
import { Avatar } from "@/components/ui";
|
||||
|
||||
interface User {
|
||||
@@ -44,7 +55,9 @@ interface ChallengesSectionProps {
|
||||
backgroundImage: string;
|
||||
}
|
||||
|
||||
export default function ChallengesSection({ backgroundImage }: ChallengesSectionProps) {
|
||||
export default function ChallengesSection({
|
||||
backgroundImage,
|
||||
}: ChallengesSectionProps) {
|
||||
const { data: session } = useSession();
|
||||
const [challenges, setChallenges] = useState<Challenge[]>([]);
|
||||
const [users, setUsers] = useState<User[]>([]);
|
||||
@@ -159,7 +172,7 @@ export default function ChallengesSection({ backgroundImage }: ChallengesSection
|
||||
const getStatusLabel = (status: string) => {
|
||||
switch (status) {
|
||||
case "PENDING":
|
||||
return "En attente d'acceptation";
|
||||
return "En attente d'acceptation";
|
||||
case "ACCEPTED":
|
||||
return "Accepté - En attente de validation admin";
|
||||
case "COMPLETED":
|
||||
@@ -284,7 +297,9 @@ export default function ChallengesSection({ backgroundImage }: ChallengesSection
|
||||
<Input
|
||||
type="number"
|
||||
value={pointsReward}
|
||||
onChange={(e) => setPointsReward(parseInt(e.target.value) || 100)}
|
||||
onChange={(e) =>
|
||||
setPointsReward(parseInt(e.target.value) || 100)
|
||||
}
|
||||
min={1}
|
||||
max={1000}
|
||||
/>
|
||||
@@ -319,7 +334,8 @@ export default function ChallengesSection({ backgroundImage }: ChallengesSection
|
||||
const isChallenged = challenge.challenged.id === currentUserId;
|
||||
const canAccept = challenge.status === "PENDING" && isChallenged;
|
||||
const canCancel =
|
||||
(challenge.status === "PENDING" || challenge.status === "ACCEPTED") &&
|
||||
(challenge.status === "PENDING" ||
|
||||
challenge.status === "ACCEPTED") &&
|
||||
(isChallenger || isChallenged);
|
||||
|
||||
return (
|
||||
@@ -339,7 +355,9 @@ export default function ChallengesSection({ backgroundImage }: ChallengesSection
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<p className="text-gray-300 mb-4">{challenge.description}</p>
|
||||
<p className="text-gray-300 mb-4">
|
||||
{challenge.description}
|
||||
</p>
|
||||
|
||||
<div className="flex items-center gap-4 mb-2">
|
||||
<div className="flex items-center gap-2">
|
||||
@@ -385,7 +403,10 @@ export default function ChallengesSection({ backgroundImage }: ChallengesSection
|
||||
)}
|
||||
|
||||
<div className="text-xs text-gray-500 mt-2">
|
||||
Créé le: {new Date(challenge.createdAt).toLocaleDateString("fr-FR")}
|
||||
Créé le:{" "}
|
||||
{new Date(challenge.createdAt).toLocaleDateString(
|
||||
"fr-FR"
|
||||
)}
|
||||
{challenge.acceptedAt &&
|
||||
` • Accepté le: ${new Date(challenge.acceptedAt).toLocaleDateString("fr-FR")}`}
|
||||
{challenge.completedAt &&
|
||||
@@ -425,4 +446,3 @@ export default function ChallengesSection({ backgroundImage }: ChallengesSection
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user