Refactor event status handling: Remove EventStatus enum from the Prisma schema and update related API routes and UI components to calculate event status dynamically based on event date. This change simplifies event management and enhances data integrity by ensuring status is always derived from the date.

This commit is contained in:
Julien Froidefond
2025-12-10 05:45:25 +01:00
parent fb830c6fcc
commit a69613a232
15 changed files with 167 additions and 298 deletions

View File

@@ -1,6 +1,7 @@
"use client";
import { useState, useEffect } from "react";
import { calculateEventStatus } from "@/lib/eventStatus";
interface Event {
id: string;
@@ -22,7 +23,6 @@ interface EventFormData {
name: string;
description: string;
type: "SUMMIT" | "LAUNCH" | "FESTIVAL" | "COMPETITION" | "CODE_KATA";
status: "UPCOMING" | "LIVE" | "PAST";
room?: string;
time?: string;
maxPlaces?: number;
@@ -35,8 +35,6 @@ const eventTypes: Event["type"][] = [
"COMPETITION",
"CODE_KATA",
];
const eventStatuses: Event["status"][] = ["UPCOMING", "LIVE", "PAST"];
const getEventTypeLabel = (type: Event["type"]) => {
switch (type) {
case "SUMMIT":
@@ -78,7 +76,6 @@ export default function EventManagement() {
name: "",
description: "",
type: "SUMMIT",
status: "UPCOMING",
room: "",
time: "",
maxPlaces: undefined,
@@ -110,7 +107,6 @@ export default function EventManagement() {
name: "",
description: "",
type: "SUMMIT",
status: "UPCOMING",
room: "",
time: "",
maxPlaces: undefined,
@@ -125,7 +121,6 @@ export default function EventManagement() {
name: event.name,
description: event.description,
type: event.type,
status: event.status,
room: event.room || "",
time: event.time || "",
maxPlaces: event.maxPlaces || undefined,
@@ -163,7 +158,6 @@ export default function EventManagement() {
name: "",
description: "",
type: "SUMMIT",
status: "UPCOMING",
room: "",
time: "",
maxPlaces: undefined,
@@ -210,7 +204,6 @@ export default function EventManagement() {
name: "",
description: "",
type: "SUMMIT",
status: "UPCOMING",
room: "",
time: "",
maxPlaces: undefined,
@@ -300,27 +293,6 @@ export default function EventManagement() {
))}
</select>
</div>
<div>
<label className="block text-sm text-gray-300 mb-1">
Statut
</label>
<select
value={formData.status}
onChange={(e) =>
setFormData({
...formData,
status: e.target.value as Event["status"],
})
}
className="w-full px-3 py-2 bg-black/60 border border-pixel-gold/30 rounded text-white text-sm"
>
{eventStatuses.map((status) => (
<option key={status} value={status}>
{getStatusLabel(status)}
</option>
))}
</select>
</div>
</div>
<div className="grid grid-cols-3 gap-4">
<div>
@@ -411,15 +383,16 @@ export default function EventManagement() {
{getEventTypeLabel(event.type)}
</span>
<span
className={`px-2 py-1 text-xs uppercase rounded ${
event.status === "UPCOMING"
className={`px-2 py-1 text-xs uppercase rounded ${(() => {
const status = calculateEventStatus(event.date);
return status === "UPCOMING"
? "bg-green-900/50 border border-green-500/50 text-green-400"
: event.status === "LIVE"
: status === "LIVE"
? "bg-yellow-900/50 border border-yellow-500/50 text-yellow-400"
: "bg-gray-900/50 border border-gray-500/50 text-gray-400"
}`}
: "bg-gray-900/50 border border-gray-500/50 text-gray-400";
})()}`}
>
{getStatusLabel(event.status)}
{getStatusLabel(calculateEventStatus(event.date))}
</span>
</div>
<p className="text-gray-400 text-sm mb-2">