|
|
|
@ -1,6 +1,7 @@
|
|
|
|
import React, { useEffect, useState, useRef } from "react";
|
|
|
|
import React, { useEffect, useState, useRef } from "react";
|
|
|
|
|
|
|
|
|
|
|
|
function App() {
|
|
|
|
function App() {
|
|
|
|
|
|
|
|
const API_BASE = process.env.REACT_APP_API_URL || "myday.samuelzielke.de";
|
|
|
|
const [datum, setDatum] = useState("2025-05-14");
|
|
|
|
const [datum, setDatum] = useState("2025-05-14");
|
|
|
|
const [data, setData] = useState({ abwesenheiten: [], zeitslots: [] });
|
|
|
|
const [data, setData] = useState({ abwesenheiten: [], zeitslots: [] });
|
|
|
|
const [startzeit, setStartzeit] = useState(null);
|
|
|
|
const [startzeit, setStartzeit] = useState(null);
|
|
|
|
@ -48,8 +49,8 @@ function App() {
|
|
|
|
const handleSaveEdit = async (typ) => {
|
|
|
|
const handleSaveEdit = async (typ) => {
|
|
|
|
const url =
|
|
|
|
const url =
|
|
|
|
typ === "abwesenheit"
|
|
|
|
typ === "abwesenheit"
|
|
|
|
? `http://localhost:3001/api/abwesenheit/${editAbwesenheitId}`
|
|
|
|
? `${API_BASE}/api/abwesenheit/${editAbwesenheitId}`
|
|
|
|
: `http://localhost:3001/api/zeitslot/${editZeitslotId}`;
|
|
|
|
: `${API_BASE}/api/zeitslot/${editZeitslotId}`;
|
|
|
|
await fetch(url, {
|
|
|
|
await fetch(url, {
|
|
|
|
method: "PUT",
|
|
|
|
method: "PUT",
|
|
|
|
headers: { "Content-Type": "application/json" },
|
|
|
|
headers: { "Content-Type": "application/json" },
|
|
|
|
@ -63,7 +64,7 @@ function App() {
|
|
|
|
|
|
|
|
|
|
|
|
const handleSaveNew = async () => {
|
|
|
|
const handleSaveNew = async () => {
|
|
|
|
const endpoint = isAbwesenheit ? "abwesenheit" : "zeitslot";
|
|
|
|
const endpoint = isAbwesenheit ? "abwesenheit" : "zeitslot";
|
|
|
|
await fetch(`http://localhost:3001/api/${endpoint}`, {
|
|
|
|
await fetch(`${API_BASE}/api/${endpoint}`, {
|
|
|
|
method: "POST",
|
|
|
|
method: "POST",
|
|
|
|
headers: { "Content-Type": "application/json" },
|
|
|
|
headers: { "Content-Type": "application/json" },
|
|
|
|
body: JSON.stringify({ datum, ...newEntry }),
|
|
|
|
body: JSON.stringify({ datum, ...newEntry }),
|
|
|
|
@ -74,7 +75,7 @@ function App() {
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const deleteEntry = async (id, typ) => {
|
|
|
|
const deleteEntry = async (id, typ) => {
|
|
|
|
const url = `http://localhost:3001/api/${typ}/${id}`;
|
|
|
|
const url = `${API_BASE}/api/${typ}/${id}`;
|
|
|
|
await fetch(url, { method: "DELETE" });
|
|
|
|
await fetch(url, { method: "DELETE" });
|
|
|
|
reloadData();
|
|
|
|
reloadData();
|
|
|
|
if (typ === "abwesenheit") setEditAbwesenheitId(null);
|
|
|
|
if (typ === "abwesenheit") setEditAbwesenheitId(null);
|
|
|
|
@ -83,7 +84,7 @@ function App() {
|
|
|
|
|
|
|
|
|
|
|
|
// Daten laden
|
|
|
|
// Daten laden
|
|
|
|
useEffect(() => {
|
|
|
|
useEffect(() => {
|
|
|
|
fetch(`http://localhost:3001/api/data/${datum}`)
|
|
|
|
fetch(`${API_BASE}/api/data/${datum}`)
|
|
|
|
.then((res) => res.json())
|
|
|
|
.then((res) => res.json())
|
|
|
|
.then((data) => {
|
|
|
|
.then((data) => {
|
|
|
|
setData(data);
|
|
|
|
setData(data);
|
|
|
|
@ -94,7 +95,7 @@ function App() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const reloadData = () => {
|
|
|
|
const reloadData = () => {
|
|
|
|
fetch(`http://localhost:3001/api/data/${datum}`)
|
|
|
|
fetch(`${API_BASE}/api/data/${datum}`)
|
|
|
|
.then((res) => res.json())
|
|
|
|
.then((res) => res.json())
|
|
|
|
.then((data) => {
|
|
|
|
.then((data) => {
|
|
|
|
setData(data);
|
|
|
|
setData(data);
|
|
|
|
@ -111,7 +112,7 @@ function App() {
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const saveManualEndzeit = async () => {
|
|
|
|
const saveManualEndzeit = async () => {
|
|
|
|
await fetch("http://localhost:3001/api/endzeit", {
|
|
|
|
await fetch(`${API_BASE}/api/endzeit`, {
|
|
|
|
method: "POST",
|
|
|
|
method: "POST",
|
|
|
|
headers: { "Content-Type": "application/json" },
|
|
|
|
headers: { "Content-Type": "application/json" },
|
|
|
|
body: JSON.stringify({ datum, zeit: manualEndzeit }),
|
|
|
|
body: JSON.stringify({ datum, zeit: manualEndzeit }),
|
|
|
|
@ -129,7 +130,7 @@ function App() {
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const saveManualStartzeit = async () => {
|
|
|
|
const saveManualStartzeit = async () => {
|
|
|
|
await fetch("http://localhost:3001/api/startzeit", {
|
|
|
|
await fetch(`${API_BASE}/api/startzeit`, {
|
|
|
|
method: "POST",
|
|
|
|
method: "POST",
|
|
|
|
headers: { "Content-Type": "application/json" },
|
|
|
|
headers: { "Content-Type": "application/json" },
|
|
|
|
body: JSON.stringify({ datum, zeit: manualStartzeit }),
|
|
|
|
body: JSON.stringify({ datum, zeit: manualStartzeit }),
|
|
|
|
|