feat: add user management features including user creation, editing, and password reset dialogs

- Implemented CreateUserDrawer for adding new users with validation.
- Added EditDrawer for editing existing user details.
- Created InitialPasswordDialog to display generated passwords after user creation.
- Developed ResetPasswordDialogs for resetting user passwords with copy functionality.
- Enhanced user listing page with filtering, pagination, and role assignment capabilities.
- Updated company picker import path to reflect new directory structure.
This commit is contained in:
mlogclub
2026-04-15 17:19:36 +08:00
parent 4d8856b9a5
commit 3d98cf1e27
80 changed files with 1 additions and 1 deletions
@@ -0,0 +1,71 @@
"use client"
import Link from "next/link"
import { ArrowRightIcon, ShieldAlertIcon } from "lucide-react"
import type { DashboardAlert } from "@/lib/api/dashboard"
import { Badge } from "@/components/ui/badge"
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from "@/components/ui/card"
type AlertListProps = {
alerts: DashboardAlert[]
}
function getAlertBadgeVariant(level: DashboardAlert["level"]) {
if (level === "error") {
return "destructive" as const
}
if (level === "warning") {
return "secondary" as const
}
return "outline" as const
}
export function AlertList({ alerts }: AlertListProps) {
return (
<Card>
<CardHeader>
<CardTitle></CardTitle>
<CardDescription> AI </CardDescription>
</CardHeader>
<CardContent className="space-y-3">
{alerts.length === 0 ? (
<div className="rounded-2xl border border-dashed px-4 py-10 text-center">
<ShieldAlertIcon className="mx-auto mb-3 size-8 text-muted-foreground" />
<div className="text-sm font-medium"></div>
<div className="mt-1 text-sm text-muted-foreground">
AI
</div>
</div>
) : (
alerts.map((item) => (
<Link key={item.id} href={item.link} className="block">
<div className="rounded-2xl border p-4 transition-colors hover:border-primary/40">
<div className="flex items-start justify-between gap-3">
<div>
<div className="flex items-center gap-2">
<div className="font-medium">{item.title}</div>
<Badge variant={getAlertBadgeVariant(item.level)}>
{item.count}
</Badge>
</div>
<div className="mt-1 text-sm text-muted-foreground">
{item.description}
</div>
</div>
<ArrowRightIcon className="mt-0.5 size-4 text-muted-foreground" />
</div>
</div>
</Link>
))
)}
</CardContent>
</Card>
)
}
@@ -0,0 +1,105 @@
"use client"
import Link from "next/link"
import {
BotMessageSquareIcon,
CircleDashedIcon,
HeadsetIcon,
SparklesIcon,
WavesIcon,
} from "lucide-react"
import type { DashboardOverview } from "@/lib/api/dashboard"
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from "@/components/ui/card"
type SummaryCardsProps = {
summary: DashboardOverview["summary"]
}
type SummaryCardItem = {
key: keyof DashboardOverview["summary"]
title: string
description: string
link: string
icon: typeof BotMessageSquareIcon
format?: (value: number) => string
}
const cards: SummaryCardItem[] = [
{
key: "todayNewConversations",
title: "今日新增会话",
description: "今日进入系统的新增咨询量",
link: "/conversations",
icon: BotMessageSquareIcon,
},
{
key: "processingConversations",
title: "当前处理中",
description: "正在由 AI 或人工接待的会话",
link: "/conversations",
icon: WavesIcon,
},
{
key: "pendingDispatchConversations",
title: "待分配会话",
description: "仍在待接入池中等待分配",
link: "/conversations",
icon: CircleDashedIcon,
},
{
key: "onlineAgents",
title: "在线客服",
description: "近 15 分钟内仍有活跃心跳的客服",
link: "/agents",
icon: HeadsetIcon,
},
{
key: "aiServiceRate",
title: "AI 接待占比",
description: "当前活跃会话中 AI 参与服务比例",
link: "/ai-agents",
icon: SparklesIcon,
format: (value: number) => `${value.toFixed(1)}%`,
},
]
export function SummaryCards({ summary }: SummaryCardsProps) {
return (
<div className="grid gap-4 md:grid-cols-2 xl:grid-cols-3 2xl:grid-cols-6">
{cards.map((item) => {
const Icon = item.icon
const rawValue = summary[item.key]
const value =
typeof item.format === "function"
? item.format(Number(rawValue))
: Number(rawValue).toLocaleString()
return (
<Link key={item.key} href={item.link}>
<Card className="h-full transition-colors hover:border-primary/40">
<CardHeader className="flex flex-row items-start justify-between space-y-0 pb-3">
<div className="space-y-1">
<CardTitle className="text-sm font-medium">{item.title}</CardTitle>
<CardDescription>{item.description}</CardDescription>
</div>
<div className="rounded-full bg-primary/10 p-2 text-primary">
<Icon className="size-4" />
</div>
</CardHeader>
<CardContent>
<div className="text-3xl font-semibold tracking-tight">{value}</div>
</CardContent>
</Card>
</Link>
)
})}
</div>
)
}
@@ -0,0 +1,98 @@
"use client"
import { Badge } from "@/components/ui/badge"
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from "@/components/ui/card"
import type { DashboardOverview } from "@/lib/api/dashboard"
type TeamLoadPanelProps = {
agentStats: DashboardOverview["agentStats"]
}
function getLoadTone(loadRate: number) {
if (loadRate >= 85) {
return "bg-red-500"
}
if (loadRate >= 60) {
return "bg-amber-500"
}
return "bg-emerald-500"
}
export function TeamLoadPanel({ agentStats }: TeamLoadPanelProps) {
return (
<Card>
<CardHeader>
<CardTitle></CardTitle>
<CardDescription>
线 {agentStats.onlineAgents} {agentStats.busyAgents}线 {agentStats.offlineAgents}
</CardDescription>
</CardHeader>
<CardContent className="space-y-4">
{agentStats.teamLoads.length === 0 ? (
<div className="rounded-xl border border-dashed px-4 py-8 text-center text-sm text-muted-foreground">
</div>
) : (
agentStats.teamLoads.map((item) => (
<div key={item.teamId} className="rounded-2xl border p-4">
<div className="flex flex-wrap items-center justify-between gap-3">
<div>
<div className="flex items-center gap-2">
<div className="font-medium">{item.teamName}</div>
{item.hasScheduleNow ? (
<Badge variant="secondary"></Badge>
) : (
<Badge variant="outline"></Badge>
)}
</div>
<div className="mt-1 text-sm text-muted-foreground">
{item.totalAgents}线 {item.onlineAgents} {item.busyAgents}线{" "}
{item.offlineAgents}
</div>
</div>
<div className="text-right">
<div className="text-2xl font-semibold">{item.loadRate.toFixed(1)}%</div>
<div className="text-xs text-muted-foreground">
{item.processingConversations}/{item.maxConcurrentCapacity || 0}
</div>
</div>
</div>
<div className="mt-4 h-2 rounded-full bg-muted">
<div
className={`h-2 rounded-full ${getLoadTone(item.loadRate)}`}
style={{ width: `${Math.min(item.loadRate, 100)}%` }}
/>
</div>
<div className="mt-4 grid gap-3 text-sm md:grid-cols-2 xl:grid-cols-4">
<div className="rounded-xl bg-muted/40 px-3 py-2">
<div className="text-muted-foreground"></div>
<div className="mt-1 text-lg font-semibold">{item.waitingConversations}</div>
</div>
<div className="rounded-xl bg-muted/40 px-3 py-2">
<div className="text-muted-foreground"></div>
<div className="mt-1 text-lg font-semibold">{item.processingConversations}</div>
</div>
<div className="rounded-xl bg-muted/40 px-3 py-2">
<div className="text-muted-foreground"></div>
<div className="mt-1 text-lg font-semibold">{item.maxConcurrentCapacity}</div>
</div>
<div className="rounded-xl bg-muted/40 px-3 py-2">
<div className="text-muted-foreground"></div>
<div className="mt-1 text-lg font-semibold">{item.busyAgents}</div>
</div>
</div>
</div>
))
)}
</CardContent>
</Card>
)
}
@@ -0,0 +1,117 @@
"use client"
import { Area, AreaChart, Bar, BarChart, CartesianGrid, XAxis, YAxis } from "recharts"
import type { DashboardStatusDistributionItem, DashboardTrendItem } from "@/lib/api/dashboard"
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from "@/components/ui/card"
import {
ChartContainer,
ChartTooltip,
ChartTooltipContent,
type ChartConfig,
} from "@/components/ui/chart"
type TrendPanelProps = {
title: string
description: string
trend: DashboardTrendItem[]
distribution: DashboardStatusDistributionItem[]
}
const trendConfig = {
newCount: {
label: "新增",
color: "hsl(24 95% 53%)",
},
closedCount: {
label: "关闭",
color: "hsl(190 95% 39%)",
},
} satisfies ChartConfig
const distributionConfig = {
count: {
label: "数量",
theme: {
light: "hsl(222 47% 11%)",
dark: "hsl(210 40% 98%)",
},
},
} satisfies ChartConfig
export function TrendPanel({
title,
description,
trend,
distribution,
}: TrendPanelProps) {
return (
<div className="grid gap-4 xl:grid-cols-[1.5fr_0.9fr]">
<Card>
<CardHeader>
<CardTitle>{title}</CardTitle>
<CardDescription>{description}</CardDescription>
</CardHeader>
<CardContent>
<ChartContainer config={trendConfig} className="h-72 w-full">
<AreaChart data={trend}>
<CartesianGrid vertical={false} />
<XAxis dataKey="date" tickLine={false} axisLine={false} tickMargin={8} />
<ChartTooltip content={<ChartTooltipContent />} />
<Area
type="monotone"
dataKey="newCount"
stroke="var(--color-newCount)"
fill="var(--color-newCount)"
fillOpacity={0.18}
strokeWidth={2}
/>
<Area
type="monotone"
dataKey="closedCount"
stroke="var(--color-closedCount)"
fill="var(--color-closedCount)"
fillOpacity={0.08}
strokeWidth={2}
/>
</AreaChart>
</ChartContainer>
</CardContent>
</Card>
<Card>
<CardHeader>
<CardTitle></CardTitle>
<CardDescription></CardDescription>
</CardHeader>
<CardContent className="space-y-4">
<ChartContainer config={distributionConfig} className="h-72 w-full">
<BarChart data={distribution} layout="vertical" margin={{ left: 20 }}>
<CartesianGrid horizontal={false} />
<YAxis
type="category"
dataKey="label"
tickLine={false}
axisLine={false}
width={64}
/>
<XAxis type="number" hide />
<ChartTooltip content={<ChartTooltipContent hideLabel />} />
<Bar
dataKey="count"
fill="var(--color-count)"
radius={[0, 8, 8, 0]}
/>
</BarChart>
</ChartContainer>
</CardContent>
</Card>
</div>
)
}