-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
created allert slice and updated some messages
- Loading branch information
1 parent
7070e5a
commit 8daeb22
Showing
10 changed files
with
72 additions
and
16 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,28 @@ | ||
import { useEffect } from 'react' | ||
import { useDispatch, useSelector } from 'react-redux' | ||
import { ToastContainer, toast } from 'react-toastify' | ||
import { clearAlert, selectAlertSlice } from '../../redux/slices/alertSlice' | ||
import 'react-toastify/dist/ReactToastify.css' | ||
|
||
const Alert = () => { | ||
const dispatch = useDispatch() | ||
const alertMessage = useSelector(selectAlertSlice) | ||
|
||
useEffect(() => { | ||
if (alertMessage?.trim()) { | ||
toast.info(alertMessage, { | ||
onClose: () => dispatch(clearAlert()), | ||
}) | ||
} | ||
}, [alertMessage, dispatch]) | ||
|
||
return ( | ||
<ToastContainer | ||
postion="top-right" | ||
autoClose={2000} | ||
bodyClassName="toast-message" | ||
/> | ||
) | ||
} | ||
|
||
export default Alert |
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
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,22 @@ | ||
import { createSlice } from '@reduxjs/toolkit' | ||
|
||
const initialState = '' | ||
|
||
const alertSlice = createSlice({ | ||
name: 'alert', | ||
initialState, | ||
reducers: { | ||
setAlert: (state, action) => { | ||
return action.payload | ||
}, | ||
clearAlert: () => { | ||
return initialState | ||
}, | ||
}, | ||
}) | ||
|
||
export const { setAlert, clearAlert } = alertSlice.actions | ||
|
||
export const selectAlertSlice = (state) => state.alertMessage | ||
|
||
export default alertSlice.reducer |
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