This commit is contained in:
@@ -6,6 +6,8 @@ import { useAuth } from "@/context/AuthContext";
|
||||
const AdminDashboard = () => {
|
||||
const { isAuthenticated, username, isAdmin, logout } = useAuth();
|
||||
|
||||
const defaultImage = "/images/tgl-ball.png";
|
||||
|
||||
return (
|
||||
<div className="max-w-6xl mx-auto py-12 px-4">
|
||||
<div className="flex justify-between items-center mb-8">
|
||||
|
||||
@@ -5,6 +5,7 @@ import { Button } from "@/components/ui/button";
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import { toast } from "sonner";
|
||||
import { set } from "date-fns";
|
||||
|
||||
const apiBase = import.meta.env.VITE_API_URL;
|
||||
|
||||
@@ -115,6 +116,38 @@ const TeamDetail = () => {
|
||||
}
|
||||
};
|
||||
|
||||
const handleCarouselUpload = async (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const files = e.target.files;
|
||||
if(!files) return;
|
||||
|
||||
const uploadPaths: string[] = JSON.parse(carouselImages || "[]");
|
||||
|
||||
for (const file of files){
|
||||
const formData = new FormData();
|
||||
formData.append("image", file);
|
||||
|
||||
const res = await fetch(`${apiBase}/api/teams/${id}/carousel-upload`, {
|
||||
method: "POST",
|
||||
body: formData,
|
||||
});
|
||||
|
||||
if(res.ok){
|
||||
const {path} = await res.json();
|
||||
uploadPaths.push(path);
|
||||
}else{
|
||||
toast.error("Fehler beim Hochladen des Bildes.");
|
||||
}
|
||||
}
|
||||
|
||||
setCarouselImages(JSON.stringify(uploadPaths));
|
||||
};
|
||||
|
||||
const removeCarouselImage = (index: number) => {
|
||||
const paths: string[] = JSON.parse(carouselImages || "[]");
|
||||
paths.splice(index, 1);
|
||||
setCarouselImages(JSON.stringify(paths));
|
||||
};
|
||||
|
||||
if (loading) return <p className="text-center py-12">Lade Team...</p>;
|
||||
|
||||
return (
|
||||
@@ -144,11 +177,31 @@ const TeamDetail = () => {
|
||||
<label className="text-gray-700">Neue Spieler gesucht?</label>
|
||||
</div>
|
||||
|
||||
<Textarea
|
||||
value={carouselImages}
|
||||
onChange={(e) => setCarouselImages(e.target.value)}
|
||||
placeholder="Karussell-Bilder (JSON-Array z.B. [\"//uploads/x.jpg\"])"
|
||||
/>
|
||||
<div>
|
||||
<label className="block mb-1 font-medium text-gray-700">Karussell-Bilder</label>
|
||||
<input
|
||||
type="file"
|
||||
accept="image/*"
|
||||
multiple
|
||||
onChange={handleCarouselUpload}
|
||||
className="block"
|
||||
/>
|
||||
<div className="grid grid-cols-3 gap-4 mt-4">
|
||||
{JSON.parse(carouselImages || "[]").map((img: string, idx: number) => (
|
||||
<div key={idx} className="relative group">
|
||||
<img src={`${apiBase}${img}`} className="rounded shadow" />
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => removeCarouselImage(idx)}
|
||||
className="absolute top-1 right-1 bg-red-600 text-white rounded-full px-2 py-1 text-xs opacity-80 group-hover:opacity-100"
|
||||
>
|
||||
✕
|
||||
</button>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<Button onClick={handleUpdateTeam} className="bg-frog-500 hover:bg-frog-600 text-white">
|
||||
Team speichern
|
||||
|
||||
Reference in New Issue
Block a user