Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor notification Component #127

Open
wants to merge 1 commit into
base: suite
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/components/LoadAccountMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export const LoadAccountMenu = (props: {
const ref = useRef(null)
const dispatch = useAppDispatch()
const setAccount = account => dispatch(updateAccount(account))
const dispatchNotification = ({ message, type }) =>
dispatch(updateNotificationStatus({ message, severity: type }))
const dispatchNotification = ({ message, type, title }) =>
dispatch(updateNotificationStatus({ message, severity: type, title }))
useEffectOnce(() => {
mountAccountMenu(ref.current, {
...props,
Expand Down
4 changes: 2 additions & 2 deletions src/components/Navbar/LoadMyKeysComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ const LoadMyKeysComponent = () => {
const ref = useRef(null)
const dispatch = useAppDispatch()

const dispatchNotification = ({ message, type }) =>
dispatch(updateNotificationStatus({ message, severity: type }))
const dispatchNotification = ({ message, type, title }) =>
dispatch(updateNotificationStatus({ message, severity: type, title }))
useEffectOnce(() => {
mountKyesComponent(ref.current, { dispatchNotification })
}) // eslint-disable-line react-hooks/exhaustive-deps
Expand Down
4 changes: 2 additions & 2 deletions src/components/Navbar/LoadSaveKeysComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ const LoadSaveKeysComponent = () => {
const ref = useRef(null)
const dispatch = useAppDispatch()
const setAccount = account => dispatch(updateAccount(account))
const dispatchNotification = ({ message, type }) =>
dispatch(updateNotificationStatus({ message, severity: type }))
const dispatchNotification = ({ message, type, title }) =>
dispatch(updateNotificationStatus({ message, severity: type, title }))
useEffectOnce(() => {
mountSaveKyesButton(ref.current, { dispatchNotification, setAccount })
}) // eslint-disable-line react-hooks/exhaustive-deps
Expand Down
39 changes: 34 additions & 5 deletions src/components/Notification.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React, { useEffect, useState } from 'react'
import { Alert, Snackbar } from '@mui/material'
import { Alert, Box, Snackbar, Typography } from '@mui/material'
import Slide, { SlideProps } from '@mui/material/Slide'
import { useAppDispatch, useAppSelector } from '../hooks/reduxHooks'
import {
getNotificationMessage,
getNotificationSeverity,
getNotificationStatus,
getNotificationTitle,
updateNotificationStatus,
} from '../redux/slices/app-config'

Expand All @@ -18,6 +19,7 @@ function TransitionUp(props: TransitionProps) {
export default function Notifications() {
const notificationStatus = useAppSelector(getNotificationStatus)
const notificationMessage = useAppSelector(getNotificationMessage)
const notificationTitle = useAppSelector(getNotificationTitle)
const notificationSeverity = useAppSelector(getNotificationSeverity)
const [open, setOpen] = useState(false)
const dispatch = useAppDispatch()
Expand Down Expand Up @@ -46,11 +48,38 @@ export default function Notifications() {
TransitionComponent={transition}
key={transition ? transition.name : ''}
autoHideDuration={5000}
sx={{ top: { xs: '69px !important', md: '72px !important' } }}
sx={{
top: {
xs: '69px !important',
md: '72px !important',
},
}}
>
<Alert severity={notificationSeverity} sx={{ borderRadius: '12px' }}>
{notificationMessage}
</Alert>
<Box
sx={{
padding: '6px 16px',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the reasoning for adding this padding?

backgroundColor: 'rgb(6, 12, 5)',
display: 'flex',
flexDirection: 'column',
borderRadius: '12px',
border: '1px solid rgba(145, 158, 171, 0.24)',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this makes it different from what we have in the BE

}}
>
{notificationTitle && (
<Typography variant="h6">{notificationTitle}</Typography>
)}
<Alert
severity={notificationSeverity}
sx={{
borderRadius: '0px',
display: 'flex',
alignItems: 'center',
borderWidth: 0,
}}
>
<Typography>{notificationMessage}</Typography>
</Alert>
</Box>
</Snackbar>
)}
</>
Expand Down
7 changes: 7 additions & 0 deletions src/redux/slices/app-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ interface InitialStateAppConfigType {
status: Status
notificationStatus: boolean
notificationMessage: string
notificationTitle: string
notificationSeverity: NotificationSeverityType
isAuth: boolean
walletStore: any
Expand All @@ -23,6 +24,7 @@ let initialState: InitialStateAppConfigType = {
notificationStatus: false,
notificationSeverity: 'success',
notificationMessage: '',
notificationTitle: '',
account: null,
showButton: false,
}
Expand Down Expand Up @@ -50,6 +52,8 @@ const appConfigSlice = createSlice({
if (payload && payload.severity) {
state.notificationSeverity = state.notificationStatus ? payload.severity : ''
state.notificationMessage = state.notificationStatus ? payload.message : ''
state.notificationTitle =
state.notificationStatus && payload.title ? payload.title : ''
}
},
updateShowButton(state) {
Expand All @@ -76,6 +80,9 @@ export const getNotificationStatus = (state: RootState) => state.appConfig.notif
//select notification message
export const getNotificationMessage = (state: RootState) => state.appConfig.notificationMessage

//select notification message
export const getNotificationTitle = (state: RootState) => state.appConfig.notificationTitle

//select notification severity
export const getNotificationSeverity = (state: RootState) => state.appConfig.notificationSeverity

Expand Down
4 changes: 2 additions & 2 deletions src/views/wallet/WalletApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ const LoadWallet = () => {
const ref = useRef(null)
const navigate = useNavigate()

const dispatchNotification = ({ message, type }) =>
dispatch(updateNotificationStatus({ message, severity: type }))
const dispatchNotification = ({ message, type, title }) =>
dispatch(updateNotificationStatus({ message, severity: type, title }))
const setAccount = account => dispatch(updateAccount(account))
useEffect(() => {
dispatch(updateValues(updateStore))
Expand Down