feat: streamline dashboard actions by removing inline add-entry form and manual refresh
This commit is contained in:
163
src/App.js
163
src/App.js
@@ -2,14 +2,6 @@ import React, { useState, useEffect, useCallback, useMemo } from 'react';
|
||||
import { BrowserRouter as Router, Routes, Route, Navigate, Link, useLocation } from 'react-router-dom';
|
||||
import './App.css';
|
||||
|
||||
const emptyEntry = {
|
||||
id: '',
|
||||
label: '',
|
||||
active: false,
|
||||
checkProfileId: true,
|
||||
onlyNotify: false
|
||||
};
|
||||
|
||||
const TOKEN_STORAGE_KEY = 'pickupConfigToken';
|
||||
|
||||
function App() {
|
||||
@@ -20,8 +12,6 @@ function App() {
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [status, setStatus] = useState('');
|
||||
const [error, setError] = useState('');
|
||||
const [newEntry, setNewEntry] = useState(emptyEntry);
|
||||
const [showNewEntryForm, setShowNewEntryForm] = useState(false);
|
||||
const [availableCollapsed, setAvailableCollapsed] = useState(true);
|
||||
const [adminSettings, setAdminSettings] = useState(null);
|
||||
const [adminSettingsLoading, setAdminSettingsLoading] = useState(false);
|
||||
@@ -115,8 +105,6 @@ function App() {
|
||||
setStores([]);
|
||||
setStatus('');
|
||||
setError('');
|
||||
setShowNewEntryForm(false);
|
||||
setNewEntry(emptyEntry);
|
||||
setAdminSettings(null);
|
||||
setAdminSettingsLoading(false);
|
||||
setAvailableCollapsed(true);
|
||||
@@ -588,26 +576,6 @@ function App() {
|
||||
}
|
||||
};
|
||||
|
||||
const addEntry = () => {
|
||||
if (!newEntry.id || !newEntry.label) {
|
||||
setError('ID und Bezeichnung müssen ausgefüllt werden!');
|
||||
return;
|
||||
}
|
||||
|
||||
const normalized = {
|
||||
...newEntry,
|
||||
id: String(newEntry.id),
|
||||
hidden: false
|
||||
};
|
||||
|
||||
const updatedConfig = [...config.filter((item) => item.id !== normalized.id), normalized];
|
||||
setConfig(updatedConfig);
|
||||
setNewEntry(emptyEntry);
|
||||
setShowNewEntryForm(false);
|
||||
setStatus('Neuer Eintrag hinzugefügt!');
|
||||
setTimeout(() => setStatus(''), 3000);
|
||||
};
|
||||
|
||||
const deleteEntry = (entryId) => {
|
||||
if (window.confirm('Soll dieser Eintrag dauerhaft gelöscht werden?')) {
|
||||
const updatedConfig = config.filter((item) => item.id !== entryId);
|
||||
@@ -681,14 +649,6 @@ function App() {
|
||||
);
|
||||
};
|
||||
|
||||
const handleNewEntryChange = (event) => {
|
||||
const { name, value, type, checked } = event.target;
|
||||
setNewEntry({
|
||||
...newEntry,
|
||||
[name]: type === 'checkbox' ? checked : value
|
||||
});
|
||||
};
|
||||
|
||||
const configMap = useMemo(() => {
|
||||
const map = new Map();
|
||||
config.forEach((item) => {
|
||||
@@ -1165,128 +1125,7 @@ function App() {
|
||||
</table>
|
||||
</div>
|
||||
|
||||
{showNewEntryForm ? (
|
||||
<div className="bg-gray-50 p-4 rounded-lg border border-gray-200 mb-6">
|
||||
<h2 className="text-lg font-semibold mb-4">Neuen Eintrag hinzufügen</h2>
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4 mb-4">
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 mb-1">ID *</label>
|
||||
<input
|
||||
type="text"
|
||||
name="id"
|
||||
value={newEntry.id}
|
||||
onChange={handleNewEntryChange}
|
||||
className="border rounded p-2 w-full focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 mb-1">Bezeichnung *</label>
|
||||
<input
|
||||
type="text"
|
||||
name="label"
|
||||
value={newEntry.label}
|
||||
onChange={handleNewEntryChange}
|
||||
className="border rounded p-2 w-full focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-wrap gap-6 mb-4">
|
||||
<label className="flex items-center">
|
||||
<input
|
||||
type="checkbox"
|
||||
name="active"
|
||||
checked={newEntry.active}
|
||||
onChange={handleNewEntryChange}
|
||||
className="h-5 w-5 text-blue-600 rounded focus:ring-2 focus:ring-blue-500 mr-2"
|
||||
/>
|
||||
<span className="text-sm font-medium text-gray-700">Aktiv</span>
|
||||
</label>
|
||||
<label className="flex items-center">
|
||||
<input
|
||||
type="checkbox"
|
||||
name="checkProfileId"
|
||||
checked={newEntry.checkProfileId}
|
||||
onChange={handleNewEntryChange}
|
||||
className="h-5 w-5 text-blue-600 rounded focus:ring-2 focus:ring-blue-500 mr-2"
|
||||
/>
|
||||
<span className="text-sm font-medium text-gray-700">Profil prüfen</span>
|
||||
</label>
|
||||
<label className="flex items-center">
|
||||
<input
|
||||
type="checkbox"
|
||||
name="onlyNotify"
|
||||
checked={newEntry.onlyNotify}
|
||||
onChange={handleNewEntryChange}
|
||||
className="h-5 w-5 text-blue-600 rounded focus:ring-2 focus:ring-blue-500 mr-2"
|
||||
/>
|
||||
<span className="text-sm font-medium text-gray-700">Nur benachrichtigen</span>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4 mb-4">
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 mb-1">Wochentag</label>
|
||||
<select
|
||||
name="desiredWeekday"
|
||||
value={newEntry.desiredWeekday || ''}
|
||||
onChange={handleNewEntryChange}
|
||||
className="border rounded p-2 w-full bg-white focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500"
|
||||
>
|
||||
<option value="">Kein Wochentag</option>
|
||||
{weekdays.map((day) => (
|
||||
<option key={day} value={day}>
|
||||
{day}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 mb-1">Spezifisches Datum</label>
|
||||
<input
|
||||
type="date"
|
||||
name="desiredDate"
|
||||
value={newEntry.desiredDate || ''}
|
||||
onChange={handleNewEntryChange}
|
||||
className="border rounded p-2 w-full focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500"
|
||||
disabled={newEntry.desiredWeekday}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex justify-end space-x-2">
|
||||
<button
|
||||
onClick={() => setShowNewEntryForm(false)}
|
||||
className="bg-gray-300 hover:bg-gray-400 text-gray-800 px-4 py-2 rounded focus:outline-none focus:ring-2 focus:ring-gray-500"
|
||||
>
|
||||
Abbrechen
|
||||
</button>
|
||||
<button
|
||||
onClick={addEntry}
|
||||
className="bg-blue-500 hover:bg-blue-600 text-white px-4 py-2 rounded focus:outline-none focus:ring-2 focus:ring-blue-500"
|
||||
>
|
||||
Hinzufügen
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<button
|
||||
onClick={() => setShowNewEntryForm(true)}
|
||||
className="bg-green-500 hover:bg-green-600 text-white px-4 py-2 rounded mb-6 focus:outline-none focus:ring-2 focus:ring-green-500"
|
||||
>
|
||||
Neuen Eintrag hinzufügen
|
||||
</button>
|
||||
)}
|
||||
|
||||
<div className="flex justify-between mb-6">
|
||||
<button
|
||||
onClick={fetchConfig}
|
||||
className="bg-gray-500 hover:bg-gray-600 text-white py-2 px-4 rounded focus:outline-none focus:ring-2 focus:ring-gray-500 transition-colors"
|
||||
>
|
||||
Aktualisieren
|
||||
</button>
|
||||
<div className="flex justify-end mb-6">
|
||||
<button
|
||||
onClick={saveConfig}
|
||||
className="bg-blue-500 hover:bg-blue-600 text-white py-2 px-4 rounded focus:outline-none focus:ring-2 focus:ring-blue-500 transition-colors"
|
||||
|
||||
Reference in New Issue
Block a user