refactor: migrate from ESLint to Biome and extract SQL queries to data.ts

- Replace ESLint with Biome for linting and formatting
- Configure Biome with tabs, double quotes, and organized imports
- Move all SQL/Drizzle queries from page.tsx files to data.ts files
- Create new data.ts files for: ajustes, dashboard, relatorios/categorias
- Update existing data.ts files: extrato, fatura (add lancamentos queries)
- Remove all drizzle-orm imports from page.tsx files
- Update README.md with new tooling info

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Felipe Coutinho
2026-01-27 13:15:37 +00:00
parent 8ffe61c59b
commit a7f63fb77a
442 changed files with 66141 additions and 69292 deletions

View File

@@ -1,81 +1,81 @@
"use client";
import * as React from "react";
import { Logo } from "@/components/logo";
import { NavMain } from "@/components/sidebar/nav-main";
import { NavSecondary } from "@/components/sidebar/nav-secondary";
import { NavUser } from "@/components/sidebar/nav-user";
import {
Sidebar,
SidebarContent,
SidebarFooter,
SidebarHeader,
SidebarMenu,
SidebarMenuButton,
SidebarMenuItem,
useSidebar,
Sidebar,
SidebarContent,
SidebarFooter,
SidebarHeader,
SidebarMenu,
SidebarMenuButton,
SidebarMenuItem,
useSidebar,
} from "@/components/ui/sidebar";
import * as React from "react";
import { createSidebarNavData, type PagadorLike, type SidebarNavOptions } from "./nav-link";
import { createSidebarNavData, type PagadorLike } from "./nav-link";
type AppUser = {
id: string;
name: string;
email: string;
image: string | null;
id: string;
name: string;
email: string;
image: string | null;
};
interface AppSidebarProps extends React.ComponentProps<typeof Sidebar> {
user: AppUser;
pagadorAvatarUrl: string | null;
pagadores: PagadorLike[];
preLancamentosCount?: number;
user: AppUser;
pagadorAvatarUrl: string | null;
pagadores: PagadorLike[];
preLancamentosCount?: number;
}
export function AppSidebar({
user,
pagadorAvatarUrl,
pagadores,
preLancamentosCount = 0,
...props
user,
pagadorAvatarUrl,
pagadores,
preLancamentosCount = 0,
...props
}: AppSidebarProps) {
if (!user) {
throw new Error("AppSidebar requires a user but received undefined.");
}
if (!user) {
throw new Error("AppSidebar requires a user but received undefined.");
}
const navigation = React.useMemo(
() => createSidebarNavData({ pagadores, preLancamentosCount }),
[pagadores, preLancamentosCount]
);
const navigation = React.useMemo(
() => createSidebarNavData({ pagadores, preLancamentosCount }),
[pagadores, preLancamentosCount],
);
return (
<Sidebar collapsible="icon" {...props}>
<SidebarHeader>
<SidebarMenu>
<SidebarMenuItem>
<SidebarMenuButton
asChild
className="data-[slot=sidebar-menu-button]:px-1.5! hover:bg-transparent active:bg-transparent pt-4 justify-center hover:scale-105 transition-all duration-200"
>
<a href="/dashboard">
<LogoContent />
</a>
</SidebarMenuButton>
</SidebarMenuItem>
</SidebarMenu>
</SidebarHeader>
<SidebarContent>
<NavMain sections={navigation.navMain} />
<NavSecondary items={navigation.navSecondary} className="mt-auto" />
</SidebarContent>
<SidebarFooter>
<NavUser user={user} pagadorAvatarUrl={pagadorAvatarUrl} />
</SidebarFooter>
</Sidebar>
);
return (
<Sidebar collapsible="icon" {...props}>
<SidebarHeader>
<SidebarMenu>
<SidebarMenuItem>
<SidebarMenuButton
asChild
className="data-[slot=sidebar-menu-button]:px-1.5! hover:bg-transparent active:bg-transparent pt-4 justify-center hover:scale-105 transition-all duration-200"
>
<a href="/dashboard">
<LogoContent />
</a>
</SidebarMenuButton>
</SidebarMenuItem>
</SidebarMenu>
</SidebarHeader>
<SidebarContent>
<NavMain sections={navigation.navMain} />
<NavSecondary items={navigation.navSecondary} className="mt-auto" />
</SidebarContent>
<SidebarFooter>
<NavUser user={user} pagadorAvatarUrl={pagadorAvatarUrl} />
</SidebarFooter>
</Sidebar>
);
}
function LogoContent() {
const { state } = useSidebar();
const isCollapsed = state === "collapsed";
const { state } = useSidebar();
const isCollapsed = state === "collapsed";
return <Logo variant={isCollapsed ? "small" : "full"} />;
return <Logo variant={isCollapsed ? "small" : "full"} />;
}

