ultisuite-client/components/compte/compte-authentik-panel.tsx
R3D347HR4Y 9ea2d3325d
Some checks are pending
E2E / Playwright e2e (push) Waiting to run
feat(auth): enhance authentication flows with embedded support and UI improvements
- Updated login and signup components to utilize AuthCard for better user experience during redirection.
- Introduced AuthentikEmbedDialog for seamless integration of Authentik's identity portal within the application.
- Enhanced password recovery and signup flows with dynamic theme handling and improved loading states.
- Refactored existing components to streamline authentication processes and improve maintainability.
2026-06-21 00:12:45 +02:00

103 lines
2.7 KiB
TypeScript

"use client"
import { useMemo, useState } from "react"
import { useTheme } from "next-themes"
import { Button } from "@/components/ui/button"
import { AuthentikEmbedDialog } from "@/components/compte/authentik-embed-dialog"
import { CompteSettingsCard } from "@/components/compte/compte-settings-card"
import {
buildAuthentikUrl,
resolveAuthentikTheme,
type AuthentikUserSettingsTab,
} from "@/lib/auth/authentik-user-url"
import { useClientThemeStore } from "@/lib/stores/client-theme-store"
type CompteAuthentikPanelProps = {
title: string
description: string
tab?: AuthentikUserSettingsTab
flowSlug?: string
actionLabel: string
icon?: React.ReactNode
}
export function CompteAuthentikPanel({
title,
description,
tab,
flowSlug,
actionLabel,
icon,
}: CompteAuthentikPanelProps) {
const [embedOpen, setEmbedOpen] = useState(false)
const themeMode = useClientThemeStore((s) => s.themeMode)
const { resolvedTheme } = useTheme()
const authentikTheme = resolveAuthentikTheme(themeMode, resolvedTheme)
const url = useMemo(
() => buildAuthentikUrl({ tab, flowSlug, theme: authentikTheme }),
[tab, flowSlug, authentikTheme]
)
if (!url) {
return (
<CompteSettingsCard>
<PanelHeader icon={icon} title={title} description={description} />
<p className="mt-3 text-xs text-muted-foreground">
Portail d&apos;identité non configuré.
</p>
</CompteSettingsCard>
)
}
return (
<>
<CompteSettingsCard>
<div className="flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between">
<PanelHeader icon={icon} title={title} description={description} />
<Button
type="button"
variant="outline"
className="h-9 shrink-0 rounded-full px-4 text-sm font-medium"
onClick={() => setEmbedOpen(true)}
>
{actionLabel}
</Button>
</div>
</CompteSettingsCard>
<AuthentikEmbedDialog
url={url}
title={title}
description={description}
open={embedOpen}
onOpenChange={setEmbedOpen}
/>
</>
)
}
function PanelHeader({
icon,
title,
description,
}: {
icon?: React.ReactNode
title: string
description: string
}) {
return (
<div className="flex min-w-0 flex-1 gap-3">
{icon ? (
<span className="flex size-10 shrink-0 items-center justify-center rounded-full bg-accent text-muted-foreground">
{icon}
</span>
) : null}
<div className="min-w-0">
<h3 className="text-sm font-medium text-foreground">{title}</h3>
<p className="mt-0.5 text-sm text-muted-foreground">{description}</p>
</div>
</div>
)
}