Skip to content

Commit

Permalink
fix(dashboard): inconsistent interaction for profile menu options
Browse files Browse the repository at this point in the history
Signed-off-by: amitamrutiya2210 <[email protected]>
  • Loading branch information
amitamrutiya committed May 5, 2024
1 parent 0006351 commit dd67581
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 52 deletions.
52 changes: 12 additions & 40 deletions apps/dashboard/components/color-toggle.tsx
Original file line number Diff line number Diff line change
@@ -1,58 +1,30 @@
"use client"
import * as React from "react"
import { useColorScheme } from "@mui/joy/styles"
import IconButton, { IconButtonProps } from "@mui/joy/IconButton"

import DarkModeRoundedIcon from "@mui/icons-material/DarkModeRounded"
import LightModeIcon from "@mui/icons-material/LightMode"
import { MenuItem } from "@mui/joy"

export default function ColorSchemeToggle({ onClick, sx, ...props }: IconButtonProps) {
export default function ColorSchemeToggle() {
const { mode, setMode } = useColorScheme()
const [mounted, setMounted] = React.useState(false)
React.useEffect(() => {
setMounted(true)
}, [])
if (!mounted) {
return (
<IconButton
size="sm"
variant="outlined"
color="neutral"
{...props}
sx={sx}
disabled
/>
)
}
return (
<IconButton
id="toggle-mode"
size="sm"
variant="outlined"
color="neutral"
{...props}
onClick={(event) => {
<MenuItem
onClick={() => {
if (mode === "light") {
setMode("dark")
} else {
setMode("light")
}
onClick?.(event)
}}
sx={[
{
"& > *:first-of-type": {
display: mode === "dark" ? "none" : "initial",
},
"& > *:last-of-type": {
display: mode === "light" ? "none" : "initial",
},
},
...(Array.isArray(sx) ? sx : [sx]),
]}
sx={{
display: "flex",
justifyContent: "space-between",
fontWeight: "500",
}}
>
<DarkModeRoundedIcon />
<LightModeIcon />
</IconButton>
{mode === "light" ? "Dark Mode" : "Light Mode"}
{mode === "light" ? <DarkModeRoundedIcon /> : <LightModeIcon />}
</MenuItem>
)
}
14 changes: 2 additions & 12 deletions apps/dashboard/components/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ export default function Header() {
placement="bottom-end"
>
<MenuItem
onClick={() => navigator.clipboard.writeText(userData?.defaultAccount.id)}
sx={{
display: "flex",
flexDirection: "column",
alignItems: "flex-start",
}}
>
<Box
onClick={() => navigator.clipboard.writeText(userData?.defaultAccount.id)}
sx={{
width: "100%",
display: "flex",
Expand Down Expand Up @@ -128,17 +128,7 @@ export default function Header() {
Logout
<LogoutOutlinedIcon></LogoutOutlinedIcon>
</MenuItem>

<MenuItem
sx={{
display: "flex",
justifyContent: "space-between",
fontWeight: "500",
}}
>
Dark Mode
<ColorSchemeToggle></ColorSchemeToggle>
</MenuItem>
<ColorSchemeToggle></ColorSchemeToggle>
</Menu>
</Dropdown>
</Sheet>
Expand Down

0 comments on commit dd67581

Please sign in to comment.