-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
754d33d
commit c59fca4
Showing
8 changed files
with
82 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,23 @@ | ||
import React from 'react'; | ||
import { connect } from 'react-redux'; | ||
import { Alert } from 'react-bootstrap'; | ||
import { useNotificationsSystem } from '../contexts/NotificationsContext'; | ||
import { NotificationsSystemActions } from '../store/slices/Notifications'; | ||
|
||
function NotificationsArea() { | ||
const NotificationsSystem = useNotificationsSystem(); | ||
const { currentNotifications } = NotificationsSystem; | ||
if(!currentNotifications) return null; | ||
|
||
const hideNotifications = () => { NotificationsSystem.clear(); }; | ||
function NotificationsArea({ hasNotifications, message, clearNotifications }) { | ||
if(!hasNotifications) return null; | ||
|
||
return ( | ||
<Alert variant="info" onClose={hideNotifications} dismissible> | ||
{currentNotifications.message} | ||
<Alert variant="info" onClose={clearNotifications} dismissible> | ||
{message} | ||
</Alert> | ||
); | ||
} | ||
|
||
export default NotificationsArea; | ||
export default connect( | ||
(state) => ({ | ||
hasNotifications: state.notifications.currentNotifications != null, | ||
message: state.notifications.currentNotifications?.message | ||
}), { | ||
clearNotifications: NotificationsSystemActions.clear | ||
} | ||
)(NotificationsArea); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { createSlice } from '@reduxjs/toolkit'; | ||
|
||
export const NotificationsSlice = createSlice({ | ||
name: 'notifications', | ||
initialState: { | ||
currentNotifications: null | ||
}, | ||
reducers: { | ||
alert: (state, action) => { | ||
state.currentNotifications = action.payload; | ||
}, | ||
clear: state => { | ||
state.currentNotifications = null; | ||
} | ||
} | ||
}); | ||
|
||
export const NotificationsSystemActions = NotificationsSlice.actions; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters