diff --git a/src/pages/notification/ManageNotification.tsx b/src/pages/notification/ManageNotification.tsx
index 58f154e..3f26388 100644
--- a/src/pages/notification/ManageNotification.tsx
+++ b/src/pages/notification/ManageNotification.tsx
@@ -1,10 +1,17 @@
+import { Container, DataGridInner } from '@/components';
+import { ManageNotifContextProvider } from './hooks/ManageNotificationContext';
+import AddDialog from './blocks/AddDialog';
+
const ManageNotification = () => {
return (
-
-
-
Manage Notification
-
-
+
+
+
+
+
+
+
+
);
};
diff --git a/src/pages/notification/blocks/AddDialog.tsx b/src/pages/notification/blocks/AddDialog.tsx
new file mode 100644
index 0000000..9daebf8
--- /dev/null
+++ b/src/pages/notification/blocks/AddDialog.tsx
@@ -0,0 +1,147 @@
+import { apiConfig } from '@/config/api.config';
+import { useRef, useState } from 'react';
+import { Alert, KeenIcon, useDataGrid } from '@/components';
+import { useCallApi } from '@/hooks';
+import {
+ Dialog,
+ DialogBody,
+ DialogContent,
+ DialogDescription,
+ DialogHeader,
+ DialogTitle
+} from '@/components/ui/dialog';
+import { Input } from '@/components/ui/input';
+import { Button } from '@/components/ui/button';
+import { useManageNotificationContext } from '../hooks/useManageNotificationContext';
+
+const API_URL = apiConfig.service_dashboard;
+
+const AddDialog = () => {
+ const parentRef = useRef(null);
+ const {
+ handleAddDialog,
+ handleEditDialog,
+ showAddDialog,
+ showEditDialog,
+ selectedNotification,
+ notifications
+ } = useManageNotificationContext();
+
+ const { reload } = useDataGrid();
+ const { PostData, PutData } = useCallApi();
+ const [alert, setAlert] = useState({
+ show: false,
+ message: ''
+ });
+
+ const initialState = {
+ name: '',
+ destination_module: ''
+ };
+
+ const [formField, setFormField] = useState(initialState);
+ const resetForm = () => {
+ setFormField(initialState);
+ };
+ const [isSubmitting, setIsSubmitting] = useState(false);
+
+ const handleSubmit = (e: React.FormEvent) => {
+ e.preventDefault();
+
+ if (formField.name === '' || formField.destination_module === '') {
+ setAlert({ show: true, message: 'Please fill in all required fields.' });
+ return;
+ }
+ console.log(formField);
+ setAlert({ show: false, message: '' });
+ };
+
+ const handleReset = () => {
+ setFormField(initialState);
+ };
+
+ return (
+
+ );
+};
+
+export default AddDialog;
diff --git a/src/pages/notification/blocks/ListToolbar.tsx b/src/pages/notification/blocks/ListToolbar.tsx
new file mode 100644
index 0000000..aa88983
--- /dev/null
+++ b/src/pages/notification/blocks/ListToolbar.tsx
@@ -0,0 +1,57 @@
+import { DefaultTooltip, KeenIcon, useDataGrid } from '@/components';
+import { useManageNotificationContext } from '../hooks/useManageNotificationContext';
+import { Button } from '@/components/ui/button';
+
+const ListToolBar = () => {
+ const { table, reload } = useDataGrid();
+ const { handleAddDialog } = useManageNotificationContext();
+
+ return (
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ );
+};
+
+export { ListToolBar };
diff --git a/src/pages/notification/hooks/ManageNotificationContext.tsx b/src/pages/notification/hooks/ManageNotificationContext.tsx
new file mode 100644
index 0000000..238922f
--- /dev/null
+++ b/src/pages/notification/hooks/ManageNotificationContext.tsx
@@ -0,0 +1,142 @@
+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 (
+
+
+
Manage Notifications
+
+
+
+
+ }
+ layout={{ card: true }}
+ sorting={[{ id: 'username', desc: false }]}
+ serverSide={true}
+ >
+ {children}
+
+
+
+ );
+};
+
+export { ManageNotifContext, ManageNotifContextProvider };
+export type { SelectedNotification };
diff --git a/src/pages/notification/hooks/useManageNotificationContext.tsx b/src/pages/notification/hooks/useManageNotificationContext.tsx
new file mode 100644
index 0000000..ceb5f0a
--- /dev/null
+++ b/src/pages/notification/hooks/useManageNotificationContext.tsx
@@ -0,0 +1,12 @@
+import { useContext } from 'react';
+import { ManageNotifContext } from './ManageNotificationContext';
+
+const useManageNotificationContext = () => {
+ const context = useContext(ManageNotifContext);
+
+ if (!context) throw new Error('useManageNotificationContext must be used within AuthProvider');
+
+ return context;
+};
+
+export { useManageNotificationContext };