Skip to content

Commit

Permalink
Make notifications page (#80)
Browse files Browse the repository at this point in the history
* feat: define notifications page

* feat: define notifications path

* Update index.tsx

* patch: use components for each tab

* Create notificationsTab.tsx

* Create systemTab.tsx

* Update index.tsx

* Update notificationsTab.tsx

* Update index.tsx

* Update index.tsx
  • Loading branch information
tinashechiraya authored Nov 15, 2024
1 parent 3d5abbe commit 42a0ba6
Show file tree
Hide file tree
Showing 5 changed files with 478 additions and 27 deletions.
5 changes: 5 additions & 0 deletions django_project/frontend/src/Routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const NotFound = React.lazy(() => import("./pages/NotFound"));
const ProfileInformationPage = React.lazy(() => import("./pages/Profile"));
const OrganisationInformation = React.lazy(() => import("./pages/OrganisationInformation"));
const AnalysisResults = React.lazy(() => import("./pages/AnalysisResults"));
const NotificationsPage = React.lazy(() => import("./pages/Notifications"));
const UploadedResourcesPage = React.lazy(() => import("./pages/UploadedResources"));

const ProjectRoutes = () => {
Expand All @@ -33,6 +34,10 @@ const ProjectRoutes = () => {
path: "/analysis-results",
element: <PrivateRoute Component={AnalysisResults} />,
},
{
path: "/notifications",
element: <PrivateRoute Component={NotificationsPage} />,
},
]);

