feat: tighten auth guard in sidebar shell
Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
This commit is contained in:
parent
1a71d49b4d
commit
fe7025d433
10 changed files with 266 additions and 152 deletions
|
|
@ -23,10 +23,11 @@ export default function LoginPage() {
|
||||||
const [isHydrated, setIsHydrated] = useState(false)
|
const [isHydrated, setIsHydrated] = useState(false)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (isPending) return
|
||||||
if (!session?.user) return
|
if (!session?.user) return
|
||||||
const destination = callbackUrl ?? "/dashboard"
|
const destination = callbackUrl ?? "/dashboard"
|
||||||
router.replace(destination)
|
router.replace(destination)
|
||||||
}, [callbackUrl, router, session?.user])
|
}, [callbackUrl, isPending, router, session?.user])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setIsHydrated(true)
|
setIsHydrated(true)
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,22 @@
|
||||||
|
import { AppShell } from "@/components/app-shell"
|
||||||
import { BacklogReport } from "@/components/reports/backlog-report"
|
import { BacklogReport } from "@/components/reports/backlog-report"
|
||||||
|
import { SiteHeader } from "@/components/site-header"
|
||||||
|
|
||||||
export const dynamic = "force-dynamic"
|
export const dynamic = "force-dynamic"
|
||||||
|
|
||||||
export default function ReportsBacklogPage() {
|
export default function ReportsBacklogPage() {
|
||||||
return (
|
return (
|
||||||
<main className="mx-auto w-full max-w-6xl px-4 py-10 lg:px-0">
|
<AppShell
|
||||||
<header className="mb-8 space-y-2">
|
header={
|
||||||
<h1 className="text-3xl font-semibold tracking-tight text-neutral-900">Backlog e Prioridades</h1>
|
<SiteHeader
|
||||||
<p className="text-sm text-neutral-600">
|
title="Backlog e Prioridades"
|
||||||
Avalie o volume de tickets em aberto, prioridades e filas mais pressionadas.
|
lead="Avalie o volume de tickets em aberto, prioridades e filas mais pressionadas."
|
||||||
</p>
|
/>
|
||||||
</header>
|
}
|
||||||
|
>
|
||||||
|
<div className="mx-auto w-full max-w-6xl px-4 pb-12 lg:px-6">
|
||||||
<BacklogReport />
|
<BacklogReport />
|
||||||
</main>
|
</div>
|
||||||
|
</AppShell>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,22 @@
|
||||||
|
import { AppShell } from "@/components/app-shell"
|
||||||
import { CsatReport } from "@/components/reports/csat-report"
|
import { CsatReport } from "@/components/reports/csat-report"
|
||||||
|
import { SiteHeader } from "@/components/site-header"
|
||||||
|
|
||||||
export const dynamic = "force-dynamic"
|
export const dynamic = "force-dynamic"
|
||||||
|
|
||||||
export default function ReportsCsatPage() {
|
export default function ReportsCsatPage() {
|
||||||
return (
|
return (
|
||||||
<main className="mx-auto w-full max-w-6xl px-4 py-10 lg:px-0">
|
<AppShell
|
||||||
<header className="mb-8 space-y-2">
|
header={
|
||||||
<h1 className="text-3xl font-semibold tracking-tight text-neutral-900">Relatório de CSAT</h1>
|
<SiteHeader
|
||||||
<p className="text-sm text-neutral-600">
|
title="Relatório de CSAT"
|
||||||
Visualize a satisfação dos clientes e identifique pontos de melhoria na entrega.
|
lead="Visualize a satisfação dos clientes e identifique pontos de melhoria na entrega."
|
||||||
</p>
|
/>
|
||||||
</header>
|
}
|
||||||
|
>
|
||||||
|
<div className="mx-auto w-full max-w-6xl px-4 pb-12 lg:px-6">
|
||||||
<CsatReport />
|
<CsatReport />
|
||||||
</main>
|
</div>
|
||||||
|
</AppShell>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,22 @@
|
||||||
|
import { AppShell } from "@/components/app-shell"
|
||||||
import { SlaReport } from "@/components/reports/sla-report"
|
import { SlaReport } from "@/components/reports/sla-report"
|
||||||
|
import { SiteHeader } from "@/components/site-header"
|
||||||
|
|
||||||
export const dynamic = "force-dynamic"
|
export const dynamic = "force-dynamic"
|
||||||
|
|
||||||
export default function ReportsSlaPage() {
|
export default function ReportsSlaPage() {
|
||||||
return (
|
return (
|
||||||
<main className="mx-auto w-full max-w-6xl px-4 py-10 lg:px-0">
|
<AppShell
|
||||||
<header className="mb-8 space-y-2">
|
header={
|
||||||
<h1 className="text-3xl font-semibold tracking-tight text-neutral-900">Relatório de SLA</h1>
|
<SiteHeader
|
||||||
<p className="text-sm text-neutral-600">
|
title="Relatório de SLA"
|
||||||
Acompanhe tempos de resposta, resolução e balanço de filas em tempo real.
|
lead="Acompanhe tempos de resposta, resolução e balanço de filas em tempo real."
|
||||||
</p>
|
/>
|
||||||
</header>
|
}
|
||||||
|
>
|
||||||
|
<div className="mx-auto w-full max-w-6xl px-4 pb-12 lg:px-6">
|
||||||
<SlaReport />
|
<SlaReport />
|
||||||
</main>
|
</div>
|
||||||
|
</AppShell>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -150,6 +150,7 @@ export default function NewTicketPage() {
|
||||||
className="min-h-[96px] w-full rounded-lg border border-slate-300 bg-white px-3 py-2 text-sm text-neutral-800 shadow-sm outline-none transition-colors focus-visible:border-[#00d6eb] focus-visible:ring-[3px] focus-visible:ring-[#00e8ff]/20"
|
className="min-h-[96px] w-full rounded-lg border border-slate-300 bg-white px-3 py-2 text-sm text-neutral-800 shadow-sm outline-none transition-colors focus-visible:border-[#00d6eb] focus-visible:ring-[3px] focus-visible:ring-[#00e8ff]/20"
|
||||||
value={summary}
|
value={summary}
|
||||||
onChange={(event) => setSummary(event.target.value)}
|
onChange={(event) => setSummary(event.target.value)}
|
||||||
|
placeholder="Resuma rapidamente o cenário ou impacto do ticket."
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import type { ReactNode } from "react"
|
import type { ReactNode } from "react"
|
||||||
|
|
||||||
import { AppSidebar } from "@/components/app-sidebar"
|
import { AppSidebar } from "@/components/app-sidebar"
|
||||||
|
import { AuthGuard } from "@/components/auth/auth-guard"
|
||||||
import { SidebarInset, SidebarProvider } from "@/components/ui/sidebar"
|
import { SidebarInset, SidebarProvider } from "@/components/ui/sidebar"
|
||||||
|
|
||||||
interface AppShellProps {
|
interface AppShellProps {
|
||||||
|
|
@ -13,6 +14,7 @@ export function AppShell({ header, children }: AppShellProps) {
|
||||||
<SidebarProvider>
|
<SidebarProvider>
|
||||||
<AppSidebar />
|
<AppSidebar />
|
||||||
<SidebarInset>
|
<SidebarInset>
|
||||||
|
<AuthGuard />
|
||||||
{header}
|
{header}
|
||||||
<main className="flex flex-1 flex-col gap-8 bg-gradient-to-br from-background via-background to-primary/10 pb-12 pt-6">
|
<main className="flex flex-1 flex-col gap-8 bg-gradient-to-br from-background via-background to-primary/10 pb-12 pt-6">
|
||||||
{children}
|
{children}
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ import { VersionSwitcher } from "@/components/version-switcher"
|
||||||
import {
|
import {
|
||||||
Sidebar,
|
Sidebar,
|
||||||
SidebarContent,
|
SidebarContent,
|
||||||
|
SidebarFooter,
|
||||||
SidebarGroup,
|
SidebarGroup,
|
||||||
SidebarGroupContent,
|
SidebarGroupContent,
|
||||||
SidebarGroupLabel,
|
SidebarGroupLabel,
|
||||||
|
|
@ -34,6 +35,7 @@ import {
|
||||||
SidebarRail,
|
SidebarRail,
|
||||||
} from "@/components/ui/sidebar"
|
} from "@/components/ui/sidebar"
|
||||||
import { Skeleton } from "@/components/ui/skeleton"
|
import { Skeleton } from "@/components/ui/skeleton"
|
||||||
|
import { NavUser } from "@/components/nav-user"
|
||||||
import { useAuth } from "@/lib/auth-client"
|
import { useAuth } from "@/lib/auth-client"
|
||||||
|
|
||||||
import type { LucideIcon } from "lucide-react"
|
import type { LucideIcon } from "lucide-react"
|
||||||
|
|
@ -103,7 +105,7 @@ const navigation: { versions: string[]; navMain: NavigationGroup[] } = {
|
||||||
|
|
||||||
export function AppSidebar({ ...props }: React.ComponentProps<typeof Sidebar>) {
|
export function AppSidebar({ ...props }: React.ComponentProps<typeof Sidebar>) {
|
||||||
const pathname = usePathname()
|
const pathname = usePathname()
|
||||||
const { isAdmin, isStaff, isCustomer } = useAuth()
|
const { session, isLoading, isAdmin, isStaff, isCustomer } = useAuth()
|
||||||
const [isHydrated, setIsHydrated] = React.useState(false)
|
const [isHydrated, setIsHydrated] = React.useState(false)
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
|
|
@ -194,6 +196,25 @@ export function AppSidebar({ ...props }: React.ComponentProps<typeof Sidebar>) {
|
||||||
)
|
)
|
||||||
})}
|
})}
|
||||||
</SidebarContent>
|
</SidebarContent>
|
||||||
|
<SidebarFooter>
|
||||||
|
{isLoading ? (
|
||||||
|
<div className="flex items-center gap-3 rounded-lg border border-border/70 bg-sidebar p-3 shadow-sm">
|
||||||
|
<Skeleton className="h-9 w-9 rounded-lg" />
|
||||||
|
<div className="flex-1 space-y-1">
|
||||||
|
<Skeleton className="h-3.5 w-24 rounded" />
|
||||||
|
<Skeleton className="h-3 w-32 rounded" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<NavUser
|
||||||
|
user={{
|
||||||
|
name: session?.user?.name,
|
||||||
|
email: session?.user?.email,
|
||||||
|
avatarUrl: session?.user?.avatarUrl ?? undefined,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</SidebarFooter>
|
||||||
<SidebarRail />
|
<SidebarRail />
|
||||||
</Sidebar>
|
</Sidebar>
|
||||||
)
|
)
|
||||||
|
|
|
||||||
29
web/src/components/auth/auth-guard.tsx
Normal file
29
web/src/components/auth/auth-guard.tsx
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
"use client"
|
||||||
|
|
||||||
|
import { useEffect } from "react"
|
||||||
|
import { usePathname, useRouter, useSearchParams } from "next/navigation"
|
||||||
|
|
||||||
|
import { useAuth } from "@/lib/auth-client"
|
||||||
|
|
||||||
|
export function AuthGuard() {
|
||||||
|
const { session, isLoading } = useAuth()
|
||||||
|
const router = useRouter()
|
||||||
|
const pathname = usePathname()
|
||||||
|
const searchParams = useSearchParams()
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (isLoading) return
|
||||||
|
if (session?.user) return
|
||||||
|
|
||||||
|
const search = searchParams?.toString()
|
||||||
|
const callbackUrl = pathname
|
||||||
|
? search && search.length > 0
|
||||||
|
? `${pathname}?${search}`
|
||||||
|
: pathname
|
||||||
|
: undefined
|
||||||
|
const nextUrl = callbackUrl ? `/login?callbackUrl=${encodeURIComponent(callbackUrl)}` : "/login"
|
||||||
|
router.replace(nextUrl)
|
||||||
|
}, [isLoading, session?.user, pathname, searchParams, router])
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
@ -1,12 +1,14 @@
|
||||||
"use client"
|
"use client"
|
||||||
|
|
||||||
|
import { useCallback, useMemo, useState } from "react"
|
||||||
|
import { useRouter } from "next/navigation"
|
||||||
import {
|
import {
|
||||||
IconCreditCard,
|
|
||||||
IconDotsVertical,
|
IconDotsVertical,
|
||||||
IconLogout,
|
IconLogout,
|
||||||
IconNotification,
|
IconNotification,
|
||||||
IconUserCircle,
|
IconUserCircle,
|
||||||
} from "@tabler/icons-react"
|
} from "@tabler/icons-react"
|
||||||
|
import { toast } from "sonner"
|
||||||
|
|
||||||
import {
|
import {
|
||||||
Avatar,
|
Avatar,
|
||||||
|
|
@ -28,17 +30,52 @@ import {
|
||||||
SidebarMenuItem,
|
SidebarMenuItem,
|
||||||
useSidebar,
|
useSidebar,
|
||||||
} from "@/components/ui/sidebar"
|
} from "@/components/ui/sidebar"
|
||||||
|
import { signOut } from "@/lib/auth-client"
|
||||||
|
|
||||||
export function NavUser({
|
type NavUserProps = {
|
||||||
user,
|
user?: {
|
||||||
}: {
|
name?: string | null
|
||||||
user: {
|
email?: string | null
|
||||||
name: string
|
avatarUrl?: string | null
|
||||||
email: string
|
} | null
|
||||||
avatar: string
|
|
||||||
}
|
}
|
||||||
}) {
|
|
||||||
|
export function NavUser({ user }: NavUserProps) {
|
||||||
|
const normalizedUser = user ?? { name: null, email: null, avatarUrl: null }
|
||||||
const { isMobile } = useSidebar()
|
const { isMobile } = useSidebar()
|
||||||
|
const router = useRouter()
|
||||||
|
const [isSigningOut, setIsSigningOut] = useState(false)
|
||||||
|
|
||||||
|
const initials = useMemo(() => {
|
||||||
|
const source = normalizedUser.name?.trim() || normalizedUser.email?.trim() || ""
|
||||||
|
if (!source) return "US"
|
||||||
|
const parts = source.split(" ").filter(Boolean)
|
||||||
|
const firstTwo = parts.slice(0, 2).map((part) => part[0]).join("")
|
||||||
|
if (firstTwo) return firstTwo.toUpperCase()
|
||||||
|
return source.slice(0, 2).toUpperCase()
|
||||||
|
}, [normalizedUser.name, normalizedUser.email])
|
||||||
|
|
||||||
|
const displayName = normalizedUser.name?.trim() || "Usuário"
|
||||||
|
const displayEmail = normalizedUser.email?.trim() || "Sem e-mail definido"
|
||||||
|
|
||||||
|
const handleProfile = useCallback(() => {
|
||||||
|
router.push("/settings")
|
||||||
|
}, [router])
|
||||||
|
|
||||||
|
const handleSignOut = useCallback(async () => {
|
||||||
|
if (isSigningOut) return
|
||||||
|
setIsSigningOut(true)
|
||||||
|
try {
|
||||||
|
await signOut()
|
||||||
|
toast.success("Sessão encerrada.")
|
||||||
|
router.replace("/login")
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Erro ao encerrar sessão", error)
|
||||||
|
toast.error("Não foi possível encerrar a sessão.")
|
||||||
|
} finally {
|
||||||
|
setIsSigningOut(false)
|
||||||
|
}
|
||||||
|
}, [isSigningOut, router])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SidebarMenu>
|
<SidebarMenu>
|
||||||
|
|
@ -50,13 +87,13 @@ export function NavUser({
|
||||||
className="data-[state=open]:bg-sidebar-accent data-[state=open]:text-sidebar-accent-foreground"
|
className="data-[state=open]:bg-sidebar-accent data-[state=open]:text-sidebar-accent-foreground"
|
||||||
>
|
>
|
||||||
<Avatar className="h-8 w-8 rounded-lg grayscale">
|
<Avatar className="h-8 w-8 rounded-lg grayscale">
|
||||||
<AvatarImage src={user.avatar} alt={user.name} />
|
<AvatarImage src={normalizedUser.avatarUrl ?? undefined} alt={displayName} />
|
||||||
<AvatarFallback className="rounded-lg">CN</AvatarFallback>
|
<AvatarFallback className="rounded-lg">{initials}</AvatarFallback>
|
||||||
</Avatar>
|
</Avatar>
|
||||||
<div className="grid flex-1 text-left text-sm leading-tight">
|
<div className="grid flex-1 text-left text-sm leading-tight">
|
||||||
<span className="truncate font-medium">{user.name}</span>
|
<span className="truncate font-medium">{displayName}</span>
|
||||||
<span className="text-muted-foreground truncate text-xs">
|
<span className="text-muted-foreground truncate text-xs">
|
||||||
{user.email}
|
{displayEmail}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<IconDotsVertical className="ml-auto size-4" />
|
<IconDotsVertical className="ml-auto size-4" />
|
||||||
|
|
@ -71,36 +108,43 @@ export function NavUser({
|
||||||
<DropdownMenuLabel className="p-0 font-normal">
|
<DropdownMenuLabel className="p-0 font-normal">
|
||||||
<div className="flex items-center gap-2 px-1 py-1.5 text-left text-sm">
|
<div className="flex items-center gap-2 px-1 py-1.5 text-left text-sm">
|
||||||
<Avatar className="h-8 w-8 rounded-lg">
|
<Avatar className="h-8 w-8 rounded-lg">
|
||||||
<AvatarImage src={user.avatar} alt={user.name} />
|
<AvatarImage src={normalizedUser.avatarUrl ?? undefined} alt={displayName} />
|
||||||
<AvatarFallback className="rounded-lg">CN</AvatarFallback>
|
<AvatarFallback className="rounded-lg">{initials}</AvatarFallback>
|
||||||
</Avatar>
|
</Avatar>
|
||||||
<div className="grid flex-1 text-left text-sm leading-tight">
|
<div className="grid flex-1 text-left text-sm leading-tight">
|
||||||
<span className="truncate font-medium">{user.name}</span>
|
<span className="truncate font-medium">{displayName}</span>
|
||||||
<span className="text-muted-foreground truncate text-xs">
|
<span className="text-muted-foreground truncate text-xs">
|
||||||
{user.email}
|
{displayEmail}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</DropdownMenuLabel>
|
</DropdownMenuLabel>
|
||||||
<DropdownMenuSeparator />
|
<DropdownMenuSeparator />
|
||||||
<DropdownMenuGroup>
|
<DropdownMenuGroup>
|
||||||
<DropdownMenuItem>
|
<DropdownMenuItem
|
||||||
<IconUserCircle />
|
onSelect={(event) => {
|
||||||
Account
|
event.preventDefault()
|
||||||
|
handleProfile()
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<IconUserCircle className="size-4" />
|
||||||
|
<span>Meu perfil</span>
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
<DropdownMenuItem>
|
<DropdownMenuItem disabled>
|
||||||
<IconCreditCard />
|
<IconNotification className="size-4" />
|
||||||
Billing
|
<span>Notificações (em breve)</span>
|
||||||
</DropdownMenuItem>
|
|
||||||
<DropdownMenuItem>
|
|
||||||
<IconNotification />
|
|
||||||
Notifications
|
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
</DropdownMenuGroup>
|
</DropdownMenuGroup>
|
||||||
<DropdownMenuSeparator />
|
<DropdownMenuSeparator />
|
||||||
<DropdownMenuItem>
|
<DropdownMenuItem
|
||||||
<IconLogout />
|
onSelect={(event) => {
|
||||||
Log out
|
event.preventDefault()
|
||||||
|
handleSignOut()
|
||||||
|
}}
|
||||||
|
disabled={isSigningOut}
|
||||||
|
>
|
||||||
|
<IconLogout className="size-4" />
|
||||||
|
<span>{isSigningOut ? "Encerrando…" : "Encerrar sessão"}</span>
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
</DropdownMenuContent>
|
</DropdownMenuContent>
|
||||||
</DropdownMenu>
|
</DropdownMenu>
|
||||||
|
|
|
||||||
|
|
@ -199,6 +199,7 @@ export function NewTicketDialog() {
|
||||||
id="summary"
|
id="summary"
|
||||||
className="min-h-[96px] w-full rounded-lg border border-slate-300 bg-background p-3 text-sm shadow-sm focus-visible:border-[#00d6eb] focus-visible:outline-none"
|
className="min-h-[96px] w-full rounded-lg border border-slate-300 bg-background p-3 text-sm shadow-sm focus-visible:border-[#00d6eb] focus-visible:outline-none"
|
||||||
{...form.register("summary")}
|
{...form.register("summary")}
|
||||||
|
placeholder="Explique em poucas linhas o contexto do chamado."
|
||||||
/>
|
/>
|
||||||
</Field>
|
</Field>
|
||||||
<Field>
|
<Field>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue