-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…-DisplayNotifications #3000-Displaying Notifications
- Loading branch information
Showing
17 changed files
with
317 additions
and
37 deletions.
There are no files selected for viewing
8 changes: 0 additions & 8 deletions
8
...ackend/src/prisma/migrations/20240910005616_add_logo_image_featured_project/migration.sql
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
...c/prisma/migrations/20240911164338_changed_logo_image_name_to_logo_image_id/migration.sql
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
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
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,57 @@ | ||
import { Box } from '@mui/material'; | ||
import React, { useEffect, useState } from 'react'; | ||
import { Notification, User } from 'shared'; | ||
import NotificationCard from './NotificationCard'; | ||
import { useRemoveUserNotification, useUserNotifications } from '../hooks/users.hooks'; | ||
import { useHistory } from 'react-router-dom'; | ||
|
||
interface NotificationAlertProps { | ||
user: User; | ||
} | ||
|
||
const NotificationAlert: React.FC<NotificationAlertProps> = ({ user }) => { | ||
const { data: notifications, isLoading: notificationsIsLoading } = useUserNotifications(user.userId); | ||
const { mutateAsync: removeNotification, isLoading: removeIsLoading } = useRemoveUserNotification(user.userId); | ||
const [currentNotification, setCurrentNotification] = useState<Notification>(); | ||
const history = useHistory(); | ||
|
||
useEffect(() => { | ||
if (notifications && notifications.length > 0) { | ||
setCurrentNotification(notifications[0]); | ||
} | ||
}, [notifications]); | ||
|
||
const removeNotificationWrapper = async (notification: Notification) => { | ||
setCurrentNotification(undefined); | ||
await removeNotification(notification); | ||
}; | ||
|
||
const onClick = async (notification: Notification) => { | ||
if (!!notification.eventLink) { | ||
await removeNotificationWrapper(notification); | ||
history.push(notification.eventLink); | ||
} | ||
}; | ||
|
||
return ( | ||
<Box | ||
sx={{ | ||
position: 'fixed', | ||
top: 16, | ||
right: 16, | ||
transform: !!currentNotification ? 'translateX(0)' : 'translateX(110%)', | ||
transition: 'transform 0.5s ease-out' | ||
}} | ||
> | ||
{!removeIsLoading && !notificationsIsLoading && currentNotification && ( | ||
<NotificationCard | ||
notification={currentNotification} | ||
removeNotification={removeNotificationWrapper} | ||
onClick={onClick} | ||
/> | ||
)} | ||
</Box> | ||
); | ||
}; | ||
|
||
export default NotificationAlert; |
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,73 @@ | ||
import { Box, Card, Icon, IconButton, Typography, useTheme } from '@mui/material'; | ||
import React from 'react'; | ||
import { Notification } from 'shared'; | ||
import CloseIcon from '@mui/icons-material/Close'; | ||
|
||
interface NotificationCardProps { | ||
notification: Notification; | ||
removeNotification: (notificationId: Notification) => Promise<void>; | ||
onClick: (notificationId: Notification) => Promise<void>; | ||
} | ||
|
||
const NotificationCard: React.FC<NotificationCardProps> = ({ notification, removeNotification, onClick }) => { | ||
const theme = useTheme(); | ||
return ( | ||
<Card | ||
variant={'outlined'} | ||
sx={{ | ||
display: 'flex', | ||
justifyContent: 'left', | ||
alignItems: 'center', | ||
gap: 1, | ||
background: theme.palette.background.paper, | ||
width: 300, | ||
borderRadius: 4, | ||
padding: 1 | ||
}} | ||
> | ||
<Box | ||
sx={{ | ||
width: '100%', | ||
display: 'flex', | ||
alignItems: 'center', | ||
justifyContent: 'space-between' | ||
}} | ||
> | ||
<Box | ||
onClick={async () => await onClick(notification)} | ||
sx={{ | ||
display: 'flex', | ||
gap: 1, | ||
cursor: !!notification.eventLink ? 'pointer' : 'default' | ||
}} | ||
> | ||
<Box | ||
sx={{ | ||
display: 'flex', | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
padding: 2, | ||
background: theme.palette.primary.main, | ||
width: '30%', | ||
borderRadius: 4 | ||
}} | ||
> | ||
<Icon | ||
sx={{ | ||
fontSize: 36 | ||
}} | ||
> | ||
{notification.iconName} | ||
</Icon> | ||
</Box> | ||
<Typography variant="subtitle2">{notification.text}</Typography> | ||
</Box> | ||
<IconButton onClick={() => removeNotification(notification)}> | ||
<CloseIcon /> | ||
</IconButton> | ||
</Box> | ||
</Card> | ||
); | ||
}; | ||
|
||
export default NotificationCard; |
Oops, something went wrong.