From 1d2e331cecf7eaaa9f2cfcfccb5f1573b524803b Mon Sep 17 00:00:00 2001 From: Ramesh Kumar Chandra <31303617+rameshkumarchandra@users.noreply.github.com> Date: Wed, 14 Feb 2024 14:55:33 +0530 Subject: [PATCH] fix: mobile responsive sidebar close on item tap (#3661) --- .../sidebar/sidebar-menu-hamburger-toggle.tsx | 14 +- web/components/project/sidebar-list-item.tsx | 41 ++--- web/components/workspace/help-section.tsx | 34 ++-- web/components/workspace/sidebar-dropdown.tsx | 29 ++- web/components/workspace/sidebar-menu.tsx | 11 +- .../profile/preferences/layout.tsx | 4 +- .../settings-layout/profile/sidebar.tsx | 6 +- web/pages/profile/activity.tsx | 17 +- web/pages/profile/change-password.tsx | 165 +++++++++--------- web/pages/profile/index.tsx | 5 +- 10 files changed, 162 insertions(+), 164 deletions(-) diff --git a/web/components/core/sidebar/sidebar-menu-hamburger-toggle.tsx b/web/components/core/sidebar/sidebar-menu-hamburger-toggle.tsx index b732d8f95..cb433de05 100644 --- a/web/components/core/sidebar/sidebar-menu-hamburger-toggle.tsx +++ b/web/components/core/sidebar/sidebar-menu-hamburger-toggle.tsx @@ -3,12 +3,20 @@ import { Menu } from "lucide-react"; import { useApplication } from "hooks/store"; import { observer } from "mobx-react"; -export const SidebarHamburgerToggle: FC = observer(() => { - const { theme: themStore } = useApplication(); +type Props = { + onClick?: () => void; +} + +export const SidebarHamburgerToggle: FC = observer((props) => { + const { onClick } = props + const { theme: themeStore } = useApplication(); return (
themStore.toggleMobileSidebar()} + onClick={() => { + if (onClick) onClick() + else themeStore.toggleMobileSidebar() + }} >
diff --git a/web/components/project/sidebar-list-item.tsx b/web/components/project/sidebar-list-item.tsx index d9cd81d5f..64134b242 100644 --- a/web/components/project/sidebar-list-item.tsx +++ b/web/components/project/sidebar-list-item.tsx @@ -18,7 +18,7 @@ import { MoreHorizontal, } from "lucide-react"; // hooks -import { useApplication,useEventTracker, useProject } from "hooks/store"; +import { useApplication, useEventTracker, useProject } from "hooks/store"; import useOutsideClickDetector from "hooks/use-outside-click-detector"; import useToast from "hooks/use-toast"; // helpers @@ -131,7 +131,7 @@ export const ProjectSidebarListItem: React.FC = observer((props) => { const handleProjectClick = () => { if (window.innerWidth < 768) { - themeStore.toggleSidebar(); + themeStore.toggleMobileSidebar(); } }; @@ -147,9 +147,8 @@ export const ProjectSidebarListItem: React.FC = observer((props) => { {({ open }) => ( <>
{provided && ( = observer((props) => { > @@ -101,10 +101,9 @@ export const WorkspaceHelpSection: React.FC = observe @@ -122,9 +121,8 @@ export const WorkspaceHelpSection: React.FC = observe leaveTo="transform opacity-0 scale-95" >
diff --git a/web/components/workspace/sidebar-dropdown.tsx b/web/components/workspace/sidebar-dropdown.tsx index 87bb4c868..7d4c6adec 100644 --- a/web/components/workspace/sidebar-dropdown.tsx +++ b/web/components/workspace/sidebar-dropdown.tsx @@ -54,7 +54,7 @@ export const WorkspaceSidebarDropdown = observer(() => { const { workspaceSlug } = router.query; // store hooks const { - theme: { sidebarCollapsed, toggleSidebar }, + theme: { sidebarCollapsed, toggleMobileSidebar }, } = useApplication(); const { setTrackElement } = useEventTracker(); const { currentUser, updateCurrentUser, isUserInstanceAdmin, signOut } = useUser(); @@ -98,7 +98,7 @@ export const WorkspaceSidebarDropdown = observer(() => { }; const handleItemClick = () => { if (window.innerWidth < 768) { - toggleSidebar(); + toggleMobileSidebar(); } }; const workspacesList = Object.values(workspaces ?? {}); @@ -110,15 +110,13 @@ export const WorkspaceSidebarDropdown = observer(() => { <>
{activeWorkspace?.logo && activeWorkspace.logo !== "" ? ( {
{!sidebarCollapsed && (
@@ -179,9 +176,8 @@ export const WorkspaceSidebarDropdown = observer(() => { >
{workspace?.logo && workspace.logo !== "" ? ( { )}
{workspace.name}
diff --git a/web/components/workspace/sidebar-menu.tsx b/web/components/workspace/sidebar-menu.tsx index 774a231db..9f3f5e1d6 100644 --- a/web/components/workspace/sidebar-menu.tsx +++ b/web/components/workspace/sidebar-menu.tsx @@ -31,7 +31,7 @@ export const WorkspaceSidebarMenu = observer(() => { const handleLinkClick = (itemKey: string) => { if (window.innerWidth < 768) { - themeStore.toggleSidebar(); + themeStore.toggleMobileSidebar(); } captureEvent(SIDEBAR_CLICKED, { destination: itemKey, @@ -52,11 +52,10 @@ export const WorkspaceSidebarMenu = observer(() => { disabled={!themeStore?.sidebarCollapsed} >
{ = (props) => { const { children, header } = props; const router = useRouter(); + const { theme: themeStore } = useApplication(); const showMenuItem = () => { const item = router.asPath.split('/'); @@ -42,7 +44,7 @@ export const ProfilePreferenceSettingsLayout: FC - + themeStore.toggleSidebar()} /> { const { setToastAlert } = useToast(); // store hooks const { - theme: { sidebarCollapsed, toggleSidebar }, + theme: { sidebarCollapsed, toggleSidebar, toggleMobileSidebar }, } = useApplication(); const { currentUser, currentUserSettings, signOut } = useUser(); const { workspaces } = useWorkspace(); @@ -78,7 +78,7 @@ export const ProfileLayoutSidebar = observer(() => { const handleItemClick = () => { if (window.innerWidth < 768) { - toggleSidebar(); + toggleMobileSidebar(); } }; @@ -111,7 +111,7 @@ export const ProfileLayoutSidebar = observer(() => { `} >
- +
{ const { data: userActivity } = useSWR(USER_ACTIVITY, () => userService.getUserActivity()); // store hooks const { currentUser } = useUser(); + const { theme: themeStore } = useApplication(); return (
- + themeStore.toggleSidebar()} />

Activity

{userActivity ? ( @@ -96,12 +97,12 @@ const ProfileActivityPage: NextPageWithLayout = observer(() => { const message = activityItem.verb === "created" && - activityItem.field !== "cycles" && - activityItem.field !== "modules" && - activityItem.field !== "attachment" && - activityItem.field !== "link" && - activityItem.field !== "estimate" && - !activityItem.field ? ( + activityItem.field !== "cycles" && + activityItem.field !== "modules" && + activityItem.field !== "attachment" && + activityItem.field !== "link" && + activityItem.field !== "estimate" && + !activityItem.field ? ( created diff --git a/web/pages/profile/change-password.tsx b/web/pages/profile/change-password.tsx index 4641837fd..15cb946ed 100644 --- a/web/pages/profile/change-password.tsx +++ b/web/pages/profile/change-password.tsx @@ -3,7 +3,7 @@ import { useRouter } from "next/router"; import { observer } from "mobx-react-lite"; import { Controller, useForm } from "react-hook-form"; // hooks -import { useUser } from "hooks/store"; +import { useApplication, useUser } from "hooks/store"; // services import { UserService } from "services/user.service"; // hooks @@ -32,7 +32,8 @@ const userService = new UserService(); const ChangePasswordPage: NextPageWithLayout = observer(() => { const [isPageLoading, setIsPageLoading] = useState(true); - + // hooks + const { theme: themeStore } = useApplication(); const { currentUser } = useUser(); const router = useRouter(); @@ -89,90 +90,90 @@ const ChangePasswordPage: NextPageWithLayout = observer(() => { return (
- + themeStore.toggleSidebar()} />
-
-

Change password

-
-
-

Current password

- ( - - )} - /> - {errors.old_password && {errors.old_password.message}} + +

Change password

+
+
+

Current password

+ ( + + )} + /> + {errors.old_password && {errors.old_password.message}} +
+ +
+

New password

+ ( + + )} + /> + {errors.new_password && {errors.new_password.message}} +
+ +
+

Confirm password

+ ( + + )} + /> + {errors.confirm_password && {errors.confirm_password.message}} +
-
-

New password

- ( - - )} - /> - {errors.new_password && {errors.new_password.message}} +
+
- -
-

Confirm password

- ( - - )} - /> - {errors.confirm_password && {errors.confirm_password.message}} -
-
- -
- -
- +
); }); diff --git a/web/pages/profile/index.tsx b/web/pages/profile/index.tsx index 655d6a4bd..da8626dd1 100644 --- a/web/pages/profile/index.tsx +++ b/web/pages/profile/index.tsx @@ -5,7 +5,7 @@ import { observer } from "mobx-react-lite"; // services import { FileService } from "services/file.service"; // hooks -import { useUser } from "hooks/store"; +import { useApplication, useUser } from "hooks/store"; import useUserAuth from "hooks/use-user-auth"; import useToast from "hooks/use-toast"; // layouts @@ -58,6 +58,7 @@ const ProfileSettingsPage: NextPageWithLayout = observer(() => { const { currentUser: myProfile, updateCurrentUser, currentUserLoader } = useUser(); // custom hooks const { } = useUserAuth({ user: myProfile, isLoading: currentUserLoader }); + const { theme: themeStore } = useApplication(); useEffect(() => { reset({ ...defaultValues, ...myProfile }); @@ -139,7 +140,7 @@ const ProfileSettingsPage: NextPageWithLayout = observer(() => { <>
- + themeStore.toggleSidebar()} />