View File

@@ -1,218 +1,221 @@
import {
RiArchiveLine,
RiArrowLeftRightLine,
RiBankCard2Line,
RiBankLine,
RiCalendarEventLine,
RiDashboardLine,
RiFileChartLine,
RiFundsLine,
RiGroupLine,
RiInboxLine,
RiNoCreditCardLine,
RiPriceTag3Line,
RiSettingsLine,
RiSparklingLine,
RiTodoLine,
RiEyeOffLine,
type RemixiconComponentType,
type RemixiconComponentType,
RiArchiveLine,
RiArrowLeftRightLine,
RiBankCard2Line,
RiBankLine,
RiCalendarEventLine,
RiDashboardLine,
RiEyeOffLine,
RiFileChartLine,
RiFundsLine,
RiGroupLine,
RiInboxLine,
RiNoCreditCardLine,
RiPriceTag3Line,
RiSettingsLine,
RiSparklingLine,
RiTodoLine,
} from "@remixicon/react";
export type SidebarSubItem = {
title: string;
url: string;
avatarUrl?: string | null;
isShared?: boolean;
key?: string;
icon?: RemixiconComponentType;
badge?: number;
title: string;
url: string;
avatarUrl?: string | null;
isShared?: boolean;
key?: string;
icon?: RemixiconComponentType;
badge?: number;
};
export type SidebarItem = {
title: string;
url: string;
icon: RemixiconComponentType;
isActive?: boolean;
items?: SidebarSubItem[];
title: string;
url: string;
icon: RemixiconComponentType;
isActive?: boolean;
items?: SidebarSubItem[];
};
export type SidebarSection = {
title: string;
items: SidebarItem[];
title: string;
items: SidebarItem[];
};
export type SidebarNavData = {
navMain: SidebarSection[];
navSecondary: {
title: string;
url: string;
icon: RemixiconComponentType;
}[];
navMain: SidebarSection[];
navSecondary: {
title: string;
url: string;
icon: RemixiconComponentType;
}[];
};
export interface PagadorLike {
id: string;
name: string | null;
avatarUrl: string | null;
canEdit?: boolean;
id: string;
name: string | null;
avatarUrl: string | null;
canEdit?: boolean;
}
export interface SidebarNavOptions {
pagadores: PagadorLike[];
preLancamentosCount?: number;
pagadores: PagadorLike[];
preLancamentosCount?: number;
}
export function createSidebarNavData(options: SidebarNavOptions): SidebarNavData {
const { pagadores, preLancamentosCount = 0 } = options;
const pagadorItems = pagadores
.map((pagador) => ({
title: pagador.name?.trim().length
? pagador.name.trim()
: "Pagador sem nome",
url: `/pagadores/${pagador.id}`,
key: pagador.canEdit ? pagador.id : `${pagador.id}-shared`,
isShared: !pagador.canEdit,
avatarUrl: pagador.avatarUrl,
}))
.sort((a, b) =>
a.title.localeCompare(b.title, "pt-BR", { sensitivity: "base" })
);
export function createSidebarNavData(
options: SidebarNavOptions,
): SidebarNavData {
const { pagadores, preLancamentosCount = 0 } = options;
const pagadorItems = pagadores
.map((pagador) => ({
title: pagador.name?.trim().length
? pagador.name.trim()
: "Pagador sem nome",
url: `/pagadores/${pagador.id}`,
key: pagador.canEdit ? pagador.id : `${pagador.id}-shared`,
isShared: !pagador.canEdit,
avatarUrl: pagador.avatarUrl,
}))
.sort((a, b) =>
a.title.localeCompare(b.title, "pt-BR", { sensitivity: "base" }),
);
const pagadorItemsWithHistory: SidebarSubItem[] = pagadorItems;
const pagadorItemsWithHistory: SidebarSubItem[] = pagadorItems;
return {
navMain: [
{
title: "Visão Geral",
items: [
{
title: "Dashboard",
url: "/dashboard",
icon: RiDashboardLine,
},
],
},
{
title: "Gestão Financeira",
items: [
{
title: "Lançamentos",
url: "/lancamentos",
icon: RiArrowLeftRightLine,
items: [
{
title: "Pré-Lançamentos",
url: "/pre-lancamentos",
key: "pre-lancamentos",
icon: RiInboxLine,
badge: preLancamentosCount > 0 ? preLancamentosCount : undefined,
},
],
},
{
title: "Calendário",
url: "/calendario",
icon: RiCalendarEventLine,
},
{
title: "Cartões",
url: "/cartoes",
icon: RiBankCard2Line,
items: [
{
title: "Inativos",
url: "/cartoes/inativos",
key: "cartoes-inativos",
icon: RiNoCreditCardLine,
},
],
},
{
title: "Contas",
url: "/contas",
icon: RiBankLine,
items: [
{
title: "Inativas",
url: "/contas/inativos",
key: "contas-inativos",
icon: RiEyeOffLine,
},
],
},
{
title: "Orçamentos",
url: "/orcamentos",
icon: RiFundsLine,
},
],
},
{
title: "Organização",
items: [
{
title: "Pagadores",
url: "/pagadores",
icon: RiGroupLine,
items: pagadorItemsWithHistory,
},
{
title: "Categorias",
url: "/categorias",
icon: RiPriceTag3Line,
},
],
},
{
title: "Análise e Anotações",
items: [
{
title: "Anotações",
url: "/anotacoes",
icon: RiTodoLine,
items: [
{
title: "Arquivadas",
url: "/anotacoes/arquivadas",
key: "anotacoes-arquivadas",
icon: RiArchiveLine,
},
],
},
{
title: "Insights",
url: "/insights",
icon: RiSparklingLine,
},
],
},
{
title: "Relatórios",
items: [
{
title: "Categorias",
url: "/relatorios/categorias",
icon: RiFileChartLine,
},
{
title: "Cartões",
url: "/relatorios/cartoes",
icon: RiBankCard2Line,
},
],
},
],
navSecondary: [
// {
// title: "Changelog",
// url: "/changelog",
// icon: RiGitCommitLine,
// },
{
title: "Ajustes",
url: "/ajustes",
icon: RiSettingsLine,
},
],
};
return {
navMain: [
{
title: "Visão Geral",
items: [
{
title: "Dashboard",
url: "/dashboard",
icon: RiDashboardLine,
},
],
},
{
title: "Gestão Financeira",
items: [
{
title: "Lançamentos",
url: "/lancamentos",
icon: RiArrowLeftRightLine,
items: [
{
title: "Pré-Lançamentos",
url: "/pre-lancamentos",
key: "pre-lancamentos",
icon: RiInboxLine,
badge:
preLancamentosCount > 0 ? preLancamentosCount : undefined,
},
],
},
{
title: "Calendário",
url: "/calendario",
icon: RiCalendarEventLine,
},
{
title: "Cartões",
url: "/cartoes",
icon: RiBankCard2Line,
items: [
{
title: "Inativos",
url: "/cartoes/inativos",
key: "cartoes-inativos",
icon: RiNoCreditCardLine,
},
],
},
{
title: "Contas",
url: "/contas",
icon: RiBankLine,
items: [
{
title: "Inativas",
url: "/contas/inativos",
key: "contas-inativos",
icon: RiEyeOffLine,
},
],
},
{
title: "Orçamentos",
url: "/orcamentos",
icon: RiFundsLine,
},
],
},
{
title: "Organização",
items: [
{
title: "Pagadores",
url: "/pagadores",
icon: RiGroupLine,
items: pagadorItemsWithHistory,
},
{
title: "Categorias",
url: "/categorias",
icon: RiPriceTag3Line,
},
],
},
{
title: "Análise e Anotações",
items: [
{
title: "Anotações",
url: "/anotacoes",
icon: RiTodoLine,
items: [
{
title: "Arquivadas",
url: "/anotacoes/arquivadas",
key: "anotacoes-arquivadas",
icon: RiArchiveLine,
},
],
},
{
title: "Insights",
url: "/insights",
icon: RiSparklingLine,
},
],
},
{
title: "Relatórios",
items: [
{
title: "Categorias",
url: "/relatorios/categorias",
icon: RiFileChartLine,
},
{
title: "Cartões",
url: "/relatorios/cartoes",
icon: RiBankCard2Line,
},
],
},
],
navSecondary: [
// {
// title: "Changelog",
// url: "/changelog",
// icon: RiGitCommitLine,
// },
{
title: "Ajustes",
url: "/ajustes",
icon: RiSettingsLine,
},
],
};
}

View File

@@ -1,213 +1,216 @@
"use client";
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
import { Badge } from "@/components/ui/badge";
import {
Collapsible,
CollapsibleContent,
CollapsibleTrigger,
} from "@/components/ui/collapsible";
import {
SidebarGroup,
SidebarGroupContent,
SidebarGroupLabel,
SidebarMenu,
SidebarMenuAction,
SidebarMenuButton,
SidebarMenuItem,
SidebarMenuSub,
SidebarMenuSubButton,
SidebarMenuSubItem,
} from "@/components/ui/sidebar";
import { getAvatarSrc } from "@/lib/pagadores/utils";
import {
RiArrowRightSLine,
RiUserSharedLine,
type RemixiconComponentType,
type RemixiconComponentType,
RiArrowRightSLine,
RiUserSharedLine,
} from "@remixicon/react";
import Link from "next/link";
import { usePathname, useSearchParams } from "next/navigation";
import * as React from "react";
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
import { Badge } from "@/components/ui/badge";
import {
Collapsible,
CollapsibleContent,
CollapsibleTrigger,
} from "@/components/ui/collapsible";
import {
SidebarGroup,
SidebarGroupContent,
SidebarGroupLabel,
SidebarMenu,
SidebarMenuAction,
SidebarMenuButton,
SidebarMenuItem,
SidebarMenuSub,
SidebarMenuSubButton,
SidebarMenuSubItem,
} from "@/components/ui/sidebar";
import { getAvatarSrc } from "@/lib/pagadores/utils";
type NavItem = {
title: string;
url: string;
icon: RemixiconComponentType;
isActive?: boolean;
items?: {
title: string;
url: string;
avatarUrl?: string | null;
isShared?: boolean;
key?: string;
icon?: RemixiconComponentType;
badge?: number;
}[];
title: string;
url: string;
icon: RemixiconComponentType;
isActive?: boolean;
items?: {
title: string;
url: string;
avatarUrl?: string | null;
isShared?: boolean;
key?: string;
icon?: RemixiconComponentType;
badge?: number;
}[];
};
type NavSection = {
title: string;
items: NavItem[];
title: string;
items: NavItem[];
};
const MONTH_PERIOD_PARAM = "periodo";
const PERIOD_AWARE_PATHS = new Set([
"/dashboard",
"/lancamentos",
"/orcamentos",
"/dashboard",
"/lancamentos",
"/orcamentos",
]);
export function NavMain({ sections }: { sections: NavSection[] }) {
const pathname = usePathname();
const searchParams = useSearchParams();
const periodParam = searchParams.get(MONTH_PERIOD_PARAM);
const pathname = usePathname();
const searchParams = useSearchParams();
const periodParam = searchParams.get(MONTH_PERIOD_PARAM);
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;
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]
);
// Verifica se é exatamente igual ou se o pathname começa com a URL
return (
normalizedPathname === normalizedUrl ||
normalizedPathname.startsWith(`${normalizedUrl}/`)
);
},
[pathname],
);
const buildHrefWithPeriod = React.useCallback(
(url: string) => {
if (!periodParam) {
return url;
}
const buildHrefWithPeriod = React.useCallback(
(url: string) => {
if (!periodParam) {
return url;
}
const [rawPathname, existingSearch = ""] = url.split("?");
const normalizedPathname =
rawPathname.endsWith("/") && rawPathname !== "/"
? rawPathname.slice(0, -1)
: rawPathname;
const [rawPathname, existingSearch = ""] = url.split("?");
const normalizedPathname =
rawPathname.endsWith("/") && rawPathname !== "/"
? rawPathname.slice(0, -1)
: rawPathname;
if (!PERIOD_AWARE_PATHS.has(normalizedPathname)) {
return url;
}
if (!PERIOD_AWARE_PATHS.has(normalizedPathname)) {
return url;
}
const params = new URLSearchParams(existingSearch);
params.set(MONTH_PERIOD_PARAM, periodParam);
const params = new URLSearchParams(existingSearch);
params.set(MONTH_PERIOD_PARAM, periodParam);
const queryString = params.toString();
return queryString
? `${normalizedPathname}?${queryString}`
: normalizedPathname;
},
[periodParam]
);
const queryString = params.toString();
return queryString
? `${normalizedPathname}?${queryString}`
: normalizedPathname;
},
[periodParam],
);
const activeLinkClasses =
"data-[active=true]:bg-sidebar-accent data-[active=true]:text-dark! hover:text-primary!";
const activeLinkClasses =
"data-[active=true]:bg-sidebar-accent data-[active=true]:text-dark! hover:text-primary!";
return (
<>
{sections.map((section) => (
<SidebarGroup key={section.title}>
<SidebarGroupLabel>{section.title}</SidebarGroupLabel>
<SidebarGroupContent>
<SidebarMenu>
{section.items.map((item) => {
const itemIsActive = isLinkActive(item.url);
return (
<Collapsible key={item.title} asChild>
<SidebarMenuItem>
<SidebarMenuButton
asChild
tooltip={item.title}
isActive={itemIsActive}
className={itemIsActive ? activeLinkClasses : ""}
>
<Link prefetch href={buildHrefWithPeriod(item.url)}>
<item.icon className="size-4" />
{item.title}
</Link>
</SidebarMenuButton>
{item.items?.length ? (
<>
<CollapsibleTrigger asChild>
<SidebarMenuAction className="data-[state=open]:rotate-90 text-foreground px-2 trasition-transform duration-200">
<RiArrowRightSLine />
<span className="sr-only">Toggle</span>
</SidebarMenuAction>
</CollapsibleTrigger>
<CollapsibleContent>
<SidebarMenuSub>
{item.items?.map((subItem) => {
const subItemIsActive = isLinkActive(
subItem.url
);
const avatarSrc = getAvatarSrc(
subItem.avatarUrl
);
const initial =
subItem.title.charAt(0).toUpperCase() || "?";
return (
<SidebarMenuSubItem
key={subItem.key ?? subItem.title}
>
<SidebarMenuSubButton
asChild
isActive={subItemIsActive}
className={
subItemIsActive ? activeLinkClasses : ""
}
>
<Link
prefetch
href={buildHrefWithPeriod(subItem.url)}
className="flex items-center gap-2"
>
{subItem.icon ? (
<subItem.icon className="size-4" />
) : subItem.avatarUrl !== undefined ? (
<Avatar className="size-5 border border-border/60 bg-background">
<AvatarImage
src={avatarSrc}
alt={`Avatar de ${subItem.title}`}
/>
<AvatarFallback className="text-xs font-medium uppercase">
{initial}
</AvatarFallback>
</Avatar>
) : null}
<span>{subItem.title}</span>
{subItem.badge ? (
<Badge variant="destructive" className="ml-auto h-5 min-w-5 px-1.5 text-xs">
{subItem.badge}
</Badge>
) : null}
{subItem.isShared ? (
<RiUserSharedLine className="size-3.5 text-muted-foreground" />
) : null}
</Link>
</SidebarMenuSubButton>
</SidebarMenuSubItem>
);
})}
</SidebarMenuSub>
</CollapsibleContent>
</>
) : null}
</SidebarMenuItem>
</Collapsible>
);
})}
</SidebarMenu>
</SidebarGroupContent>
</SidebarGroup>
))}
</>
);
return (
<>
{sections.map((section) => (
<SidebarGroup key={section.title}>
<SidebarGroupLabel>{section.title}</SidebarGroupLabel>
<SidebarGroupContent>
<SidebarMenu>
{section.items.map((item) => {
const itemIsActive = isLinkActive(item.url);
return (
<Collapsible key={item.title} asChild>
<SidebarMenuItem>
<SidebarMenuButton
asChild
tooltip={item.title}
isActive={itemIsActive}
className={itemIsActive ? activeLinkClasses : ""}
>
<Link prefetch href={buildHrefWithPeriod(item.url)}>
<item.icon className="size-4" />
{item.title}
</Link>
</SidebarMenuButton>
{item.items?.length ? (
<>
<CollapsibleTrigger asChild>
<SidebarMenuAction className="data-[state=open]:rotate-90 text-foreground px-2 trasition-transform duration-200">
<RiArrowRightSLine />
<span className="sr-only">Toggle</span>
</SidebarMenuAction>
</CollapsibleTrigger>
<CollapsibleContent>
<SidebarMenuSub>
{item.items?.map((subItem) => {
const subItemIsActive = isLinkActive(
subItem.url,
);
const avatarSrc = getAvatarSrc(
subItem.avatarUrl,
);
const initial =
subItem.title.charAt(0).toUpperCase() || "?";
return (
<SidebarMenuSubItem
key={subItem.key ?? subItem.title}
>
<SidebarMenuSubButton
asChild
isActive={subItemIsActive}
className={
subItemIsActive ? activeLinkClasses : ""
}
>
<Link
prefetch
href={buildHrefWithPeriod(subItem.url)}
className="flex items-center gap-2"
>
{subItem.icon ? (
<subItem.icon className="size-4" />
) : subItem.avatarUrl !== undefined ? (
<Avatar className="size-5 border border-border/60 bg-background">
<AvatarImage
src={avatarSrc}
alt={`Avatar de ${subItem.title}`}
/>
<AvatarFallback className="text-xs font-medium uppercase">
{initial}
</AvatarFallback>
</Avatar>
) : null}
<span>{subItem.title}</span>
{subItem.badge ? (
<Badge
variant="destructive"
className="ml-auto h-5 min-w-5 px-1.5 text-xs"
>
{subItem.badge}
</Badge>
) : null}
{subItem.isShared ? (
<RiUserSharedLine className="size-3.5 text-muted-foreground" />
) : null}
</Link>
</SidebarMenuSubButton>
</SidebarMenuSubItem>
);
})}
</SidebarMenuSub>
</CollapsibleContent>
</>
) : null}
</SidebarMenuItem>
</Collapsible>
);
})}
</SidebarMenu>
</SidebarGroupContent>
</SidebarGroup>
))}
</>
);
}