return (
Expand Down
57 changes: 30 additions & 27 deletions django_project/frontend/src/components/SideBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,26 @@ import React from "react";
import { MenuItem, Menu } from "react-pro-sidebar";
import { HamburgerIcon } from "@chakra-ui/icons";
import { useLocation, useNavigate } from "react-router-dom";
import { AppDispatch, RootState } from '../../store';
import { logoutUser } from '../../store/authSlice';
import { useDispatch } from 'react-redux';
import { AppDispatch } from '../../store';
import { useDispatch } from "react-redux";
import { logoutUser } from "../../store/authSlice";

interface Props extends ChakraProps {
className?: string;
}

export default function Sidebar(props: Props) {
const { isOpen, onOpen, onClose } = useDisclosure();
const dispatch = useDispatch<AppDispatch>();
const location = useLocation();
const navigate = useNavigate();
const isActive = (path: string) => location.pathname === path;
const dispatch = useDispatch<AppDispatch>();

const handleLogout = () => {
dispatch(logoutUser());
onClose();
navigate('/');
};
dispatch(logoutUser());
onClose();
navigate('/');
};

return (
<>
Expand Down Expand Up @@ -80,20 +80,23 @@ export default function Sidebar(props: Props) {
Organisation Information
</MenuItem>
<MenuItem onClick={() => navigate('/dashboard')}>My Dashboard</MenuItem>
<MenuItem
style={{ backgroundColor: isActive('/uploaded-resources') ? '#a8d159' : 'transparent' }}
onClick={() => navigate('/uploaded-resources')}
>
Uploaded Resources
</MenuItem>
<MenuItem
style={{ backgroundColor: isActive('/analysis-results') ? '#a8d159' : 'transparent' }}
onClick={() => navigate('/analysis-results')}>
Analysis Results
</MenuItem>
<MenuItem
style={{ backgroundColor: isActive('/uploaded-resources') ? '#a8d159' : 'transparent' }}
onClick={() => navigate('/uploaded-resources')}>
Uploaded Resources
</MenuItem>
<MenuItem onClick={() => navigate('/support')}>Support</MenuItem>
<MenuItem onClick={() => navigate('/notifications')}>Notifications</MenuItem>
<MenuItem onClick={() => navigate('/sign-out')}>Sign Out</MenuItem>
<MenuItem
style={{ backgroundColor: isActive('/notifications') ? '#a8d159' : 'transparent' }}
onClick={() => navigate('/notifications')}>
Notifications
</MenuItem>
<MenuItem onClick={() => handleLogout()}>Sign Out</MenuItem>
</Box>
</Box>

Expand Down Expand Up @@ -170,23 +173,23 @@ export default function Sidebar(props: Props) {
Organisation Information
</MenuItem>
<MenuItem onClick={() => { navigate('/dashboard'); onClose(); }}>My Dashboard</MenuItem>
<MenuItem
style={{ backgroundColor: isActive('/uploaded-resources') ? '#a8d159' : 'transparent' }}
onClick={() => {
navigate('/uploaded-resources');
onClose();
}}
>
Uploaded Resources
</MenuItem>
<MenuItem
style={{ backgroundColor: isActive('/analysis-results') ? '#a8d159' : 'transparent' }}
onClick={() => { navigate('/analysis-results'); onClose(); }}>
Analysis Results
</MenuItem>
<MenuItem
style={{ backgroundColor: isActive('/uploaded-resources') ? '#a8d159' : 'transparent' }}
onClick={() => { navigate('/uploaded-resources'); onClose(); }}>
Uploaded Resources
</MenuItem>
<MenuItem onClick={() => { navigate('/support'); onClose(); }}>Support</MenuItem>
<MenuItem onClick={() => { navigate('/notifications'); onClose(); }}>Notifications</MenuItem>
<MenuItem onClick={() => handleLogout()}>Sign Out</MenuItem>
<MenuItem
style={{ backgroundColor: isActive('/notifications') ? '#a8d159' : 'transparent' }}
onClick={() => { navigate('/notifications'); onClose(); }}>
Notifications
</MenuItem>
<MenuItem onClick={() => { navigate('/sign-out'); onClose(); }}>Sign Out</MenuItem>
</Box>
</Box>
</DrawerContent>
Expand Down
133 changes: 133 additions & 0 deletions django_project/frontend/src/pages/Notifications/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
import React, { useState, useEffect } from "react";
import Helmet from "react-helmet";
import {
Box,
Heading,
Flex,
Tabs,
TabList,
TabPanels,
Tab,
TabPanel,
Text,
IconButton,
} from "@chakra-ui/react";
import { FaCog } from "react-icons/fa"; // Importing the gear icon
import Header from "../../components/Header";
import Sidebar from "../../components/SideBar";
import NotificationsTab from "./notificationsTab";
import "../../styles/index.css";
import SystemTab from "./systemTab";

export default function Notifications() {
const [selectedTab, setSelectedTab] = useState("all");

const handleSettingsClick = () => {
// You can handle the settings button click here (e.g., open a modal or navigate to settings page)
alert("Settings clicked");
};

return (
<>
<Helmet>
<title>Notifications</title>
<meta name="description" content="View and manage your notifications." />
</Helmet>

<Header />
<Box bg="white" w="100%">
<Flex direction={{ base: "column", md: "row" }} gap="30px" alignItems="start">
{/* Sidebar */}
<Sidebar display={{ base: "none", md: "flex" }} />

{/* Main Content */}
<Box
flex="1"
ml={{ base: "55px", md: "0px" }}
mt={{ base: "0px", md: "20px" }}
width={{ base: "80%", md: "auto" }}
overflow={"auto"}
>
<Heading size="lg" mb={6} color="black">
Notifications
</Heading>

{/* Tabs */}
<Tabs
variant="enclosed"
isLazy
onChange={(index) =>
setSelectedTab(
index === 0
? "all"
: index === 1
? "personal"
: index === 2
? "organisations"
: "system"
)
}
>
<TabList display="flex" alignItems="center">
<Tab
_selected={{ color: "white", bg: "dark_green.800" }}
color={selectedTab === "all" ? "white" : "black"}
bg={selectedTab === "all" ? "dark_green.800" : "transparent"}
>
All
</Tab>
<Tab
_selected={{ color: "white", bg: "dark_green.800" }}
color={selectedTab === "personal" ? "white" : "black"}
bg={selectedTab === "personal" ? "dark_green.800" : "transparent"}
>
Personal
</Tab>
<Tab
_selected={{ color: "white", bg: "dark_green.800" }}
color={selectedTab === "organisations" ? "white" : "black"}
bg={selectedTab === "organisations" ? "dark_green.800" : "transparent"}
>
Organisations
</Tab>
<Tab
_selected={{ color: "white", bg: "dark_green.800" }}
color={selectedTab === "system" ? "white" : "black"}
bg={selectedTab === "system" ? "dark_green.800" : "transparent"}
>
System
</Tab>

{/* Gear Icon on the extreme right */}
<IconButton
icon={<FaCog />}
aria-label="Settings"
onClick={handleSettingsClick}
size="lg"
variant="ghost"
colorScheme="green"
ml="auto"
/>
</TabList>

<TabPanels>
<TabPanel>
<NotificationsTab />
</TabPanel>
<TabPanel>
<Text>No data available for Personal notifications.</Text>
</TabPanel>
<TabPanel>
<Text>No data available for Organisations notifications.</Text>
</TabPanel>
<TabPanel>
<SystemTab />
</TabPanel>
</TabPanels>
</Tabs>
</Box>
</Flex>
</Box>
</>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import React, { useState, useEffect } from "react";
import {
Box,
Heading,
Text,
Badge,
} from "@chakra-ui/react";
import "../../styles/index.css";

export default function NotificationsTab() {
const [allNotifications, setAllNotifications] = useState<any[]>([]);

useEffect(() => {
// Simulate fetching data for "All" notifications
const fetchNotificationsData = () => {

setAllNotifications([]);
};

fetchNotificationsData();
}, []);

return (
<>
<Box>
{allNotifications.map((notification) => (
<Box
key={notification.id}
p={4}
mb={4}
bg="gray.50"
borderRadius="md"
boxShadow="sm"
display="flex"
flexDirection="column"
position="relative"
minHeight="150px"
>
{/* Badge - Custom styled */}
<Badge
colorScheme="green"
position="absolute"
top={2}
right={2}
fontSize="sm"
fontWeight="normal"
px={2}
py={1}
>
{notification.badge}
</Badge>

{/* Title */}
<Heading size="sm" mb={2} color="black">
{notification.title}
</Heading>

{/* Description */}
<Text color="black" mb={4}>
{notification.description}
</Text>

{/* Timestamp */}
<Text
color="black"
position="absolute"
bottom={4}
left={4}
fontSize="sm"
>
{notification.timestamp}
</Text>
</Box>
))}
</Box>
</>
);
}
Loading

0 comments on commit 42a0ba6

Please sign in to comment.