diff --git a/CLAUDE.md b/CLAUDE.md index 8b109a3..a767967 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -154,6 +154,14 @@ If Playwright's browser download fails (CDN returns 403 on this machine), set `P - **Read `docs/ui-guide.md` before building pages.** Logged-in pages live under `src/app/(app)/` (shared frame: topbar, role-based sidebar); don't render `
`; start with `PageHeader`; one primary action per view. - Styling: Tailwind CSS v4 with design tokens in `src/app/globals.css` (`@theme`) — use token classes (`bg-primary`, `text-muted`, `rounded-card`…), never hard-coded colors, never dynamically built class names. - Formatting only via `src/lib/format.ts` / `MoneyDisplay` / `StatusBadge` (status labels from `src/lib/application-status.ts`); shared components in `src/components/ui/` (ConfirmDialog for irreversible actions, Field/ErrorSummary for forms, DataTable for lists). +- Visual style follows the two mockups (`docs/風格2_*.png`): + - Buttons: always `Button` / `ButtonLink` / `buttonClass()` (`src/components/ui/button.tsx`). Never hand-write button classes. Filter toggles use `pillClass(active)`. + - Page headers: `PageHeader size="hero"` + `illustration` only for the dashboard and the application form. Other pages use the default size. + - Platform names: show them with `PlatformIcon` (`src/components/ui/platform-icon.tsx`; display info in `src/lib/platform-display.ts`), always next to the text name. +- Decorative images: + - Cropped from the mockups by `scripts/crop-mockup-images.ts` into `public/images/`, shown via `Illustration`. To upgrade, replace the files with higher-resolution ones under the same names. + - `public/images/` is excluded from the login redirect in `src/proxy.ts`. The Dockerfile copies `public/` into the runtime image (standalone output doesn't). +- Login, dev login and 403 pages use `AuthShell` (`src/components/auth-shell.tsx`). - Component tests: `// @vitest-environment jsdom` + Testing Library. ## Code layout diff --git a/Dockerfile b/Dockerfile index e2daa1f..0949ed0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -29,6 +29,8 @@ ENV NODE_ENV=production \ # 正式環境的 /app/data 是 bind mount,擁有者為 1000:1000;node 使用者正是 UID/GID 1000。 COPY --from=build --chown=node:node /app/.next/standalone ./ COPY --from=build --chown=node:node /app/.next/static ./.next/static +# standalone 輸出不含 public/(插圖等靜態檔),要另外複製。 +COPY --from=build --chown=node:node /app/public ./public # migration 在啟動時由 src/instrumentation.ts 套用,standalone 不會自動帶上這些 SQL 檔。 COPY --from=build --chown=node:node /app/src/server/db/migrations ./src/server/db/migrations RUN mkdir -p /app/data && chown node:node /app/data diff --git a/docs/ui-guide.md b/docs/ui-guide.md index 087fc40..c75facc 100644 --- a/docs/ui-guide.md +++ b/docs/ui-guide.md @@ -31,6 +31,9 @@ export default async function Page() { - **不要在頁面裡放 `
`**,框架已經提供。 - `PageHeader` 的 `actions`:一個頁面只有一個主要操作;手機寬度會自動變成畫面底部固定操作列。 表單底部的按鈕用 `StickyActions` 包起來,效果相同。 +- `PageHeader size="hero"`:首頁與新增申請的大標題,主要操作放在說明下方;`illustration` 加右側插圖 + (寬度 ≥ 1024px 才顯示,左緣淡入),`aside` 放標題列右側的輔助內容(例如完成進度)。 +- `Card` 的 `icon` 放在標題前,`link={{ href, label }}` 是標題列右側的「查看詳情 →」。 - 新增導覽項目:在 `src/lib/navigation.ts` 的 `NAV_ITEMS` 加一筆,並在 `ROUTE_RULES` 設定角色;側欄與權限檢查共用同一份設定。 ## 設計 tokens @@ -41,10 +44,12 @@ export default async function Page() { |---|---| | 頁面底色/卡片 | `bg-canvas`、`bg-surface` | | 文字 | `text-ink`(主要)、`text-muted`(次要) | -| 主要按鈕 | `bg-primary hover:bg-primary-hover text-on-primary` | +| 主要按鈕 | 用 `Button`/`ButtonLink`/`buttonClass()`(見下方),不要自己組按鈕類別 | | 強調、連結、導覽選中 | `text-accent`、`bg-accent-soft` | | 語意色 | `success`、`warning`、`danger`、`info`、`violet`、`neutral`(各有 `-soft` 淺底) | | 圓角、陰影 | `rounded-control`(輸入框、按鈕)、`rounded-card`、`shadow-card`、`shadow-overlay` | +| 字級 | `text-hero`(頁首大標題)、`text-display`(頁面標題)、`text-figure`(卡片大數字) | +| 裝飾 | `deco-blue`、`deco-yellow`(含 `-strong`):側欄波浪與 Logo;`brand-*` 只給 `PlatformIcon` 用 | Tailwind 只認得原始碼中**完整寫出**的類別名稱,不能用 `` `text-${tone}` `` 動態組合;需要依條件變化時,用對照表列出完整類別(參考 `src/components/ui/status-badge.tsx`)。 @@ -64,7 +69,10 @@ Tailwind 只認得原始碼中**完整寫出**的類別名稱,不能用 `` `te | 元件 | 用途 | |---|---| -| `MoneyDisplay` | 金額。月結前用 `kind="estimate"`(顯示「預估」),月結後 `kind="final"`(「最終」);`emphasis` 為綠色強調 | +| `Button`/`ButtonLink` | 按鈕與按鈕樣式的連結:`variant`(primary、secondary、ghost、danger、danger-outline)、`size`(sm、md、lg)、`icon` 前置圖示、`arrow` 尾端箭頭。交給其他元件的觸發按鈕用 `buttonClass(variant, size)` | +| `PlatformIcon` | AI 平台圖示(ChatGPT、Claude、Gemini 專屬,其他平台通用「…」),一定要搭配平台名稱文字;顯示資訊(廠商、用途)在 `src/lib/platform-display.ts` | +| `Illustration` | 裝飾插圖(`src/components/illustration.tsx`,檔案在 `public/images/`,自風格稿以 `scripts/crop-mockup-images.ts` 裁切)。純裝飾、對輔助技術隱藏;換高解析素材時直接取代同名檔案 | +| `MoneyDisplay` | 金額。月結前用 `kind="estimate"`(顯示「預估」),月結後 `kind="final"`(「最終」);`emphasis` 為綠色強調;`size="figure"` 為卡片大字 | | `StatusBadge` | 案件狀態,文字依 `src/lib/application-status.ts`(例如 `pending_review` →「待審核」);其他狀態用 `ToneBadge` | | `MonthPicker` | 月份選擇,值 `YYYY-MM`、顯示 `YYYY/MM` | | `ConfirmDialog` | 不核准、提交月結、最終核定、標記已發放等重要操作;`description` 寫清楚後果;取消不執行 | diff --git a/public/images/good-ideas.webp b/public/images/good-ideas.webp new file mode 100644 index 0000000..feb6c8e Binary files /dev/null and b/public/images/good-ideas.webp differ diff --git a/public/images/hero-application.webp b/public/images/hero-application.webp new file mode 100644 index 0000000..9d5def2 Binary files /dev/null and b/public/images/hero-application.webp differ diff --git a/public/images/hero-home.webp b/public/images/hero-home.webp new file mode 100644 index 0000000..f8c3421 Binary files /dev/null and b/public/images/hero-home.webp differ diff --git a/public/images/notes-books.webp b/public/images/notes-books.webp new file mode 100644 index 0000000..e309e92 Binary files /dev/null and b/public/images/notes-books.webp differ diff --git a/scripts/crop-mockup-images.ts b/scripts/crop-mockup-images.ts new file mode 100644 index 0000000..eba51c4 --- /dev/null +++ b/scripts/crop-mockup-images.ts @@ -0,0 +1,66 @@ +/** + * 一次性工具:從風格稿裁出頁面的裝飾插圖,輸出到 public/images/(WebP)。 + * 執行:npx tsx scripts/crop-mockup-images.ts + * + * 風格稿是 1672×941 的點陣圖,裁出來的圖解析度有限;之後若有高解析素材, + * 直接以同名檔案取代 public/images/ 裡的檔案即可,程式不用改。 + * sharp 是 Next.js 的相依套件,這支腳本不進正式流程。 + */ +import { mkdirSync } from "node:fs"; +import path from "node:path"; +import sharp from "sharp"; + +const HOME = "docs/風格2_首頁.png"; +const NEW_APPLICATION = "docs/風格2_新增申請頁.png"; +const OUT = "public/images"; + +interface Crop { + source: string; + file: string; + left: number; + top: number; + width: number; + height: number; +} + +const CROPS: Crop[] = [ + // 首頁頁首右側:便利貼、書本與標語 + { source: HOME, file: "hero-home.webp", left: 1100, top: 62, width: 572, height: 258 }, + // 首頁右下:「Good Ideas Deserve Support.」圖卡 + { source: HOME, file: "good-ideas.webp", left: 1180, top: 637, width: 469, height: 278 }, + // 新增申請頁首右側:「Good Ideas Better Tomorrow」便利貼 + { + source: NEW_APPLICATION, + file: "hero-application.webp", + left: 1296, + top: 62, + width: 376, + height: 180, + }, + // 新增申請注意事項底部:手寫標語、書本與馬克杯 + { + source: NEW_APPLICATION, + file: "notes-books.webp", + left: 1340, + top: 722, + width: 332, + height: 219, + }, +]; + +async function main() { + mkdirSync(OUT, { recursive: true }); + for (const c of CROPS) { + const target = path.join(OUT, c.file); + await sharp(c.source) + .extract({ left: c.left, top: c.top, width: c.width, height: c.height }) + .webp({ quality: 88 }) + .toFile(target); + console.log(`${target}(${c.width}×${c.height})`); + } +} + +main().catch((error: unknown) => { + console.error(error); + process.exitCode = 1; +}); diff --git a/src/app/(app)/admin/accounts/import/import-form.tsx b/src/app/(app)/admin/accounts/import/import-form.tsx index 8274196..fba57e5 100644 --- a/src/app/(app)/admin/accounts/import/import-form.tsx +++ b/src/app/(app)/admin/accounts/import/import-form.tsx @@ -2,8 +2,11 @@ import { useActionState } from "react"; import { commitRosterAction, previewRosterAction, type ImportState } from "./actions"; +import { buttonClass } from "@/components/ui/button"; +import { Card } from "@/components/page-header"; +import { Alert } from "@/components/ui/alert"; -// 暫時樣式:FileUploader、ErrorSummary 等共用元件由 add-app-shell 建立。 +/** 名冊 CSV 匯入:先上傳檢查,全部列正確才能確認匯入(有錯誤時不寫入任何資料)。 */ export function ImportForm() { const [previewState, preview, previewing] = useActionState( previewRosterAction, @@ -18,22 +21,49 @@ export function ImportForm() { return ( <> -
- - - -
- {state.step === "upload" && state.error &&

{state.error}

} + +
+
+ + +
+ +
+ {state.step === "upload" && state.error && ( +
+ {state.error} +
+ )} +
{state.step === "preview" && ( -
-

檢查結果:{state.fileName}

+
+

+ 檢查結果:{state.fileName} +

{state.errors.length > 0 ? ( -
-

有 {state.errors.length} 列錯誤,未匯入任何資料。請修正後重新上傳。

-
    +
    +

    + 有 {state.errors.length} 列錯誤,未匯入任何資料。請修正後重新上傳。 +

    +
      {state.errors.map((e) => (
    • 第 {e.line} 列:{e.message} @@ -42,13 +72,13 @@ export function ImportForm() {
    ) : ( -
    -

    + +

    將新增 {state.create} 筆、更新 {state.update} 筆人員資料。

    -
    diff --git a/src/app/(app)/admin/accounts/page.tsx b/src/app/(app)/admin/accounts/page.tsx index 3fa1daa..d1889be 100644 --- a/src/app/(app)/admin/accounts/page.tsx +++ b/src/app/(app)/admin/accounts/page.tsx @@ -1,5 +1,9 @@ -import { PageHeader } from "@/components/page-header"; import Link from "next/link"; +import { Card, PageHeader } from "@/components/page-header"; +import { Alert } from "@/components/ui/alert"; +import { buttonClass, ButtonLink, pillClass } from "@/components/ui/button"; +import { EmptyState } from "@/components/ui/empty-state"; +import { ToneBadge } from "@/components/ui/status-badge"; import { localDate } from "@/domain/calendar"; import { ROLES, ROLE_LABELS } from "@/lib/roles"; import { requireRouteAccess } from "@/server/auth/current-user"; @@ -20,7 +24,6 @@ const FILTERS: { value: AccountFilter; label: string }[] = [ { value: "inactive", label: "已停用" }, ]; -// 暫時樣式:表格、表單元件與確認視窗由 add-app-shell 統一。 export default async function AccountsPage({ searchParams, }: { @@ -42,120 +45,152 @@ export default async function AccountsPage({ + 匯入名冊 CSV + + } /> -

    - 匯入名冊 CSV -

    - {error &&

    {error}

    } - {notice &&

    {notice}

    } - - {accounts.length === 0 ? ( -

    沒有符合條件的帳號。

    - ) : ( - - - - - - - - - - - - {accounts.map((a) => ( - - - - + + + ))} + +
    員工編號姓名/Email部門角色狀態
    {a.employeeNo} - {a.name ?? "(尚未登入)"} -
    - {a.email ?? ""} -
    - {a.departmentName ?? "待指派部門"} - {a.active && ( -
    - - - + + + + + + + + + + + {accounts.map((a) => ( + + + + + - - - - ))} - -
    員工編號姓名/Email部門角色狀態
    {a.employeeNo} + {a.name ?? "(尚未登入)"} + {a.email ?? ""} + + {a.departmentName ?? "待指派部門"} + {a.active && ( + + + + + + + + )} + +
    + + + {ROLES.map((role) => ( + ))} - - - -
    - )} -
    -
    - - - {ROLES.map((role) => ( - - ))} - -
    - {a.roles.includes("admin") && ( -
    - - - - 檢視操作紀錄:{a.canViewAuditLog ? "已授權" : "未授權"} - -
    - )} -
    - {a.active ? "在職" : "已停用"} -
    - - - - -
    -
    - )} + + + {a.roles.includes("admin") && ( +
    + + + + 檢視操作紀錄:{a.canViewAuditLog ? "已授權" : "未授權"} + +
    + )} +
    + + {a.active ? "在職" : "已停用"} + +
    + + + + +
    +
    +
+ )} + ); } diff --git a/src/app/(app)/admin/audit-log/page.tsx b/src/app/(app)/admin/audit-log/page.tsx index dfc34a5..ddd5a47 100644 --- a/src/app/(app)/admin/audit-log/page.tsx +++ b/src/app/(app)/admin/audit-log/page.tsx @@ -19,6 +19,7 @@ import { DataTable } from "@/components/ui/data-table"; import { requireRouteAccess } from "@/server/auth/current-user"; import { getDb } from "@/server/db/client"; import { getEnv } from "@/server/env"; +import { buttonClass } from "@/components/ui/button"; const PAGE = "/admin/audit-log"; @@ -43,7 +44,6 @@ function formatValue(value: unknown): string { return JSON.stringify(value); } -// 暫時樣式:表格、抽屜與 EmptyState 等共用元件由 add-app-shell 統一。 export default async function AuditLogPage({ searchParams, }: { @@ -72,7 +72,7 @@ export default async function AuditLogPage({ method="get" action={PAGE} aria-label="篩選操作紀錄" - className="grid items-end gap-4 rounded-card bg-surface p-5 shadow-card sm:grid-cols-2 lg:grid-cols-4 [&_label]:flex [&_label]:flex-col [&_label]:gap-1.5 [&_label]:text-sm [&_label]:font-medium" + className="grid items-end gap-4 rounded-card bg-surface p-5 shadow-card sm:grid-cols-2 lg:grid-cols-4 [&_label]:flex [&_label]:flex-col [&_label]:gap-2 [&_label]:font-medium md:p-7" >