fixed user deletion

This commit is contained in:
2025-10-08 22:02:14 +02:00
parent f4aaac4679
commit bc15e644b8
9 changed files with 716 additions and 206 deletions

View File

@@ -0,0 +1,94 @@
// frontend/src/contexts/NotificationContext.tsx
import React, { createContext, useContext, useState } from 'react';
export type NotificationType = 'info' | 'success' | 'warning' | 'error';
export interface Notification {
id: string;
type: NotificationType;
title: string;
message: string;
duration?: number;
}
interface NotificationContextType {
notifications: Notification[];
showNotification: (notification: Omit<Notification, 'id'>) => void;
removeNotification: (id: string) => void;
confirmDialog: (options: ConfirmDialogOptions) => Promise<boolean>;
}
interface ConfirmDialogOptions {
title: string;
message: string;
confirmText?: string;
cancelText?: string;
type?: NotificationType;
}
const NotificationContext = createContext<NotificationContextType | undefined>(undefined);
export const NotificationProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
const [notifications, setNotifications] = useState<Notification[]>([]);
const showNotification = (notification: Omit<Notification, 'id'>) => {
const id = Date.now().toString();
const newNotification: Notification = {
id,
duration: 5000,
...notification
};
setNotifications(prev => [...prev, newNotification]);
// Auto-remove after duration
if (newNotification.duration) {
setTimeout(() => {
removeNotification(id);
}, newNotification.duration);
}
};
const removeNotification = (id: string) => {
setNotifications(prev => prev.filter(notif => notif.id !== id));
};
const confirmDialog = (options: ConfirmDialogOptions): Promise<boolean> => {
return new Promise((resolve) => {
const {
title,
message,
confirmText = 'OK',
cancelText = 'Abbrechen',
type = 'warning'
} = options;
const userConfirmed = window.confirm(
`${title}\n\n${message}\n\n${confirmText} / ${cancelText}`
);
resolve(userConfirmed);
});
};
const value = {
notifications,
showNotification,
removeNotification,
confirmDialog
};
return (
<NotificationContext.Provider value={value}>
{children}
</NotificationContext.Provider>
);
};
export const useNotification = () => {
const context = useContext(NotificationContext);
if (context === undefined) {
throw new Error('useNotification must be used within a NotificationProvider');
}
return context;
};