feat: 統一全系統頁面標題樣式、優化側邊欄與實作角色成員查看功能

This commit is contained in:
2026-01-13 17:00:58 +08:00
parent 6600cde3bc
commit f18fb169f3
33 changed files with 938 additions and 472 deletions

View File

@@ -8,7 +8,7 @@ import { Checkbox } from '@/Components/ui/checkbox';
import { FormEvent } from 'react';
interface Props {
roles: Record<string, string>; // ID -> Name map from pluck
roles: Record<string, string>; // Name (ID) -> DisplayName map from pluck
}
export default function UserCreate({ roles }: Props) {
@@ -34,16 +34,6 @@ export default function UserCreate({ roles }: Props) {
}
};
const translateRoleName = (name: string) => {
const map: Record<string, string> = {
'super-admin': '超級管理員',
'admin': '管理員',
'warehouse-manager': '倉庫主管',
'purchaser': '採購人員',
'viewer': '檢視者',
};
return map[name] || name;
}
return (
<AuthenticatedLayout
@@ -55,29 +45,34 @@ export default function UserCreate({ roles }: Props) {
>
<Head title="新增使用者" />
<div className="p-8 max-w-4xl mx-auto">
<form onSubmit={handleSubmit} className="space-y-8">
{/* Header */}
<div className="flex items-center justify-between">
<div>
<h1 className="text-2xl font-bold text-grey-0 flex items-center gap-2">
<Users className="h-6 w-6 text-[#01ab83]" />
使
</h1>
<p className="text-gray-500 mt-1">
</p>
</div>
<div className="flex items-center gap-3">
<Link href={route('users.index')}>
<Button variant="outline" type="button">
<ArrowLeft className="h-4 w-4 mr-2" />
</Button>
</Link>
<div className="container mx-auto p-6 max-w-7xl">
<form onSubmit={handleSubmit} className="space-y-6">
{/* Header Area */}
<div>
<Link href={route('users.index')}>
<Button
variant="outline"
type="button"
className="gap-2 button-outlined-primary mb-2"
>
<ArrowLeft className="h-4 w-4" />
使
</Button>
</Link>
<div className="flex items-center justify-between">
<div>
<h1 className="text-2xl font-bold text-grey-0 flex items-center gap-2">
<Users className="h-6 w-6 text-[#01ab83]" />
使
</h1>
<p className="text-gray-500 mt-1">
</p>
</div>
<Button
type="submit"
className="bg-[#01ab83] hover:bg-[#019a76]"
className="button-filled-primary"
disabled={processing}
>
<Check className="h-4 w-4 mr-2" />
@@ -170,22 +165,22 @@ export default function UserCreate({ roles }: Props) {
<div className="bg-white p-6 rounded-xl border border-gray-200 shadow-sm h-full">
<h3 className="font-bold text-gray-900 border-b pb-2 mb-4"></h3>
<div className="space-y-4">
{Object.entries(roles).map(([id, name]) => (
<div key={id} className="flex items-start space-x-3 p-2 hover:bg-gray-50 rounded-lg transition-colors">
{Object.entries(roles).map(([roleName, displayName]) => (
<div key={roleName} className="flex items-start space-x-3 p-2 hover:bg-gray-50 rounded-lg transition-colors">
<Checkbox
id={`role-${id}`}
checked={data.roles.includes(name)}
onCheckedChange={() => toggleRole(name)}
id={`role-${roleName}`}
checked={data.roles.includes(roleName)}
onCheckedChange={() => toggleRole(roleName)}
/>
<div className="grid gap-1.5 leading-none">
<label
htmlFor={`role-${id}`}
htmlFor={`role-${roleName}`}
className="text-sm font-medium leading-none cursor-pointer"
>
{translateRoleName(name)}
{displayName}
</label>
<p className="text-xs text-gray-500 font-mono">
{name}
{roleName}
</p>
</div>
</div>

View File

@@ -10,6 +10,7 @@ import { FormEvent } from 'react';
interface Role {
id: number;
name: string;
display_name: string;
}
interface UserData {
@@ -48,16 +49,6 @@ export default function UserEdit({ user, roles, currentRoles }: Props) {
}
};
const translateRoleName = (name: string) => {
const map: Record<string, string> = {
'super-admin': '超級管理員',
'admin': '管理員',
'warehouse-manager': '倉庫主管',
'purchaser': '採購人員',
'viewer': '檢視者',
};
return map[name] || name;
}
return (
<AuthenticatedLayout
@@ -69,29 +60,34 @@ export default function UserEdit({ user, roles, currentRoles }: Props) {
>
<Head title={`編輯使用者 - ${user.name}`} />
<div className="p-8 max-w-4xl mx-auto">
<form onSubmit={handleSubmit} className="space-y-8">
{/* Header */}
<div className="flex items-center justify-between">
<div>
<h1 className="text-2xl font-bold text-grey-0 flex items-center gap-2">
<Users className="h-6 w-6 text-[#01ab83]" />
使
</h1>
<p className="text-gray-500 mt-1">
使
</p>
</div>
<div className="flex items-center gap-3">
<Link href={route('users.index')}>
<Button variant="outline" type="button">
<ArrowLeft className="h-4 w-4 mr-2" />
</Button>
</Link>
<div className="container mx-auto p-6 max-w-7xl">
<form onSubmit={handleSubmit} className="space-y-6">
{/* Header Area */}
<div>
<Link href={route('users.index')}>
<Button
variant="outline"
type="button"
className="gap-2 button-outlined-primary mb-2"
>
<ArrowLeft className="h-4 w-4" />
使
</Button>
</Link>
<div className="flex items-center justify-between">
<div>
<h1 className="text-2xl font-bold text-grey-0 flex items-center gap-2">
<Users className="h-6 w-6 text-[#01ab83]" />
使
</h1>
<p className="text-gray-500 mt-1">
使
</p>
</div>
<Button
type="submit"
className="bg-[#01ab83] hover:bg-[#019a76]"
className="button-filled-primary"
disabled={processing}
>
<Check className="h-4 w-4 mr-2" />
@@ -203,7 +199,7 @@ export default function UserEdit({ user, roles, currentRoles }: Props) {
htmlFor={`role-${role.id}`}
className="text-sm font-medium leading-none cursor-pointer"
>
{translateRoleName(role.name)}
{role.display_name}
</label>
<p className="text-xs text-gray-500 font-mono">
{role.name}

View File

@@ -12,6 +12,7 @@ import {
} from "@/Components/ui/table";
import { format } from 'date-fns';
import { toast } from 'sonner';
import { Can } from '@/Components/Permission/Can';
interface Role {
id: number;
@@ -88,12 +89,14 @@ export default function UserIndex({ users }: Props) {
使
</p>
</div>
<Link href={route('users.create')}>
<Button className="button-filled-primary">
<Plus className="h-4 w-4 mr-2" />
使
</Button>
</Link>
<Can permission="users.create">
<Link href={route('users.create')}>
<Button className="button-filled-primary">
<Plus className="h-4 w-4 mr-2" />
使
</Button>
</Link>
</Can>
</div>
<div className="bg-white rounded-xl border border-gray-200 shadow-sm overflow-hidden">
@@ -151,25 +154,29 @@ export default function UserIndex({ users }: Props) {
</TableCell>
<TableCell className="text-center">
<div className="flex items-center justify-center gap-2">
<Link href={route('users.edit', user.id)}>
<Can permission="users.edit">
<Link href={route('users.edit', user.id)}>
<Button
variant="outline"
size="sm"
className="button-outlined-primary"
title="編輯"
>
<Pencil className="h-4 w-4" />
</Button>
</Link>
</Can>
<Can permission="users.delete">
<Button
variant="outline"
size="sm"
className="button-outlined-primary"
title="編輯"
className="button-outlined-error"
title="刪除"
onClick={() => handleDelete(user.id, user.name)}
>
<Pencil className="h-4 w-4" />
<Trash2 className="h-4 w-4" />
</Button>
</Link>
<Button
variant="outline"
size="sm"
className="button-outlined-error"
title="刪除"
onClick={() => handleDelete(user.id, user.name)}
>
<Trash2 className="h-4 w-4" />
</Button>
</Can>
</div>
</TableCell>
</TableRow>