Skip to content

Commit

Permalink
Refactor Notifications component to utilize SnackbarContext for notif…
Browse files Browse the repository at this point in the history
…ications handling and fix the bug with the reverse background color
  • Loading branch information
S-e-b-a-s committed Nov 5, 2024
1 parent 65a412f commit 43042dd
Showing 1 changed file with 6 additions and 22 deletions.
28 changes: 6 additions & 22 deletions frontend/src/components/shared/Notifications.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import React, { useState } from 'react';

// Custom Hooks
import { useSnackbar } from '../context/SnackbarContext';

// Custom Components
import { getApiUrl } from '../../assets/getApi';
import SnackbarAlert from '../common/SnackBarAlert';
import { handleError } from '../../assets/handleError';

// Material UI
Expand Down Expand Up @@ -34,28 +36,16 @@ const Notifications = ({
notifications,
getNotifications,
}) => {
const { showSnack } = useSnackbar();
const [anchorElOptions, setAnchorElOptions] = useState(null);
const openOptions = Boolean(anchorElOptions);
const [notificationStatus, setNotificationStatus] = useState(false);
const [notificationId, setNotificationId] = useState(null);
const [openSnack, setOpenSnack] = useState(false);
const [message, setMessage] = useState('');
const [severity, setSeverity] = useState('');

const handleClose = () => {
setAnchorNotification(null);
};

const showSnack = (severity, message) => {
setMessage(message);
setSeverity(severity);
setOpenSnack(true);
};

const closeSnack = () => {
setOpenSnack(false);
};

const handleCloseOptions = () => {
setAnchorElOptions(null);
};
Expand Down Expand Up @@ -122,12 +112,6 @@ const Notifications = ({

return (
<Box>
<SnackbarAlert
message={message}
severity={severity}
openSnack={openSnack}
closeSnack={closeSnack}
/>
<Menu
id="notifications-menu"
anchorEl={anchorNotification}
Expand Down Expand Up @@ -161,8 +145,8 @@ const Notifications = ({
key={notification.id}
sx={{
backgroundColor: notification.read
? '#f5fafc'
: '#fff',
? '#fff'
: '#f5fafc',
width: '100%',
maxWidth: 400,
}}
Expand Down

0 comments on commit 43042dd

Please sign in to comment.