Skip to content

Commit

Permalink
notifications UI ready
Browse files Browse the repository at this point in the history
  • Loading branch information
tanmoyAtb committed Oct 25, 2021
1 parent c6e935b commit 58e486d
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 5 deletions.
7 changes: 7 additions & 0 deletions packages/common-components/src/Icons/icons/Bell.icon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import * as React from "react"
import createSvgIcon from "../createSvgIcon"
import { ReactComponent as BellSvg } from "../svgs/bell.svg"

export { BellSvg }

export default createSvgIcon(<BellSvg />)
1 change: 1 addition & 0 deletions packages/common-components/src/Icons/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export { default as AppleLogoIcon, AppleLogoSvg } from "./icons/AppleLogo.icon"
export { default as AmexCardIcon, AmexCardSvg } from "./icons/AmexCard.icon"
export { default as ArrowLeftIcon, ArrowLeftSvg } from "./icons/ArrowLeft.icon"
export { default as ArrowRightIcon, ArrowRightSvg } from "./icons/ArrowRight.icon"
export { default as BellIcon, BellSvg } from "./icons/Bell.icon"
export { default as BulbIcon, BulbSvg } from "./icons/Bulb.icon"
export { default as CaretDownIcon, CaretDownSvg } from "./icons/CaretDown.icon"
export { default as CaretUpIcon, CaretUpSvg } from "./icons/CaretUp.icon"
Expand Down
4 changes: 4 additions & 0 deletions packages/common-components/src/Icons/svgs/bell.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 9 additions & 2 deletions packages/common-components/src/MenuDropdown/MenuDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,9 @@ interface IMenuDropdownProps {
title?: string
titleText?: string
}
hideIndicator?: boolean
testId?: string
children?: React.ReactNode
}

const MenuDropdown = ({
Expand All @@ -189,7 +191,9 @@ const MenuDropdown = ({
animation = "flip",
title,
classNames,
testId
testId,
children,
hideIndicator
}: IMenuDropdownProps) => {
const Icon = indicator
const classes = useStyles()
Expand All @@ -201,6 +205,7 @@ const MenuDropdown = ({
setOpen(false)
}
})

return (
<div
ref={ref}
Expand All @@ -222,11 +227,13 @@ const MenuDropdown = ({
{title}
</Typography>
)}
<Icon
{children && children}
{!hideIndicator && <Icon
className={clsx(classes.icon, animation, classNames?.icon, {
["open"]: open
})}
/>
}
</section>
<Paper
shadow="shadow2"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import React from "react"
import { Button, BellIcon, MenuDropdown, Typography } from "@chainsafe/common-components"
import { createStyles, ITheme, makeStyles } from "@chainsafe/common-theme"
import dayjs from "dayjs"
import relativeTime from "dayjs/plugin/relativeTime"
dayjs.extend(relativeTime)

const useStyles = makeStyles(({ palette, constants }: ITheme) =>
createStyles({
notificationsButton: {
position: "relative"
},
badge: {
position: "absolute",
background: palette.additional["red"][6],
color: palette.additional["gray"][1],
top: "-2px",
left: "13px",
borderRadius: constants.generalUnit,
padding: `${constants.generalUnit * 0.25}px ${constants.generalUnit * 0.5}px`,
fontSize: "12px",
lineHeight: "12px"
},
notificationBody: {
margin: `0 ${constants.generalUnit * 1.5}px`,
padding: constants.generalUnit,
display: "flex",
alignItems: "center"
},
notificationItem: {
padding: 0,
borderBottom: `1px solid ${palette.additional["gray"][5]}`,
":last-child": {
border: "none"
}
},
notificationTitle: {
color: palette.additional["gray"][9],
paddingRight: constants.generalUnit * 1.5,
width: 180
},
notificationTime: {
color: palette.primary.main
}
})
)

interface INotificationsDropdownProps {
notifications: {
title: string
subtitle?: string
createdAt: Date
onClick?: () => void
}[]
}

const NotificationsDropdown: React.FC<INotificationsDropdownProps> = ({ notifications }) => {
const classes = useStyles()

return (
<MenuDropdown
menuItems={notifications.map((n) => ({
contents: <div className={classes.notificationBody}>
<Typography variant="body2"
className={classes.notificationTitle}
component="p"
>
{n.title}
</Typography>
<Typography
variant="body2"
className={classes.notificationTime}
component="p"
>
{dayjs(n.createdAt).fromNow()}
</Typography>
</div>,
onClick: n.onClick
}))}
hideIndicator={true}
anchor="bottom-right"
classNames={{
item: classes.notificationItem
}}
>
<Button variant="outline">
<div className={classes.notificationsButton}>
<BellIcon />
{!!notifications.length && <div className={classes.badge}>
{notifications.length}
</div>
}
</div>
</Button>
</MenuDropdown>
)
}

export default NotificationsDropdown
17 changes: 14 additions & 3 deletions packages/files-ui/src/Components/Layouts/AppHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { CSFTheme } from "../../Themes/types"
import { useUser } from "../../Contexts/UserContext"
import { useFilesApi } from "../../Contexts/FilesApiContext"
import TeamModal from "../Elements/TeamModal"
import NotificationsDropdown from "../Elements/NotificationsDropdown"

const useStyles = makeStyles(
({ palette, animation, breakpoints, constants, zIndex }: CSFTheme) => {
Expand Down Expand Up @@ -155,6 +156,13 @@ const useStyles = makeStyles(
marginLeft: constants.generalUnit * 2
}
}
},
headerSection: {
display: "flex",
alignItems: "center"
},
searchBox: {
flex: 1
}
})
}
Expand Down Expand Up @@ -211,8 +219,8 @@ const AppHeader = ({ navOpen, setNavOpen }: IAppHeader) => {
!shouldInitializeAccount && (
<>
{desktop ? (
<>
<section>
<section className={classes.headerSection}>
<section className={classes.searchBox}>
<SearchModule
className={classes.searchModule}
searchActive={searchActive}
Expand All @@ -239,6 +247,9 @@ const AppHeader = ({ navOpen, setNavOpen }: IAppHeader) => {
<Trans>Start a team</Trans>
</Button>
</section>
<section>
<NotificationsDropdown notifications={[]} />
</section>
<section className={classes.accountControls}>
<MenuDropdown
title={getProfileTitle()}
Expand Down Expand Up @@ -266,7 +277,7 @@ const AppHeader = ({ navOpen, setNavOpen }: IAppHeader) => {
]}
/>
</section>
</>
</section>
) : (
<>
{!searchActive && (
Expand Down

0 comments on commit 58e486d

Please sign in to comment.