-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #64 from metrico/alexey-notifications
Added generic notification component + multi-notifications refs and fixes #60
- Loading branch information
Showing
14 changed files
with
158 additions
and
133 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
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,15 @@ | ||
import store from '../store/store'; | ||
|
||
export const createAlert = ( action) => (dispatch) => { | ||
console.log(action) | ||
const notifications = store.getState().notifications | ||
notifications.push({ | ||
message: action.message, | ||
type: action.type, | ||
visible: true | ||
}) | ||
dispatch({ | ||
type: "ADD_NOTIFICATION", | ||
payload: [...notifications] | ||
}); | ||
} |
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,10 @@ | ||
import store from '../store/store'; | ||
|
||
export const removeAlert = ( index) => (dispatch) => { | ||
let notifications = store.getState().notifications | ||
notifications[index].visible = false; | ||
dispatch({ | ||
type: "REMOVE_NOTIFICATION", | ||
payload: [...notifications] | ||
}); | ||
} |
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 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,6 @@ | ||
export const notificationTypes = { | ||
info: 'info', | ||
warning: 'warning', | ||
error: 'error', | ||
success: 'success' | ||
} |
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,51 @@ | ||
import React, { useState, useEffect } from "react"; | ||
|
||
import { useSelector, useDispatch } from "react-redux"; | ||
import { Alert} from "@mui/material"; | ||
import { removeAlert } from "../../actions"; | ||
|
||
|
||
|
||
export function Notification() { | ||
const { notifications } = useSelector(state => state); | ||
const dispatch = useDispatch(); | ||
const handleClose = (index) => { | ||
dispatch(removeAlert(index)) | ||
}; | ||
const Expire = props => { | ||
useEffect(() => { | ||
setTimeout(() => { | ||
dispatch(removeAlert(props.index)) | ||
}, props.delay); | ||
}, [props]); | ||
|
||
return <div>{props.children}</div>; | ||
}; | ||
|
||
return ( | ||
<div className={'alertWrapper'}> | ||
{ | ||
notifications.map((notification, index) => { | ||
if (notification.visible) { | ||
return <Expire key={index} delay='5000' index={index}> | ||
<div className={'alert'}> | ||
<Alert | ||
elevation={6} | ||
variant="filled" | ||
onClose={() => handleClose(index)} | ||
severity={notification.type} | ||
sx={{ width: "100%" }} | ||
> | ||
{notification.message} | ||
</Alert> | ||
</div> | ||
</Expire> | ||
} else { | ||
return undefined; | ||
} | ||
} | ||
) | ||
} | ||
</div> | ||
); | ||
} |
Oops, something went wrong.