This repository has been archived by the owner on Mar 23, 2024. It is now read-only.
-
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
Showing
5 changed files
with
100 additions
and
18 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
62 changes: 62 additions & 0 deletions
62
client/src/widgets/sidebar/ui/notification-item/friend-notification.tsx
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,62 @@ | ||
import React from 'react'; | ||
|
||
import { Flex } from '@/shared/ui'; | ||
import { LightningIcon } from '@/shared/assets'; | ||
import { getElapsedTime } from '@/shared/lib'; | ||
|
||
import styles from './notification-item.module.scss'; | ||
import { IFriendNotification } from '@teameights/types'; | ||
import { FriendButton } from '@/features/friend-button'; | ||
import { useGetFriends } from '@/entities/session'; | ||
|
||
interface SystemNotificationProps { | ||
notification: IFriendNotification; | ||
} | ||
|
||
/** | ||
* SidebarFriendNotification component renders system notification content. | ||
* | ||
* @component | ||
* @param {Object} props - The properties object. | ||
* @param {SystemNotification} props.notification - The system notification object. | ||
* | ||
* @example | ||
* <SidebarFriendNotification | ||
* notification={systemNotificationObj} | ||
* /> | ||
*/ | ||
export const SidebarFriendNotification: React.FC<SystemNotificationProps> = props => { | ||
const { notification } = props; | ||
|
||
const myId = notification.receiver.id; | ||
const userId = notification.data.creator.id; | ||
const { data: friendships } = useGetFriends(userId); | ||
|
||
const isPending = friendships?.data.some( | ||
friendship => | ||
(friendship.creator.id === myId || friendship.receiver.id === myId) && | ||
friendship.status === 'pending' | ||
); | ||
|
||
return ( | ||
<> | ||
<Flex gap='12px'> | ||
<div className={`${styles.messagePicture} ${styles.small}`}> | ||
{!notification.read && <div className={styles.messageCircle} />} | ||
<LightningIcon /> | ||
</div> | ||
<Flex align='start' gap='12px' direction='column'> | ||
<p className={styles.messageText}> | ||
{notification.data.creator.username} sent you friend request! | ||
</p> | ||
{isPending && ( | ||
<Flex gap='8px'> | ||
<FriendButton size='s' short={true} userId={userId} myId={myId} /> | ||
</Flex> | ||
)} | ||
</Flex> | ||
</Flex> | ||
<p className={styles.sendingTime}>{getElapsedTime(notification.createdAt)}</p> | ||
</> | ||
); | ||
}; |
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 |
---|---|---|
|
@@ -83,3 +83,7 @@ | |
opacity: 0.8; | ||
} | ||
} | ||
|
||
.notification_button { | ||
width: 85px; | ||
} |
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