View File

@@ -1,75 +1,74 @@
"use client";
import type { RemixiconComponentType } from "@remixicon/react";
import Link from "next/link";
import { usePathname } from "next/navigation";
import * as React from "react";
import {
SidebarGroup,
SidebarGroupContent,
SidebarMenu,
SidebarMenuButton,
SidebarMenuItem,
SidebarGroup,
SidebarGroupContent,
SidebarMenu,
SidebarMenuButton,
SidebarMenuItem,
} from "@/components/ui/sidebar";
import Link from "next/link";
export function NavSecondary({
items,
...props
items,
...props
}: {
items: {
title: string;
url: string;
icon: RemixiconComponentType;
}[];
items: {
title: string;
url: string;
icon: RemixiconComponentType;
}[];
} & React.ComponentPropsWithoutRef<typeof SidebarGroup>) {
const pathname = usePathname();
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;
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]
);
// 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);
return (
<SidebarMenuItem key={item.title}>
<SidebarMenuButton
asChild
isActive={itemIsActive}
className={
itemIsActive
? "data-[active=true]:bg-sidebar-accent data-[active=true]:text-dark! hover:text-primary!"
: ""
}
>
<Link prefetch href={item.url}>
<item.icon className={"h-4 w-4"} />
<span>{item.title}</span>
</Link>
</SidebarMenuButton>
</SidebarMenuItem>
);
})}
</SidebarMenu>
</SidebarGroupContent>
</SidebarGroup>
);
return (
<SidebarGroup {...props}>
<SidebarGroupContent>
<SidebarMenu>
{items.map((item) => {
const itemIsActive = isLinkActive(item.url);
return (
<SidebarMenuItem key={item.title}>
<SidebarMenuButton
asChild
isActive={itemIsActive}
className={
itemIsActive
? "data-[active=true]:bg-sidebar-accent data-[active=true]:text-dark! hover:text-primary!"
: ""
}
>
<Link prefetch href={item.url}>
<item.icon className={"h-4 w-4"} />
<span>{item.title}</span>
</Link>
</SidebarMenuButton>
</SidebarMenuItem>
);
})}
</SidebarMenu>
</SidebarGroupContent>
</SidebarGroup>
);
}

