mirror of
https://github.com/felipegcoutinho/openmonetis.git
synced 2026-05-09 11:01:45 +00:00
refactor(core): centraliza hooks, providers e base compartilhada
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
"use client";
|
||||
import * as React from "react";
|
||||
import { Logo } from "@/components/logo";
|
||||
import { Logo } from "@/components/shared/logo";
|
||||
import { NavMain } from "@/components/navigation/sidebar/nav-main";
|
||||
import { NavSecondary } from "@/components/navigation/sidebar/nav-secondary";
|
||||
import { NavUser } from "@/components/navigation/sidebar/nav-user";
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import type { RemixiconComponentType } from "@remixicon/react";
|
||||
import Link from "next/link";
|
||||
import { usePathname } from "next/navigation";
|
||||
import * as React from "react";
|
||||
import type * as React from "react";
|
||||
import {
|
||||
SidebarGroup,
|
||||
SidebarGroupContent,
|
||||
@@ -24,30 +24,22 @@ export function NavSecondary({
|
||||
} & React.ComponentPropsWithoutRef<typeof SidebarGroup>) {
|
||||
const pathname = usePathname();
|
||||
|
||||
const isLinkActive = React.useCallback(
|
||||
(url: string) => {
|
||||
const normalizedPathname =
|
||||
pathname.endsWith("/") && pathname !== "/"
|
||||
? pathname.slice(0, -1)
|
||||
: pathname;
|
||||
const normalizedUrl =
|
||||
url.endsWith("/") && url !== "/" ? url.slice(0, -1) : url;
|
||||
|
||||
// Verifica se é exatamente igual ou se o pathname começa com a URL
|
||||
return (
|
||||
normalizedPathname === normalizedUrl ||
|
||||
normalizedPathname.startsWith(`${normalizedUrl}/`)
|
||||
);
|
||||
},
|
||||
[pathname],
|
||||
);
|
||||
|
||||
return (
|
||||
<SidebarGroup {...props}>
|
||||
<SidebarGroupContent>
|
||||
<SidebarMenu>
|
||||
{items.map((item) => {
|
||||
const itemIsActive = isLinkActive(item.url);
|
||||
const normalizedPathname =
|
||||
pathname.endsWith("/") && pathname !== "/"
|
||||
? pathname.slice(0, -1)
|
||||
: pathname;
|
||||
const normalizedUrl =
|
||||
item.url.endsWith("/") && item.url !== "/"
|
||||
? item.url.slice(0, -1)
|
||||
: item.url;
|
||||
const itemIsActive =
|
||||
normalizedPathname === normalizedUrl ||
|
||||
normalizedPathname.startsWith(`${normalizedUrl}/`);
|
||||
return (
|
||||
<SidebarMenuItem key={item.title}>
|
||||
<SidebarMenuButton
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
"use client";
|
||||
|
||||
import Image from "next/image";
|
||||
import { useMemo } from "react";
|
||||
import {
|
||||
SidebarMenu,
|
||||
SidebarMenuButton,
|
||||
SidebarMenuItem,
|
||||
useSidebar,
|
||||
} from "@/components/ui/sidebar";
|
||||
import { getAvatarSrc } from "@/lib/pagadores/utils";
|
||||
|
||||
@@ -21,19 +19,9 @@ type NavUserProps = {
|
||||
};
|
||||
|
||||
export function NavUser({ user, pagadorAvatarUrl }: NavUserProps) {
|
||||
useSidebar();
|
||||
|
||||
const avatarSrc = useMemo(() => {
|
||||
// Priorizar o avatar do pagador admin quando disponível
|
||||
if (pagadorAvatarUrl) {
|
||||
return getAvatarSrc(pagadorAvatarUrl);
|
||||
}
|
||||
// Fallback para a imagem do usuário (Google, etc)
|
||||
if (user.image) {
|
||||
return user.image;
|
||||
}
|
||||
return getAvatarSrc(null);
|
||||
}, [user.image, pagadorAvatarUrl]);
|
||||
const avatarSrc = pagadorAvatarUrl
|
||||
? getAvatarSrc(pagadorAvatarUrl)
|
||||
: user.image || getAvatarSrc(null);
|
||||
|
||||
return (
|
||||
<SidebarMenu>
|
||||
|
||||
Reference in New Issue
Block a user