CoreControl/components/cards/settings/NotificationSettings.tsx

60 lines
3.0 KiB
TypeScript
Raw Normal View History

2025-05-25 00:32:16 +02:00
'use client';
import { useState } from 'react';
import AddNotification from '@/components/dialogues/AddNotification';
2025-05-25 00:56:54 +02:00
import DeleteNotification from '@/components/dialogues/DeleteNotification';
2025-05-25 00:32:16 +02:00
import useNotifications from '@/hooks/useNotifications';
2025-05-25 00:56:54 +02:00
import { Plus, Trash2, Play } from 'lucide-react';
2025-05-25 00:32:16 +02:00
export const NotificationSettings = ({ onError, onSuccess }: { onError: (message: string) => void, onSuccess: (message: string) => void }) => {
2025-05-25 00:56:54 +02:00
const { loadNotifications, notifications } = useNotifications();
const [deleteNotificationId, setDeleteNotificationId] = useState<number | null>(null);
2025-05-25 00:32:16 +02:00
return (
<div>
<div className="w-full bg-base-200 p-4 rounded-2xl border border-stone-800">
<div className="flex items-center justify-between">
<div>
<h2 className="text-lg font-bold">Notification Settings</h2>
<p className="text-sm opacity-70">Manage your notification settings</p>
</div>
<button className="btn btn-primary" onClick={() => (document.getElementById('add_notification') as HTMLDialogElement)?.showModal()}>
<Plus className="w-5 h-5" />
Add Provider
</button>
</div>
2025-05-25 00:56:54 +02:00
<div className='overflow-x-auto pt-4'>
<table className='table table-zebra table-pin-cols'>
<thead>
<tr>
<th>#</th>
<th>Name</th>
<th>Type</th>
<th className='w-24 text-center'>Actions</th>
</tr>
</thead>
<tbody>
{notifications.map((notification: any) => (
<tr key={notification.id}>
<td>{notification.id}</td>
<td>{notification.name}</td>
<td>{notification.type}</td>
<td>
<div className='flex items-center gap-2'>
<button className='btn btn-sm btn-success'><Play className='w-4 h-4' /></button>
<button className='btn btn-sm btn-error' onClick={() => {setDeleteNotificationId(notification.id); (document.getElementById('delete_notification') as HTMLDialogElement)?.showModal()}}><Trash2 className='w-4 h-4' /></button>
</div>
</td>
</tr>
))}
</tbody>
</table>
</div>
2025-05-25 00:32:16 +02:00
<AddNotification onNotificationAdded={loadNotifications} onSuccess={onSuccess} onError={onError} />
2025-05-25 00:56:54 +02:00
{deleteNotificationId && (
<DeleteNotification notificationId={deleteNotificationId} onNotificationDeleted={loadNotifications} onError={onError} onSuccess={onSuccess} />
)}
2025-05-25 00:32:16 +02:00
</div>
</div>
);
};