Paar minor Fixes & Users brauchen nun auch Email
Some checks are pending
Deploy Volleyball Dev / deploy (push) Waiting to run

This commit is contained in:
Marc Wieland 2025-04-23 15:19:53 +02:00
parent 9eb917d086
commit 4d53aa4b50
6 changed files with 30 additions and 14 deletions

View File

@ -4,6 +4,8 @@ import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input"; import { Input } from "@/components/ui/input";
import { Textarea } from "@/components/ui/textarea"; import { Textarea } from "@/components/ui/textarea";
const apiBase = import.meta.env.VITE_API_URL;
type NewsItem = { type NewsItem = {
id: number; id: number;
title: string; title: string;
@ -31,7 +33,7 @@ const NewsManager = () => {
const loadNews = async () => { const loadNews = async () => {
try { try {
const res = await fetch("http://192.168.50.65:3000/api/news"); const res = await fetch(`${apiBase}/api/news`);
const data = await res.json(); const data = await res.json();
setNews(data); setNews(data);
} catch (err) { } catch (err) {
@ -42,8 +44,8 @@ const NewsManager = () => {
const handleCreateOrUpdateNews = async () => { const handleCreateOrUpdateNews = async () => {
const method = editMode ? "PUT" : "POST"; const method = editMode ? "PUT" : "POST";
const url = editMode const url = editMode
? `http://192.168.50.65:3000/api/news/${currentId}` ? `${apiBase}/api/news/${currentId}`
: `http://192.168.50.65:3000/api/news`; : `${apiBase}/api/news`;
try { try {
const res = await fetch(url, { const res = await fetch(url, {
@ -89,7 +91,7 @@ const NewsManager = () => {
if (!deleteId) return; if (!deleteId) return;
try { try {
const res = await fetch(`http://192.168.50.65:3000/api/news/${deleteId}`, { const res = await fetch(`${apiBase}/api/news/${deleteId}`, {
method: "DELETE", method: "DELETE",
}); });

View File

@ -5,12 +5,13 @@ import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { useNavigate } from "react-router-dom"; import { useNavigate } from "react-router-dom";
import { useAuth } from "@/context/AuthContext"; import { useAuth } from "@/context/AuthContext";
const apiBase = import.meta.env.VITE_API_URL;
const UserCreatePage = () => { const UserCreatePage = () => {
const [username, setUsername] = useState(""); const [username, setUsername] = useState("");
const [password, setPassword] = useState(""); const [password, setPassword] = useState("");
const [role, setRole] = useState("user"); const [role, setRole] = useState("user");
const [email, setEmail] = useState("");
const { token } = useAuth(); const { token } = useAuth();
const {isAuthenticated, isAdmin} = useAuth(); const {isAuthenticated, isAdmin} = useAuth();
@ -27,13 +28,13 @@ useEffect(() => {
const handleSubmit = async (e: React.FormEvent) => { const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault(); e.preventDefault();
try { try {
const res = await fetch("http://192.168.50.65:3000/api/users", { const res = await fetch(`${apiBase}/api/users`, {
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
Authorization: `Bearer ${token}`, Authorization: `Bearer ${token}`,
}, },
body: JSON.stringify({ username, password, role }), body: JSON.stringify({ username, password, role, email }),
}); });
if (!res.ok) { if (!res.ok) {
@ -55,6 +56,13 @@ useEffect(() => {
</CardHeader> </CardHeader>
<CardContent> <CardContent>
<form onSubmit={handleSubmit} className="space-y-4"> <form onSubmit={handleSubmit} className="space-y-4">
<Input
type="email"
placeholder="E-Mail"
value={email}
onChange={(e) => setEmail(e.target.value)}
required
/>
<Input <Input
placeholder="Benutzername" placeholder="Benutzername"
value={username} value={username}

View File

@ -5,6 +5,8 @@ import { Button } from "@/components/ui/button";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { useAuth } from "@/context/AuthContext"; import { useAuth } from "@/context/AuthContext";
const apiBase = import.meta.env.VITE_API_URL;
const UserEditPage = () => { const UserEditPage = () => {
const { id } = useParams<{ id: string }>(); const { id } = useParams<{ id: string }>();
const { token, isAuthenticated, isAdmin } = useAuth(); const { token, isAuthenticated, isAdmin } = useAuth();
@ -23,7 +25,7 @@ const UserEditPage = () => {
useEffect(() => { useEffect(() => {
const fetchUser = async () => { const fetchUser = async () => {
try { try {
const res = await fetch(`http://192.168.50.65:3000/api/users/${id}`, { const res = await fetch(`${apiBase}/api/users/${id}`, {
headers: { headers: {
Authorization: `Bearer ${token}`, Authorization: `Bearer ${token}`,
}, },
@ -44,7 +46,7 @@ const UserEditPage = () => {
const handleSubmit = async (e: React.FormEvent) => { const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault(); e.preventDefault();
try { try {
await fetch(`http://192.168.50.65:3000/api/users/${id}`, { await fetch(`${apiBase}/api/users/${id}`, {
method: "PUT", method: "PUT",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",

View File

@ -6,7 +6,7 @@ import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter } from "
import { useAuth } from "@/context/AuthContext"; import { useAuth } from "@/context/AuthContext";
import { useNavigate } from "react-router-dom"; import { useNavigate } from "react-router-dom";
const apiBase = import.meta.env.VITE_API_URL;
interface User { interface User {
id: number; id: number;
@ -33,7 +33,7 @@ useEffect(() => {
useEffect(() => { useEffect(() => {
const fetchUsers = async () => { const fetchUsers = async () => {
try { try {
const res = await fetch("http://192.168.50.65:3000/api/users", { const res = await fetch(`${apiBase}/api/users`, {
headers: { headers: {
Authorization: `Bearer ${token}`, Authorization: `Bearer ${token}`,
}, },
@ -52,7 +52,7 @@ useEffect(() => {
if (!userToDelete) return; if (!userToDelete) return;
try { try {
await fetch(`http://192.168.50.65:3000/api/users/${userToDelete.id}`, { await fetch(`${apiBase}/api/users/${userToDelete.id}`, {
method: "DELETE", method: "DELETE",
headers: { headers: {
Authorization: `Bearer ${token}`, Authorization: `Bearer ${token}`,

View File

@ -1,6 +1,8 @@
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
const apiBase = import.meta.env.VITE_API_URL;
type NewsItem = { type NewsItem = {
id: number; id: number;
title: string; title: string;
@ -14,7 +16,7 @@ const AlleNeuigkeitenPage = () => {
const [news, setNews] = useState<NewsItem[]>([]); const [news, setNews] = useState<NewsItem[]>([]);
useEffect(() => { useEffect(() => {
fetch("http://192.168.50.65:3000/api/news") fetch(`${apiBase}/api/news`)
.then((res) => res.json()) .then((res) => res.json())
.then((data) => setNews(data)) .then((data) => setNews(data))
.catch((err) => console.error("Fehler beim Laden der News:", err)); .catch((err) => console.error("Fehler beim Laden der News:", err));

View File

@ -4,6 +4,8 @@ import { Input } from "@/components/ui/input";
import { Button } from "@/components/ui/button"; import { Button } from "@/components/ui/button";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
const apiBase = import.meta.env.VITE_API_URL;
const LoginPage = () => { const LoginPage = () => {
const [email, setEmail] = useState(""); // Wird eigentlich Username sein! const [email, setEmail] = useState(""); // Wird eigentlich Username sein!
const [password, setPassword] = useState(""); const [password, setPassword] = useState("");
@ -15,7 +17,7 @@ const LoginPage = () => {
setError(""); setError("");
try { try {
const res = await fetch("http://192.168.50.65:3000/api/login", { const res = await fetch(`${apiBase}/api/login`, {
method: "POST", method: "POST",
headers: { "Content-Type": "application/json" }, headers: { "Content-Type": "application/json" },
body: JSON.stringify({ username: email, password }), body: JSON.stringify({ username: email, password }),