diff --git a/.changeset/ninety-berries-promise.md b/.changeset/ninety-berries-promise.md new file mode 100644 index 000000000..a89184d8e --- /dev/null +++ b/.changeset/ninety-berries-promise.md @@ -0,0 +1,5 @@ +--- +"nextjs-website": patch +--- + +[DEV-1239] Implementation of user profile mobile menu diff --git a/apps/nextjs-website/src/components/molecules/MobileProfileMenu/MobileProfileMenu.tsx b/apps/nextjs-website/src/components/molecules/MobileProfileMenu/MobileProfileMenu.tsx index e6c3baa2a..1ada79b49 100644 --- a/apps/nextjs-website/src/components/molecules/MobileProfileMenu/MobileProfileMenu.tsx +++ b/apps/nextjs-website/src/components/molecules/MobileProfileMenu/MobileProfileMenu.tsx @@ -1,19 +1,26 @@ 'use client'; -import React, { useCallback, useState } from 'react'; +import { profileMenuItems } from '@/config'; +import EContainer from '@/editorialComponents/EContainer/EContainer'; +import { useTranslations } from 'next-intl'; +import Link from 'next/link'; +import { useCallback, useEffect, useState } from 'react'; + +import ArrowDropDownOutlinedIcon from '@mui/icons-material/ArrowDropDownOutlined'; +import CloseIcon from '@mui/icons-material/Close'; import { + Dialog, + DialogContent, + DialogTitle, IconButton, - Link as MuiLink, - Menu, MenuItem, + MenuList, + Link as MuiLink, + Typography, useTheme, + Stack, + useMediaQuery, + Theme, } from '@mui/material'; -import Typography from '@mui/material/Typography'; -import { useTranslations } from 'next-intl'; -import { Stack } from '@mui/system'; -import ArrowDropDownOutlinedIcon from '@mui/icons-material/ArrowDropDownOutlined'; -import { profileMenuItems } from '@/config'; -import EContainer from '@/editorialComponents/EContainer/EContainer'; -import Link from 'next/link'; type MobileProfileMenuProps = { userFullName: string | null; @@ -22,30 +29,56 @@ type MobileProfileMenuProps = { const MobileProfileMenu = ({ userFullName }: MobileProfileMenuProps) => { const { palette } = useTheme(); const t = useTranslations('profile'); + const isDesktop = useMediaQuery((theme: Theme) => theme.breakpoints.up('lg')); - const [menu, setMenu] = useState(null); - const open = Boolean(menu); - + const [open, setOpen] = useState(false); const handleClose = () => { - setMenu(null); + setOpen(false); }; - const handleClick = useCallback((event: React.MouseEvent) => { - setMenu(event.currentTarget); + const handleClick = useCallback(() => { + setOpen((prev) => !prev); }, []); + useEffect(() => { + if (isDesktop) { + setOpen(false); + } + }, [isDesktop]); + + const items = ( + + {profileMenuItems.map(({ label, href }, index: number) => ( + + + {t(label)} + + + ))} + + ); + return ( { alignItems='center' justifyContent='flex-start' onClick={handleClick} - sx={{ padding: 3 }} + sx={{ py: 2, cursor: 'pointer' }} > - - {userFullName} + + {t('title')} - + @@ -66,48 +102,50 @@ const MobileProfileMenu = ({ userFullName }: MobileProfileMenuProps) => { - - {profileMenuItems.map( - ({ label, href }: { label: string; href: string }, index: number) => ( - + + + {t('title')} + + + + + + + - - {t(label)} - - - ) - )} - + {userFullName} + + {items} + + + )} ); }; diff --git a/apps/nextjs-website/src/components/organisms/ProfileMenu/ProfileMenu.tsx b/apps/nextjs-website/src/components/organisms/ProfileMenu/ProfileMenu.tsx index 0c32fe2e4..082ff15ea 100644 --- a/apps/nextjs-website/src/components/organisms/ProfileMenu/ProfileMenu.tsx +++ b/apps/nextjs-website/src/components/organisms/ProfileMenu/ProfileMenu.tsx @@ -33,7 +33,7 @@ const ProfileMenu = ({ children }: { children: ReactNode }) => { <> - +