eigenen 'Löschen'-Dialog
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
|
import { useState } from 'react';
|
||||||
import { WerteEntry } from '@/types/werte';
|
import { WerteEntry } from '@/types/werte';
|
||||||
|
|
||||||
interface WerteListProps {
|
interface WerteListProps {
|
||||||
@@ -8,7 +9,38 @@ interface WerteListProps {
|
|||||||
onEdit?: (entry: WerteEntry) => void;
|
onEdit?: (entry: WerteEntry) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function ConfirmDialog({
|
||||||
|
onConfirm,
|
||||||
|
onCancel,
|
||||||
|
}: {
|
||||||
|
onConfirm: () => void;
|
||||||
|
onCancel: () => void;
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/40">
|
||||||
|
<div className="bg-white border border-gray-300 rounded-lg shadow-lg p-6 w-80 text-center">
|
||||||
|
<p className="mb-6 text-gray-800 font-medium">Eintrag wirklich löschen?</p>
|
||||||
|
<div className="flex justify-center gap-4">
|
||||||
|
<button
|
||||||
|
onClick={onConfirm}
|
||||||
|
className="bg-red-500 hover:bg-red-600 text-white font-medium py-1.5 px-6 rounded-lg transition-colors"
|
||||||
|
>
|
||||||
|
Löschen
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={onCancel}
|
||||||
|
className="bg-[#85B7D7] hover:bg-[#6a9fc5] text-black font-medium py-1.5 px-6 rounded-lg transition-colors"
|
||||||
|
>
|
||||||
|
Abbrechen
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export default function WerteList({ entries, onDelete, onEdit }: WerteListProps) {
|
export default function WerteList({ entries, onDelete, onEdit }: WerteListProps) {
|
||||||
|
const [confirmId, setConfirmId] = useState<number | null>(null);
|
||||||
const formatValue = (value: number | string | null | undefined) => {
|
const formatValue = (value: number | string | null | undefined) => {
|
||||||
if (value === null || value === undefined || value === '' || value === '0' || value === '0.0') {
|
if (value === null || value === undefined || value === '' || value === '0' || value === '0.0') {
|
||||||
return '-';
|
return '-';
|
||||||
@@ -44,10 +76,6 @@ export default function WerteList({ entries, onDelete, onEdit }: WerteListProps)
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleDelete = async (id: number) => {
|
const handleDelete = async (id: number) => {
|
||||||
if (!confirm('Eintrag wirklich löschen?')) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`/api/werte/${id}`, {
|
const response = await fetch(`/api/werte/${id}`, {
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
@@ -61,6 +89,8 @@ export default function WerteList({ entries, onDelete, onEdit }: WerteListProps)
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error:', error);
|
console.error('Error:', error);
|
||||||
alert('Fehler beim Löschen!');
|
alert('Fehler beim Löschen!');
|
||||||
|
} finally {
|
||||||
|
setConfirmId(null);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -74,6 +104,12 @@ export default function WerteList({ entries, onDelete, onEdit }: WerteListProps)
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="overflow-x-auto">
|
<div className="overflow-x-auto">
|
||||||
|
{confirmId !== null && (
|
||||||
|
<ConfirmDialog
|
||||||
|
onConfirm={() => handleDelete(confirmId)}
|
||||||
|
onCancel={() => setConfirmId(null)}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
<table className="w-full border-collapse">
|
<table className="w-full border-collapse">
|
||||||
<thead>
|
<thead>
|
||||||
<tr className="bg-[#CCCCFF] border-b-2 border-gray-400">
|
<tr className="bg-[#CCCCFF] border-b-2 border-gray-400">
|
||||||
@@ -117,7 +153,7 @@ export default function WerteList({ entries, onDelete, onEdit }: WerteListProps)
|
|||||||
)}
|
)}
|
||||||
{onDelete && (
|
{onDelete && (
|
||||||
<button
|
<button
|
||||||
onClick={() => entry.ID && handleDelete(entry.ID)}
|
onClick={() => entry.ID && setConfirmId(entry.ID)}
|
||||||
className="text-red-600 hover:text-red-800 text-sm"
|
className="text-red-600 hover:text-red-800 text-sm"
|
||||||
>
|
>
|
||||||
Löschen
|
Löschen
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ set -e
|
|||||||
|
|
||||||
# Konfiguration
|
# Konfiguration
|
||||||
REGISTRY="docker.citysensor.de"
|
REGISTRY="docker.citysensor.de"
|
||||||
IMAGE_NAME="werte-next_multi"
|
IMAGE_NAME="werte-next"
|
||||||
TAG="${1:-latest}" # Erster Parameter oder "latest"
|
TAG="${1:-latest}" # Erster Parameter oder "latest"
|
||||||
FULL_IMAGE="${REGISTRY}/${IMAGE_NAME}:${TAG}"
|
FULL_IMAGE="${REGISTRY}/${IMAGE_NAME}:${TAG}"
|
||||||
|
|
||||||
|
|||||||
4
proxy.ts
4
proxy.ts
@@ -1,5 +1,4 @@
|
|||||||
import { NextRequest, NextResponse } from 'next/server';
|
import { NextRequest, NextResponse } from 'next/server';
|
||||||
import { cookies } from 'next/headers';
|
|
||||||
import { jwtVerify } from 'jose';
|
import { jwtVerify } from 'jose';
|
||||||
|
|
||||||
const SESSION_COOKIE_NAME = 'auth_session';
|
const SESSION_COOKIE_NAME = 'auth_session';
|
||||||
@@ -28,8 +27,7 @@ export async function proxy(request: NextRequest) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check for session cookie
|
// Check for session cookie
|
||||||
const cookieStore = await cookies();
|
const sessionCookie = request.cookies.get(SESSION_COOKIE_NAME);
|
||||||
const sessionCookie = cookieStore.get(SESSION_COOKIE_NAME);
|
|
||||||
|
|
||||||
if (!sessionCookie) {
|
if (!sessionCookie) {
|
||||||
return NextResponse.redirect(new URL('/login', request.url));
|
return NextResponse.redirect(new URL('/login', request.url));
|
||||||
|
|||||||
Reference in New Issue
Block a user