import { DataGridColumnHeader, DataGridProvider } from '@/components'; import { Toaster } from '@/components/ui/sonner'; import { apiConfig } from '@/config/api.config'; import { ColumnDef } from '@tanstack/react-table'; import React, { createContext, useCallback, useMemo, useState } from 'react'; import { ListToolBar } from '../blocks/ListToolbar'; interface ContextProps { showEditDialog: boolean; handleEditDialog: (show: boolean, selected_user: string | null) => void; showAddDialog: boolean; handleAddDialog: (show: boolean) => void; selectedNotification: string | null; notifications: NotificationProps[]; } interface SelectedNotification { id: string; name: string; destination_module: string; } interface NotificationProps { id: string; name: string; destination_module: string; } const initialProps: ContextProps = { showEditDialog: false, showAddDialog: false, handleEditDialog: () => {}, handleAddDialog: () => {}, selectedNotification: null, notifications: [] }; const ManageNotifContext = createContext(initialProps); const API_URL = apiConfig.service_dashboard; const ManageNotifContextProvider = ({ children }: { children: React.ReactNode }) => { const [showEditDialog, setShowEditDialog] = useState(false); const [showAddDialog, setShowAddDialog] = useState(false); const [selectedNotification, setSelectedNotification] = useState(null); const [notifications, setNotifications] = useState([]); const handleAddDialog = useCallback((show: boolean) => { setShowAddDialog(show); }, []); const handleEditDialog = useCallback((show: boolean, selected_notification: string | null) => { setSelectedNotification(show ? selected_notification : null); setShowEditDialog(show); }, []); const columns = useMemo[]>( () => [ { accessorFn: (row) => row.id, id: 'id', header: ({ column }) => , enableSorting: true, enableHiding: false, meta: { headerClassName: 'w-[100px]' } }, { accessorFn: (row) => row.name, id: 'name', header: ({ column }) => , enableSorting: true, enableHiding: false }, { accessorFn: (row) => row.destination_module, id: 'destination_module', header: ({ column }) => , enableSorting: true, enableHiding: false }, { id: 'actions', header: ({ column }) => , meta: { headerClassName: 'w-[100px]', cellClassName: 'text-center' }, cell: (data: any) => { const row = data.row.original; return (
); } } ], [handleEditDialog, handleAddDialog] ); return (
} layout={{ card: true }} sorting={[{ id: 'username', desc: false }]} serverSide={true} > {children}
); }; export { ManageNotifContext, ManageNotifContextProvider }; export type { SelectedNotification };