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

View File

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

View File

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

View File

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

View File

@ -1,6 +1,8 @@
import { useEffect, useState } from "react";
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
const apiBase = import.meta.env.VITE_API_URL;
type NewsItem = {
id: number;
title: string;
@ -14,7 +16,7 @@ const AlleNeuigkeitenPage = () => {
const [news, setNews] = useState<NewsItem[]>([]);
useEffect(() => {
fetch("http://192.168.50.65:3000/api/news")
fetch(`${apiBase}/api/news`)
.then((res) => res.json())
.then((data) => setNews(data))
.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 { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
const apiBase = import.meta.env.VITE_API_URL;
const LoginPage = () => {
const [email, setEmail] = useState(""); // Wird eigentlich Username sein!
const [password, setPassword] = useState("");
@ -15,7 +17,7 @@ const LoginPage = () => {
setError("");
try {
const res = await fetch("http://192.168.50.65:3000/api/login", {
const res = await fetch(`${apiBase}/api/login`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ username: email, password }),