feat: Enhance dashboard UI with new layout and client management

This commit is contained in:
wood chen 2025-02-08 19:54:27 +08:00
parent 9ff0dfdf7f
commit 00538187c6
5 changed files with 215 additions and 113 deletions

View File

@ -26,50 +26,49 @@ export default async function ClientsPage() {
const clients = await fetchClients(user.id as string);
return (
<div className="container mx-auto py-10">
<div className="mb-5 flex items-center justify-between">
<h1 className="text-3xl font-bold">Clients</h1>
<div className="mb-4">
{/* <Input
type="text"
placeholder="Search clients..."
value={searchTerm}
onChange={(e) => setSearchTerm(e.target.value)}
className="max-w-sm"
/> */}
<div className="mx-auto max-w-7xl px-4 py-8 sm:px-6 lg:px-8">
<div className="mb-6 flex items-center justify-between">
<div>
<h2 className="text-base text-muted-foreground">
OAuth
</h2>
</div>
<AddClientButton />
</div>
<Table>
<TableHeader>
<TableRow>
<TableHead>Name</TableHead>
<TableHead>Client ID</TableHead>
<TableHead>Client Secret Key</TableHead>
<TableHead>Redirect URI</TableHead>
<TableHead>Actions</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{clients.map((client) => (
<TableRow key={client.id}>
<TableCell>{client.name}</TableCell>
<TableCell>{client.clientId}</TableCell>
<TableCell>{client.clientSecret}</TableCell>
<TableCell>{client.redirectUri}</TableCell>
<TableCell>
<Button variant="outline" size="sm" className="mr-2">
Edit
</Button>
<Button variant="destructive" size="sm">
Delete
</Button>
</TableCell>
<div className="rounded-md border">
<Table>
<TableHeader>
<TableRow>
<TableHead></TableHead>
<TableHead>Client ID</TableHead>
<TableHead>Client Secret</TableHead>
<TableHead></TableHead>
<TableHead className="text-right"></TableHead>
</TableRow>
))}
</TableBody>
</Table>
</TableHeader>
<TableBody>
{clients.map((client) => (
<TableRow key={client.id}>
<TableCell>{client.name}</TableCell>
<TableCell className="font-mono">{client.clientId}</TableCell>
<TableCell className="font-mono">
{client.clientSecret}
</TableCell>
<TableCell>{client.redirectUri}</TableCell>
<TableCell className="text-right">
<Button variant="outline" size="sm" className="mr-2">
</Button>
<Button variant="destructive" size="sm">
</Button>
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</div>
</div>
);
}

View File

@ -1,34 +1,53 @@
import Link from "next/link";
import { AppWindow, Settings } from "lucide-react";
import { Button } from "@/components/ui/button";
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from "@/components/ui/card";
export default function DashboardPage() {
return (
<div className="flex h-screen">
{/* Sidebar Navigation */}
<nav className="w-64 bg-gray-800 p-4 text-white">
<h2 className="mb-4 text-2xl font-bold">Dashboard</h2>
<ul>
<li className="mb-2">
<a
href="/dashboard"
className="block rounded px-4 py-2 hover:bg-gray-700"
>
Home
</a>
</li>
<li className="mb-2">
<a
href="/dashboard/clients"
className="block rounded px-4 py-2 hover:bg-gray-700"
>
Client
</a>
</li>
</ul>
</nav>
<div className="mx-auto max-w-7xl px-4 py-8 sm:px-6 lg:px-8">
<div className="grid gap-4 md:grid-cols-2 lg:grid-cols-3">
<Card>
<CardHeader>
<CardTitle className="flex items-center gap-2">
<AppWindow className="h-6 w-6" />
</CardTitle>
<CardDescription>
OAuth
</CardDescription>
</CardHeader>
<CardContent>
<Link href="/dashboard/clients">
<Button className="w-full"></Button>
</Link>
</CardContent>
</Card>
{/* Main Content Area */}
<main className="flex-1 p-8">
<h1 className="mb-4 text-3xl font-bold">Welcome to Your Dashboard</h1>
<p>Select an option from the menu to get started.</p>
</main>
<Card>
<CardHeader>
<CardTitle className="flex items-center gap-2">
<Settings className="h-6 w-6" />
</CardTitle>
<CardDescription>
</CardDescription>
</CardHeader>
<CardContent>
<Button className="w-full" variant="outline">
</Button>
</CardContent>
</Card>
</div>
</div>
);
}

View File

@ -1,6 +1,7 @@
import { redirect } from "next/navigation";
import { getCurrentUser } from "@/lib/session";
import { DashboardHeader } from "@/components/layout/dashboard-header";
export default async function DashboardLayout({
children,
@ -10,5 +11,10 @@ export default async function DashboardLayout({
const user = await getCurrentUser();
if (!user) redirect("/sign-in");
return <div className="min-h-screen">{children}</div>;
return (
<div className="min-h-screen">
<DashboardHeader />
{children}
</div>
);
}

View File

@ -1,12 +1,17 @@
"use client";
import { useState } from "react";
import { useRouter } from "next/navigation";
import { AddClientAction } from "@/actions/add-client";
import { Plus } from "lucide-react";
import { useToast } from "@/hooks/use-toast";
import { Button } from "@/components/ui/button";
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
DialogTrigger,
@ -15,65 +20,111 @@ import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
export function AddClientButton() {
const [isAddClientOpen, setIsAddClientOpen] = useState(false);
const [open, setOpen] = useState(false);
const [isLoading, setIsLoading] = useState(false);
const { toast } = useToast();
const router = useRouter();
async function onSubmit(event: React.FormEvent<HTMLFormElement>) {
event.preventDefault();
setIsLoading(true);
const formData = new FormData(event.currentTarget);
const response = await AddClientAction(formData);
setIsLoading(false);
if (response.success) {
setOpen(false);
router.refresh();
toast({
title: "应用创建成功",
description: "您可以开始使用新创建的应用了",
});
} else {
toast({
variant: "destructive",
title: "创建失败",
description: response.error,
});
}
}
return (
<Dialog open={isAddClientOpen} onOpenChange={setIsAddClientOpen}>
<Dialog open={open} onOpenChange={setOpen}>
<DialogTrigger asChild>
<Button>Add Client</Button>
<Button>
<Plus className="mr-2 h-4 w-4" />
</Button>
</DialogTrigger>
<DialogContent>
<DialogHeader>
<DialogTitle>Add New Client</DialogTitle>
</DialogHeader>
<form action={AddClientAction}>
<form onSubmit={onSubmit}>
<DialogHeader>
<DialogTitle></DialogTitle>
<DialogDescription>
OAuth 使 Q58 Connect
</DialogDescription>
</DialogHeader>
<div className="grid gap-4 py-4">
<div className="grid grid-cols-4 items-center gap-4">
<Label htmlFor="name" className="text-right">
Name
</Label>
<Input id="name" name="name" className="col-span-3" />
</div>
<div className="grid grid-cols-4 items-center gap-4">
<Label htmlFor="home" className="text-right">
Home Page
</Label>
<Input id="home" name="home" className="col-span-3" />
</div>
<div className="grid grid-cols-4 items-center gap-4">
<Label htmlFor="logo" className="text-right">
Logo
</Label>
<Input id="logo" name="logo" className="col-span-3" />
</div>
<div className="grid grid-cols-4 items-center gap-4">
<Label htmlFor="description" className="text-right">
Description
</Label>
<div className="grid gap-2">
<Label htmlFor="name"></Label>
<Input
id="description"
name="description"
className="col-span-3"
id="name"
name="name"
placeholder="例如:我的博客"
disabled={isLoading}
/>
</div>
<div className="grid grid-cols-4 items-center gap-4">
<Label htmlFor="redirectUri" className="text-right">
Redirect URI
</Label>
<div className="grid gap-2">
<Label htmlFor="home"></Label>
<Input
id="home"
name="home"
placeholder="https://example.com"
disabled={isLoading}
/>
</div>
<div className="grid gap-2">
<Label htmlFor="logo"></Label>
<Input
id="logo"
name="logo"
placeholder="https://example.com/logo.png"
disabled={isLoading}
/>
</div>
<div className="grid gap-2">
<Label htmlFor="redirectUri"></Label>
<Input
id="redirectUri"
name="redirectUri"
className="col-span-3"
placeholder="https://example.com/oauth/callback"
disabled={isLoading}
/>
</div>
<div className="grid gap-2">
<Label htmlFor="description"></Label>
<Input
id="description"
name="description"
placeholder="简单描述一下您的应用"
disabled={isLoading}
/>
</div>
</div>
<div className="flex justify-end">
<Button type="submit">Add Client</Button>
</div>
<DialogFooter>
<Button
variant="outline"
onClick={() => setOpen(false)}
disabled={isLoading}
>
</Button>
<Button type="submit" disabled={isLoading}>
</Button>
</DialogFooter>
</form>
</DialogContent>
</Dialog>

View File

@ -0,0 +1,27 @@
"use client";
import { usePathname } from "next/navigation";
import { NavBar } from "./nav-bar";
export function DashboardHeader() {
const pathname = usePathname();
const getTitle = () => {
if (pathname === "/dashboard") return "控制台";
if (pathname === "/dashboard/clients") return "应用管理";
if (pathname.includes("/dashboard/clients/")) return "应用编辑";
return "";
};
return (
<div className="flex flex-col">
<NavBar />
<div className="border-b">
<div className="mx-auto flex h-16 max-w-7xl items-center px-4 sm:px-6 lg:px-8">
<h1 className="text-2xl font-bold">{getTitle()}</h1>
</div>
</div>
</div>
);
}