View File

@@ -1,57 +1,57 @@
"use client";
import {
SidebarMenu,
SidebarMenuButton,
SidebarMenuItem,
useSidebar,
} from "@/components/ui/sidebar";
import { getAvatarSrc } from "@/lib/pagadores/utils";
import Image from "next/image";
import { useMemo } from "react";
import {
SidebarMenu,
SidebarMenuButton,
SidebarMenuItem,
useSidebar,
} from "@/components/ui/sidebar";
import { getAvatarSrc } from "@/lib/pagadores/utils";
type NavUserProps = {
user: {
id: string;
name: string;
email: string;
image: string | null;
};
pagadorAvatarUrl: string | null;
user: {
id: string;
name: string;
email: string;
image: string | null;
};
pagadorAvatarUrl: string | null;
};
export function NavUser({ user, pagadorAvatarUrl }: NavUserProps) {
useSidebar();
useSidebar();
const avatarSrc = useMemo(() => {
if (user.image) {
return user.image;
}
return getAvatarSrc(pagadorAvatarUrl);
}, [user.image, pagadorAvatarUrl]);
const avatarSrc = useMemo(() => {
if (user.image) {
return user.image;
}
return getAvatarSrc(pagadorAvatarUrl);
}, [user.image, pagadorAvatarUrl]);
return (
<SidebarMenu>
<SidebarMenuItem>
<SidebarMenuButton
size="lg"
className="data-popup-open:bg-sidebar-accent data-popup-open:text-sidebar-accent-foreground "
>
<Image
src={avatarSrc}
alt={user.name}
width={32}
height={32}
className="size-8 shrink-0 rounded-full object-cover"
/>
<div className="grid flex-1 text-left text-sm leading-tight">
<span className="truncate font-medium">{user.name}</span>
<span className="text-muted-foreground truncate text-xs">
{user.email}
</span>
</div>
</SidebarMenuButton>
</SidebarMenuItem>
</SidebarMenu>
);
return (
<SidebarMenu>
<SidebarMenuItem>
<SidebarMenuButton
size="lg"
className="data-popup-open:bg-sidebar-accent data-popup-open:text-sidebar-accent-foreground "
>
<Image
src={avatarSrc}
alt={user.name}
width={32}
height={32}
className="size-8 shrink-0 rounded-full object-cover"
/>
<div className="grid flex-1 text-left text-sm leading-tight">
<span className="truncate font-medium">{user.name}</span>
<span className="text-muted-foreground truncate text-xs">
{user.email}
</span>
</div>
</SidebarMenuButton>
</SidebarMenuItem>
</SidebarMenu>
);
}