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

notifications for billing #1656

Merged
merged 9 commits into from
Nov 3, 2021
Merged
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
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.
18 changes: 14 additions & 4 deletions packages/common-components/src/MenuDropdown/MenuDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ interface IMenuDropdownProps {
| "bottom-left"
| "bottom-center"
| "bottom-right"
menuItems: IMenuItem[]
menuItems?: IMenuItem[]
title?: string
classNames?: {
icon?: string
Expand All @@ -177,7 +177,10 @@ interface IMenuDropdownProps {
title?: string
titleText?: string
}
hideIndicator?: boolean
testId?: string
children?: React.ReactNode
dropdown?: React.ReactNode
}

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

return (
<div
ref={ref}
Expand All @@ -222,19 +229,21 @@ const MenuDropdown = ({
{title}
</Typography>
)}
<Icon
{children}
{!hideIndicator && <Icon
className={clsx(classes.icon, animation, classNames?.icon, {
["open"]: open
})}
/>
}
</section>
<Paper
shadow="shadow2"
className={clsx(classes.options, classNames?.options, anchor, {
["open"]: open
})}
>
{menuItems.map((item: IMenuItem, index: number) => (
{menuItems && menuItems.map((item: IMenuItem, index: number) => (
<div
data-testid={`dropdown-item-${testId}`}
key={`menu-${index}`}
Expand All @@ -247,6 +256,7 @@ const MenuDropdown = ({
{item.contents}
</div>
))}
{dropdown}
</Paper>
</div>
)
Expand Down
122 changes: 122 additions & 0 deletions packages/files-ui/src/Components/Elements/NotificationsDropdown.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import React from "react"
import { Button, BellIcon, MenuDropdown, Typography, ScrollbarWrapper } 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",
"span": {
transition: "none"
}
},
badge: {
position: "absolute",
background: palette.additional["volcano"][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: "11px",
lineHeight: "11px",
height: "0.9rem",
minWidth: "1rem"
},
notificationBody: {
padding: `${constants.generalUnit}px ${constants.generalUnit * 1.5}px`,
display: "flex",
alignItems: "center",
cursor: "pointer",
backgroundColor: "initial",
"&:hover": {
backgroundColor: palette.additional["gray"][3]
},
"svg": {
fill: palette.additional["gray"][9]
},
borderBottom: `1px solid ${palette.additional["gray"][5]}`,
":last-child": {
border: "none"
}
},
notificationTitle: {
color: palette.additional["gray"][9],
paddingRight: constants.generalUnit * 1.5,
width: 180
},
scrollContent: {
minWidth: 300
},
notificationTime: {
color: palette.additional["blue"][6]
},
icon: {
transition: "none"
}
})
)

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

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

return (
<MenuDropdown
dropdown={
<ScrollbarWrapper
autoHide={true}
maxHeight={300}
className={classes.scrollContent}
>
<div>
{notifications.map((n, i) => (
<div key={i}
className={classes.notificationBody}
onClick={n.onClick}
>
<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>
))}
</div>
</ScrollbarWrapper>
}
hideIndicator={true}
anchor="bottom-right"
>
<Button variant="tertiary">
<div className={classes.notificationsButton}>
<BellIcon className={classes.icon} />
{!!notifications.length && <div className={classes.badge}>
{notifications.length}
</div>
}
</div>
</Button>
</MenuDropdown>
)
}

export default NotificationsDropdown
19 changes: 16 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,11 @@ 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 +279,7 @@ const AppHeader = ({ navOpen, setNavOpen }: IAppHeader) => {
]}
/>
</section>
</>
</section>
) : (
<>
{!searchActive && (
Expand Down