refactor(Layouts): optimize imports and enhance UserInfo component

- Moved the useIsMobile hook import to the correct position in conditional-layout.tsx.
- Added type="button" to the ThemeToggleSwitch button for better accessibility.
- Introduced truncateString utility in UserInfo component to limit email display length.
- Set Image component in UserInfo to unoptimized for performance improvement.
This commit is contained in:
AmirReza Jamali
2026-04-11 12:18:55 +03:30
parent 677e457dc1
commit 93140b3cb6
3 changed files with 8 additions and 4 deletions
@@ -1,12 +1,12 @@
"use client";
import { AuthGuard, LoginGuard } from "@/contexts";
import { useIsMobile } from "@/hooks/use-mobile";
import { usePathname } from "next/navigation";
import type { PropsWithChildren } from "react";
import { Header } from "./header";
import Notification from "./notification";
import { Sidebar } from "./sidebar";
import { useIsMobile } from "@/hooks/use-mobile";
function MainLayout({ children }: PropsWithChildren) {
const isMobile = useIsMobile();
@@ -30,6 +30,7 @@ export function ThemeToggleSwitch() {
<button
onClick={() => setTheme(theme === "light" ? "dark" : "light")}
className="group rounded-full bg-gray-3 p-[5px] text-[#111928] outline-1 outline-primary focus-visible:outline dark:bg-[#020D1A] dark:text-current"
type="button"
>
<span className="sr-only">
Switch to {theme === "light" ? "dark" : "light"} mode
@@ -8,6 +8,7 @@ import {
} from "@/components/ui/dropdown";
import { useUser } from "@/contexts";
import { cn } from "@/lib/utils";
import { truncateString } from "@/utils/shared";
import Image from "next/image";
import Link from "next/link";
import { useState } from "react";
@@ -53,6 +54,7 @@ export function UserInfo() {
<Image
src={user.profile_image}
className="size-12"
unoptimized
alt={`Avatar for ${user.full_name}`}
role="presentation"
width={200}
@@ -69,7 +71,9 @@ export function UserInfo() {
{user?.full_name}
</div>
<div className="leading-none text-gray-6">{user?.email}</div>
<div className="leading-none text-gray-6">
{truncateString(user?.email ?? "")}
</div>
</figcaption>
</figure>
@@ -107,7 +111,6 @@ export function UserInfo() {
onClick={() => {
setIsOpen(false);
logout();
}}
>
<LogOutIcon />