feat: Faz 2 - frontend iskeleti
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@@ -6,6 +6,31 @@ Biçim [Keep a Changelog](https://keepachangelog.com/tr-TR/1.1.0/) esas alınır
|
||||
|
||||
## [Yayınlanmamış]
|
||||
|
||||
## [0.2.0] - 2026-11-05
|
||||
|
||||
Faz 2: Frontend iskeleti (veriler Faz 3'e kadar mock).
|
||||
|
||||
### Eklendi
|
||||
|
||||
- Marka paleti: mavi/beyaz oklch tema (açık), lacivert/açık mavi (koyu); anlamsal `--income`, `--expense`, `--budget`, `--warning` değişkenleri ve grafik renkleri.
|
||||
- Açık / Koyu / Sistem tema (next-themes) ve her ekranda tema seçici.
|
||||
- Giriş ekranı (`/login`): kullanıcı adı veya e-posta + şifre, zod doğrulama, şifre göster/gizle, yükleniyor durumu; kayıt bağlantısı yok. `/` her zaman `/login`'e yönlenir.
|
||||
- Uygulama kabuğu: masaüstünde daraltılabilir yan menü, mobilde alt gezinme çubuğu (ortada Hızlı ekle, "Daha fazla" ile menü), üst bar (hane seçici, Hızlı ekle, tema, kullanıcı menüsü: ad, rol, sürüm, Çıkış yap). Henüz gelmeyen sayfalar "Yakında" olarak pasif.
|
||||
- Hızlı ekle (gider / gelir / transfer) seçimi; mobilde alttan açılan Drawer, masaüstünde Dialog (`ResponsiveDialog`).
|
||||
- Dashboard: karşılama ve özet kartları (Suspense + Skeleton).
|
||||
- Admin kullanıcı yönetimi (`/admin/kullanicilar`): TanStack Table v9 ile Türkçe duyarlı arama, sıralama, sayfalama; oluşturma, düzenleme, rol değiştirme, şifre sıfırlama, askıya alma/kaldırma, silme (onaylı). Kendini silememe ve son admini düşürememe kuralları (`checkAdminAction`).
|
||||
- Paylaşılan zod şemaları (`src/shared/schemas`: giriş, kullanıcı, şifre, askı), Türkçe arama/sıralama (`foldTr`, `compareTr`), TL ve İstanbul saatli tarih biçimleri (`formatMoney`, `formatDate`).
|
||||
- PWA temeli: `manifest.webmanifest`, tema rengi, Apple web app meta, ikonlar.
|
||||
- `npm run icons`: `public/brand/icon.png`'den favicon.ico, uygulama, Apple ve maskable PWA ikonları üretir (sharp).
|
||||
- Yer tutucu marka dosyaları (`public/brand/logo.svg`, `logo-dark.svg`, `icon.png`).
|
||||
- 404, hata (`retry`) ve global hata sayfaları; yükleniyor ekranları.
|
||||
- `ActionResult` sonuç tipi (Faz 3 Server Action sözleşmesi).
|
||||
|
||||
### Değişti
|
||||
|
||||
- `use-mobile` hook'u `useSyncExternalStore` ile yeniden yazıldı (effect içinde setState yok, hydration güvenli).
|
||||
- ESLint: `_` önekli bilinçli kullanılmayan değişkenlere izin.
|
||||
|
||||
## [0.1.0] - 2026-11-05
|
||||
|
||||
Faz 1: Framework, klasör yapısı ve altyapı.
|
||||
@@ -25,5 +50,6 @@ Faz 1: Framework, klasör yapısı ve altyapı.
|
||||
- `.nvmrc` (Node 26), `engines.node`, `typecheck`, `test`, `format`, `db:up`, `seed` scriptleri.
|
||||
- `docs/PROMPT.md` (ana prompt ve Faz 0 kararları), `README.md`, `CHANGELOG.md`.
|
||||
|
||||
[Yayınlanmamış]: https://gitea.ta1sph.info/suphicakir/butcem/compare/v0.1.0...HEAD
|
||||
[Yayınlanmamış]: https://gitea.ta1sph.info/suphicakir/butcem/compare/v0.2.0...HEAD
|
||||
[0.2.0]: https://gitea.ta1sph.info/suphicakir/butcem/compare/v0.1.0...v0.2.0
|
||||
[0.1.0]: https://gitea.ta1sph.info/suphicakir/butcem/releases/tag/v0.1.0
|
||||
|
||||
@@ -43,6 +43,10 @@ npm run dev # http://localhost:3000
|
||||
| `npm run db:up` / `db:down` | Lokal MongoDB'yi başlat / durdur |
|
||||
| `npm run seed` / `seed:reset` | Örnek veri (Faz 4) |
|
||||
|
||||
## Marka dosyaları
|
||||
|
||||
`public/brand/` altındaki `logo.svg`, `logo-dark.svg` ve `icon.png` (512×512) şu an **yer tutucudur**. Gerçek logoları aynı adlarla koyup `npm run icons` çalıştırın.
|
||||
|
||||
## Docker imajı
|
||||
|
||||
```bash
|
||||
|
||||
@@ -5,6 +5,15 @@ import nextTs from "eslint-config-next/typescript";
|
||||
const eslintConfig = defineConfig([
|
||||
...nextVitals,
|
||||
...nextTs,
|
||||
{
|
||||
rules: {
|
||||
// "_" ile başlayan adlar bilinçli olarak kullanılmayan değişkenlerdir.
|
||||
"@typescript-eslint/no-unused-vars": [
|
||||
"warn",
|
||||
{ argsIgnorePattern: "^_", varsIgnorePattern: "^_", destructuredArrayIgnorePattern: "^_" },
|
||||
],
|
||||
},
|
||||
},
|
||||
// Override default ignores of eslint-config-next.
|
||||
globalIgnores([
|
||||
// Default ignores of eslint-config-next:
|
||||
|
||||
@@ -24,8 +24,10 @@
|
||||
"react-hook-form": "^7.91.0",
|
||||
"server-only": "^0.0.1",
|
||||
"shadcn": "^4.23.0",
|
||||
"sharp": "^0.35.5",
|
||||
"sonner": "^2.0.8",
|
||||
"tw-animate-css": "^1.4.0",
|
||||
"vaul": "^1.1.2",
|
||||
"zod": "^4.6.7"
|
||||
},
|
||||
"devDependencies": {
|
||||
@@ -42,6 +44,9 @@
|
||||
"tsx": "^4.23.15",
|
||||
"typescript": "^5",
|
||||
"vitest": "^5.1.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=26 <27"
|
||||
}
|
||||
},
|
||||
"node_modules/@alloc/quick-lru": {
|
||||
@@ -1650,7 +1655,6 @@
|
||||
"resolved": "https://registry.npmjs.org/@img/colour/-/colour-1.1.0.tgz",
|
||||
"integrity": "sha512-Td76q7j57o/tLVdgS746cYARfSyxk8iEfRxewL9h4OMzYhbW4TAcppl0mT4eyqXddh6L/jwoM75mo7ixa/pCeQ==",
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
}
|
||||
@@ -6776,7 +6780,6 @@
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.1.2.tgz",
|
||||
"integrity": "sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ==",
|
||||
"devOptional": true,
|
||||
"license": "Apache-2.0",
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
@@ -11199,7 +11202,6 @@
|
||||
"resolved": "https://registry.npmjs.org/sharp/-/sharp-0.35.5.tgz",
|
||||
"integrity": "sha512-Ywn4OnzGukp7CDMrp08RQ50YKmuwG47brZgIVPTvBaaAfQlRlygrRqSrxdCiL9M+LlzLBiJ68IR1QqvzHyjC7g==",
|
||||
"license": "Apache-2.0",
|
||||
"optional": true,
|
||||
"dependencies": {
|
||||
"@img/colour": "^1.1.0",
|
||||
"detect-libc": "^2.1.2",
|
||||
@@ -11249,7 +11251,6 @@
|
||||
"resolved": "https://registry.npmjs.org/semver/-/semver-7.8.6.tgz",
|
||||
"integrity": "sha512-9lpSSU4Mly3mrtruwLs1eLK6+gzbzqeBFwRNjIjE+9LuDpWdYctrQlQ3ej1Ilgi7gknpsTRnPoLP8DpCHqHIJw==",
|
||||
"license": "ISC",
|
||||
"optional": true,
|
||||
"bin": {
|
||||
"semver": "bin/semver.js"
|
||||
},
|
||||
@@ -12340,6 +12341,19 @@
|
||||
"node": "^20.17.0 || >=22.9.0"
|
||||
}
|
||||
},
|
||||
"node_modules/vaul": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/vaul/-/vaul-1.1.2.tgz",
|
||||
"integrity": "sha512-ZFkClGpWyI2WUQjdLJ/BaGuV6AVQiJ3uELGk3OYtP+B6yCO7Cmn9vPFXVJkRaGkOJu3m8bQMgtyzNHixULceQA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@radix-ui/react-dialog": "^1.1.1"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0.0 || ^19.0.0-rc",
|
||||
"react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0.0 || ^19.0.0-rc"
|
||||
}
|
||||
},
|
||||
"node_modules/vite": {
|
||||
"version": "8.3.5",
|
||||
"resolved": "https://registry.npmjs.org/vite/-/vite-8.3.5.tgz",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "butcem",
|
||||
"version": "0.1.0",
|
||||
"version": "0.2.0",
|
||||
"private": true,
|
||||
"description": "BÜTÇEM — aile bütçe, cari, birikim, ev stoğu ve akıllı alışveriş uygulaması",
|
||||
"engines": {
|
||||
@@ -19,7 +19,8 @@
|
||||
"db:up": "docker compose up -d --wait",
|
||||
"db:down": "docker compose down",
|
||||
"seed": "tsx --env-file=.env.local scripts/seed.ts",
|
||||
"seed:reset": "tsx --env-file=.env.local scripts/seed.ts --reset"
|
||||
"seed:reset": "tsx --env-file=.env.local scripts/seed.ts --reset",
|
||||
"icons": "tsx scripts/generate-icons.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"@hookform/resolvers": "^7.0.2",
|
||||
@@ -38,8 +39,10 @@
|
||||
"react-hook-form": "^7.91.0",
|
||||
"server-only": "^0.0.1",
|
||||
"shadcn": "^4.23.0",
|
||||
"sharp": "^0.35.5",
|
||||
"sonner": "^2.0.8",
|
||||
"tw-animate-css": "^1.4.0",
|
||||
"vaul": "^1.1.2",
|
||||
"zod": "^4.6.7"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
|
After Width: | Height: | Size: 15 KiB |
@@ -0,0 +1,5 @@
|
||||
<!-- YER TUTUCU: gerçek BÜTÇEM logosu ile değiştirin (koyu tema). -->
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="240" height="64" viewBox="0 0 240 64" role="img" aria-label="BÜTÇEM">
|
||||
<rect x="1" y="1" width="238" height="62" rx="12" fill="none" stroke="#6bb9f8" stroke-width="2" stroke-dasharray="6 4"/>
|
||||
<text x="120" y="40" text-anchor="middle" font-family="sans-serif" font-size="26" font-weight="700" fill="#6bb9f8">BÜTÇEM</text>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 457 B |
@@ -0,0 +1,5 @@
|
||||
<!-- YER TUTUCU: gerçek BÜTÇEM logosu ile değiştirin (açık tema). -->
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="240" height="64" viewBox="0 0 240 64" role="img" aria-label="BÜTÇEM">
|
||||
<rect x="1" y="1" width="238" height="62" rx="12" fill="none" stroke="#105bbe" stroke-width="2" stroke-dasharray="6 4"/>
|
||||
<text x="120" y="40" text-anchor="middle" font-family="sans-serif" font-size="26" font-weight="700" fill="#105bbe">BÜTÇEM</text>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 459 B |
|
After Width: | Height: | Size: 7.5 KiB |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 17 KiB |
@@ -0,0 +1,90 @@
|
||||
/**
|
||||
* Uygulama ikonlarını logodan üretir: npm run icons
|
||||
*
|
||||
* Kaynak: public/brand/icon.png (kare, en az 512×512).
|
||||
* Çıktılar (commit edilir):
|
||||
* src/app/favicon.ico 16/32/48 px (PNG gömülü ICO)
|
||||
* src/app/icon.png 192 px → <link rel="icon">
|
||||
* src/app/apple-icon.png 180 px, saydamsız → iOS ana ekran
|
||||
* public/icons/icon-192.png PWA manifest
|
||||
* public/icons/icon-512.png PWA manifest
|
||||
* public/icons/maskable-512.png PWA manifest (purpose: maskable, %80 güvenli alan)
|
||||
*
|
||||
* Logoyu değiştirdikten sonra bu betiği yeniden çalıştırın.
|
||||
*/
|
||||
import { mkdir, writeFile } from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import sharp from "sharp";
|
||||
|
||||
const ROOT = process.cwd();
|
||||
const SOURCE = path.join(ROOT, "public/brand/icon.png");
|
||||
/** Saydamlık kabul etmeyen ikonlarda arka plan: marka mavisi (--primary, açık tema). */
|
||||
const BRAND_BG = "#105bbe";
|
||||
|
||||
async function png(size: number, opts: { flatten?: boolean; padding?: number } = {}) {
|
||||
const inner = Math.round(size * (1 - (opts.padding ?? 0) * 2));
|
||||
const resized = await sharp(SOURCE).resize(inner, inner, { fit: "contain" }).png().toBuffer();
|
||||
let img = sharp({
|
||||
create: {
|
||||
width: size,
|
||||
height: size,
|
||||
channels: 4,
|
||||
background: opts.flatten || opts.padding ? BRAND_BG : { r: 0, g: 0, b: 0, alpha: 0 },
|
||||
},
|
||||
}).composite([{ input: resized, gravity: "center" }]);
|
||||
if (opts.flatten) img = img.flatten({ background: BRAND_BG });
|
||||
return img.png({ compressionLevel: 9 }).toBuffer();
|
||||
}
|
||||
|
||||
/** PNG görüntülerinden ICO dosyası oluşturur (Vista+ tüm tarayıcılar PNG gömülü ICO destekler). */
|
||||
function toIco(images: { size: number; data: Buffer }[]): Buffer {
|
||||
const header = Buffer.alloc(6);
|
||||
header.writeUInt16LE(0, 0); // reserved
|
||||
header.writeUInt16LE(1, 2); // type: icon
|
||||
header.writeUInt16LE(images.length, 4);
|
||||
const entries: Buffer[] = [];
|
||||
let offset = 6 + images.length * 16;
|
||||
for (const { size, data } of images) {
|
||||
const e = Buffer.alloc(16);
|
||||
e.writeUInt8(size >= 256 ? 0 : size, 0);
|
||||
e.writeUInt8(size >= 256 ? 0 : size, 1);
|
||||
e.writeUInt8(0, 2); // palette
|
||||
e.writeUInt8(0, 3); // reserved
|
||||
e.writeUInt16LE(1, 4); // color planes
|
||||
e.writeUInt16LE(32, 6); // bpp
|
||||
e.writeUInt32LE(data.length, 8);
|
||||
e.writeUInt32LE(offset, 12);
|
||||
offset += data.length;
|
||||
entries.push(e);
|
||||
}
|
||||
return Buffer.concat([header, ...entries, ...images.map((i) => i.data)]);
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const meta = await sharp(SOURCE).metadata();
|
||||
if (!meta.width || !meta.height || meta.width !== meta.height || meta.width < 512) {
|
||||
throw new Error(`${SOURCE} kare ve en az 512×512 olmalı (şu an ${meta.width}×${meta.height}).`);
|
||||
}
|
||||
await mkdir(path.join(ROOT, "public/icons"), { recursive: true });
|
||||
|
||||
const out: [string, Buffer][] = [
|
||||
["src/app/icon.png", await png(192)],
|
||||
["src/app/apple-icon.png", await png(180, { flatten: true })],
|
||||
["public/icons/icon-192.png", await png(192)],
|
||||
["public/icons/icon-512.png", await png(512)],
|
||||
["public/icons/maskable-512.png", await png(512, { padding: 0.1 })],
|
||||
[
|
||||
"src/app/favicon.ico",
|
||||
toIco(await Promise.all([16, 32, 48].map(async (size) => ({ size, data: await png(size) })))),
|
||||
],
|
||||
];
|
||||
for (const [file, data] of out) {
|
||||
await writeFile(path.join(ROOT, file), data);
|
||||
console.log(`✓ ${file} (${data.length} bayt)`);
|
||||
}
|
||||
}
|
||||
|
||||
main().catch((err: unknown) => {
|
||||
console.error(err instanceof Error ? err.message : err);
|
||||
process.exit(1);
|
||||
});
|
||||
@@ -0,0 +1,18 @@
|
||||
import type { Metadata } from "next";
|
||||
import { PageHeader } from "@/components/page-header";
|
||||
import { UsersTable } from "@/features/admin-users/components/users-table";
|
||||
import { MOCK_ADMIN_USERS } from "@/features/admin-users/mock";
|
||||
import { MOCK_SESSION_USER } from "@/features/auth/mock";
|
||||
import { tr } from "@/i18n/tr";
|
||||
|
||||
export const metadata: Metadata = { title: tr.adminUsers.title };
|
||||
|
||||
export default function AdminUsersPage() {
|
||||
// FAZ 3: const users = await listUsers() (Better Auth admin API)
|
||||
return (
|
||||
<>
|
||||
<PageHeader title={tr.adminUsers.title} description={tr.adminUsers.description} />
|
||||
<UsersTable initialUsers={MOCK_ADMIN_USERS} currentUserId={MOCK_SESSION_USER.id} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import { notFound } from "next/navigation";
|
||||
import { MOCK_SESSION_USER } from "@/features/auth/mock";
|
||||
|
||||
/**
|
||||
* Yalnızca sistem admini. Admin olmayana 404 (sayfanın varlığını bile göstermez).
|
||||
* FAZ 3: `await requireRole("admin")` (lib/dal.ts) — sunucu tarafı gerçek kontrol.
|
||||
*/
|
||||
export default function AdminLayout({ children }: { children: React.ReactNode }) {
|
||||
if (MOCK_SESSION_USER.role !== "admin") notFound();
|
||||
return children;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import { SummaryCardsSkeleton } from "@/features/dashboard/components/summary-cards-skeleton";
|
||||
|
||||
export default function DashboardLoading() {
|
||||
return (
|
||||
<>
|
||||
<div className="space-y-2">
|
||||
<Skeleton className="h-8 w-56" />
|
||||
<Skeleton className="h-4 w-80 max-w-full" />
|
||||
</div>
|
||||
<SummaryCardsSkeleton />
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
import type { Metadata } from "next";
|
||||
import { Suspense } from "react";
|
||||
import { PageHeader } from "@/components/page-header";
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { MOCK_SESSION_USER } from "@/features/auth/mock";
|
||||
import { SummaryCardsSkeleton } from "@/features/dashboard/components/summary-cards-skeleton";
|
||||
import { tr } from "@/i18n/tr";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { formatMoney } from "@/shared/format";
|
||||
|
||||
export const metadata: Metadata = { title: tr.dashboard.title };
|
||||
|
||||
type SummaryCard = {
|
||||
key: keyof typeof tr.dashboard.cards;
|
||||
tone?: string;
|
||||
amountMinor: number | null;
|
||||
};
|
||||
|
||||
/** FAZ 14: gerçek özet verisi (gelir, gider, bakiye, kart borcu, net varlık). */
|
||||
async function getSummary(): Promise<SummaryCard[]> {
|
||||
return [
|
||||
{ key: "monthIncome", tone: "text-income", amountMinor: null },
|
||||
{ key: "monthExpense", tone: "text-expense", amountMinor: null },
|
||||
{ key: "monthRemaining", tone: "text-budget", amountMinor: null },
|
||||
{ key: "totalBalance", amountMinor: null },
|
||||
{ key: "cardDebt", tone: "text-expense", amountMinor: null },
|
||||
{ key: "netWorth", amountMinor: null },
|
||||
];
|
||||
}
|
||||
|
||||
async function SummaryCards() {
|
||||
const cards = await getSummary();
|
||||
return (
|
||||
<div className="grid grid-cols-2 gap-3 lg:grid-cols-3 xl:grid-cols-6">
|
||||
{cards.map((c) => (
|
||||
<Card key={c.key} size="sm">
|
||||
<CardHeader>
|
||||
<CardDescription>{tr.dashboard.cards[c.key]}</CardDescription>
|
||||
<CardTitle className={cn("text-lg tabular-nums", c.tone)}>
|
||||
{c.amountMinor === null ? "—" : formatMoney(c.amountMinor)}
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
{c.amountMinor === null ? (
|
||||
<CardContent className="text-xs text-muted-foreground">
|
||||
{tr.dashboard.noData}
|
||||
</CardContent>
|
||||
) : null}
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default function DashboardPage() {
|
||||
const user = MOCK_SESSION_USER;
|
||||
return (
|
||||
<>
|
||||
<PageHeader
|
||||
title={tr.dashboard.welcome(user.name.split(" ")[0] ?? user.name)}
|
||||
description={tr.dashboard.welcomeDescription}
|
||||
/>
|
||||
<Suspense fallback={<SummaryCardsSkeleton />}>
|
||||
<SummaryCards />
|
||||
</Suspense>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
import { AppHeader } from "@/components/layout/app-header";
|
||||
import { AppSidebar } from "@/components/layout/app-sidebar";
|
||||
import { BottomNav } from "@/components/layout/bottom-nav";
|
||||
import { QuickAddProvider } from "@/components/layout/quick-add";
|
||||
import { SidebarInset, SidebarProvider } from "@/components/ui/sidebar";
|
||||
import { MOCK_SESSION_USER } from "@/features/auth/mock";
|
||||
import { MOCK_HOUSEHOLDS } from "@/features/households/mock";
|
||||
import { APP_VERSION } from "@/lib/version";
|
||||
|
||||
/**
|
||||
* Oturum gerektiren alan: yan menü (masaüstü), üst bar, alt menü (mobil), hızlı ekle.
|
||||
* FAZ 3: `const session = await requireSession()` — oturum yoksa /login.
|
||||
*/
|
||||
export default function AppLayout({ children }: { children: React.ReactNode }) {
|
||||
const user = MOCK_SESSION_USER;
|
||||
return (
|
||||
<SidebarProvider>
|
||||
<QuickAddProvider>
|
||||
<AppSidebar isAdmin={user.role === "admin"} version={APP_VERSION} />
|
||||
<SidebarInset>
|
||||
<AppHeader user={user} households={MOCK_HOUSEHOLDS} version={APP_VERSION} />
|
||||
{/* Mobilde alt menü yüksekliği kadar boşluk */}
|
||||
<div className="flex flex-1 flex-col gap-4 p-4 pb-24 md:p-6 md:pb-6">{children}</div>
|
||||
</SidebarInset>
|
||||
<BottomNav />
|
||||
</QuickAddProvider>
|
||||
</SidebarProvider>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { ThemeToggle } from "@/components/layout/theme-toggle";
|
||||
|
||||
/** Oturum gerektirmeyen ekranlar (yalnızca giriş). */
|
||||
export default function AuthLayout({ children }: { children: React.ReactNode }) {
|
||||
return (
|
||||
<div className="relative flex min-h-dvh flex-1 flex-col items-center justify-center bg-gradient-to-b from-primary/5 via-background to-background px-4 py-10">
|
||||
<div className="absolute top-3 right-3">
|
||||
<ThemeToggle />
|
||||
</div>
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
"use client";
|
||||
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { Loader2 } from "lucide-react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import { Controller, useForm } from "react-hook-form";
|
||||
import { PasswordInput } from "@/components/password-input";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Field, FieldError, FieldGroup, FieldLabel } from "@/components/ui/field";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { tr } from "@/i18n/tr";
|
||||
import { loginSchema, type LoginInput } from "@/shared/schemas/auth";
|
||||
|
||||
export function LoginForm() {
|
||||
const router = useRouter();
|
||||
const [formError, setFormError] = useState<string | null>(null);
|
||||
const form = useForm<LoginInput>({
|
||||
resolver: zodResolver(loginSchema),
|
||||
defaultValues: { identifier: "", password: "" },
|
||||
});
|
||||
|
||||
async function onSubmit(_values: LoginInput) {
|
||||
setFormError(null);
|
||||
// FAZ 3: looksLikeEmail(identifier) ? authClient.signIn.email : authClient.signIn.username
|
||||
await new Promise((r) => setTimeout(r, 400));
|
||||
router.replace("/dashboard");
|
||||
}
|
||||
|
||||
const submitting = form.formState.isSubmitting;
|
||||
|
||||
return (
|
||||
<form onSubmit={form.handleSubmit(onSubmit)} noValidate aria-busy={submitting}>
|
||||
<FieldGroup>
|
||||
<Controller
|
||||
name="identifier"
|
||||
control={form.control}
|
||||
render={({ field, fieldState }) => (
|
||||
<Field data-invalid={fieldState.invalid}>
|
||||
<FieldLabel htmlFor="identifier">{tr.auth.identifier}</FieldLabel>
|
||||
<Input
|
||||
{...field}
|
||||
id="identifier"
|
||||
autoComplete="username"
|
||||
autoCapitalize="none"
|
||||
autoCorrect="off"
|
||||
spellCheck={false}
|
||||
inputMode="email"
|
||||
placeholder={tr.auth.identifierPlaceholder}
|
||||
aria-invalid={fieldState.invalid}
|
||||
autoFocus
|
||||
/>
|
||||
{fieldState.invalid ? <FieldError errors={[fieldState.error]} /> : null}
|
||||
</Field>
|
||||
)}
|
||||
/>
|
||||
<Controller
|
||||
name="password"
|
||||
control={form.control}
|
||||
render={({ field, fieldState }) => (
|
||||
<Field data-invalid={fieldState.invalid}>
|
||||
<FieldLabel htmlFor="password">{tr.auth.password}</FieldLabel>
|
||||
<PasswordInput
|
||||
{...field}
|
||||
id="password"
|
||||
autoComplete="current-password"
|
||||
aria-invalid={fieldState.invalid}
|
||||
/>
|
||||
{fieldState.invalid ? <FieldError errors={[fieldState.error]} /> : null}
|
||||
</Field>
|
||||
)}
|
||||
/>
|
||||
{formError ? <FieldError>{formError}</FieldError> : null}
|
||||
<Button type="submit" size="lg" disabled={submitting} className="w-full">
|
||||
{submitting ? <Loader2 className="animate-spin" /> : null}
|
||||
{submitting ? tr.auth.submitting : tr.auth.submit}
|
||||
</Button>
|
||||
</FieldGroup>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import type { Metadata } from "next";
|
||||
import { Logo } from "@/components/brand/logo";
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { tr } from "@/i18n/tr";
|
||||
import { LoginForm } from "./login-form";
|
||||
|
||||
export const metadata: Metadata = { title: tr.auth.loginTitle };
|
||||
|
||||
export default function LoginPage() {
|
||||
return (
|
||||
<main className="flex w-full max-w-sm flex-col items-center gap-6">
|
||||
<Logo priority className="scale-125" />
|
||||
<Card className="w-full">
|
||||
<CardHeader>
|
||||
<CardTitle className="text-xl">{tr.auth.loginTitle}</CardTitle>
|
||||
<CardDescription>{tr.auth.loginDescription}</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<LoginForm />
|
||||
</CardContent>
|
||||
</Card>
|
||||
<p className="text-center text-xs text-muted-foreground">{tr.auth.noSignUp}</p>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
After Width: | Height: | Size: 6.3 KiB |
@@ -0,0 +1,27 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect } from "react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { tr } from "@/i18n/tr";
|
||||
|
||||
/** Rota hata sınırı. İç detay gösterilmez; yalnızca sunucu loglarıyla eşleşen hata kodu (digest). */
|
||||
export default function ErrorPage({ error, retry }: { error: unknown; retry: () => void }) {
|
||||
useEffect(() => {
|
||||
console.error(error);
|
||||
}, [error]);
|
||||
|
||||
const digest = error instanceof Error && "digest" in error ? String(error.digest) : undefined;
|
||||
|
||||
return (
|
||||
<main className="flex flex-1 flex-col items-center justify-center gap-4 p-8 text-center">
|
||||
<h1 className="text-2xl font-semibold tracking-tight">{tr.errors.errorTitle}</h1>
|
||||
<p className="max-w-md text-muted-foreground">{tr.errors.errorDescription}</p>
|
||||
{digest ? (
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{tr.errors.reference}: <code>{digest}</code>
|
||||
</p>
|
||||
) : null}
|
||||
<Button onClick={() => retry()}>{tr.errors.retry}</Button>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 3.3 KiB |
@@ -0,0 +1,23 @@
|
||||
"use client";
|
||||
|
||||
import { tr } from "@/i18n/tr";
|
||||
import "./globals.css";
|
||||
|
||||
/** Kök layout hataları için son çare sınırı (kendi <html>/<body> etiketini render eder). */
|
||||
export default function GlobalError({ retry }: { error: unknown; retry: () => void }) {
|
||||
return (
|
||||
<html lang="tr">
|
||||
<body className="flex min-h-dvh flex-col items-center justify-center gap-4 p-8 text-center">
|
||||
<h1 className="text-2xl font-semibold tracking-tight">{tr.errors.errorTitle}</h1>
|
||||
<p className="max-w-md text-muted-foreground">{tr.errors.errorDescription}</p>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => retry()}
|
||||
className="rounded-lg bg-primary px-4 py-2 text-sm font-medium text-primary-foreground"
|
||||
>
|
||||
{tr.errors.retry}
|
||||
</button>
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
@@ -18,6 +18,14 @@
|
||||
--color-sidebar-primary: var(--sidebar-primary);
|
||||
--color-sidebar-foreground: var(--sidebar-foreground);
|
||||
--color-sidebar: var(--sidebar);
|
||||
--color-income: var(--income);
|
||||
--color-income-foreground: var(--income-foreground);
|
||||
--color-expense: var(--expense);
|
||||
--color-expense-foreground: var(--expense-foreground);
|
||||
--color-budget: var(--budget);
|
||||
--color-budget-foreground: var(--budget-foreground);
|
||||
--color-warning: var(--warning);
|
||||
--color-warning-foreground: var(--warning-foreground);
|
||||
--color-chart-5: var(--chart-5);
|
||||
--color-chart-4: var(--chart-4);
|
||||
--color-chart-3: var(--chart-3);
|
||||
@@ -48,73 +56,98 @@
|
||||
--radius-4xl: calc(var(--radius) * 2.6);
|
||||
}
|
||||
|
||||
/*
|
||||
* BÜTÇEM marka paleti — mavi ve beyaz tonları (oklch). Sabit renk kodu yalnızca burada.
|
||||
* Anlamsal renkler: --income (gelir/yeşil), --expense (gider/kırmızı),
|
||||
* --budget (bütçe-plan/mavi), --warning (uyarı/turuncu). Grafikler de bunları kullanır.
|
||||
*/
|
||||
:root {
|
||||
--background: oklch(1 0 0);
|
||||
--foreground: oklch(0.145 0 0);
|
||||
--background: oklch(0.99 0.004 250);
|
||||
--foreground: oklch(0.22 0.04 262);
|
||||
--card: oklch(1 0 0);
|
||||
--card-foreground: oklch(0.145 0 0);
|
||||
--card-foreground: oklch(0.22 0.04 262);
|
||||
--popover: oklch(1 0 0);
|
||||
--popover-foreground: oklch(0.145 0 0);
|
||||
--primary: oklch(0.205 0 0);
|
||||
--primary-foreground: oklch(0.985 0 0);
|
||||
--secondary: oklch(0.97 0 0);
|
||||
--secondary-foreground: oklch(0.205 0 0);
|
||||
--muted: oklch(0.97 0 0);
|
||||
--muted-foreground: oklch(0.556 0 0);
|
||||
--accent: oklch(0.97 0 0);
|
||||
--accent-foreground: oklch(0.205 0 0);
|
||||
--destructive: oklch(0.577 0.245 27.325);
|
||||
--border: oklch(0.922 0 0);
|
||||
--input: oklch(0.922 0 0);
|
||||
--ring: oklch(0.708 0 0);
|
||||
--chart-1: oklch(0.87 0 0);
|
||||
--chart-2: oklch(0.556 0 0);
|
||||
--chart-3: oklch(0.439 0 0);
|
||||
--chart-4: oklch(0.371 0 0);
|
||||
--chart-5: oklch(0.269 0 0);
|
||||
--popover-foreground: oklch(0.22 0.04 262);
|
||||
--primary: oklch(0.49 0.17 258);
|
||||
--primary-foreground: oklch(0.99 0.004 250);
|
||||
--secondary: oklch(0.955 0.016 250);
|
||||
--secondary-foreground: oklch(0.3 0.06 260);
|
||||
--muted: oklch(0.955 0.012 250);
|
||||
--muted-foreground: oklch(0.5 0.03 258);
|
||||
--accent: oklch(0.935 0.03 250);
|
||||
--accent-foreground: oklch(0.3 0.08 260);
|
||||
--destructive: oklch(0.56 0.21 25);
|
||||
--border: oklch(0.905 0.016 252);
|
||||
--input: oklch(0.89 0.018 252);
|
||||
--ring: oklch(0.6 0.15 258);
|
||||
|
||||
--income: oklch(0.58 0.15 152);
|
||||
--income-foreground: oklch(0.99 0.004 250);
|
||||
--expense: oklch(0.56 0.21 25);
|
||||
--expense-foreground: oklch(0.99 0.004 250);
|
||||
--budget: oklch(0.55 0.17 258);
|
||||
--budget-foreground: oklch(0.99 0.004 250);
|
||||
--warning: oklch(0.68 0.17 55);
|
||||
--warning-foreground: oklch(0.22 0.04 262);
|
||||
|
||||
--chart-1: var(--income);
|
||||
--chart-2: var(--budget);
|
||||
--chart-3: var(--expense);
|
||||
--chart-4: var(--warning);
|
||||
--chart-5: oklch(0.65 0.08 230);
|
||||
--radius: 0.625rem;
|
||||
--sidebar: oklch(0.985 0 0);
|
||||
--sidebar-foreground: oklch(0.145 0 0);
|
||||
--sidebar-primary: oklch(0.205 0 0);
|
||||
--sidebar-primary-foreground: oklch(0.985 0 0);
|
||||
--sidebar-accent: oklch(0.97 0 0);
|
||||
--sidebar-accent-foreground: oklch(0.205 0 0);
|
||||
--sidebar-border: oklch(0.922 0 0);
|
||||
--sidebar-ring: oklch(0.708 0 0);
|
||||
--sidebar: oklch(0.975 0.008 250);
|
||||
--sidebar-foreground: oklch(0.22 0.04 262);
|
||||
--sidebar-primary: oklch(0.49 0.17 258);
|
||||
--sidebar-primary-foreground: oklch(0.99 0.004 250);
|
||||
--sidebar-accent: oklch(0.935 0.03 250);
|
||||
--sidebar-accent-foreground: oklch(0.3 0.08 260);
|
||||
--sidebar-border: oklch(0.905 0.016 252);
|
||||
--sidebar-ring: oklch(0.6 0.15 258);
|
||||
}
|
||||
|
||||
.dark {
|
||||
--background: oklch(0.145 0 0);
|
||||
--foreground: oklch(0.985 0 0);
|
||||
--card: oklch(0.205 0 0);
|
||||
--card-foreground: oklch(0.985 0 0);
|
||||
--popover: oklch(0.205 0 0);
|
||||
--popover-foreground: oklch(0.985 0 0);
|
||||
--primary: oklch(0.922 0 0);
|
||||
--primary-foreground: oklch(0.205 0 0);
|
||||
--secondary: oklch(0.269 0 0);
|
||||
--secondary-foreground: oklch(0.985 0 0);
|
||||
--muted: oklch(0.269 0 0);
|
||||
--muted-foreground: oklch(0.708 0 0);
|
||||
--accent: oklch(0.269 0 0);
|
||||
--accent-foreground: oklch(0.985 0 0);
|
||||
--destructive: oklch(0.704 0.191 22.216);
|
||||
--border: oklch(1 0 0 / 10%);
|
||||
--input: oklch(1 0 0 / 15%);
|
||||
--ring: oklch(0.556 0 0);
|
||||
--chart-1: oklch(0.87 0 0);
|
||||
--chart-2: oklch(0.556 0 0);
|
||||
--chart-3: oklch(0.439 0 0);
|
||||
--chart-4: oklch(0.371 0 0);
|
||||
--chart-5: oklch(0.269 0 0);
|
||||
--sidebar: oklch(0.205 0 0);
|
||||
--sidebar-foreground: oklch(0.985 0 0);
|
||||
--sidebar-primary: oklch(0.488 0.243 264.376);
|
||||
--sidebar-primary-foreground: oklch(0.985 0 0);
|
||||
--sidebar-accent: oklch(0.269 0 0);
|
||||
--sidebar-accent-foreground: oklch(0.985 0 0);
|
||||
--sidebar-border: oklch(1 0 0 / 10%);
|
||||
--sidebar-ring: oklch(0.556 0 0);
|
||||
--background: oklch(0.18 0.04 264);
|
||||
--foreground: oklch(0.96 0.01 250);
|
||||
--card: oklch(0.22 0.045 264);
|
||||
--card-foreground: oklch(0.96 0.01 250);
|
||||
--popover: oklch(0.22 0.045 264);
|
||||
--popover-foreground: oklch(0.96 0.01 250);
|
||||
--primary: oklch(0.76 0.12 245);
|
||||
--primary-foreground: oklch(0.18 0.04 264);
|
||||
--secondary: oklch(0.27 0.045 264);
|
||||
--secondary-foreground: oklch(0.96 0.01 250);
|
||||
--muted: oklch(0.26 0.04 264);
|
||||
--muted-foreground: oklch(0.73 0.03 250);
|
||||
--accent: oklch(0.3 0.06 262);
|
||||
--accent-foreground: oklch(0.96 0.01 250);
|
||||
--destructive: oklch(0.7 0.18 22);
|
||||
--border: oklch(1 0 0 / 11%);
|
||||
--input: oklch(1 0 0 / 16%);
|
||||
--ring: oklch(0.7 0.12 245);
|
||||
|
||||
--income: oklch(0.75 0.16 152);
|
||||
--income-foreground: oklch(0.18 0.04 264);
|
||||
--expense: oklch(0.7 0.18 22);
|
||||
--expense-foreground: oklch(0.18 0.04 264);
|
||||
--budget: oklch(0.73 0.13 245);
|
||||
--budget-foreground: oklch(0.18 0.04 264);
|
||||
--warning: oklch(0.79 0.15 62);
|
||||
--warning-foreground: oklch(0.18 0.04 264);
|
||||
|
||||
--chart-1: var(--income);
|
||||
--chart-2: var(--budget);
|
||||
--chart-3: var(--expense);
|
||||
--chart-4: var(--warning);
|
||||
--chart-5: oklch(0.7 0.07 230);
|
||||
--sidebar: oklch(0.2 0.045 264);
|
||||
--sidebar-foreground: oklch(0.96 0.01 250);
|
||||
--sidebar-primary: oklch(0.76 0.12 245);
|
||||
--sidebar-primary-foreground: oklch(0.18 0.04 264);
|
||||
--sidebar-accent: oklch(0.28 0.055 262);
|
||||
--sidebar-accent-foreground: oklch(0.96 0.01 250);
|
||||
--sidebar-border: oklch(1 0 0 / 11%);
|
||||
--sidebar-ring: oklch(0.7 0.12 245);
|
||||
}
|
||||
|
||||
@layer base {
|
||||
@@ -128,3 +161,8 @@
|
||||
@apply font-sans;
|
||||
}
|
||||
}
|
||||
|
||||
/* Mobil alt menü + iOS ana ekran çentiği için güvenli alan */
|
||||
@utility pb-safe {
|
||||
padding-bottom: env(safe-area-inset-bottom);
|
||||
}
|
||||
|
||||
|
After Width: | Height: | Size: 7.5 KiB |
@@ -1,5 +1,6 @@
|
||||
import type { Metadata, Viewport } from "next";
|
||||
import { Geist, Geist_Mono } from "next/font/google";
|
||||
import { Providers } from "@/components/providers";
|
||||
import { tr } from "@/i18n/tr";
|
||||
import "./globals.css";
|
||||
|
||||
@@ -18,17 +19,31 @@ export const metadata: Metadata = {
|
||||
title: { default: tr.app.name, template: `%s · ${tr.app.name}` },
|
||||
description: tr.app.tagline,
|
||||
applicationName: tr.app.name,
|
||||
appleWebApp: { capable: true, title: tr.app.name, statusBarStyle: "default" },
|
||||
formatDetection: { telephone: false },
|
||||
};
|
||||
|
||||
export const viewport: Viewport = {
|
||||
width: "device-width",
|
||||
initialScale: 1,
|
||||
viewportFit: "cover",
|
||||
// Manifest/tarayıcı çubuğu rengi CSS değişkeni okuyamaz; --background değerlerinin hex karşılığı.
|
||||
themeColor: [
|
||||
{ media: "(prefers-color-scheme: light)", color: "#fafcfe" },
|
||||
{ media: "(prefers-color-scheme: dark)", color: "#081123" },
|
||||
],
|
||||
};
|
||||
|
||||
export default function RootLayout({ children }: LayoutProps<"/">) {
|
||||
return (
|
||||
<html lang="tr" className={`${geistSans.variable} ${geistMono.variable} h-full antialiased`}>
|
||||
<body className="flex min-h-full flex-col">{children}</body>
|
||||
<html
|
||||
lang="tr"
|
||||
suppressHydrationWarning
|
||||
className={`${geistSans.variable} ${geistMono.variable} h-full antialiased`}
|
||||
>
|
||||
<body className="flex min-h-full flex-col">
|
||||
<Providers>{children}</Providers>
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
import { Loader2 } from "lucide-react";
|
||||
import { tr } from "@/i18n/tr";
|
||||
|
||||
export default function Loading() {
|
||||
return (
|
||||
<div
|
||||
role="status"
|
||||
className="flex flex-1 items-center justify-center gap-2 p-8 text-muted-foreground"
|
||||
>
|
||||
<Loader2 className="size-5 animate-spin" />
|
||||
<span>{tr.common.loading}</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import type { MetadataRoute } from "next";
|
||||
import { tr } from "@/i18n/tr";
|
||||
|
||||
/** PWA manifest: "Ana ekrana ekle" ile kurulabilir. İkonlar: npm run icons. */
|
||||
export default function manifest(): MetadataRoute.Manifest {
|
||||
return {
|
||||
id: "/",
|
||||
name: tr.app.name,
|
||||
short_name: tr.app.name,
|
||||
description: tr.app.tagline,
|
||||
lang: "tr-TR",
|
||||
dir: "ltr",
|
||||
start_url: "/dashboard",
|
||||
scope: "/",
|
||||
display: "standalone",
|
||||
orientation: "portrait",
|
||||
background_color: "#fafcfe",
|
||||
theme_color: "#105bbe",
|
||||
categories: ["finance", "productivity"],
|
||||
icons: [
|
||||
{ src: "/icons/icon-192.png", sizes: "192x192", type: "image/png", purpose: "any" },
|
||||
{ src: "/icons/icon-512.png", sizes: "512x512", type: "image/png", purpose: "any" },
|
||||
{ src: "/icons/maskable-512.png", sizes: "512x512", type: "image/png", purpose: "maskable" },
|
||||
],
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import Link from "next/link";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { tr } from "@/i18n/tr";
|
||||
|
||||
export default function NotFound() {
|
||||
return (
|
||||
<main className="flex flex-1 flex-col items-center justify-center gap-4 p-8 text-center">
|
||||
<p className="text-6xl font-semibold text-primary tabular-nums">404</p>
|
||||
<h1 className="text-2xl font-semibold tracking-tight">{tr.errors.notFoundTitle}</h1>
|
||||
<p className="max-w-md text-muted-foreground">{tr.errors.notFoundDescription}</p>
|
||||
<Button asChild>
|
||||
<Link href="/">{tr.errors.backHome}</Link>
|
||||
</Button>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
@@ -1,15 +1,6 @@
|
||||
import { tr } from "@/i18n/tr";
|
||||
import { APP_VERSION } from "@/lib/version";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
/** Geçici açılış sayfası — Faz 2'de /login'e yönlendirme ile değişecek. */
|
||||
/** Uygulama her zaman login ile açılır. FAZ 3: oturum varsa /dashboard'a yönlenecek. */
|
||||
export default function Home() {
|
||||
return (
|
||||
<main className="flex flex-1 flex-col items-center justify-center gap-3 p-8 text-center">
|
||||
<h1 className="text-3xl font-semibold tracking-tight">{tr.app.name}</h1>
|
||||
<p className="max-w-md text-muted-foreground">{tr.app.setupDescription}</p>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
{tr.app.version} {APP_VERSION}
|
||||
</p>
|
||||
</main>
|
||||
);
|
||||
redirect("/login");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
import Image from "next/image";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { tr } from "@/i18n/tr";
|
||||
|
||||
/**
|
||||
* Marka logosu: açık temada logo.svg, koyu temada logo-dark.svg (CSS ile seçilir,
|
||||
* hydration uyumsuzluğu olmaz). Dosyalar public/brand/ altında.
|
||||
*/
|
||||
export function Logo({ className, priority }: { className?: string; priority?: boolean }) {
|
||||
const common = { width: 120, height: 32, priority, unoptimized: true } as const;
|
||||
return (
|
||||
<span className={cn("inline-flex items-center", className)}>
|
||||
<Image
|
||||
src="/brand/logo.svg"
|
||||
alt={tr.app.name}
|
||||
className="h-8 w-auto dark:hidden"
|
||||
{...common}
|
||||
/>
|
||||
<Image
|
||||
src="/brand/logo-dark.svg"
|
||||
alt=""
|
||||
className="hidden h-8 w-auto dark:block"
|
||||
{...common}
|
||||
/>
|
||||
</span>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import { SidebarTrigger } from "@/components/ui/sidebar";
|
||||
import type { SessionUser } from "@/features/auth/types";
|
||||
import type { HouseholdSummary } from "@/features/households/types";
|
||||
import { tr } from "@/i18n/tr";
|
||||
import { HouseholdSwitcher } from "./household-switcher";
|
||||
import { QuickAddButton } from "./quick-add";
|
||||
import { ThemeToggle } from "./theme-toggle";
|
||||
import { UserMenu } from "./user-menu";
|
||||
|
||||
/** Üst bar: menü düğmesi (masaüstü), hane seçici, hızlı ekle, tema ve kullanıcı menüsü. */
|
||||
export function AppHeader({
|
||||
user,
|
||||
households,
|
||||
version,
|
||||
}: {
|
||||
user: SessionUser;
|
||||
households: HouseholdSummary[];
|
||||
version: string;
|
||||
}) {
|
||||
return (
|
||||
<header className="sticky top-0 z-30 flex h-14 items-center gap-2 border-b bg-background/95 px-3 backdrop-blur supports-backdrop-filter:bg-background/80 md:px-4">
|
||||
<SidebarTrigger className="hidden md:inline-flex" aria-label={tr.nav.toggleSidebar} />
|
||||
<HouseholdSwitcher households={households} />
|
||||
<div className="ml-auto flex items-center gap-1">
|
||||
<QuickAddButton className="hidden md:inline-flex" />
|
||||
<ThemeToggle />
|
||||
<UserMenu user={user} version={version} />
|
||||
</div>
|
||||
</header>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
"use client";
|
||||
|
||||
import Link from "next/link";
|
||||
import { usePathname } from "next/navigation";
|
||||
import { Logo } from "@/components/brand/logo";
|
||||
import {
|
||||
Sidebar,
|
||||
SidebarContent,
|
||||
SidebarFooter,
|
||||
SidebarGroup,
|
||||
SidebarGroupContent,
|
||||
SidebarGroupLabel,
|
||||
SidebarHeader,
|
||||
SidebarMenu,
|
||||
SidebarMenuBadge,
|
||||
SidebarMenuButton,
|
||||
SidebarMenuItem,
|
||||
SidebarRail,
|
||||
useSidebar,
|
||||
} from "@/components/ui/sidebar";
|
||||
import { tr } from "@/i18n/tr";
|
||||
import { ADMIN_NAV, MAIN_NAV, isActivePath, isAvailable, type NavItem } from "./nav-config";
|
||||
|
||||
function NavList({ items, pathname }: { items: NavItem[]; pathname: string }) {
|
||||
const { setOpenMobile } = useSidebar();
|
||||
return (
|
||||
<SidebarMenu>
|
||||
{items.map((item) => {
|
||||
const Icon = item.icon;
|
||||
if (!isAvailable(item)) {
|
||||
return (
|
||||
<SidebarMenuItem key={item.href}>
|
||||
<SidebarMenuButton
|
||||
aria-disabled
|
||||
disabled
|
||||
tooltip={`${item.label} · ${tr.common.comingSoon}`}
|
||||
>
|
||||
<Icon />
|
||||
<span>{item.label}</span>
|
||||
</SidebarMenuButton>
|
||||
<SidebarMenuBadge className="text-[0.65rem] opacity-70">
|
||||
{tr.common.comingSoon}
|
||||
</SidebarMenuBadge>
|
||||
</SidebarMenuItem>
|
||||
);
|
||||
}
|
||||
const active = isActivePath(pathname, item.href);
|
||||
return (
|
||||
<SidebarMenuItem key={item.href}>
|
||||
<SidebarMenuButton asChild isActive={active} tooltip={item.label}>
|
||||
<Link
|
||||
href={item.href}
|
||||
aria-current={active ? "page" : undefined}
|
||||
onClick={() => setOpenMobile(false)}
|
||||
>
|
||||
<Icon />
|
||||
<span>{item.label}</span>
|
||||
</Link>
|
||||
</SidebarMenuButton>
|
||||
</SidebarMenuItem>
|
||||
);
|
||||
})}
|
||||
</SidebarMenu>
|
||||
);
|
||||
}
|
||||
|
||||
/** Masaüstünde sabit yan menü; mobilde "Daha fazla" ile açılan Sheet. */
|
||||
export function AppSidebar({ isAdmin, version }: { isAdmin: boolean; version: string }) {
|
||||
const pathname = usePathname();
|
||||
return (
|
||||
<Sidebar collapsible="icon">
|
||||
<SidebarHeader className="h-14 justify-center px-3">
|
||||
<Link
|
||||
href="/dashboard"
|
||||
aria-label={tr.nav.dashboard}
|
||||
className="group-data-[collapsible=icon]:hidden"
|
||||
>
|
||||
<Logo />
|
||||
</Link>
|
||||
</SidebarHeader>
|
||||
<SidebarContent>
|
||||
<SidebarGroup>
|
||||
<SidebarGroupLabel>{tr.nav.main}</SidebarGroupLabel>
|
||||
<SidebarGroupContent>
|
||||
<NavList items={MAIN_NAV} pathname={pathname} />
|
||||
</SidebarGroupContent>
|
||||
</SidebarGroup>
|
||||
{isAdmin ? (
|
||||
<SidebarGroup>
|
||||
<SidebarGroupLabel>{tr.nav.admin}</SidebarGroupLabel>
|
||||
<SidebarGroupContent>
|
||||
<NavList items={ADMIN_NAV} pathname={pathname} />
|
||||
</SidebarGroupContent>
|
||||
</SidebarGroup>
|
||||
) : null}
|
||||
</SidebarContent>
|
||||
<SidebarFooter className="px-4 pb-3 text-xs text-muted-foreground group-data-[collapsible=icon]:hidden">
|
||||
{tr.app.name} · {tr.app.version} {version}
|
||||
</SidebarFooter>
|
||||
<SidebarRail />
|
||||
</Sidebar>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
"use client";
|
||||
|
||||
import { Menu, Plus } from "lucide-react";
|
||||
import Link from "next/link";
|
||||
import { usePathname } from "next/navigation";
|
||||
import { useSidebar } from "@/components/ui/sidebar";
|
||||
import { tr } from "@/i18n/tr";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { BOTTOM_NAV, isActivePath, isAvailable, type NavItem } from "./nav-config";
|
||||
import { useQuickAdd } from "./quick-add";
|
||||
|
||||
const itemClass =
|
||||
"flex min-h-14 flex-1 flex-col items-center justify-center gap-0.5 text-[0.7rem] font-medium outline-none focus-visible:bg-muted";
|
||||
|
||||
function BottomNavLink({ item, pathname }: { item: NavItem; pathname: string }) {
|
||||
const Icon = item.icon;
|
||||
if (!isAvailable(item)) {
|
||||
return (
|
||||
<span
|
||||
aria-disabled
|
||||
className={cn(itemClass, "text-muted-foreground/50")}
|
||||
title={tr.common.comingSoon}
|
||||
>
|
||||
<Icon className="size-5" />
|
||||
{item.label}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
const active = isActivePath(pathname, item.href);
|
||||
return (
|
||||
<Link
|
||||
href={item.href}
|
||||
aria-current={active ? "page" : undefined}
|
||||
className={cn(itemClass, active ? "text-primary" : "text-muted-foreground")}
|
||||
>
|
||||
<Icon className="size-5" />
|
||||
{item.label}
|
||||
</Link>
|
||||
);
|
||||
}
|
||||
|
||||
/** Mobil alt gezinme çubuğu (md altı). */
|
||||
export function BottomNav() {
|
||||
const pathname = usePathname();
|
||||
const { openQuickAdd } = useQuickAdd();
|
||||
const { setOpenMobile } = useSidebar();
|
||||
return (
|
||||
<nav
|
||||
aria-label={tr.nav.main}
|
||||
className="fixed inset-x-0 bottom-0 z-40 border-t bg-background/95 pb-safe backdrop-blur supports-backdrop-filter:bg-background/80 md:hidden"
|
||||
>
|
||||
<div className="flex items-stretch">
|
||||
{BOTTOM_NAV.left.map((item) => (
|
||||
<BottomNavLink key={item.href} item={item} pathname={pathname} />
|
||||
))}
|
||||
<div className="flex flex-1 items-center justify-center">
|
||||
<button
|
||||
type="button"
|
||||
onClick={openQuickAdd}
|
||||
aria-label={tr.quickAdd.button}
|
||||
className="-mt-5 flex size-14 items-center justify-center rounded-full bg-primary text-primary-foreground shadow-lg outline-none focus-visible:ring-4 focus-visible:ring-ring/50"
|
||||
>
|
||||
<Plus className="size-6" />
|
||||
</button>
|
||||
</div>
|
||||
{BOTTOM_NAV.right.map((item) => (
|
||||
<BottomNavLink key={item.href} item={item} pathname={pathname} />
|
||||
))}
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setOpenMobile(true)}
|
||||
className={cn(itemClass, "text-muted-foreground")}
|
||||
>
|
||||
<Menu className="size-5" />
|
||||
{tr.nav.more}
|
||||
</button>
|
||||
</div>
|
||||
</nav>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
"use client";
|
||||
|
||||
import { House } from "lucide-react";
|
||||
import { useState } from "react";
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "@/components/ui/select";
|
||||
import type { HouseholdSummary } from "@/features/households/types";
|
||||
import { tr } from "@/i18n/tr";
|
||||
|
||||
/** Üst bar aktif hane seçici. FAZ 5: seçim sunucuda (cookie) saklanacak. */
|
||||
export function HouseholdSwitcher({ households }: { households: HouseholdSummary[] }) {
|
||||
const [value, setValue] = useState(households[0]?.id);
|
||||
const current = households.find((h) => h.id === value);
|
||||
if (households.length === 0) return null;
|
||||
return (
|
||||
<Select value={value} onValueChange={setValue}>
|
||||
<SelectTrigger aria-label={tr.household.label} className="w-[min(46vw,13rem)]">
|
||||
<House className="text-muted-foreground" />
|
||||
{/* Etiket children ile verilir: Radix aksi halde hydration'a kadar boş gösterir. */}
|
||||
<SelectValue placeholder={tr.household.select}>{current?.name}</SelectValue>
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{households.map((h) => (
|
||||
<SelectItem key={h.id} value={h.id}>
|
||||
{h.name}
|
||||
<span className="text-xs text-muted-foreground">· {tr.household.roles[h.role]}</span>
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
import {
|
||||
ArrowLeftRight,
|
||||
CalendarClock,
|
||||
ChartColumn,
|
||||
Coins,
|
||||
House,
|
||||
LayoutDashboard,
|
||||
Package,
|
||||
Settings,
|
||||
ShoppingCart,
|
||||
Target,
|
||||
UserCog,
|
||||
Users,
|
||||
Wallet,
|
||||
type LucideIcon,
|
||||
} from "lucide-react";
|
||||
import { tr } from "@/i18n/tr";
|
||||
|
||||
export type NavItem = {
|
||||
href: string;
|
||||
label: string;
|
||||
icon: LucideIcon;
|
||||
/** Sayfanın ekleneceği faz; mevcut fazdan büyükse "Yakında" olarak pasif gösterilir. */
|
||||
phase: number;
|
||||
};
|
||||
|
||||
/** Şu an tamamlanmış en yüksek faz — sayfalar eklendikçe artar. */
|
||||
export const CURRENT_PHASE = 2;
|
||||
|
||||
export const isAvailable = (item: NavItem) => item.phase <= CURRENT_PHASE;
|
||||
|
||||
export const MAIN_NAV: NavItem[] = [
|
||||
{ href: "/dashboard", label: tr.nav.dashboard, icon: LayoutDashboard, phase: 2 },
|
||||
{ href: "/islemler", label: tr.nav.transactions, icon: ArrowLeftRight, phase: 6 },
|
||||
{ href: "/hesaplar", label: tr.nav.accounts, icon: Wallet, phase: 6 },
|
||||
{ href: "/planli", label: tr.nav.planned, icon: CalendarClock, phase: 7 },
|
||||
{ href: "/cari", label: tr.nav.contacts, icon: Users, phase: 8 },
|
||||
{ href: "/birikim", label: tr.nav.savings, icon: Coins, phase: 9 },
|
||||
{ href: "/butce", label: tr.nav.budget, icon: Target, phase: 10 },
|
||||
{ href: "/stok", label: tr.nav.stock, icon: Package, phase: 11 },
|
||||
{ href: "/alisveris", label: tr.nav.shopping, icon: ShoppingCart, phase: 13 },
|
||||
{ href: "/raporlar", label: tr.nav.reports, icon: ChartColumn, phase: 14 },
|
||||
{ href: "/ayarlar", label: tr.nav.settings, icon: Settings, phase: 5 },
|
||||
];
|
||||
|
||||
export const ADMIN_NAV: NavItem[] = [
|
||||
{ href: "/admin/kullanicilar", label: tr.nav.adminUsers, icon: UserCog, phase: 2 },
|
||||
{ href: "/admin/haneler", label: tr.nav.adminHouseholds, icon: House, phase: 5 },
|
||||
];
|
||||
|
||||
/** Mobil alt menü: ortada Hızlı ekle, sağda "Daha fazla" (yan menüyü açar). */
|
||||
export const BOTTOM_NAV = {
|
||||
left: [MAIN_NAV[0]!, MAIN_NAV[1]!],
|
||||
right: [MAIN_NAV[6]!],
|
||||
};
|
||||
|
||||
export function isActivePath(pathname: string, href: string) {
|
||||
return pathname === href || pathname.startsWith(`${href}/`);
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
"use client";
|
||||
|
||||
import { ArrowDownLeft, ArrowLeftRight, ArrowUpRight, Plus } from "lucide-react";
|
||||
import { createContext, use, useState } from "react";
|
||||
import { toast } from "sonner";
|
||||
import { ResponsiveDialog } from "@/components/responsive-dialog";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { tr } from "@/i18n/tr";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
type QuickAddKind = "expense" | "income" | "transfer";
|
||||
|
||||
const QuickAddContext = createContext<{ openQuickAdd: () => void } | null>(null);
|
||||
|
||||
export function useQuickAdd() {
|
||||
const ctx = use(QuickAddContext);
|
||||
if (!ctx) throw new Error("useQuickAdd, QuickAddProvider içinde kullanılmalı");
|
||||
return ctx;
|
||||
}
|
||||
|
||||
const CHOICES: {
|
||||
kind: QuickAddKind;
|
||||
label: string;
|
||||
hint: string;
|
||||
icon: typeof Plus;
|
||||
tone: string;
|
||||
}[] = [
|
||||
{
|
||||
kind: "expense",
|
||||
label: tr.quickAdd.expense,
|
||||
hint: tr.quickAdd.expenseHint,
|
||||
icon: ArrowUpRight,
|
||||
tone: "text-expense bg-expense/10",
|
||||
},
|
||||
{
|
||||
kind: "income",
|
||||
label: tr.quickAdd.income,
|
||||
hint: tr.quickAdd.incomeHint,
|
||||
icon: ArrowDownLeft,
|
||||
tone: "text-income bg-income/10",
|
||||
},
|
||||
{
|
||||
kind: "transfer",
|
||||
label: tr.quickAdd.transfer,
|
||||
hint: tr.quickAdd.transferHint,
|
||||
icon: ArrowLeftRight,
|
||||
tone: "text-budget bg-budget/10",
|
||||
},
|
||||
];
|
||||
|
||||
/** Hızlı ekle (gider / gelir / transfer) — her ekrandan açılabilir. */
|
||||
export function QuickAddProvider({ children }: { children: React.ReactNode }) {
|
||||
const [open, setOpen] = useState(false);
|
||||
|
||||
function choose(kind: QuickAddKind) {
|
||||
setOpen(false);
|
||||
// FAZ 6: ilgili işlem formu açılacak.
|
||||
toast.info(`${CHOICES.find((c) => c.kind === kind)?.label}: ${tr.quickAdd.notYet}`);
|
||||
}
|
||||
|
||||
return (
|
||||
<QuickAddContext value={{ openQuickAdd: () => setOpen(true) }}>
|
||||
{children}
|
||||
<ResponsiveDialog
|
||||
open={open}
|
||||
onOpenChange={setOpen}
|
||||
title={tr.quickAdd.title}
|
||||
description={tr.quickAdd.description}
|
||||
>
|
||||
<div className="grid gap-2 pb-2 sm:grid-cols-3">
|
||||
{CHOICES.map(({ kind, label, hint, icon: Icon, tone }) => (
|
||||
<button
|
||||
key={kind}
|
||||
type="button"
|
||||
onClick={() => choose(kind)}
|
||||
className="flex items-center gap-3 rounded-xl border p-4 text-left transition-colors outline-none hover:bg-muted focus-visible:ring-3 focus-visible:ring-ring/50 sm:flex-col sm:text-center"
|
||||
>
|
||||
<span className={cn("flex size-10 items-center justify-center rounded-full", tone)}>
|
||||
<Icon className="size-5" />
|
||||
</span>
|
||||
<span className="flex flex-col">
|
||||
<span className="font-medium">{label}</span>
|
||||
<span className="text-xs text-muted-foreground">{hint}</span>
|
||||
</span>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</ResponsiveDialog>
|
||||
</QuickAddContext>
|
||||
);
|
||||
}
|
||||
|
||||
/** Masaüstü üst bar düğmesi. */
|
||||
export function QuickAddButton({ className }: { className?: string }) {
|
||||
const { openQuickAdd } = useQuickAdd();
|
||||
return (
|
||||
<Button onClick={openQuickAdd} className={className}>
|
||||
<Plus />
|
||||
{tr.quickAdd.button}
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
"use client";
|
||||
|
||||
import { Monitor, Moon, Sun } from "lucide-react";
|
||||
import { useTheme } from "next-themes";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuLabel,
|
||||
DropdownMenuRadioGroup,
|
||||
DropdownMenuRadioItem,
|
||||
DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
import { tr } from "@/i18n/tr";
|
||||
|
||||
const OPTIONS = [
|
||||
{ value: "light", label: tr.theme.light, icon: Sun },
|
||||
{ value: "dark", label: tr.theme.dark, icon: Moon },
|
||||
{ value: "system", label: tr.theme.system, icon: Monitor },
|
||||
] as const;
|
||||
|
||||
/** Açık / Koyu / Sistem tema seçici. İkon CSS ile değişir (hydration güvenli). */
|
||||
export function ThemeToggle() {
|
||||
const { theme, setTheme } = useTheme();
|
||||
return (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="ghost" size="icon" aria-label={tr.theme.label}>
|
||||
<Sun className="scale-100 rotate-0 transition-transform dark:scale-0 dark:-rotate-90" />
|
||||
<Moon className="absolute scale-0 rotate-90 transition-transform dark:scale-100 dark:rotate-0" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end" className="min-w-36">
|
||||
<DropdownMenuLabel>{tr.theme.label}</DropdownMenuLabel>
|
||||
<DropdownMenuRadioGroup value={theme ?? "system"} onValueChange={setTheme}>
|
||||
{OPTIONS.map(({ value, label, icon: Icon }) => (
|
||||
<DropdownMenuRadioItem key={value} value={value}>
|
||||
<Icon />
|
||||
{label}
|
||||
</DropdownMenuRadioItem>
|
||||
))}
|
||||
</DropdownMenuRadioGroup>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
"use client";
|
||||
|
||||
import { LogOut } from "lucide-react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { toast } from "sonner";
|
||||
import { Avatar, AvatarFallback } from "@/components/ui/avatar";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuLabel,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
import type { SessionUser } from "@/features/auth/types";
|
||||
import { tr } from "@/i18n/tr";
|
||||
|
||||
export function initials(name: string) {
|
||||
return name
|
||||
.split(/\s+/)
|
||||
.filter(Boolean)
|
||||
.slice(0, 2)
|
||||
.map((p) => p.charAt(0).toLocaleUpperCase("tr-TR"))
|
||||
.join("");
|
||||
}
|
||||
|
||||
/** Kullanıcı menüsü: ad, rol, sürüm ve Çıkış yap. */
|
||||
export function UserMenu({ user, version }: { user: SessionUser; version: string }) {
|
||||
const router = useRouter();
|
||||
|
||||
function logout() {
|
||||
// FAZ 3: authClient.signOut() sonrası yönlendirme.
|
||||
toast.success(tr.userMenu.loggedOut);
|
||||
router.replace("/login");
|
||||
}
|
||||
|
||||
return (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-lg"
|
||||
className="rounded-full"
|
||||
aria-label={tr.userMenu.open}
|
||||
>
|
||||
<Avatar>
|
||||
<AvatarFallback className="bg-primary/10 font-medium text-primary">
|
||||
{initials(user.name)}
|
||||
</AvatarFallback>
|
||||
</Avatar>
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end" className="w-60">
|
||||
<DropdownMenuLabel className="flex flex-col gap-1 font-normal">
|
||||
<span className="truncate font-medium text-foreground">{user.name}</span>
|
||||
<span className="truncate text-xs text-muted-foreground">@{user.username}</span>
|
||||
<Badge variant={user.role === "admin" ? "default" : "secondary"} className="mt-1">
|
||||
{tr.roles[user.role]}
|
||||
</Badge>
|
||||
</DropdownMenuLabel>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem variant="destructive" onSelect={logout}>
|
||||
<LogOut />
|
||||
{tr.userMenu.logout}
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuSeparator />
|
||||
<div className="px-2 py-1.5 text-xs text-muted-foreground">
|
||||
{tr.app.name} · {tr.app.version} {version}
|
||||
</div>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
/** Sayfa başlığı + açıklama + sağda isteğe bağlı aksiyonlar. */
|
||||
export function PageHeader({
|
||||
title,
|
||||
description,
|
||||
actions,
|
||||
}: {
|
||||
title: string;
|
||||
description?: string;
|
||||
actions?: React.ReactNode;
|
||||
}) {
|
||||
return (
|
||||
<div className="flex flex-wrap items-end justify-between gap-3">
|
||||
<div className="min-w-0">
|
||||
<h1 className="text-2xl font-semibold tracking-tight">{title}</h1>
|
||||
{description ? <p className="mt-1 text-sm text-muted-foreground">{description}</p> : null}
|
||||
</div>
|
||||
{actions ? <div className="flex items-center gap-2">{actions}</div> : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
"use client";
|
||||
|
||||
import { Eye, EyeOff } from "lucide-react";
|
||||
import { useState } from "react";
|
||||
import {
|
||||
InputGroup,
|
||||
InputGroupAddon,
|
||||
InputGroupButton,
|
||||
InputGroupInput,
|
||||
} from "@/components/ui/input-group";
|
||||
import { tr } from "@/i18n/tr";
|
||||
|
||||
/** Göster/gizle düğmeli şifre alanı. */
|
||||
export function PasswordInput(props: Omit<React.ComponentProps<typeof InputGroupInput>, "type">) {
|
||||
const [visible, setVisible] = useState(false);
|
||||
const label = visible ? tr.common.hidePassword : tr.common.showPassword;
|
||||
return (
|
||||
<InputGroup>
|
||||
<InputGroupInput type={visible ? "text" : "password"} {...props} />
|
||||
<InputGroupAddon align="inline-end">
|
||||
<InputGroupButton
|
||||
size="icon-xs"
|
||||
aria-label={label}
|
||||
title={label}
|
||||
aria-pressed={visible}
|
||||
onClick={() => setVisible((v) => !v)}
|
||||
>
|
||||
{visible ? <EyeOff /> : <Eye />}
|
||||
</InputGroupButton>
|
||||
</InputGroupAddon>
|
||||
</InputGroup>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
"use client";
|
||||
|
||||
import { ThemeProvider } from "next-themes";
|
||||
import { Toaster } from "@/components/ui/sonner";
|
||||
import { TooltipProvider } from "@/components/ui/tooltip";
|
||||
|
||||
/** Kök istemci sağlayıcıları: tema (açık/koyu/sistem), tooltip ve bildirimler. */
|
||||
export function Providers({ children }: { children: React.ReactNode }) {
|
||||
return (
|
||||
<ThemeProvider attribute="class" defaultTheme="system" enableSystem disableTransitionOnChange>
|
||||
<TooltipProvider delayDuration={300}>
|
||||
{children}
|
||||
<Toaster position="top-center" richColors closeButton />
|
||||
</TooltipProvider>
|
||||
</ThemeProvider>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
"use client";
|
||||
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from "@/components/ui/dialog";
|
||||
import {
|
||||
Drawer,
|
||||
DrawerContent,
|
||||
DrawerDescription,
|
||||
DrawerFooter,
|
||||
DrawerHeader,
|
||||
DrawerTitle,
|
||||
} from "@/components/ui/drawer";
|
||||
import { useIsMobile } from "@/hooks/use-mobile";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
type Props = {
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
title: React.ReactNode;
|
||||
description?: React.ReactNode;
|
||||
children: React.ReactNode;
|
||||
footer?: React.ReactNode;
|
||||
className?: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* Masaüstünde Dialog, mobilde (neredeyse) tam ekran alttan açılan Drawer.
|
||||
* Formlar bu bileşenle açılır (Bölüm 4: "formlar mobilde tam ekran Sheet/Drawer").
|
||||
*/
|
||||
export function ResponsiveDialog({
|
||||
open,
|
||||
onOpenChange,
|
||||
title,
|
||||
description,
|
||||
children,
|
||||
footer,
|
||||
className,
|
||||
}: Props) {
|
||||
const isMobile = useIsMobile();
|
||||
|
||||
if (isMobile) {
|
||||
return (
|
||||
<Drawer open={open} onOpenChange={onOpenChange}>
|
||||
<DrawerContent className="max-h-[96dvh]">
|
||||
<DrawerHeader className="text-left">
|
||||
<DrawerTitle>{title}</DrawerTitle>
|
||||
{description ? <DrawerDescription>{description}</DrawerDescription> : null}
|
||||
</DrawerHeader>
|
||||
<div className={cn("overflow-y-auto px-4 pb-2", className)}>{children}</div>
|
||||
{footer ? <DrawerFooter className="pb-safe">{footer}</DrawerFooter> : null}
|
||||
</DrawerContent>
|
||||
</Drawer>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="max-h-[90dvh] overflow-y-auto sm:max-w-lg">
|
||||
<DialogHeader>
|
||||
<DialogTitle>{title}</DialogTitle>
|
||||
{description ? <DialogDescription>{description}</DialogDescription> : null}
|
||||
</DialogHeader>
|
||||
<div className={className}>{children}</div>
|
||||
{footer ? <DialogFooter>{footer}</DialogFooter> : null}
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,182 @@
|
||||
"use client";
|
||||
|
||||
import * as React from "react";
|
||||
import { cn } from "cn";
|
||||
import { AlertDialog as AlertDialogPrimitive } from "radix-ui";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
|
||||
function AlertDialog({ ...props }: React.ComponentProps<typeof AlertDialogPrimitive.Root>) {
|
||||
return <AlertDialogPrimitive.Root data-slot="alert-dialog" {...props} />;
|
||||
}
|
||||
|
||||
function AlertDialogTrigger({
|
||||
...props
|
||||
}: React.ComponentProps<typeof AlertDialogPrimitive.Trigger>) {
|
||||
return <AlertDialogPrimitive.Trigger data-slot="alert-dialog-trigger" {...props} />;
|
||||
}
|
||||
|
||||
function AlertDialogPortal({ ...props }: React.ComponentProps<typeof AlertDialogPrimitive.Portal>) {
|
||||
return <AlertDialogPrimitive.Portal data-slot="alert-dialog-portal" {...props} />;
|
||||
}
|
||||
|
||||
function AlertDialogOverlay({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof AlertDialogPrimitive.Overlay>) {
|
||||
return (
|
||||
<AlertDialogPrimitive.Overlay
|
||||
data-slot="alert-dialog-overlay"
|
||||
className={cn(
|
||||
"fixed inset-0 z-50 bg-black/10 duration-100 supports-backdrop-filter:backdrop-blur-xs data-open:animate-in data-open:fade-in-0 data-closed:animate-out data-closed:fade-out-0",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function AlertDialogContent({
|
||||
className,
|
||||
size = "default",
|
||||
...props
|
||||
}: React.ComponentProps<typeof AlertDialogPrimitive.Content> & {
|
||||
size?: "default" | "sm";
|
||||
}) {
|
||||
return (
|
||||
<AlertDialogPortal>
|
||||
<AlertDialogOverlay />
|
||||
<AlertDialogPrimitive.Content
|
||||
data-slot="alert-dialog-content"
|
||||
data-size={size}
|
||||
className={cn(
|
||||
"group/alert-dialog-content fixed top-1/2 left-1/2 z-50 grid w-full -translate-x-1/2 -translate-y-1/2 gap-4 rounded-xl bg-popover p-4 text-popover-foreground ring-1 ring-foreground/10 duration-100 outline-none data-[size=default]:max-w-xs data-[size=sm]:max-w-xs data-[size=default]:sm:max-w-sm data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
</AlertDialogPortal>
|
||||
);
|
||||
}
|
||||
|
||||
function AlertDialogHeader({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="alert-dialog-header"
|
||||
className={cn(
|
||||
"grid grid-rows-[auto_1fr] place-items-center gap-1.5 text-center has-data-[slot=alert-dialog-media]:grid-rows-[auto_auto_1fr] has-data-[slot=alert-dialog-media]:gap-x-4 sm:group-data-[size=default]/alert-dialog-content:place-items-start sm:group-data-[size=default]/alert-dialog-content:text-left sm:group-data-[size=default]/alert-dialog-content:has-data-[slot=alert-dialog-media]:grid-rows-[auto_1fr]",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function AlertDialogFooter({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="alert-dialog-footer"
|
||||
className={cn(
|
||||
"-mx-4 -mb-4 flex flex-col-reverse gap-2 rounded-b-xl border-t bg-muted/50 p-4 group-data-[size=sm]/alert-dialog-content:grid group-data-[size=sm]/alert-dialog-content:grid-cols-2 sm:flex-row sm:justify-end",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function AlertDialogMedia({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="alert-dialog-media"
|
||||
className={cn(
|
||||
"mb-2 inline-flex size-10 items-center justify-center rounded-md bg-muted sm:group-data-[size=default]/alert-dialog-content:row-span-2 *:[svg:not([class*='size-'])]:size-6",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function AlertDialogTitle({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof AlertDialogPrimitive.Title>) {
|
||||
return (
|
||||
<AlertDialogPrimitive.Title
|
||||
data-slot="alert-dialog-title"
|
||||
className={cn(
|
||||
"font-heading text-base font-medium sm:group-data-[size=default]/alert-dialog-content:group-has-data-[slot=alert-dialog-media]/alert-dialog-content:col-start-2",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function AlertDialogDescription({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof AlertDialogPrimitive.Description>) {
|
||||
return (
|
||||
<AlertDialogPrimitive.Description
|
||||
data-slot="alert-dialog-description"
|
||||
className={cn(
|
||||
"text-sm text-balance text-muted-foreground md:text-pretty *:[a]:underline *:[a]:underline-offset-3 *:[a]:hover:text-foreground",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function AlertDialogAction({
|
||||
className,
|
||||
variant = "default",
|
||||
size = "default",
|
||||
...props
|
||||
}: React.ComponentProps<typeof AlertDialogPrimitive.Action> &
|
||||
Pick<React.ComponentProps<typeof Button>, "variant" | "size">) {
|
||||
return (
|
||||
<Button variant={variant} size={size} asChild>
|
||||
<AlertDialogPrimitive.Action
|
||||
data-slot="alert-dialog-action"
|
||||
className={cn(className)}
|
||||
{...props}
|
||||
/>
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
|
||||
function AlertDialogCancel({
|
||||
className,
|
||||
variant = "outline",
|
||||
size = "default",
|
||||
...props
|
||||
}: React.ComponentProps<typeof AlertDialogPrimitive.Cancel> &
|
||||
Pick<React.ComponentProps<typeof Button>, "variant" | "size">) {
|
||||
return (
|
||||
<Button variant={variant} size={size} asChild>
|
||||
<AlertDialogPrimitive.Cancel
|
||||
data-slot="alert-dialog-cancel"
|
||||
className={cn(className)}
|
||||
{...props}
|
||||
/>
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
|
||||
export {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogMedia,
|
||||
AlertDialogOverlay,
|
||||
AlertDialogPortal,
|
||||
AlertDialogTitle,
|
||||
AlertDialogTrigger,
|
||||
};
|
||||
@@ -0,0 +1,95 @@
|
||||
"use client";
|
||||
|
||||
import * as React from "react";
|
||||
import { cn } from "cn";
|
||||
import { Avatar as AvatarPrimitive } from "radix-ui";
|
||||
|
||||
function Avatar({
|
||||
className,
|
||||
size = "default",
|
||||
...props
|
||||
}: React.ComponentProps<typeof AvatarPrimitive.Root> & {
|
||||
size?: "default" | "sm" | "lg";
|
||||
}) {
|
||||
return (
|
||||
<AvatarPrimitive.Root
|
||||
data-slot="avatar"
|
||||
data-size={size}
|
||||
className={cn(
|
||||
"group/avatar relative flex size-8 shrink-0 rounded-full select-none after:absolute after:inset-0 after:rounded-full after:border after:border-border after:mix-blend-darken data-[size=lg]:size-10 data-[size=sm]:size-6 dark:after:mix-blend-lighten",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function AvatarImage({ className, ...props }: React.ComponentProps<typeof AvatarPrimitive.Image>) {
|
||||
return (
|
||||
<AvatarPrimitive.Image
|
||||
data-slot="avatar-image"
|
||||
className={cn("aspect-square size-full rounded-full object-cover", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function AvatarFallback({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof AvatarPrimitive.Fallback>) {
|
||||
return (
|
||||
<AvatarPrimitive.Fallback
|
||||
data-slot="avatar-fallback"
|
||||
className={cn(
|
||||
"flex size-full items-center justify-center rounded-full bg-muted text-sm text-muted-foreground group-data-[size=sm]/avatar:text-xs",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function AvatarBadge({ className, ...props }: React.ComponentProps<"span">) {
|
||||
return (
|
||||
<span
|
||||
data-slot="avatar-badge"
|
||||
className={cn(
|
||||
"absolute right-0 bottom-0 z-10 inline-flex items-center justify-center rounded-full bg-primary text-primary-foreground bg-blend-color ring-2 ring-background select-none",
|
||||
"group-data-[size=sm]/avatar:size-2 group-data-[size=sm]/avatar:[&>svg]:hidden",
|
||||
"group-data-[size=default]/avatar:size-2.5 group-data-[size=default]/avatar:[&>svg]:size-2",
|
||||
"group-data-[size=lg]/avatar:size-3 group-data-[size=lg]/avatar:[&>svg]:size-2",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function AvatarGroup({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="avatar-group"
|
||||
className={cn(
|
||||
"group/avatar-group flex -space-x-2 *:data-[slot=avatar]:ring-2 *:data-[slot=avatar]:ring-background",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function AvatarGroupCount({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="avatar-group-count"
|
||||
className={cn(
|
||||
"relative flex size-8 shrink-0 items-center justify-center rounded-full bg-muted text-sm text-muted-foreground ring-2 ring-background group-has-data-[size=lg]/avatar-group:size-10 group-has-data-[size=sm]/avatar-group:size-6 [&>svg]:size-4 group-has-data-[size=lg]/avatar-group:[&>svg]:size-5 group-has-data-[size=sm]/avatar-group:[&>svg]:size-3",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export { Avatar, AvatarImage, AvatarFallback, AvatarGroup, AvatarGroupCount, AvatarBadge };
|
||||
@@ -0,0 +1,44 @@
|
||||
import * as React from "react";
|
||||
import { cva, type VariantProps } from "class-variance-authority";
|
||||
import { cn } from "cn";
|
||||
import { Slot } from "radix-ui";
|
||||
|
||||
const badgeVariants = cva(
|
||||
"group/badge inline-flex h-5 w-fit shrink-0 items-center justify-center gap-1 overflow-hidden rounded-4xl border border-transparent px-2 py-0.5 text-xs font-medium whitespace-nowrap transition-all focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&>svg]:pointer-events-none [&>svg]:size-3!",
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default: "bg-primary text-primary-foreground [a]:hover:bg-primary/80",
|
||||
secondary: "bg-secondary text-secondary-foreground [a]:hover:bg-secondary/80",
|
||||
destructive:
|
||||
"bg-destructive/10 text-destructive focus-visible:ring-destructive/20 dark:bg-destructive/20 dark:focus-visible:ring-destructive/40 [a]:hover:bg-destructive/20",
|
||||
outline: "border-border text-foreground [a]:hover:bg-muted [a]:hover:text-muted-foreground",
|
||||
ghost: "hover:bg-muted hover:text-muted-foreground dark:hover:bg-muted/50",
|
||||
link: "text-primary underline-offset-4 hover:underline",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: "default",
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
function Badge({
|
||||
className,
|
||||
variant = "default",
|
||||
asChild = false,
|
||||
...props
|
||||
}: React.ComponentProps<"span"> & VariantProps<typeof badgeVariants> & { asChild?: boolean }) {
|
||||
const Comp = asChild ? Slot.Root : "span";
|
||||
|
||||
return (
|
||||
<Comp
|
||||
data-slot="badge"
|
||||
data-variant={variant}
|
||||
className={cn(badgeVariants({ variant }), className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export { Badge, badgeVariants };
|
||||
@@ -0,0 +1,87 @@
|
||||
import * as React from "react";
|
||||
import { cn } from "cn";
|
||||
|
||||
function Card({
|
||||
className,
|
||||
size = "default",
|
||||
...props
|
||||
}: React.ComponentProps<"div"> & { size?: "default" | "sm" }) {
|
||||
return (
|
||||
<div
|
||||
data-slot="card"
|
||||
data-size={size}
|
||||
className={cn(
|
||||
"group/card flex flex-col gap-(--card-spacing) overflow-hidden rounded-xl bg-card py-(--card-spacing) text-sm text-card-foreground ring-1 ring-foreground/10 [--card-spacing:--spacing(4)] has-data-[slot=card-footer]:pb-0 has-[>img:first-child]:pt-0 data-[size=sm]:[--card-spacing:--spacing(3)] data-[size=sm]:has-data-[slot=card-footer]:pb-0 *:[img:first-child]:rounded-t-xl *:[img:last-child]:rounded-b-xl",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function CardHeader({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="card-header"
|
||||
className={cn(
|
||||
"group/card-header @container/card-header grid auto-rows-min items-start gap-1 rounded-t-xl px-(--card-spacing) has-data-[slot=card-action]:grid-cols-[1fr_auto] has-data-[slot=card-description]:grid-rows-[auto_auto] [.border-b]:pb-(--card-spacing)",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function CardTitle({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="card-title"
|
||||
className={cn(
|
||||
"font-heading text-base leading-snug font-medium group-data-[size=sm]/card:text-sm",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function CardDescription({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="card-description"
|
||||
className={cn("text-sm text-muted-foreground", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function CardAction({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="card-action"
|
||||
className={cn("col-start-2 row-span-2 row-start-1 self-start justify-self-end", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function CardContent({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div data-slot="card-content" className={cn("px-(--card-spacing)", className)} {...props} />
|
||||
);
|
||||
}
|
||||
|
||||
function CardFooter({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="card-footer"
|
||||
className={cn(
|
||||
"flex items-center rounded-b-xl border-t bg-muted/50 p-(--card-spacing)",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export { Card, CardHeader, CardFooter, CardTitle, CardAction, CardDescription, CardContent };
|
||||
@@ -0,0 +1,28 @@
|
||||
"use client";
|
||||
|
||||
import * as React from "react";
|
||||
import { cn } from "cn";
|
||||
import { Checkbox as CheckboxPrimitive } from "radix-ui";
|
||||
import { CheckIcon } from "lucide-react";
|
||||
|
||||
function Checkbox({ className, ...props }: React.ComponentProps<typeof CheckboxPrimitive.Root>) {
|
||||
return (
|
||||
<CheckboxPrimitive.Root
|
||||
data-slot="checkbox"
|
||||
className={cn(
|
||||
"peer relative flex size-4 shrink-0 items-center justify-center rounded-[4px] border border-input transition-colors outline-none group-has-disabled/field:opacity-50 group-has-[:focus-visible]/field-label:ring-0 group-has-[:focus-visible]/field-label:not-data-checked:border-input after:absolute after:-inset-x-3 after:-inset-y-2 focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 aria-invalid:aria-checked:border-primary dark:bg-input/30 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 data-checked:border-primary data-checked:bg-primary data-checked:text-primary-foreground group-has-[:focus-visible]/field-label:data-checked:border-primary dark:data-checked:bg-primary",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<CheckboxPrimitive.Indicator
|
||||
data-slot="checkbox-indicator"
|
||||
className="grid place-content-center text-current transition-none [&>svg]:size-3.5"
|
||||
>
|
||||
<CheckIcon />
|
||||
</CheckboxPrimitive.Indicator>
|
||||
</CheckboxPrimitive.Root>
|
||||
);
|
||||
}
|
||||
|
||||
export { Checkbox };
|
||||
@@ -0,0 +1,21 @@
|
||||
"use client";
|
||||
|
||||
import { Collapsible as CollapsiblePrimitive } from "radix-ui";
|
||||
|
||||
function Collapsible({ ...props }: React.ComponentProps<typeof CollapsiblePrimitive.Root>) {
|
||||
return <CollapsiblePrimitive.Root data-slot="collapsible" {...props} />;
|
||||
}
|
||||
|
||||
function CollapsibleTrigger({
|
||||
...props
|
||||
}: React.ComponentProps<typeof CollapsiblePrimitive.CollapsibleTrigger>) {
|
||||
return <CollapsiblePrimitive.CollapsibleTrigger data-slot="collapsible-trigger" {...props} />;
|
||||
}
|
||||
|
||||
function CollapsibleContent({
|
||||
...props
|
||||
}: React.ComponentProps<typeof CollapsiblePrimitive.CollapsibleContent>) {
|
||||
return <CollapsiblePrimitive.CollapsibleContent data-slot="collapsible-content" {...props} />;
|
||||
}
|
||||
|
||||
export { Collapsible, CollapsibleTrigger, CollapsibleContent };
|
||||
@@ -0,0 +1,145 @@
|
||||
"use client";
|
||||
|
||||
import * as React from "react";
|
||||
import { cn } from "cn";
|
||||
import { Dialog as DialogPrimitive } from "radix-ui";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { XIcon } from "lucide-react";
|
||||
|
||||
function Dialog({ ...props }: React.ComponentProps<typeof DialogPrimitive.Root>) {
|
||||
return <DialogPrimitive.Root data-slot="dialog" {...props} />;
|
||||
}
|
||||
|
||||
function DialogTrigger({ ...props }: React.ComponentProps<typeof DialogPrimitive.Trigger>) {
|
||||
return <DialogPrimitive.Trigger data-slot="dialog-trigger" {...props} />;
|
||||
}
|
||||
|
||||
function DialogPortal({ ...props }: React.ComponentProps<typeof DialogPrimitive.Portal>) {
|
||||
return <DialogPrimitive.Portal data-slot="dialog-portal" {...props} />;
|
||||
}
|
||||
|
||||
function DialogClose({ ...props }: React.ComponentProps<typeof DialogPrimitive.Close>) {
|
||||
return <DialogPrimitive.Close data-slot="dialog-close" {...props} />;
|
||||
}
|
||||
|
||||
function DialogOverlay({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DialogPrimitive.Overlay>) {
|
||||
return (
|
||||
<DialogPrimitive.Overlay
|
||||
data-slot="dialog-overlay"
|
||||
className={cn(
|
||||
"fixed inset-0 isolate z-50 bg-black/10 duration-100 supports-backdrop-filter:backdrop-blur-xs data-open:animate-in data-open:fade-in-0 data-closed:animate-out data-closed:fade-out-0",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function DialogContent({
|
||||
className,
|
||||
children,
|
||||
showCloseButton = true,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DialogPrimitive.Content> & {
|
||||
showCloseButton?: boolean;
|
||||
}) {
|
||||
return (
|
||||
<DialogPortal>
|
||||
<DialogOverlay />
|
||||
<DialogPrimitive.Content
|
||||
data-slot="dialog-content"
|
||||
className={cn(
|
||||
"fixed top-1/2 left-1/2 z-50 grid w-full max-w-[calc(100%-2rem)] -translate-x-1/2 -translate-y-1/2 gap-4 rounded-xl bg-popover p-4 text-sm text-popover-foreground ring-1 ring-foreground/10 duration-100 outline-none sm:max-w-sm data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
{showCloseButton && (
|
||||
<DialogPrimitive.Close data-slot="dialog-close" asChild>
|
||||
<Button variant="ghost" className="absolute top-2 right-2" size="icon-sm">
|
||||
<XIcon />
|
||||
<span className="sr-only">Close</span>
|
||||
</Button>
|
||||
</DialogPrimitive.Close>
|
||||
)}
|
||||
</DialogPrimitive.Content>
|
||||
</DialogPortal>
|
||||
);
|
||||
}
|
||||
|
||||
function DialogHeader({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div data-slot="dialog-header" className={cn("flex flex-col gap-2", className)} {...props} />
|
||||
);
|
||||
}
|
||||
|
||||
function DialogFooter({
|
||||
className,
|
||||
showCloseButton = false,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<"div"> & {
|
||||
showCloseButton?: boolean;
|
||||
}) {
|
||||
return (
|
||||
<div
|
||||
data-slot="dialog-footer"
|
||||
className={cn(
|
||||
"-mx-4 -mb-4 flex flex-col-reverse gap-2 rounded-b-xl border-t bg-muted/50 p-4 sm:flex-row sm:justify-end",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
{showCloseButton && (
|
||||
<DialogPrimitive.Close asChild>
|
||||
<Button variant="outline">Close</Button>
|
||||
</DialogPrimitive.Close>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function DialogTitle({ className, ...props }: React.ComponentProps<typeof DialogPrimitive.Title>) {
|
||||
return (
|
||||
<DialogPrimitive.Title
|
||||
data-slot="dialog-title"
|
||||
className={cn("font-heading text-base leading-none font-medium", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function DialogDescription({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DialogPrimitive.Description>) {
|
||||
return (
|
||||
<DialogPrimitive.Description
|
||||
data-slot="dialog-description"
|
||||
className={cn(
|
||||
"text-sm text-muted-foreground *:[a]:underline *:[a]:underline-offset-3 *:[a]:hover:text-foreground",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export {
|
||||
Dialog,
|
||||
DialogClose,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogOverlay,
|
||||
DialogPortal,
|
||||
DialogTitle,
|
||||
DialogTrigger,
|
||||
};
|
||||
@@ -0,0 +1,119 @@
|
||||
"use client";
|
||||
|
||||
import * as React from "react";
|
||||
import { cn } from "cn";
|
||||
import { Drawer as DrawerPrimitive } from "vaul";
|
||||
|
||||
function Drawer({ ...props }: React.ComponentProps<typeof DrawerPrimitive.Root>) {
|
||||
return <DrawerPrimitive.Root data-slot="drawer" {...props} />;
|
||||
}
|
||||
|
||||
function DrawerTrigger({ ...props }: React.ComponentProps<typeof DrawerPrimitive.Trigger>) {
|
||||
return <DrawerPrimitive.Trigger data-slot="drawer-trigger" {...props} />;
|
||||
}
|
||||
|
||||
function DrawerPortal({ ...props }: React.ComponentProps<typeof DrawerPrimitive.Portal>) {
|
||||
return <DrawerPrimitive.Portal data-slot="drawer-portal" {...props} />;
|
||||
}
|
||||
|
||||
function DrawerClose({ ...props }: React.ComponentProps<typeof DrawerPrimitive.Close>) {
|
||||
return <DrawerPrimitive.Close data-slot="drawer-close" {...props} />;
|
||||
}
|
||||
|
||||
function DrawerOverlay({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DrawerPrimitive.Overlay>) {
|
||||
return (
|
||||
<DrawerPrimitive.Overlay
|
||||
data-slot="drawer-overlay"
|
||||
className={cn(
|
||||
"fixed inset-0 z-50 bg-black/10 supports-backdrop-filter:backdrop-blur-xs data-open:animate-in data-open:fade-in-0 data-closed:animate-out data-closed:fade-out-0",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function DrawerContent({
|
||||
className,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DrawerPrimitive.Content>) {
|
||||
return (
|
||||
<DrawerPortal data-slot="drawer-portal">
|
||||
<DrawerOverlay />
|
||||
<DrawerPrimitive.Content
|
||||
data-slot="drawer-content"
|
||||
className={cn(
|
||||
"group/drawer-content fixed z-50 flex h-auto flex-col bg-popover text-sm text-popover-foreground data-[vaul-drawer-direction=bottom]:inset-x-0 data-[vaul-drawer-direction=bottom]:bottom-0 data-[vaul-drawer-direction=bottom]:mt-24 data-[vaul-drawer-direction=bottom]:max-h-[80vh] data-[vaul-drawer-direction=bottom]:rounded-t-xl data-[vaul-drawer-direction=bottom]:border-t data-[vaul-drawer-direction=left]:inset-y-0 data-[vaul-drawer-direction=left]:left-0 data-[vaul-drawer-direction=left]:w-3/4 data-[vaul-drawer-direction=left]:rounded-r-xl data-[vaul-drawer-direction=left]:border-r data-[vaul-drawer-direction=right]:inset-y-0 data-[vaul-drawer-direction=right]:right-0 data-[vaul-drawer-direction=right]:w-3/4 data-[vaul-drawer-direction=right]:rounded-l-xl data-[vaul-drawer-direction=right]:border-l data-[vaul-drawer-direction=top]:inset-x-0 data-[vaul-drawer-direction=top]:top-0 data-[vaul-drawer-direction=top]:mb-24 data-[vaul-drawer-direction=top]:max-h-[80vh] data-[vaul-drawer-direction=top]:rounded-b-xl data-[vaul-drawer-direction=top]:border-b data-[vaul-drawer-direction=left]:sm:max-w-sm data-[vaul-drawer-direction=right]:sm:max-w-sm",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<div className="mx-auto mt-4 hidden h-1 w-[100px] shrink-0 rounded-full bg-muted group-data-[vaul-drawer-direction=bottom]/drawer-content:block" />
|
||||
{children}
|
||||
</DrawerPrimitive.Content>
|
||||
</DrawerPortal>
|
||||
);
|
||||
}
|
||||
|
||||
function DrawerHeader({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="drawer-header"
|
||||
className={cn(
|
||||
"flex flex-col gap-0.5 p-4 group-data-[vaul-drawer-direction=bottom]/drawer-content:text-center group-data-[vaul-drawer-direction=top]/drawer-content:text-center md:gap-0.5 md:text-left",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function DrawerFooter({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="drawer-footer"
|
||||
className={cn("mt-auto flex flex-col gap-2 p-4", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function DrawerTitle({ className, ...props }: React.ComponentProps<typeof DrawerPrimitive.Title>) {
|
||||
return (
|
||||
<DrawerPrimitive.Title
|
||||
data-slot="drawer-title"
|
||||
className={cn("font-heading text-base font-medium text-foreground", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function DrawerDescription({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DrawerPrimitive.Description>) {
|
||||
return (
|
||||
<DrawerPrimitive.Description
|
||||
data-slot="drawer-description"
|
||||
className={cn("text-sm text-muted-foreground", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export {
|
||||
Drawer,
|
||||
DrawerPortal,
|
||||
DrawerOverlay,
|
||||
DrawerTrigger,
|
||||
DrawerClose,
|
||||
DrawerContent,
|
||||
DrawerHeader,
|
||||
DrawerFooter,
|
||||
DrawerTitle,
|
||||
DrawerDescription,
|
||||
};
|
||||
@@ -0,0 +1,249 @@
|
||||
"use client";
|
||||
|
||||
import * as React from "react";
|
||||
import { cn } from "cn";
|
||||
import { DropdownMenu as DropdownMenuPrimitive } from "radix-ui";
|
||||
import { CheckIcon, ChevronRightIcon } from "lucide-react";
|
||||
|
||||
function DropdownMenu({ ...props }: React.ComponentProps<typeof DropdownMenuPrimitive.Root>) {
|
||||
return <DropdownMenuPrimitive.Root data-slot="dropdown-menu" {...props} />;
|
||||
}
|
||||
|
||||
function DropdownMenuPortal({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.Portal>) {
|
||||
return <DropdownMenuPrimitive.Portal data-slot="dropdown-menu-portal" {...props} />;
|
||||
}
|
||||
|
||||
function DropdownMenuTrigger({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.Trigger>) {
|
||||
return <DropdownMenuPrimitive.Trigger data-slot="dropdown-menu-trigger" {...props} />;
|
||||
}
|
||||
|
||||
function DropdownMenuContent({
|
||||
className,
|
||||
align = "start",
|
||||
sideOffset = 4,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.Content>) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.Portal>
|
||||
<DropdownMenuPrimitive.Content
|
||||
data-slot="dropdown-menu-content"
|
||||
sideOffset={sideOffset}
|
||||
align={align}
|
||||
className={cn(
|
||||
"z-50 max-h-(--radix-dropdown-menu-content-available-height) w-(--radix-dropdown-menu-trigger-width) min-w-32 origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-lg bg-popover p-1 text-popover-foreground shadow-md ring-1 ring-foreground/10 duration-100 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:overflow-hidden data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
</DropdownMenuPrimitive.Portal>
|
||||
);
|
||||
}
|
||||
|
||||
function DropdownMenuGroup({ ...props }: React.ComponentProps<typeof DropdownMenuPrimitive.Group>) {
|
||||
return <DropdownMenuPrimitive.Group data-slot="dropdown-menu-group" {...props} />;
|
||||
}
|
||||
|
||||
function DropdownMenuItem({
|
||||
className,
|
||||
inset,
|
||||
variant = "default",
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.Item> & {
|
||||
inset?: boolean;
|
||||
variant?: "default" | "destructive";
|
||||
}) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.Item
|
||||
data-slot="dropdown-menu-item"
|
||||
data-inset={inset}
|
||||
data-variant={variant}
|
||||
className={cn(
|
||||
"group/dropdown-menu-item relative flex cursor-default items-center gap-1.5 rounded-md px-1.5 py-1 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground not-data-[variant=destructive]:focus:**:text-accent-foreground data-inset:pl-7 data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 data-[variant=destructive]:focus:text-destructive dark:data-[variant=destructive]:focus:bg-destructive/20 data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 data-[variant=destructive]:*:[svg]:text-destructive",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function DropdownMenuCheckboxItem({
|
||||
className,
|
||||
children,
|
||||
checked,
|
||||
inset,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.CheckboxItem> & {
|
||||
inset?: boolean;
|
||||
}) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.CheckboxItem
|
||||
data-slot="dropdown-menu-checkbox-item"
|
||||
data-inset={inset}
|
||||
className={cn(
|
||||
"relative flex cursor-default items-center gap-1.5 rounded-md py-1 pr-8 pl-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground focus:**:text-accent-foreground data-inset:pl-7 data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||
className,
|
||||
)}
|
||||
checked={checked}
|
||||
{...props}
|
||||
>
|
||||
<span
|
||||
className="pointer-events-none absolute right-2 flex items-center justify-center"
|
||||
data-slot="dropdown-menu-checkbox-item-indicator"
|
||||
>
|
||||
<DropdownMenuPrimitive.ItemIndicator>
|
||||
<CheckIcon />
|
||||
</DropdownMenuPrimitive.ItemIndicator>
|
||||
</span>
|
||||
{children}
|
||||
</DropdownMenuPrimitive.CheckboxItem>
|
||||
);
|
||||
}
|
||||
|
||||
function DropdownMenuRadioGroup({
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.RadioGroup>) {
|
||||
return <DropdownMenuPrimitive.RadioGroup data-slot="dropdown-menu-radio-group" {...props} />;
|
||||
}
|
||||
|
||||
function DropdownMenuRadioItem({
|
||||
className,
|
||||
children,
|
||||
inset,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.RadioItem> & {
|
||||
inset?: boolean;
|
||||
}) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.RadioItem
|
||||
data-slot="dropdown-menu-radio-item"
|
||||
data-inset={inset}
|
||||
className={cn(
|
||||
"relative flex cursor-default items-center gap-1.5 rounded-md py-1 pr-8 pl-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground focus:**:text-accent-foreground data-inset:pl-7 data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<span
|
||||
className="pointer-events-none absolute right-2 flex items-center justify-center"
|
||||
data-slot="dropdown-menu-radio-item-indicator"
|
||||
>
|
||||
<DropdownMenuPrimitive.ItemIndicator>
|
||||
<CheckIcon />
|
||||
</DropdownMenuPrimitive.ItemIndicator>
|
||||
</span>
|
||||
{children}
|
||||
</DropdownMenuPrimitive.RadioItem>
|
||||
);
|
||||
}
|
||||
|
||||
function DropdownMenuLabel({
|
||||
className,
|
||||
inset,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.Label> & {
|
||||
inset?: boolean;
|
||||
}) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.Label
|
||||
data-slot="dropdown-menu-label"
|
||||
data-inset={inset}
|
||||
className={cn(
|
||||
"px-1.5 py-1 text-xs font-medium text-muted-foreground data-inset:pl-7",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function DropdownMenuSeparator({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.Separator>) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.Separator
|
||||
data-slot="dropdown-menu-separator"
|
||||
className={cn("-mx-1 my-1 h-px bg-border", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function DropdownMenuShortcut({ className, ...props }: React.ComponentProps<"span">) {
|
||||
return (
|
||||
<span
|
||||
data-slot="dropdown-menu-shortcut"
|
||||
className={cn(
|
||||
"ml-auto text-xs tracking-widest text-muted-foreground group-focus/dropdown-menu-item:text-accent-foreground",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function DropdownMenuSub({ ...props }: React.ComponentProps<typeof DropdownMenuPrimitive.Sub>) {
|
||||
return <DropdownMenuPrimitive.Sub data-slot="dropdown-menu-sub" {...props} />;
|
||||
}
|
||||
|
||||
function DropdownMenuSubTrigger({
|
||||
className,
|
||||
inset,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.SubTrigger> & {
|
||||
inset?: boolean;
|
||||
}) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.SubTrigger
|
||||
data-slot="dropdown-menu-sub-trigger"
|
||||
data-inset={inset}
|
||||
className={cn(
|
||||
"flex cursor-default items-center gap-1.5 rounded-md px-1.5 py-1 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground not-data-[variant=destructive]:focus:**:text-accent-foreground data-inset:pl-7 data-open:bg-accent data-open:text-accent-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
<ChevronRightIcon className="ml-auto" />
|
||||
</DropdownMenuPrimitive.SubTrigger>
|
||||
);
|
||||
}
|
||||
|
||||
function DropdownMenuSubContent({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.SubContent>) {
|
||||
return (
|
||||
<DropdownMenuPrimitive.SubContent
|
||||
data-slot="dropdown-menu-sub-content"
|
||||
className={cn(
|
||||
"z-50 min-w-[96px] origin-(--radix-dropdown-menu-content-transform-origin) overflow-hidden rounded-lg bg-popover p-1 text-popover-foreground shadow-lg ring-1 ring-foreground/10 duration-100 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export {
|
||||
DropdownMenu,
|
||||
DropdownMenuPortal,
|
||||
DropdownMenuTrigger,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuGroup,
|
||||
DropdownMenuLabel,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuCheckboxItem,
|
||||
DropdownMenuRadioGroup,
|
||||
DropdownMenuRadioItem,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuShortcut,
|
||||
DropdownMenuSub,
|
||||
DropdownMenuSubTrigger,
|
||||
DropdownMenuSubContent,
|
||||
};
|
||||
@@ -0,0 +1,224 @@
|
||||
"use client";
|
||||
|
||||
import { useMemo } from "react";
|
||||
import { cva, type VariantProps } from "class-variance-authority";
|
||||
import { cn } from "cn";
|
||||
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { Separator } from "@/components/ui/separator";
|
||||
|
||||
function FieldSet({ className, ...props }: React.ComponentProps<"fieldset">) {
|
||||
return (
|
||||
<fieldset
|
||||
data-slot="field-set"
|
||||
className={cn(
|
||||
"flex flex-col gap-4 has-[>[data-slot=checkbox-group]]:gap-3 has-[>[data-slot=radio-group]]:gap-3",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function FieldLegend({
|
||||
className,
|
||||
variant = "legend",
|
||||
...props
|
||||
}: React.ComponentProps<"legend"> & { variant?: "legend" | "label" }) {
|
||||
return (
|
||||
<legend
|
||||
data-slot="field-legend"
|
||||
data-variant={variant}
|
||||
className={cn(
|
||||
"mb-1.5 font-medium data-[variant=label]:text-sm data-[variant=legend]:text-base",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function FieldGroup({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="field-group"
|
||||
className={cn(
|
||||
"group/field-group @container/field-group flex w-full flex-col gap-5 data-[slot=checkbox-group]:gap-3 *:data-[slot=field-group]:gap-4",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
const fieldVariants = cva("group/field flex w-full gap-2 data-[invalid=true]:text-destructive", {
|
||||
variants: {
|
||||
orientation: {
|
||||
vertical: "flex-col *:w-full [&>.sr-only]:w-auto",
|
||||
horizontal:
|
||||
"flex-row items-center has-[>[data-slot=field-content]]:items-start *:data-[slot=field-label]:flex-auto has-[>[data-slot=field-content]]:[&>[role=checkbox],[role=radio]]:mt-px",
|
||||
responsive:
|
||||
"flex-col *:w-full @md/field-group:flex-row @md/field-group:items-center @md/field-group:*:w-auto @md/field-group:has-[>[data-slot=field-content]]:items-start @md/field-group:*:data-[slot=field-label]:flex-auto [&>.sr-only]:w-auto @md/field-group:has-[>[data-slot=field-content]]:[&>[role=checkbox],[role=radio]]:mt-px",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
orientation: "vertical",
|
||||
},
|
||||
});
|
||||
|
||||
function Field({
|
||||
className,
|
||||
orientation = "vertical",
|
||||
...props
|
||||
}: React.ComponentProps<"div"> & VariantProps<typeof fieldVariants>) {
|
||||
return (
|
||||
<div
|
||||
role="group"
|
||||
data-slot="field"
|
||||
data-orientation={orientation}
|
||||
className={cn(fieldVariants({ orientation }), className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function FieldContent({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="field-content"
|
||||
className={cn("group/field-content flex flex-1 flex-col gap-0.5 leading-snug", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function FieldLabel({ className, ...props }: React.ComponentProps<typeof Label>) {
|
||||
return (
|
||||
<Label
|
||||
data-slot="field-label"
|
||||
className={cn(
|
||||
"group/field-label peer/field-label flex w-fit gap-2 leading-snug group-data-[disabled=true]/field:opacity-50 has-data-checked:border-primary/30 has-data-checked:bg-primary/5 has-[>[data-slot=field]]:rounded-lg has-[>[data-slot=field]]:border has-[>[data-slot=field]]:not-has-[:disabled,[data-disabled]]:hover:bg-muted/50 has-[>[data-slot=field]]:has-[:focus-visible]:border-ring has-[>[data-slot=field]]:has-[:focus-visible]:ring-3 has-[>[data-slot=field]]:has-[:focus-visible]:ring-ring/50 *:data-[slot=field]:p-2.5 dark:has-data-checked:border-primary/20 dark:has-data-checked:bg-primary/10",
|
||||
"has-[>[data-slot=field]]:w-full has-[>[data-slot=field]]:flex-col",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function FieldTitle({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="field-label"
|
||||
className={cn(
|
||||
"flex w-fit items-center gap-2 text-sm font-medium group-data-[disabled=true]/field:opacity-50",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function FieldDescription({ className, ...props }: React.ComponentProps<"p">) {
|
||||
return (
|
||||
<p
|
||||
data-slot="field-description"
|
||||
className={cn(
|
||||
"text-left text-sm leading-normal font-normal text-muted-foreground group-has-data-horizontal/field:text-balance [[data-variant=legend]+&]:-mt-1.5",
|
||||
"last:mt-0 nth-last-2:-mt-1",
|
||||
"[&>a]:underline [&>a]:underline-offset-4 [&>a:hover]:text-primary",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function FieldSeparator({
|
||||
children,
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"div"> & {
|
||||
children?: React.ReactNode;
|
||||
}) {
|
||||
return (
|
||||
<div
|
||||
data-slot="field-separator"
|
||||
data-content={!!children}
|
||||
className={cn(
|
||||
"relative -my-2 h-5 text-sm group-data-[variant=outline]/field-group:-mb-2",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<Separator className="absolute inset-0 top-1/2" />
|
||||
{children && (
|
||||
<span
|
||||
className="relative mx-auto block w-fit bg-background px-2 text-muted-foreground"
|
||||
data-slot="field-separator-content"
|
||||
>
|
||||
{children}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function FieldError({
|
||||
className,
|
||||
children,
|
||||
errors,
|
||||
...props
|
||||
}: React.ComponentProps<"div"> & {
|
||||
errors?: Array<{ message?: string } | undefined>;
|
||||
}) {
|
||||
const content = useMemo(() => {
|
||||
if (children) {
|
||||
return children;
|
||||
}
|
||||
|
||||
if (!errors?.length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const uniqueErrors = [...new Map(errors.map((error) => [error?.message, error])).values()];
|
||||
|
||||
if (uniqueErrors?.length == 1) {
|
||||
return uniqueErrors[0]?.message;
|
||||
}
|
||||
|
||||
return (
|
||||
<ul className="ml-4 flex list-disc flex-col gap-1">
|
||||
{uniqueErrors.map((error, index) => error?.message && <li key={index}>{error.message}</li>)}
|
||||
</ul>
|
||||
);
|
||||
}, [children, errors]);
|
||||
|
||||
if (!content) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
role="alert"
|
||||
data-slot="field-error"
|
||||
className={cn("text-sm font-normal text-destructive", className)}
|
||||
{...props}
|
||||
>
|
||||
{content}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export {
|
||||
Field,
|
||||
FieldLabel,
|
||||
FieldDescription,
|
||||
FieldError,
|
||||
FieldGroup,
|
||||
FieldLegend,
|
||||
FieldSeparator,
|
||||
FieldSet,
|
||||
FieldContent,
|
||||
FieldTitle,
|
||||
};
|
||||
@@ -0,0 +1,144 @@
|
||||
"use client";
|
||||
|
||||
import * as React from "react";
|
||||
import { cva, type VariantProps } from "class-variance-authority";
|
||||
import { cn } from "cn";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
|
||||
function InputGroup({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="input-group"
|
||||
role="group"
|
||||
className={cn(
|
||||
"group/input-group relative flex h-8 w-full min-w-0 items-center rounded-lg border border-input transition-colors outline-none in-data-[slot=combobox-content]:focus-within:border-inherit in-data-[slot=combobox-content]:focus-within:ring-0 has-disabled:bg-input/50 has-disabled:opacity-50 has-[[data-slot=input-group-control]:focus-visible]:border-ring has-[[data-slot=input-group-control]:focus-visible]:ring-3 has-[[data-slot=input-group-control]:focus-visible]:ring-ring/50 has-[[data-slot][aria-invalid=true]]:border-destructive has-[[data-slot][aria-invalid=true]]:ring-3 has-[[data-slot][aria-invalid=true]]:ring-destructive/20 has-[>[data-align=block-end]]:h-auto has-[>[data-align=block-end]]:flex-col has-[>[data-align=block-start]]:h-auto has-[>[data-align=block-start]]:flex-col has-[>textarea]:h-auto dark:bg-input/30 dark:has-disabled:bg-input/80 dark:has-[[data-slot][aria-invalid=true]]:ring-destructive/40 has-[>[data-align=block-end]]:[&>input]:pt-3 has-[>[data-align=block-start]]:[&>input]:pb-3 has-[>[data-align=inline-end]]:[&>input]:pr-1.5 has-[>[data-align=inline-start]]:[&>input]:pl-1.5",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
const inputGroupAddonVariants = cva(
|
||||
"flex h-auto cursor-text items-center justify-center gap-2 py-1.5 text-sm font-medium text-muted-foreground select-none group-data-[disabled=true]/input-group:opacity-50 [&>kbd]:rounded-[calc(var(--radius)-5px)] [&>svg:not([class*='size-'])]:size-4",
|
||||
{
|
||||
variants: {
|
||||
align: {
|
||||
"inline-start": "order-first pl-2 has-[>button]:ml-[-0.3rem] has-[>kbd]:ml-[-0.15rem]",
|
||||
"inline-end": "order-last pr-2 has-[>button]:mr-[-0.3rem] has-[>kbd]:mr-[-0.15rem]",
|
||||
"block-start":
|
||||
"order-first w-full justify-start px-2.5 pt-2 group-has-[>input]/input-group:pt-2 [.border-b]:pb-2",
|
||||
"block-end":
|
||||
"order-last w-full justify-start px-2.5 pb-2 group-has-[>input]/input-group:pb-2 [.border-t]:pt-2",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
align: "inline-start",
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
function InputGroupAddon({
|
||||
className,
|
||||
align = "inline-start",
|
||||
...props
|
||||
}: React.ComponentProps<"div"> & VariantProps<typeof inputGroupAddonVariants>) {
|
||||
return (
|
||||
<div
|
||||
role="group"
|
||||
data-slot="input-group-addon"
|
||||
data-align={align}
|
||||
className={cn(inputGroupAddonVariants({ align }), className)}
|
||||
onClick={(e) => {
|
||||
if ((e.target as HTMLElement).closest("button")) {
|
||||
return;
|
||||
}
|
||||
e.currentTarget.parentElement?.querySelector("input")?.focus();
|
||||
}}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
const inputGroupButtonVariants = cva("flex items-center gap-2 text-sm shadow-none", {
|
||||
variants: {
|
||||
size: {
|
||||
xs: "h-6 gap-1 rounded-[calc(var(--radius)-3px)] px-1.5 [&>svg:not([class*='size-'])]:size-3.5",
|
||||
sm: "",
|
||||
"icon-xs": "size-6 rounded-[calc(var(--radius)-3px)] p-0 has-[>svg]:p-0",
|
||||
"icon-sm": "size-8 p-0 has-[>svg]:p-0",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
size: "xs",
|
||||
},
|
||||
});
|
||||
|
||||
function InputGroupButton({
|
||||
className,
|
||||
type = "button",
|
||||
variant = "ghost",
|
||||
size = "xs",
|
||||
...props
|
||||
}: Omit<React.ComponentProps<typeof Button>, "size"> &
|
||||
VariantProps<typeof inputGroupButtonVariants>) {
|
||||
return (
|
||||
<Button
|
||||
type={type}
|
||||
data-size={size}
|
||||
variant={variant}
|
||||
className={cn(inputGroupButtonVariants({ size }), className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function InputGroupText({ className, ...props }: React.ComponentProps<"span">) {
|
||||
return (
|
||||
<span
|
||||
className={cn(
|
||||
"flex items-center gap-2 text-sm text-muted-foreground [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function InputGroupInput({ className, ...props }: React.ComponentProps<"input">) {
|
||||
return (
|
||||
<Input
|
||||
data-slot="input-group-control"
|
||||
className={cn(
|
||||
"flex-1 rounded-none border-0 bg-transparent shadow-none ring-0 focus-visible:ring-0 disabled:bg-transparent aria-invalid:ring-0 dark:bg-transparent dark:disabled:bg-transparent",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function InputGroupTextarea({ className, ...props }: React.ComponentProps<"textarea">) {
|
||||
return (
|
||||
<Textarea
|
||||
data-slot="input-group-control"
|
||||
className={cn(
|
||||
"flex-1 resize-none rounded-none border-0 bg-transparent py-2 shadow-none ring-0 focus-visible:ring-0 disabled:bg-transparent aria-invalid:ring-0 dark:bg-transparent dark:disabled:bg-transparent",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export {
|
||||
InputGroup,
|
||||
InputGroupAddon,
|
||||
InputGroupButton,
|
||||
InputGroupText,
|
||||
InputGroupInput,
|
||||
InputGroupTextarea,
|
||||
};
|
||||
@@ -0,0 +1,18 @@
|
||||
import * as React from "react";
|
||||
import { cn } from "cn";
|
||||
|
||||
function Input({ className, type, ...props }: React.ComponentProps<"input">) {
|
||||
return (
|
||||
<input
|
||||
type={type}
|
||||
data-slot="input"
|
||||
className={cn(
|
||||
"h-8 w-full min-w-0 rounded-lg border border-input bg-transparent px-2.5 py-1 text-base transition-colors outline-none file:inline-flex file:h-6 file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:pointer-events-none disabled:cursor-not-allowed disabled:bg-input/50 disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 md:text-sm dark:bg-input/30 dark:disabled:bg-input/80 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export { Input };
|
||||
@@ -0,0 +1,20 @@
|
||||
"use client";
|
||||
|
||||
import * as React from "react";
|
||||
import { cn } from "cn";
|
||||
import { Label as LabelPrimitive } from "radix-ui";
|
||||
|
||||
function Label({ className, ...props }: React.ComponentProps<typeof LabelPrimitive.Root>) {
|
||||
return (
|
||||
<LabelPrimitive.Root
|
||||
data-slot="label"
|
||||
className={cn(
|
||||
"flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export { Label };
|
||||
@@ -0,0 +1,184 @@
|
||||
"use client";
|
||||
|
||||
import * as React from "react";
|
||||
import { cn } from "cn";
|
||||
import { Select as SelectPrimitive } from "radix-ui";
|
||||
import { ChevronDownIcon, CheckIcon, ChevronUpIcon } from "lucide-react";
|
||||
|
||||
function Select({ ...props }: React.ComponentProps<typeof SelectPrimitive.Root>) {
|
||||
return <SelectPrimitive.Root data-slot="select" {...props} />;
|
||||
}
|
||||
|
||||
function SelectGroup({ className, ...props }: React.ComponentProps<typeof SelectPrimitive.Group>) {
|
||||
return (
|
||||
<SelectPrimitive.Group
|
||||
data-slot="select-group"
|
||||
className={cn("scroll-my-1 p-1", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function SelectValue({ ...props }: React.ComponentProps<typeof SelectPrimitive.Value>) {
|
||||
return <SelectPrimitive.Value data-slot="select-value" {...props} />;
|
||||
}
|
||||
|
||||
function SelectTrigger({
|
||||
className,
|
||||
size = "default",
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<typeof SelectPrimitive.Trigger> & {
|
||||
size?: "sm" | "default";
|
||||
}) {
|
||||
return (
|
||||
<SelectPrimitive.Trigger
|
||||
data-slot="select-trigger"
|
||||
data-size={size}
|
||||
className={cn(
|
||||
"flex w-fit items-center justify-between gap-1.5 rounded-lg border border-input bg-transparent py-2 pr-2 pl-2.5 text-sm whitespace-nowrap transition-colors outline-none select-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 data-placeholder:text-muted-foreground data-[size=default]:h-8 data-[size=sm]:h-7 data-[size=sm]:rounded-[min(var(--radius-md),10px)] *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-1.5 dark:bg-input/30 dark:hover:bg-input/50 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
<SelectPrimitive.Icon asChild>
|
||||
<ChevronDownIcon className="pointer-events-none size-4 text-muted-foreground" />
|
||||
</SelectPrimitive.Icon>
|
||||
</SelectPrimitive.Trigger>
|
||||
);
|
||||
}
|
||||
|
||||
function SelectContent({
|
||||
className,
|
||||
children,
|
||||
position = "item-aligned",
|
||||
align = "center",
|
||||
...props
|
||||
}: React.ComponentProps<typeof SelectPrimitive.Content>) {
|
||||
return (
|
||||
<SelectPrimitive.Portal>
|
||||
<SelectPrimitive.Content
|
||||
data-slot="select-content"
|
||||
data-align-trigger={position === "item-aligned"}
|
||||
className={cn(
|
||||
"relative z-50 max-h-(--radix-select-content-available-height) min-w-36 origin-(--radix-select-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-lg bg-popover text-popover-foreground shadow-md ring-1 ring-foreground/10 duration-100 data-[align-trigger=true]:animate-none data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95",
|
||||
position === "popper" &&
|
||||
"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",
|
||||
className,
|
||||
)}
|
||||
position={position}
|
||||
align={align}
|
||||
{...props}
|
||||
>
|
||||
<SelectScrollUpButton />
|
||||
<SelectPrimitive.Viewport
|
||||
data-position={position}
|
||||
className={cn(
|
||||
"data-[position=popper]:h-(--radix-select-trigger-height) data-[position=popper]:w-full data-[position=popper]:min-w-(--radix-select-trigger-width)",
|
||||
position === "popper" && "",
|
||||
)}
|
||||
>
|
||||
{children}
|
||||
</SelectPrimitive.Viewport>
|
||||
<SelectScrollDownButton />
|
||||
</SelectPrimitive.Content>
|
||||
</SelectPrimitive.Portal>
|
||||
);
|
||||
}
|
||||
|
||||
function SelectLabel({ className, ...props }: React.ComponentProps<typeof SelectPrimitive.Label>) {
|
||||
return (
|
||||
<SelectPrimitive.Label
|
||||
data-slot="select-label"
|
||||
className={cn("px-1.5 py-1 text-xs text-muted-foreground", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function SelectItem({
|
||||
className,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<typeof SelectPrimitive.Item>) {
|
||||
return (
|
||||
<SelectPrimitive.Item
|
||||
data-slot="select-item"
|
||||
className={cn(
|
||||
"relative flex w-full cursor-default items-center gap-1.5 rounded-md py-1 pr-8 pl-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground not-data-[variant=destructive]:focus:**:text-accent-foreground data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<span className="pointer-events-none absolute right-2 flex size-4 items-center justify-center">
|
||||
<SelectPrimitive.ItemIndicator>
|
||||
<CheckIcon className="pointer-events-none" />
|
||||
</SelectPrimitive.ItemIndicator>
|
||||
</span>
|
||||
<SelectPrimitive.ItemText>{children}</SelectPrimitive.ItemText>
|
||||
</SelectPrimitive.Item>
|
||||
);
|
||||
}
|
||||
|
||||
function SelectSeparator({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof SelectPrimitive.Separator>) {
|
||||
return (
|
||||
<SelectPrimitive.Separator
|
||||
data-slot="select-separator"
|
||||
className={cn("pointer-events-none -mx-1 my-1 h-px bg-border", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function SelectScrollUpButton({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof SelectPrimitive.ScrollUpButton>) {
|
||||
return (
|
||||
<SelectPrimitive.ScrollUpButton
|
||||
data-slot="select-scroll-up-button"
|
||||
className={cn(
|
||||
"z-10 flex cursor-default items-center justify-center bg-popover py-1 [&_svg:not([class*='size-'])]:size-4",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<ChevronUpIcon />
|
||||
</SelectPrimitive.ScrollUpButton>
|
||||
);
|
||||
}
|
||||
|
||||
function SelectScrollDownButton({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof SelectPrimitive.ScrollDownButton>) {
|
||||
return (
|
||||
<SelectPrimitive.ScrollDownButton
|
||||
data-slot="select-scroll-down-button"
|
||||
className={cn(
|
||||
"z-10 flex cursor-default items-center justify-center bg-popover py-1 [&_svg:not([class*='size-'])]:size-4",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<ChevronDownIcon />
|
||||
</SelectPrimitive.ScrollDownButton>
|
||||
);
|
||||
}
|
||||
|
||||
export {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectGroup,
|
||||
SelectItem,
|
||||
SelectLabel,
|
||||
SelectScrollDownButton,
|
||||
SelectScrollUpButton,
|
||||
SelectSeparator,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
};
|
||||
@@ -0,0 +1,27 @@
|
||||
"use client";
|
||||
|
||||
import * as React from "react";
|
||||
import { cn } from "cn";
|
||||
import { Separator as SeparatorPrimitive } from "radix-ui";
|
||||
|
||||
function Separator({
|
||||
className,
|
||||
orientation = "horizontal",
|
||||
decorative = true,
|
||||
...props
|
||||
}: React.ComponentProps<typeof SeparatorPrimitive.Root>) {
|
||||
return (
|
||||
<SeparatorPrimitive.Root
|
||||
data-slot="separator"
|
||||
decorative={decorative}
|
||||
orientation={orientation}
|
||||
className={cn(
|
||||
"shrink-0 bg-border data-horizontal:h-px data-horizontal:w-full data-vertical:w-px data-vertical:self-stretch",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export { Separator };
|
||||
@@ -0,0 +1,130 @@
|
||||
"use client";
|
||||
|
||||
import * as React from "react";
|
||||
import { cn } from "cn";
|
||||
import { Dialog as SheetPrimitive } from "radix-ui";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { XIcon } from "lucide-react";
|
||||
|
||||
function Sheet({ ...props }: React.ComponentProps<typeof SheetPrimitive.Root>) {
|
||||
return <SheetPrimitive.Root data-slot="sheet" {...props} />;
|
||||
}
|
||||
|
||||
function SheetTrigger({ ...props }: React.ComponentProps<typeof SheetPrimitive.Trigger>) {
|
||||
return <SheetPrimitive.Trigger data-slot="sheet-trigger" {...props} />;
|
||||
}
|
||||
|
||||
function SheetClose({ ...props }: React.ComponentProps<typeof SheetPrimitive.Close>) {
|
||||
return <SheetPrimitive.Close data-slot="sheet-close" {...props} />;
|
||||
}
|
||||
|
||||
function SheetPortal({ ...props }: React.ComponentProps<typeof SheetPrimitive.Portal>) {
|
||||
return <SheetPrimitive.Portal data-slot="sheet-portal" {...props} />;
|
||||
}
|
||||
|
||||
function SheetOverlay({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof SheetPrimitive.Overlay>) {
|
||||
return (
|
||||
<SheetPrimitive.Overlay
|
||||
data-slot="sheet-overlay"
|
||||
className={cn(
|
||||
"fixed inset-0 z-50 bg-black/10 duration-100 supports-backdrop-filter:backdrop-blur-xs data-open:animate-in data-open:fade-in-0 data-closed:animate-out data-closed:fade-out-0",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function SheetContent({
|
||||
className,
|
||||
children,
|
||||
side = "right",
|
||||
showCloseButton = true,
|
||||
...props
|
||||
}: React.ComponentProps<typeof SheetPrimitive.Content> & {
|
||||
side?: "top" | "right" | "bottom" | "left";
|
||||
showCloseButton?: boolean;
|
||||
}) {
|
||||
return (
|
||||
<SheetPortal>
|
||||
<SheetOverlay />
|
||||
<SheetPrimitive.Content
|
||||
data-slot="sheet-content"
|
||||
data-side={side}
|
||||
className={cn(
|
||||
"fixed z-50 flex flex-col gap-4 bg-popover bg-clip-padding text-sm text-popover-foreground shadow-lg transition duration-200 ease-in-out data-[side=bottom]:inset-x-0 data-[side=bottom]:bottom-0 data-[side=bottom]:h-auto data-[side=bottom]:border-t data-[side=left]:inset-y-0 data-[side=left]:left-0 data-[side=left]:h-full data-[side=left]:w-3/4 data-[side=left]:border-r data-[side=right]:inset-y-0 data-[side=right]:right-0 data-[side=right]:h-full data-[side=right]:w-3/4 data-[side=right]:border-l data-[side=top]:inset-x-0 data-[side=top]:top-0 data-[side=top]:h-auto data-[side=top]:border-b data-[side=left]:sm:max-w-sm data-[side=right]:sm:max-w-sm data-open:animate-in data-open:fade-in-0 data-[side=bottom]:data-open:slide-in-from-bottom-10 data-[side=left]:data-open:slide-in-from-left-10 data-[side=right]:data-open:slide-in-from-right-10 data-[side=top]:data-open:slide-in-from-top-10 data-closed:animate-out data-closed:fade-out-0 data-[side=bottom]:data-closed:slide-out-to-bottom-10 data-[side=left]:data-closed:slide-out-to-left-10 data-[side=right]:data-closed:slide-out-to-right-10 data-[side=top]:data-closed:slide-out-to-top-10",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
{showCloseButton && (
|
||||
<SheetPrimitive.Close data-slot="sheet-close" asChild>
|
||||
<Button variant="ghost" className="absolute top-3 right-3" size="icon-sm">
|
||||
<XIcon />
|
||||
<span className="sr-only">Close</span>
|
||||
</Button>
|
||||
</SheetPrimitive.Close>
|
||||
)}
|
||||
</SheetPrimitive.Content>
|
||||
</SheetPortal>
|
||||
);
|
||||
}
|
||||
|
||||
function SheetHeader({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="sheet-header"
|
||||
className={cn("flex flex-col gap-0.5 p-4", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function SheetFooter({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="sheet-footer"
|
||||
className={cn("mt-auto flex flex-col gap-2 p-4", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function SheetTitle({ className, ...props }: React.ComponentProps<typeof SheetPrimitive.Title>) {
|
||||
return (
|
||||
<SheetPrimitive.Title
|
||||
data-slot="sheet-title"
|
||||
className={cn("font-heading text-base font-medium text-foreground", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function SheetDescription({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof SheetPrimitive.Description>) {
|
||||
return (
|
||||
<SheetPrimitive.Description
|
||||
data-slot="sheet-description"
|
||||
className={cn("text-sm text-muted-foreground", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export {
|
||||
Sheet,
|
||||
SheetTrigger,
|
||||
SheetClose,
|
||||
SheetContent,
|
||||
SheetHeader,
|
||||
SheetFooter,
|
||||
SheetTitle,
|
||||
SheetDescription,
|
||||
};
|
||||
@@ -0,0 +1,671 @@
|
||||
"use client";
|
||||
|
||||
import * as React from "react";
|
||||
import { cva, type VariantProps } from "class-variance-authority";
|
||||
import { cn } from "cn";
|
||||
import { Slot } from "radix-ui";
|
||||
|
||||
import { useIsMobile } from "@/hooks/use-mobile";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Separator } from "@/components/ui/separator";
|
||||
import {
|
||||
Sheet,
|
||||
SheetContent,
|
||||
SheetDescription,
|
||||
SheetHeader,
|
||||
SheetTitle,
|
||||
} from "@/components/ui/sheet";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
|
||||
import { PanelLeftIcon } from "lucide-react";
|
||||
|
||||
const SIDEBAR_COOKIE_NAME = "sidebar_state";
|
||||
const SIDEBAR_COOKIE_MAX_AGE = 60 * 60 * 24 * 7;
|
||||
const SIDEBAR_WIDTH = "16rem";
|
||||
const SIDEBAR_WIDTH_MOBILE = "18rem";
|
||||
const SIDEBAR_WIDTH_ICON = "3rem";
|
||||
const SIDEBAR_KEYBOARD_SHORTCUT = "b";
|
||||
|
||||
type SidebarContextProps = {
|
||||
state: "expanded" | "collapsed";
|
||||
open: boolean;
|
||||
setOpen: (open: boolean) => void;
|
||||
openMobile: boolean;
|
||||
setOpenMobile: (open: boolean) => void;
|
||||
isMobile: boolean;
|
||||
toggleSidebar: () => void;
|
||||
};
|
||||
|
||||
const SidebarContext = React.createContext<SidebarContextProps | null>(null);
|
||||
|
||||
function useSidebar() {
|
||||
const context = React.useContext(SidebarContext);
|
||||
if (!context) {
|
||||
throw new Error("useSidebar must be used within a SidebarProvider.");
|
||||
}
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
function SidebarProvider({
|
||||
defaultOpen = true,
|
||||
open: openProp,
|
||||
onOpenChange: setOpenProp,
|
||||
className,
|
||||
style,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<"div"> & {
|
||||
defaultOpen?: boolean;
|
||||
open?: boolean;
|
||||
onOpenChange?: (open: boolean) => void;
|
||||
}) {
|
||||
const isMobile = useIsMobile();
|
||||
const [openMobile, setOpenMobile] = React.useState(false);
|
||||
|
||||
// This is the internal state of the sidebar.
|
||||
// We use openProp and setOpenProp for control from outside the component.
|
||||
const [_open, _setOpen] = React.useState(defaultOpen);
|
||||
const open = openProp ?? _open;
|
||||
const setOpen = React.useCallback(
|
||||
(value: boolean | ((value: boolean) => boolean)) => {
|
||||
const openState = typeof value === "function" ? value(open) : value;
|
||||
if (setOpenProp) {
|
||||
setOpenProp(openState);
|
||||
} else {
|
||||
_setOpen(openState);
|
||||
}
|
||||
|
||||
// This sets the cookie to keep the sidebar state.
|
||||
document.cookie = `${SIDEBAR_COOKIE_NAME}=${openState}; path=/; max-age=${SIDEBAR_COOKIE_MAX_AGE}`;
|
||||
},
|
||||
[setOpenProp, open],
|
||||
);
|
||||
|
||||
// Helper to toggle the sidebar.
|
||||
const toggleSidebar = React.useCallback(() => {
|
||||
return isMobile ? setOpenMobile((open) => !open) : setOpen((open) => !open);
|
||||
}, [isMobile, setOpen, setOpenMobile]);
|
||||
|
||||
// Adds a keyboard shortcut to toggle the sidebar.
|
||||
React.useEffect(() => {
|
||||
const handleKeyDown = (event: KeyboardEvent) => {
|
||||
if (event.key === SIDEBAR_KEYBOARD_SHORTCUT && (event.metaKey || event.ctrlKey)) {
|
||||
event.preventDefault();
|
||||
toggleSidebar();
|
||||
}
|
||||
};
|
||||
|
||||
window.addEventListener("keydown", handleKeyDown);
|
||||
return () => window.removeEventListener("keydown", handleKeyDown);
|
||||
}, [toggleSidebar]);
|
||||
|
||||
// We add a state so that we can do data-state="expanded" or "collapsed".
|
||||
// This makes it easier to style the sidebar with Tailwind classes.
|
||||
const state = open ? "expanded" : "collapsed";
|
||||
|
||||
const contextValue = React.useMemo<SidebarContextProps>(
|
||||
() => ({
|
||||
state,
|
||||
open,
|
||||
setOpen,
|
||||
isMobile,
|
||||
openMobile,
|
||||
setOpenMobile,
|
||||
toggleSidebar,
|
||||
}),
|
||||
[state, open, setOpen, isMobile, openMobile, setOpenMobile, toggleSidebar],
|
||||
);
|
||||
|
||||
return (
|
||||
<SidebarContext.Provider value={contextValue}>
|
||||
<div
|
||||
data-slot="sidebar-wrapper"
|
||||
style={
|
||||
{
|
||||
"--sidebar-width": SIDEBAR_WIDTH,
|
||||
"--sidebar-width-icon": SIDEBAR_WIDTH_ICON,
|
||||
...style,
|
||||
} as React.CSSProperties
|
||||
}
|
||||
className={cn(
|
||||
"group/sidebar-wrapper flex min-h-svh w-full has-data-[variant=inset]:bg-sidebar",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
</SidebarContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
function Sidebar({
|
||||
side = "left",
|
||||
variant = "sidebar",
|
||||
collapsible = "offcanvas",
|
||||
className,
|
||||
children,
|
||||
dir,
|
||||
...props
|
||||
}: React.ComponentProps<"div"> & {
|
||||
side?: "left" | "right";
|
||||
variant?: "sidebar" | "floating" | "inset";
|
||||
collapsible?: "offcanvas" | "icon" | "none";
|
||||
}) {
|
||||
const { isMobile, state, openMobile, setOpenMobile } = useSidebar();
|
||||
|
||||
if (collapsible === "none") {
|
||||
return (
|
||||
<div
|
||||
data-slot="sidebar"
|
||||
className={cn(
|
||||
"flex h-full w-(--sidebar-width) flex-col bg-sidebar text-sidebar-foreground",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (isMobile) {
|
||||
return (
|
||||
<Sheet open={openMobile} onOpenChange={setOpenMobile} {...props}>
|
||||
<SheetContent
|
||||
dir={dir}
|
||||
data-sidebar="sidebar"
|
||||
data-slot="sidebar"
|
||||
data-mobile="true"
|
||||
className="w-(--sidebar-width) bg-sidebar p-0 text-sidebar-foreground [&>button]:hidden"
|
||||
style={
|
||||
{
|
||||
"--sidebar-width": SIDEBAR_WIDTH_MOBILE,
|
||||
} as React.CSSProperties
|
||||
}
|
||||
side={side}
|
||||
>
|
||||
<SheetHeader className="sr-only">
|
||||
<SheetTitle>Sidebar</SheetTitle>
|
||||
<SheetDescription>Displays the mobile sidebar.</SheetDescription>
|
||||
</SheetHeader>
|
||||
<div className="flex h-full w-full flex-col">{children}</div>
|
||||
</SheetContent>
|
||||
</Sheet>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
className="group peer hidden text-sidebar-foreground md:block"
|
||||
data-state={state}
|
||||
data-collapsible={state === "collapsed" ? collapsible : ""}
|
||||
data-variant={variant}
|
||||
data-side={side}
|
||||
data-slot="sidebar"
|
||||
>
|
||||
{/* This is what handles the sidebar gap on desktop */}
|
||||
<div
|
||||
data-slot="sidebar-gap"
|
||||
className={cn(
|
||||
"relative w-(--sidebar-width) bg-transparent transition-[width] duration-200 ease-linear",
|
||||
"group-data-[collapsible=offcanvas]:w-0",
|
||||
"group-data-[side=right]:rotate-180",
|
||||
variant === "floating" || variant === "inset"
|
||||
? "group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)+(--spacing(4)))]"
|
||||
: "group-data-[collapsible=icon]:w-(--sidebar-width-icon)",
|
||||
)}
|
||||
/>
|
||||
<div
|
||||
data-slot="sidebar-container"
|
||||
data-side={side}
|
||||
className={cn(
|
||||
"fixed inset-y-0 z-10 hidden h-svh w-(--sidebar-width) transition-[left,right,width] duration-200 ease-linear data-[side=left]:left-0 data-[side=left]:group-data-[collapsible=offcanvas]:left-[calc(var(--sidebar-width)*-1)] data-[side=right]:right-0 data-[side=right]:group-data-[collapsible=offcanvas]:right-[calc(var(--sidebar-width)*-1)] md:flex",
|
||||
// Adjust the padding for floating and inset variants.
|
||||
variant === "floating" || variant === "inset"
|
||||
? "p-2 group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)+(--spacing(4))+2px)]"
|
||||
: "group-data-[collapsible=icon]:w-(--sidebar-width-icon) group-data-[side=left]:border-r group-data-[side=right]:border-l",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<div
|
||||
data-sidebar="sidebar"
|
||||
data-slot="sidebar-inner"
|
||||
className="flex size-full flex-col bg-sidebar group-data-[variant=floating]:rounded-lg group-data-[variant=floating]:shadow-sm group-data-[variant=floating]:ring-1 group-data-[variant=floating]:ring-sidebar-border"
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function SidebarTrigger({ className, onClick, ...props }: React.ComponentProps<typeof Button>) {
|
||||
const { toggleSidebar } = useSidebar();
|
||||
|
||||
return (
|
||||
<Button
|
||||
data-sidebar="trigger"
|
||||
data-slot="sidebar-trigger"
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
className={cn(className)}
|
||||
onClick={(event) => {
|
||||
onClick?.(event);
|
||||
toggleSidebar();
|
||||
}}
|
||||
{...props}
|
||||
>
|
||||
<PanelLeftIcon />
|
||||
<span className="sr-only">Toggle Sidebar</span>
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
|
||||
function SidebarRail({ className, ...props }: React.ComponentProps<"button">) {
|
||||
const { toggleSidebar } = useSidebar();
|
||||
|
||||
return (
|
||||
<button
|
||||
data-sidebar="rail"
|
||||
data-slot="sidebar-rail"
|
||||
aria-label="Toggle Sidebar"
|
||||
tabIndex={-1}
|
||||
onClick={toggleSidebar}
|
||||
title="Toggle Sidebar"
|
||||
className={cn(
|
||||
"absolute inset-y-0 z-20 hidden w-4 transition-all ease-linear group-data-[side=left]:-right-4 group-data-[side=right]:left-0 after:absolute after:inset-y-0 after:start-1/2 after:w-[2px] hover:after:bg-sidebar-border sm:flex ltr:-translate-x-1/2 rtl:-translate-x-1/2",
|
||||
"in-data-[side=left]:cursor-w-resize in-data-[side=right]:cursor-e-resize",
|
||||
"[[data-side=left][data-state=collapsed]_&]:cursor-e-resize [[data-side=right][data-state=collapsed]_&]:cursor-w-resize",
|
||||
"group-data-[collapsible=offcanvas]:translate-x-0 group-data-[collapsible=offcanvas]:after:left-full hover:group-data-[collapsible=offcanvas]:bg-sidebar",
|
||||
"[[data-side=left][data-collapsible=offcanvas]_&]:-right-2",
|
||||
"[[data-side=right][data-collapsible=offcanvas]_&]:-left-2",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function SidebarInset({ className, ...props }: React.ComponentProps<"main">) {
|
||||
return (
|
||||
<main
|
||||
data-slot="sidebar-inset"
|
||||
className={cn(
|
||||
"relative flex w-full flex-1 flex-col bg-background md:peer-data-[variant=inset]:m-2 md:peer-data-[variant=inset]:ml-0 md:peer-data-[variant=inset]:rounded-xl md:peer-data-[variant=inset]:shadow-sm md:peer-data-[variant=inset]:peer-data-[state=collapsed]:ml-2",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function SidebarInput({ className, ...props }: React.ComponentProps<typeof Input>) {
|
||||
return (
|
||||
<Input
|
||||
data-slot="sidebar-input"
|
||||
data-sidebar="input"
|
||||
className={cn("h-8 w-full bg-background shadow-none", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function SidebarHeader({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="sidebar-header"
|
||||
data-sidebar="header"
|
||||
className={cn("flex flex-col gap-2 p-2", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function SidebarFooter({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="sidebar-footer"
|
||||
data-sidebar="footer"
|
||||
className={cn("flex flex-col gap-2 p-2", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function SidebarSeparator({ className, ...props }: React.ComponentProps<typeof Separator>) {
|
||||
return (
|
||||
<Separator
|
||||
data-slot="sidebar-separator"
|
||||
data-sidebar="separator"
|
||||
className={cn("mx-2 w-auto bg-sidebar-border", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function SidebarContent({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="sidebar-content"
|
||||
data-sidebar="content"
|
||||
className={cn(
|
||||
"no-scrollbar flex min-h-0 flex-1 flex-col gap-0 overflow-auto group-data-[collapsible=icon]:overflow-hidden",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function SidebarGroup({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="sidebar-group"
|
||||
data-sidebar="group"
|
||||
className={cn("relative flex w-full min-w-0 flex-col p-2", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function SidebarGroupLabel({
|
||||
className,
|
||||
asChild = false,
|
||||
...props
|
||||
}: React.ComponentProps<"div"> & { asChild?: boolean }) {
|
||||
const Comp = asChild ? Slot.Root : "div";
|
||||
|
||||
return (
|
||||
<Comp
|
||||
data-slot="sidebar-group-label"
|
||||
data-sidebar="group-label"
|
||||
className={cn(
|
||||
"flex h-8 shrink-0 items-center rounded-md px-2 text-xs font-medium text-sidebar-foreground/70 ring-sidebar-ring outline-hidden transition-[margin,opacity] duration-200 ease-linear group-data-[collapsible=icon]:-mt-8 group-data-[collapsible=icon]:opacity-0 focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function SidebarGroupAction({
|
||||
className,
|
||||
asChild = false,
|
||||
...props
|
||||
}: React.ComponentProps<"button"> & { asChild?: boolean }) {
|
||||
const Comp = asChild ? Slot.Root : "button";
|
||||
|
||||
return (
|
||||
<Comp
|
||||
data-slot="sidebar-group-action"
|
||||
data-sidebar="group-action"
|
||||
className={cn(
|
||||
"absolute top-3.5 right-3 flex aspect-square w-5 items-center justify-center rounded-md p-0 text-sidebar-foreground ring-sidebar-ring outline-hidden transition-transform group-data-[collapsible=icon]:hidden after:absolute after:-inset-2 hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 md:after:hidden [&>svg]:size-4 [&>svg]:shrink-0",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function SidebarGroupContent({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="sidebar-group-content"
|
||||
data-sidebar="group-content"
|
||||
className={cn("w-full text-sm", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function SidebarMenu({ className, ...props }: React.ComponentProps<"ul">) {
|
||||
return (
|
||||
<ul
|
||||
data-slot="sidebar-menu"
|
||||
data-sidebar="menu"
|
||||
className={cn("flex w-full min-w-0 flex-col gap-0", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function SidebarMenuItem({ className, ...props }: React.ComponentProps<"li">) {
|
||||
return (
|
||||
<li
|
||||
data-slot="sidebar-menu-item"
|
||||
data-sidebar="menu-item"
|
||||
className={cn("group/menu-item relative", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
const sidebarMenuButtonVariants = cva(
|
||||
"peer/menu-button group/menu-button flex w-full items-center gap-2 overflow-hidden rounded-md p-2 text-left text-sm ring-sidebar-ring outline-hidden transition-[width,height,padding] group-has-data-[sidebar=menu-action]/menu-item:pr-8 group-data-[collapsible=icon]:size-8! group-data-[collapsible=icon]:p-2! hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 active:bg-sidebar-accent active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 data-open:hover:bg-sidebar-accent data-open:hover:text-sidebar-accent-foreground data-active:bg-sidebar-accent data-active:font-medium data-active:text-sidebar-accent-foreground [&_svg]:size-4 [&_svg]:shrink-0 [&>span:last-child]:truncate",
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default: "hover:bg-sidebar-accent hover:text-sidebar-accent-foreground",
|
||||
outline:
|
||||
"bg-background shadow-[0_0_0_1px_var(--sidebar-border)] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground hover:shadow-[0_0_0_1px_var(--sidebar-accent)]",
|
||||
},
|
||||
size: {
|
||||
default: "h-8 text-sm",
|
||||
sm: "h-7 text-xs",
|
||||
lg: "h-12 text-sm group-data-[collapsible=icon]:p-0!",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: "default",
|
||||
size: "default",
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
function SidebarMenuButton({
|
||||
asChild = false,
|
||||
isActive = false,
|
||||
variant = "default",
|
||||
size = "default",
|
||||
tooltip,
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"button"> & {
|
||||
asChild?: boolean;
|
||||
isActive?: boolean;
|
||||
tooltip?: string | React.ComponentProps<typeof TooltipContent>;
|
||||
} & VariantProps<typeof sidebarMenuButtonVariants>) {
|
||||
const Comp = asChild ? Slot.Root : "button";
|
||||
const { isMobile, state } = useSidebar();
|
||||
|
||||
const button = (
|
||||
<Comp
|
||||
data-slot="sidebar-menu-button"
|
||||
data-sidebar="menu-button"
|
||||
data-size={size}
|
||||
data-active={isActive}
|
||||
className={cn(sidebarMenuButtonVariants({ variant, size }), className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
|
||||
if (!tooltip) {
|
||||
return button;
|
||||
}
|
||||
|
||||
if (typeof tooltip === "string") {
|
||||
tooltip = {
|
||||
children: tooltip,
|
||||
};
|
||||
}
|
||||
|
||||
return (
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>{button}</TooltipTrigger>
|
||||
<TooltipContent
|
||||
side="right"
|
||||
align="center"
|
||||
hidden={state !== "collapsed" || isMobile}
|
||||
{...tooltip}
|
||||
/>
|
||||
</Tooltip>
|
||||
);
|
||||
}
|
||||
|
||||
function SidebarMenuAction({
|
||||
className,
|
||||
asChild = false,
|
||||
showOnHover = false,
|
||||
...props
|
||||
}: React.ComponentProps<"button"> & {
|
||||
asChild?: boolean;
|
||||
showOnHover?: boolean;
|
||||
}) {
|
||||
const Comp = asChild ? Slot.Root : "button";
|
||||
|
||||
return (
|
||||
<Comp
|
||||
data-slot="sidebar-menu-action"
|
||||
data-sidebar="menu-action"
|
||||
className={cn(
|
||||
"absolute top-1.5 right-1 flex aspect-square w-5 items-center justify-center rounded-md p-0 text-sidebar-foreground ring-sidebar-ring outline-hidden transition-transform group-data-[collapsible=icon]:hidden peer-hover/menu-button:text-sidebar-accent-foreground peer-data-[size=default]/menu-button:top-1.5 peer-data-[size=lg]/menu-button:top-2.5 peer-data-[size=sm]/menu-button:top-1 after:absolute after:-inset-2 hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 md:after:hidden [&>svg]:size-4 [&>svg]:shrink-0",
|
||||
showOnHover &&
|
||||
"group-focus-within/menu-item:opacity-100 group-hover/menu-item:opacity-100 peer-data-active/menu-button:text-sidebar-accent-foreground aria-expanded:opacity-100 md:opacity-0",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function SidebarMenuBadge({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="sidebar-menu-badge"
|
||||
data-sidebar="menu-badge"
|
||||
className={cn(
|
||||
"pointer-events-none absolute right-1 flex h-5 min-w-5 items-center justify-center rounded-md px-1 text-xs font-medium text-sidebar-foreground tabular-nums select-none group-data-[collapsible=icon]:hidden peer-hover/menu-button:text-sidebar-accent-foreground peer-data-[size=default]/menu-button:top-1.5 peer-data-[size=lg]/menu-button:top-2.5 peer-data-[size=sm]/menu-button:top-1 peer-data-active/menu-button:text-sidebar-accent-foreground",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function SidebarMenuSkeleton({
|
||||
className,
|
||||
showIcon = false,
|
||||
...props
|
||||
}: React.ComponentProps<"div"> & {
|
||||
showIcon?: boolean;
|
||||
}) {
|
||||
// Random width between 50 to 90%.
|
||||
const [width] = React.useState(() => {
|
||||
return `${Math.floor(Math.random() * 40) + 50}%`;
|
||||
});
|
||||
|
||||
return (
|
||||
<div
|
||||
data-slot="sidebar-menu-skeleton"
|
||||
data-sidebar="menu-skeleton"
|
||||
className={cn("flex h-8 items-center gap-2 rounded-md px-2", className)}
|
||||
{...props}
|
||||
>
|
||||
{showIcon && <Skeleton className="size-4 rounded-md" data-sidebar="menu-skeleton-icon" />}
|
||||
<Skeleton
|
||||
className="h-4 max-w-(--skeleton-width) flex-1"
|
||||
data-sidebar="menu-skeleton-text"
|
||||
style={
|
||||
{
|
||||
"--skeleton-width": width,
|
||||
} as React.CSSProperties
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function SidebarMenuSub({ className, ...props }: React.ComponentProps<"ul">) {
|
||||
return (
|
||||
<ul
|
||||
data-slot="sidebar-menu-sub"
|
||||
data-sidebar="menu-sub"
|
||||
className={cn(
|
||||
"mx-3.5 flex min-w-0 translate-x-px flex-col gap-1 border-l border-sidebar-border px-2.5 py-0.5 group-data-[collapsible=icon]:hidden",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function SidebarMenuSubItem({ className, ...props }: React.ComponentProps<"li">) {
|
||||
return (
|
||||
<li
|
||||
data-slot="sidebar-menu-sub-item"
|
||||
data-sidebar="menu-sub-item"
|
||||
className={cn("group/menu-sub-item relative", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function SidebarMenuSubButton({
|
||||
asChild = false,
|
||||
size = "md",
|
||||
isActive = false,
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"a"> & {
|
||||
asChild?: boolean;
|
||||
size?: "sm" | "md";
|
||||
isActive?: boolean;
|
||||
}) {
|
||||
const Comp = asChild ? Slot.Root : "a";
|
||||
|
||||
return (
|
||||
<Comp
|
||||
data-slot="sidebar-menu-sub-button"
|
||||
data-sidebar="menu-sub-button"
|
||||
data-size={size}
|
||||
data-active={isActive}
|
||||
className={cn(
|
||||
"flex h-7 min-w-0 -translate-x-px items-center gap-2 overflow-hidden rounded-md px-2 text-sidebar-foreground ring-sidebar-ring outline-hidden group-data-[collapsible=icon]:hidden hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 active:bg-sidebar-accent active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 data-[size=md]:text-sm data-[size=sm]:text-xs data-active:bg-sidebar-accent data-active:text-sidebar-accent-foreground [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0 [&>svg]:text-sidebar-accent-foreground",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export {
|
||||
Sidebar,
|
||||
SidebarContent,
|
||||
SidebarFooter,
|
||||
SidebarGroup,
|
||||
SidebarGroupAction,
|
||||
SidebarGroupContent,
|
||||
SidebarGroupLabel,
|
||||
SidebarHeader,
|
||||
SidebarInput,
|
||||
SidebarInset,
|
||||
SidebarMenu,
|
||||
SidebarMenuAction,
|
||||
SidebarMenuBadge,
|
||||
SidebarMenuButton,
|
||||
SidebarMenuItem,
|
||||
SidebarMenuSkeleton,
|
||||
SidebarMenuSub,
|
||||
SidebarMenuSubButton,
|
||||
SidebarMenuSubItem,
|
||||
SidebarProvider,
|
||||
SidebarRail,
|
||||
SidebarSeparator,
|
||||
SidebarTrigger,
|
||||
useSidebar,
|
||||
};
|
||||
@@ -0,0 +1,13 @@
|
||||
import { cn } from "cn";
|
||||
|
||||
function Skeleton({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="skeleton"
|
||||
className={cn("animate-pulse rounded-md bg-muted", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export { Skeleton };
|
||||
@@ -0,0 +1,45 @@
|
||||
"use client";
|
||||
|
||||
import { useTheme } from "next-themes";
|
||||
import { Toaster as Sonner, type ToasterProps } from "sonner";
|
||||
import {
|
||||
CircleCheckIcon,
|
||||
InfoIcon,
|
||||
TriangleAlertIcon,
|
||||
OctagonXIcon,
|
||||
Loader2Icon,
|
||||
} from "lucide-react";
|
||||
|
||||
const Toaster = ({ ...props }: ToasterProps) => {
|
||||
const { theme = "system" } = useTheme();
|
||||
|
||||
return (
|
||||
<Sonner
|
||||
theme={theme as ToasterProps["theme"]}
|
||||
className="toaster group"
|
||||
icons={{
|
||||
success: <CircleCheckIcon className="size-4" />,
|
||||
info: <InfoIcon className="size-4" />,
|
||||
warning: <TriangleAlertIcon className="size-4" />,
|
||||
error: <OctagonXIcon className="size-4" />,
|
||||
loading: <Loader2Icon className="size-4 animate-spin" />,
|
||||
}}
|
||||
style={
|
||||
{
|
||||
"--normal-bg": "var(--popover)",
|
||||
"--normal-text": "var(--popover-foreground)",
|
||||
"--normal-border": "var(--border)",
|
||||
"--border-radius": "var(--radius)",
|
||||
} as React.CSSProperties
|
||||
}
|
||||
toastOptions={{
|
||||
classNames: {
|
||||
toast: "cn-toast",
|
||||
},
|
||||
}}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export { Toaster };
|
||||
@@ -0,0 +1,88 @@
|
||||
"use client";
|
||||
|
||||
import * as React from "react";
|
||||
import { cn } from "cn";
|
||||
|
||||
function Table({ className, ...props }: React.ComponentProps<"table">) {
|
||||
return (
|
||||
<div data-slot="table-container" className="relative w-full overflow-x-auto">
|
||||
<table
|
||||
data-slot="table"
|
||||
className={cn("w-full caption-bottom text-sm", className)}
|
||||
{...props}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function TableHeader({ className, ...props }: React.ComponentProps<"thead">) {
|
||||
return <thead data-slot="table-header" className={cn("[&_tr]:border-b", className)} {...props} />;
|
||||
}
|
||||
|
||||
function TableBody({ className, ...props }: React.ComponentProps<"tbody">) {
|
||||
return (
|
||||
<tbody
|
||||
data-slot="table-body"
|
||||
className={cn("[&_tr:last-child]:border-0", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function TableFooter({ className, ...props }: React.ComponentProps<"tfoot">) {
|
||||
return (
|
||||
<tfoot
|
||||
data-slot="table-footer"
|
||||
className={cn("border-t bg-muted/50 font-medium [&>tr]:last:border-b-0", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function TableRow({ className, ...props }: React.ComponentProps<"tr">) {
|
||||
return (
|
||||
<tr
|
||||
data-slot="table-row"
|
||||
className={cn(
|
||||
"border-b transition-colors hover:bg-muted/50 has-aria-expanded:bg-muted/50 data-[state=selected]:bg-muted",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function TableHead({ className, ...props }: React.ComponentProps<"th">) {
|
||||
return (
|
||||
<th
|
||||
data-slot="table-head"
|
||||
className={cn(
|
||||
"h-10 px-2 text-left align-middle font-medium whitespace-nowrap text-foreground [&:has([role=checkbox])]:pr-0",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function TableCell({ className, ...props }: React.ComponentProps<"td">) {
|
||||
return (
|
||||
<td
|
||||
data-slot="table-cell"
|
||||
className={cn("p-2 align-middle whitespace-nowrap [&:has([role=checkbox])]:pr-0", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function TableCaption({ className, ...props }: React.ComponentProps<"caption">) {
|
||||
return (
|
||||
<caption
|
||||
data-slot="table-caption"
|
||||
className={cn("mt-4 text-sm text-muted-foreground", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export { Table, TableHeader, TableBody, TableFooter, TableHead, TableRow, TableCell, TableCaption };
|
||||
@@ -0,0 +1,79 @@
|
||||
"use client";
|
||||
|
||||
import * as React from "react";
|
||||
import { cva, type VariantProps } from "class-variance-authority";
|
||||
import { cn } from "cn";
|
||||
import { Tabs as TabsPrimitive } from "radix-ui";
|
||||
|
||||
function Tabs({
|
||||
className,
|
||||
orientation = "horizontal",
|
||||
...props
|
||||
}: React.ComponentProps<typeof TabsPrimitive.Root>) {
|
||||
return (
|
||||
<TabsPrimitive.Root
|
||||
data-slot="tabs"
|
||||
data-orientation={orientation}
|
||||
className={cn("group/tabs flex gap-2 data-horizontal:flex-col", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
const tabsListVariants = cva(
|
||||
"group/tabs-list inline-flex w-fit items-center justify-center rounded-lg p-[3px] text-muted-foreground group-data-horizontal/tabs:h-8 group-data-vertical/tabs:h-fit group-data-vertical/tabs:flex-col data-[variant=line]:rounded-none",
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default: "bg-muted",
|
||||
line: "gap-1 bg-transparent",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: "default",
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
function TabsList({
|
||||
className,
|
||||
variant = "default",
|
||||
...props
|
||||
}: React.ComponentProps<typeof TabsPrimitive.List> & VariantProps<typeof tabsListVariants>) {
|
||||
return (
|
||||
<TabsPrimitive.List
|
||||
data-slot="tabs-list"
|
||||
data-variant={variant}
|
||||
className={cn(tabsListVariants({ variant }), className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function TabsTrigger({ className, ...props }: React.ComponentProps<typeof TabsPrimitive.Trigger>) {
|
||||
return (
|
||||
<TabsPrimitive.Trigger
|
||||
data-slot="tabs-trigger"
|
||||
className={cn(
|
||||
"relative inline-flex h-[calc(100%-1px)] flex-1 items-center justify-center gap-1.5 rounded-md border border-transparent px-1.5 py-0.5 text-sm font-medium whitespace-nowrap text-foreground/60 transition-all group-data-vertical/tabs:w-full group-data-vertical/tabs:justify-start hover:text-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:outline-1 focus-visible:outline-ring disabled:pointer-events-none disabled:opacity-50 has-data-[icon=inline-end]:pr-1 has-data-[icon=inline-start]:pl-1 dark:text-muted-foreground dark:hover:text-foreground group-data-[variant=default]/tabs-list:data-active:shadow-sm group-data-[variant=line]/tabs-list:data-active:shadow-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||
"group-data-[variant=line]/tabs-list:bg-transparent group-data-[variant=line]/tabs-list:data-active:bg-transparent dark:group-data-[variant=line]/tabs-list:data-active:border-transparent dark:group-data-[variant=line]/tabs-list:data-active:bg-transparent",
|
||||
"data-active:bg-background data-active:text-foreground dark:data-active:border-input dark:data-active:bg-input/30 dark:data-active:text-foreground",
|
||||
"after:absolute after:bg-foreground after:opacity-0 after:transition-opacity group-data-horizontal/tabs:after:inset-x-0 group-data-horizontal/tabs:after:bottom-[-5px] group-data-horizontal/tabs:after:h-0.5 group-data-vertical/tabs:after:inset-y-0 group-data-vertical/tabs:after:-right-1 group-data-vertical/tabs:after:w-0.5 group-data-[variant=line]/tabs-list:data-active:after:opacity-100",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function TabsContent({ className, ...props }: React.ComponentProps<typeof TabsPrimitive.Content>) {
|
||||
return (
|
||||
<TabsPrimitive.Content
|
||||
data-slot="tabs-content"
|
||||
className={cn("flex-1 text-sm outline-none", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export { Tabs, TabsList, TabsTrigger, TabsContent, tabsListVariants };
|
||||
@@ -0,0 +1,17 @@
|
||||
import * as React from "react";
|
||||
import { cn } from "cn";
|
||||
|
||||
function Textarea({ className, ...props }: React.ComponentProps<"textarea">) {
|
||||
return (
|
||||
<textarea
|
||||
data-slot="textarea"
|
||||
className={cn(
|
||||
"flex field-sizing-content min-h-16 w-full rounded-lg border border-input bg-transparent px-2.5 py-2 text-base transition-colors outline-none placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:bg-input/50 disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 md:text-sm dark:bg-input/30 dark:disabled:bg-input/80 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export { Textarea };
|
||||
@@ -0,0 +1,52 @@
|
||||
"use client";
|
||||
|
||||
import * as React from "react";
|
||||
import { cn } from "cn";
|
||||
import { Tooltip as TooltipPrimitive } from "radix-ui";
|
||||
|
||||
function TooltipProvider({
|
||||
delayDuration = 0,
|
||||
...props
|
||||
}: React.ComponentProps<typeof TooltipPrimitive.Provider>) {
|
||||
return (
|
||||
<TooltipPrimitive.Provider
|
||||
data-slot="tooltip-provider"
|
||||
delayDuration={delayDuration}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function Tooltip({ ...props }: React.ComponentProps<typeof TooltipPrimitive.Root>) {
|
||||
return <TooltipPrimitive.Root data-slot="tooltip" {...props} />;
|
||||
}
|
||||
|
||||
function TooltipTrigger({ ...props }: React.ComponentProps<typeof TooltipPrimitive.Trigger>) {
|
||||
return <TooltipPrimitive.Trigger data-slot="tooltip-trigger" {...props} />;
|
||||
}
|
||||
|
||||
function TooltipContent({
|
||||
className,
|
||||
sideOffset = 0,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<typeof TooltipPrimitive.Content>) {
|
||||
return (
|
||||
<TooltipPrimitive.Portal>
|
||||
<TooltipPrimitive.Content
|
||||
data-slot="tooltip-content"
|
||||
sideOffset={sideOffset}
|
||||
className={cn(
|
||||
"z-50 inline-flex w-fit max-w-xs origin-(--radix-tooltip-content-transform-origin) items-center gap-1.5 rounded-md bg-foreground px-3 py-1.5 text-xs text-background has-data-[slot=kbd]:pr-1.5 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 **:data-[slot=kbd]:relative **:data-[slot=kbd]:isolate **:data-[slot=kbd]:z-50 **:data-[slot=kbd]:rounded-sm data-[state=delayed-open]:animate-in data-[state=delayed-open]:fade-in-0 data-[state=delayed-open]:zoom-in-95 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
<TooltipPrimitive.Arrow className="z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px] bg-foreground fill-foreground" />
|
||||
</TooltipPrimitive.Content>
|
||||
</TooltipPrimitive.Portal>
|
||||
);
|
||||
}
|
||||
|
||||
export { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger };
|
||||
@@ -0,0 +1,219 @@
|
||||
"use client";
|
||||
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { Loader2 } from "lucide-react";
|
||||
import { useEffect, useState } from "react";
|
||||
import { Controller, useForm } from "react-hook-form";
|
||||
import { PasswordInput } from "@/components/password-input";
|
||||
import { ResponsiveDialog } from "@/components/responsive-dialog";
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from "@/components/ui/alert-dialog";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Field, FieldDescription, FieldError, FieldGroup, FieldLabel } from "@/components/ui/field";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import { tr } from "@/i18n/tr";
|
||||
import type { ActionResult } from "@/lib/action-result";
|
||||
import {
|
||||
banUserSchema,
|
||||
setPasswordSchema,
|
||||
type BanUserInput,
|
||||
type SetPasswordInput,
|
||||
} from "@/shared/schemas/user";
|
||||
import type { AdminUser } from "../types";
|
||||
|
||||
const t = tr.adminUsers;
|
||||
|
||||
type DialogProps<T> = {
|
||||
user: AdminUser | undefined;
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
onConfirm: (user: AdminUser, values: T) => Promise<ActionResult>;
|
||||
};
|
||||
|
||||
export function SetPasswordDialog({
|
||||
user,
|
||||
open,
|
||||
onOpenChange,
|
||||
onConfirm,
|
||||
}: DialogProps<{ password: string }>) {
|
||||
const form = useForm<SetPasswordInput>({
|
||||
resolver: zodResolver(setPasswordSchema),
|
||||
defaultValues: { password: "" },
|
||||
});
|
||||
useEffect(() => {
|
||||
if (open) form.reset({ password: "" });
|
||||
}, [open, form]);
|
||||
|
||||
async function onSubmit(values: SetPasswordInput) {
|
||||
if (!user) return;
|
||||
const result = await onConfirm(user, values);
|
||||
if (result.ok) onOpenChange(false);
|
||||
else form.setError("root", { message: result.error });
|
||||
}
|
||||
|
||||
return (
|
||||
<ResponsiveDialog
|
||||
open={open}
|
||||
onOpenChange={onOpenChange}
|
||||
title={t.password.title}
|
||||
description={user ? t.password.description(user.name) : undefined}
|
||||
footer={
|
||||
<>
|
||||
<Button variant="outline" type="button" onClick={() => onOpenChange(false)}>
|
||||
{tr.common.cancel}
|
||||
</Button>
|
||||
<Button type="submit" form="password-form" disabled={form.formState.isSubmitting}>
|
||||
{form.formState.isSubmitting ? <Loader2 className="animate-spin" /> : null}
|
||||
{t.password.confirm}
|
||||
</Button>
|
||||
</>
|
||||
}
|
||||
>
|
||||
<form id="password-form" onSubmit={form.handleSubmit(onSubmit)} noValidate>
|
||||
<FieldGroup>
|
||||
<Controller
|
||||
name="password"
|
||||
control={form.control}
|
||||
render={({ field, fieldState }) => (
|
||||
<Field data-invalid={fieldState.invalid}>
|
||||
<FieldLabel htmlFor="new-password">{t.password.newPassword}</FieldLabel>
|
||||
<PasswordInput
|
||||
{...field}
|
||||
id="new-password"
|
||||
autoComplete="new-password"
|
||||
aria-invalid={fieldState.invalid}
|
||||
aria-describedby="new-password-hint"
|
||||
/>
|
||||
<FieldDescription id="new-password-hint">{t.form.passwordHint}</FieldDescription>
|
||||
{fieldState.invalid ? <FieldError errors={[fieldState.error]} /> : null}
|
||||
</Field>
|
||||
)}
|
||||
/>
|
||||
{form.formState.errors.root ? (
|
||||
<FieldError>{form.formState.errors.root.message}</FieldError>
|
||||
) : null}
|
||||
</FieldGroup>
|
||||
</form>
|
||||
</ResponsiveDialog>
|
||||
);
|
||||
}
|
||||
|
||||
export function BanUserDialog({
|
||||
user,
|
||||
open,
|
||||
onOpenChange,
|
||||
onConfirm,
|
||||
}: DialogProps<{ reason?: string }>) {
|
||||
const form = useForm<BanUserInput, unknown, { reason?: string }>({
|
||||
resolver: zodResolver(banUserSchema),
|
||||
defaultValues: { reason: "" },
|
||||
});
|
||||
useEffect(() => {
|
||||
if (open) form.reset({ reason: "" });
|
||||
}, [open, form]);
|
||||
|
||||
async function onSubmit(values: { reason?: string }) {
|
||||
if (!user) return;
|
||||
const result = await onConfirm(user, values);
|
||||
if (result.ok) onOpenChange(false);
|
||||
else form.setError("root", { message: result.error });
|
||||
}
|
||||
|
||||
return (
|
||||
<ResponsiveDialog
|
||||
open={open}
|
||||
onOpenChange={onOpenChange}
|
||||
title={t.ban.title}
|
||||
description={user ? t.ban.description(user.name) : undefined}
|
||||
footer={
|
||||
<>
|
||||
<Button variant="outline" type="button" onClick={() => onOpenChange(false)}>
|
||||
{tr.common.cancel}
|
||||
</Button>
|
||||
<Button
|
||||
type="submit"
|
||||
form="ban-form"
|
||||
variant="destructive"
|
||||
disabled={form.formState.isSubmitting}
|
||||
>
|
||||
{form.formState.isSubmitting ? <Loader2 className="animate-spin" /> : null}
|
||||
{t.ban.confirm}
|
||||
</Button>
|
||||
</>
|
||||
}
|
||||
>
|
||||
<form id="ban-form" onSubmit={form.handleSubmit(onSubmit)} noValidate>
|
||||
<FieldGroup>
|
||||
<Controller
|
||||
name="reason"
|
||||
control={form.control}
|
||||
render={({ field, fieldState }) => (
|
||||
<Field data-invalid={fieldState.invalid}>
|
||||
<FieldLabel htmlFor="ban-reason">{t.ban.reason}</FieldLabel>
|
||||
<Textarea
|
||||
{...field}
|
||||
value={field.value ?? ""}
|
||||
id="ban-reason"
|
||||
rows={3}
|
||||
aria-invalid={fieldState.invalid}
|
||||
/>
|
||||
{fieldState.invalid ? <FieldError errors={[fieldState.error]} /> : null}
|
||||
</Field>
|
||||
)}
|
||||
/>
|
||||
{form.formState.errors.root ? (
|
||||
<FieldError>{form.formState.errors.root.message}</FieldError>
|
||||
) : null}
|
||||
</FieldGroup>
|
||||
</form>
|
||||
</ResponsiveDialog>
|
||||
);
|
||||
}
|
||||
|
||||
export function DeleteUserDialog({ user, open, onOpenChange, onConfirm }: DialogProps<void>) {
|
||||
const [pending, setPending] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
function handleOpenChange(next: boolean) {
|
||||
if (!next) setError(null);
|
||||
onOpenChange(next);
|
||||
}
|
||||
|
||||
async function confirm() {
|
||||
if (!user) return;
|
||||
setPending(true);
|
||||
const result = await onConfirm(user, undefined);
|
||||
setPending(false);
|
||||
if (result.ok) handleOpenChange(false);
|
||||
else setError(result.error);
|
||||
}
|
||||
|
||||
return (
|
||||
<AlertDialog open={open} onOpenChange={handleOpenChange}>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>{t.remove.title}</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
{user ? t.remove.description(user.name) : null}
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
{error ? <FieldError>{error}</FieldError> : null}
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel disabled={pending}>{tr.common.cancel}</AlertDialogCancel>
|
||||
{/* AlertDialogAction otomatik kapanır; sonuç beklenmesi için normal düğme. */}
|
||||
<Button variant="destructive" onClick={confirm} disabled={pending}>
|
||||
{pending ? <Loader2 className="animate-spin" /> : null}
|
||||
{t.remove.confirm}
|
||||
</Button>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,226 @@
|
||||
"use client";
|
||||
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { Loader2 } from "lucide-react";
|
||||
import { useEffect } from "react";
|
||||
import { Controller, useForm, type Resolver } from "react-hook-form";
|
||||
import { PasswordInput } from "@/components/password-input";
|
||||
import { ResponsiveDialog } from "@/components/responsive-dialog";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Field, FieldDescription, FieldError, FieldGroup, FieldLabel } from "@/components/ui/field";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "@/components/ui/select";
|
||||
import { tr } from "@/i18n/tr";
|
||||
import type { ActionResult } from "@/lib/action-result";
|
||||
import { SYSTEM_ROLES } from "@/shared/schemas/common";
|
||||
import {
|
||||
userCreateSchema,
|
||||
userUpdateSchema,
|
||||
type UserCreate,
|
||||
type UserCreateInput,
|
||||
type UserUpdate,
|
||||
} from "@/shared/schemas/user";
|
||||
import type { AdminUser } from "../types";
|
||||
|
||||
const t = tr.adminUsers.form;
|
||||
const FORM_ID = "user-form";
|
||||
|
||||
type Props = {
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
/** Verilirse düzenleme modu. */
|
||||
user?: AdminUser;
|
||||
onCreate: (values: UserCreate) => Promise<ActionResult>;
|
||||
onUpdate: (id: string, values: UserUpdate) => Promise<ActionResult>;
|
||||
};
|
||||
|
||||
type FormOutput = UserCreate | UserUpdate;
|
||||
|
||||
const createResolver: Resolver<UserCreateInput, unknown, FormOutput> =
|
||||
zodResolver(userCreateSchema);
|
||||
/**
|
||||
* Düzenleme şeması şifre alanını içermez; zod nesnesi bilinmeyen alanı (boş "password") atar.
|
||||
* Form değer şekli aynı kaldığı için tip dönüşümü güvenlidir.
|
||||
*/
|
||||
const updateResolver = zodResolver(userUpdateSchema) as unknown as Resolver<
|
||||
UserCreateInput,
|
||||
unknown,
|
||||
FormOutput
|
||||
>;
|
||||
|
||||
const empty: UserCreateInput = { name: "", username: "", email: "", role: "user", password: "" };
|
||||
|
||||
export function UserFormDialog({ open, onOpenChange, user, onCreate, onUpdate }: Props) {
|
||||
const isEdit = Boolean(user);
|
||||
const form = useForm<UserCreateInput, unknown, FormOutput>({
|
||||
resolver: isEdit ? updateResolver : createResolver,
|
||||
defaultValues: empty,
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (open) {
|
||||
form.reset(
|
||||
user
|
||||
? {
|
||||
name: user.name,
|
||||
username: user.username,
|
||||
email: user.email ?? "",
|
||||
role: user.role,
|
||||
password: "",
|
||||
}
|
||||
: empty,
|
||||
);
|
||||
}
|
||||
}, [open, user, form]);
|
||||
|
||||
async function onSubmit(values: FormOutput) {
|
||||
const result = user ? await onUpdate(user.id, values) : await onCreate(values as UserCreate);
|
||||
if (result.ok) {
|
||||
onOpenChange(false);
|
||||
return;
|
||||
}
|
||||
for (const [name, message] of Object.entries(result.fieldErrors ?? {})) {
|
||||
if (message) form.setError(name as keyof UserCreateInput, { message });
|
||||
}
|
||||
if (!result.fieldErrors) form.setError("root", { message: result.error });
|
||||
}
|
||||
|
||||
const submitting = form.formState.isSubmitting;
|
||||
|
||||
return (
|
||||
<ResponsiveDialog
|
||||
open={open}
|
||||
onOpenChange={onOpenChange}
|
||||
title={isEdit ? t.editTitle : t.createTitle}
|
||||
description={isEdit ? t.editDescription : t.createDescription}
|
||||
footer={
|
||||
<>
|
||||
<Button variant="outline" type="button" onClick={() => onOpenChange(false)}>
|
||||
{tr.common.cancel}
|
||||
</Button>
|
||||
<Button type="submit" form={FORM_ID} disabled={submitting}>
|
||||
{submitting ? <Loader2 className="animate-spin" /> : null}
|
||||
{isEdit ? tr.common.save : tr.common.create}
|
||||
</Button>
|
||||
</>
|
||||
}
|
||||
>
|
||||
<form id={FORM_ID} onSubmit={form.handleSubmit(onSubmit)} noValidate>
|
||||
<FieldGroup>
|
||||
<Controller
|
||||
name="name"
|
||||
control={form.control}
|
||||
render={({ field, fieldState }) => (
|
||||
<Field data-invalid={fieldState.invalid}>
|
||||
<FieldLabel htmlFor="user-name">{t.name}</FieldLabel>
|
||||
<Input
|
||||
{...field}
|
||||
id="user-name"
|
||||
autoComplete="off"
|
||||
aria-invalid={fieldState.invalid}
|
||||
/>
|
||||
{fieldState.invalid ? <FieldError errors={[fieldState.error]} /> : null}
|
||||
</Field>
|
||||
)}
|
||||
/>
|
||||
<Controller
|
||||
name="username"
|
||||
control={form.control}
|
||||
render={({ field, fieldState }) => (
|
||||
<Field data-invalid={fieldState.invalid}>
|
||||
<FieldLabel htmlFor="user-username">{t.username}</FieldLabel>
|
||||
<Input
|
||||
{...field}
|
||||
id="user-username"
|
||||
autoComplete="off"
|
||||
autoCapitalize="none"
|
||||
spellCheck={false}
|
||||
aria-invalid={fieldState.invalid}
|
||||
aria-describedby="user-username-hint"
|
||||
/>
|
||||
<FieldDescription id="user-username-hint">{t.usernameHint}</FieldDescription>
|
||||
{fieldState.invalid ? <FieldError errors={[fieldState.error]} /> : null}
|
||||
</Field>
|
||||
)}
|
||||
/>
|
||||
<Controller
|
||||
name="email"
|
||||
control={form.control}
|
||||
render={({ field, fieldState }) => (
|
||||
<Field data-invalid={fieldState.invalid}>
|
||||
<FieldLabel htmlFor="user-email">{t.email}</FieldLabel>
|
||||
<Input
|
||||
{...field}
|
||||
value={field.value ?? ""}
|
||||
id="user-email"
|
||||
type="email"
|
||||
inputMode="email"
|
||||
autoComplete="off"
|
||||
aria-invalid={fieldState.invalid}
|
||||
aria-describedby="user-email-hint"
|
||||
/>
|
||||
<FieldDescription id="user-email-hint">{t.emailHint}</FieldDescription>
|
||||
{fieldState.invalid ? <FieldError errors={[fieldState.error]} /> : null}
|
||||
</Field>
|
||||
)}
|
||||
/>
|
||||
<Controller
|
||||
name="role"
|
||||
control={form.control}
|
||||
render={({ field, fieldState }) => (
|
||||
<Field data-invalid={fieldState.invalid}>
|
||||
<FieldLabel htmlFor="user-role">{t.role}</FieldLabel>
|
||||
<Select name={field.name} value={field.value} onValueChange={field.onChange}>
|
||||
<SelectTrigger
|
||||
id="user-role"
|
||||
aria-invalid={fieldState.invalid}
|
||||
onBlur={field.onBlur}
|
||||
>
|
||||
<SelectValue>{tr.roles[field.value]}</SelectValue>
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{SYSTEM_ROLES.map((r) => (
|
||||
<SelectItem key={r} value={r}>
|
||||
{tr.roles[r]}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
{fieldState.invalid ? <FieldError errors={[fieldState.error]} /> : null}
|
||||
</Field>
|
||||
)}
|
||||
/>
|
||||
{!isEdit ? (
|
||||
<Controller
|
||||
name="password"
|
||||
control={form.control}
|
||||
render={({ field, fieldState }) => (
|
||||
<Field data-invalid={fieldState.invalid}>
|
||||
<FieldLabel htmlFor="user-password">{t.password}</FieldLabel>
|
||||
<PasswordInput
|
||||
{...field}
|
||||
id="user-password"
|
||||
autoComplete="new-password"
|
||||
aria-invalid={fieldState.invalid}
|
||||
aria-describedby="user-password-hint"
|
||||
/>
|
||||
<FieldDescription id="user-password-hint">{t.passwordHint}</FieldDescription>
|
||||
{fieldState.invalid ? <FieldError errors={[fieldState.error]} /> : null}
|
||||
</Field>
|
||||
)}
|
||||
/>
|
||||
) : null}
|
||||
{form.formState.errors.root ? (
|
||||
<FieldError>{form.formState.errors.root.message}</FieldError>
|
||||
) : null}
|
||||
</FieldGroup>
|
||||
</form>
|
||||
</ResponsiveDialog>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,572 @@
|
||||
"use client";
|
||||
|
||||
import {
|
||||
ArrowDown,
|
||||
ArrowUp,
|
||||
ArrowUpDown,
|
||||
Ban,
|
||||
ChevronLeft,
|
||||
ChevronRight,
|
||||
KeyRound,
|
||||
MoreHorizontal,
|
||||
Pencil,
|
||||
Plus,
|
||||
Search,
|
||||
ShieldCheck,
|
||||
ShieldOff,
|
||||
Trash2,
|
||||
UserCheck,
|
||||
} from "lucide-react";
|
||||
import { createContext, use, useState } from "react";
|
||||
import { toast } from "sonner";
|
||||
import {
|
||||
columnFilteringFeature,
|
||||
createColumnHelper,
|
||||
createFilteredRowModel,
|
||||
createPaginatedRowModel,
|
||||
createSortedRowModel,
|
||||
globalFilteringFeature,
|
||||
rowPaginationFeature,
|
||||
rowSortingFeature,
|
||||
tableFeatures,
|
||||
useTable,
|
||||
type SortFn,
|
||||
} from "@tanstack/react-table";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuLabel,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
import { InputGroup, InputGroupAddon, InputGroupInput } from "@/components/ui/input-group";
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "@/components/ui/select";
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
TableCell,
|
||||
TableHead,
|
||||
TableHeader,
|
||||
TableRow,
|
||||
} from "@/components/ui/table";
|
||||
import { tr } from "@/i18n/tr";
|
||||
import { fail, ok, type ActionResult } from "@/lib/action-result";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { formatDate } from "@/shared/format";
|
||||
import type { SystemRole } from "@/shared/schemas/common";
|
||||
import type { UserCreate, UserUpdate } from "@/shared/schemas/user";
|
||||
import { compareTr, includesTr } from "@/shared/search";
|
||||
import {
|
||||
checkAdminAction,
|
||||
findUniqueConflicts,
|
||||
type AdminAction,
|
||||
type GuardViolation,
|
||||
} from "../guards";
|
||||
import type { AdminUser } from "../types";
|
||||
import { BanUserDialog, DeleteUserDialog, SetPasswordDialog } from "./user-action-dialogs";
|
||||
import { UserFormDialog } from "./user-form-dialog";
|
||||
|
||||
const t = tr.adminUsers;
|
||||
|
||||
// --- Tablo yapılandırması (modül seviyesinde sabit: v9 kararlı girdi ister) ---
|
||||
|
||||
const features = tableFeatures({
|
||||
rowSortingFeature,
|
||||
sortedRowModel: createSortedRowModel(),
|
||||
columnFilteringFeature,
|
||||
globalFilteringFeature,
|
||||
filteredRowModel: createFilteredRowModel(),
|
||||
rowPaginationFeature,
|
||||
paginatedRowModel: createPaginatedRowModel(),
|
||||
});
|
||||
|
||||
const byTr: SortFn<typeof features, AdminUser> = (a, b, id) =>
|
||||
compareTr(String(a.getValue(id) ?? ""), String(b.getValue(id) ?? ""));
|
||||
|
||||
const helper = createColumnHelper<typeof features, AdminUser>();
|
||||
|
||||
/** Mobilde gizlenen sütunlar. */
|
||||
const COLUMN_CLASS: Partial<Record<string, string>> = {
|
||||
username: "hidden sm:table-cell",
|
||||
email: "hidden lg:table-cell",
|
||||
createdAt: "hidden md:table-cell",
|
||||
actions: "w-12 text-right",
|
||||
};
|
||||
|
||||
const PAGE_SIZES = [10, 20, 50] as const;
|
||||
|
||||
type DialogState =
|
||||
{ kind: "create" } | { kind: "edit" | "password" | "ban" | "delete"; user: AdminUser } | null;
|
||||
|
||||
function SortableHeader({
|
||||
label,
|
||||
sorted,
|
||||
onToggle,
|
||||
}: {
|
||||
label: string;
|
||||
sorted: false | "asc" | "desc";
|
||||
onToggle: ((event: unknown) => void) | undefined;
|
||||
}) {
|
||||
const Icon = sorted === "asc" ? ArrowUp : sorted === "desc" ? ArrowDown : ArrowUpDown;
|
||||
return (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="-ml-2.5"
|
||||
onClick={onToggle}
|
||||
aria-label={`${label} — sırala`}
|
||||
>
|
||||
{label}
|
||||
<Icon className={cn("size-3.5", !sorted && "opacity-40")} />
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
|
||||
type RowActionsApi = {
|
||||
currentUserId: string;
|
||||
guard: (action: AdminAction, target: AdminUser) => GuardViolation | null;
|
||||
guardMessage: (v: GuardViolation) => string;
|
||||
setDialog: (d: DialogState) => void;
|
||||
setRole: (user: AdminUser, role: SystemRole) => void;
|
||||
unbanUser: (user: AdminUser) => void;
|
||||
};
|
||||
|
||||
/** Satır aksiyonları güncel durumu context'ten okur; sütunlar modül seviyesinde sabit kalır. */
|
||||
const RowActionsContext = createContext<RowActionsApi | null>(null);
|
||||
|
||||
function useRowActions() {
|
||||
const ctx = use(RowActionsContext);
|
||||
if (!ctx) throw new Error("RowActionsContext eksik");
|
||||
return ctx;
|
||||
}
|
||||
|
||||
function NameCell({ user }: { user: AdminUser }) {
|
||||
const { currentUserId } = useRowActions();
|
||||
return (
|
||||
<div className="flex min-w-0 flex-col">
|
||||
<span className="truncate font-medium">
|
||||
{user.name}
|
||||
{user.id === currentUserId ? (
|
||||
<span className="ml-1.5 text-xs font-normal text-muted-foreground">({t.you})</span>
|
||||
) : null}
|
||||
</span>
|
||||
<span className="truncate text-xs text-muted-foreground sm:hidden">@{user.username}</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function RowActions({ user }: { user: AdminUser }) {
|
||||
const { guard, guardMessage, setDialog, setRole, unbanUser } = useRowActions();
|
||||
const del = guard({ type: "delete" }, user);
|
||||
const ban = guard({ type: "ban" }, user);
|
||||
const toggleRole: SystemRole = user.role === "admin" ? "user" : "admin";
|
||||
const role = guard({ type: "setRole", role: toggleRole }, user);
|
||||
const blocked = del ?? role;
|
||||
return (
|
||||
// modal={false}: menüden açılan Dialog kapandıktan sonra sayfanın kilitli kalmasını önler.
|
||||
<DropdownMenu modal={false}>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="ghost" size="icon-sm" aria-label={`${user.name} — ${tr.common.actions}`}>
|
||||
<MoreHorizontal />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end" className="w-56">
|
||||
<DropdownMenuLabel className="truncate">{user.name}</DropdownMenuLabel>
|
||||
<DropdownMenuItem onSelect={() => setDialog({ kind: "edit", user })}>
|
||||
<Pencil />
|
||||
{t.actions.edit}
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem disabled={Boolean(role)} onSelect={() => setRole(user, toggleRole)}>
|
||||
{toggleRole === "admin" ? <ShieldCheck /> : <ShieldOff />}
|
||||
{toggleRole === "admin" ? t.actions.makeAdmin : t.actions.makeUser}
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem onSelect={() => setDialog({ kind: "password", user })}>
|
||||
<KeyRound />
|
||||
{t.actions.resetPassword}
|
||||
</DropdownMenuItem>
|
||||
{user.banned ? (
|
||||
<DropdownMenuItem onSelect={() => unbanUser(user)}>
|
||||
<UserCheck />
|
||||
{t.actions.unban}
|
||||
</DropdownMenuItem>
|
||||
) : (
|
||||
<DropdownMenuItem
|
||||
disabled={Boolean(ban)}
|
||||
onSelect={() => setDialog({ kind: "ban", user })}
|
||||
>
|
||||
<Ban />
|
||||
{t.actions.ban}
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem
|
||||
variant="destructive"
|
||||
disabled={Boolean(del)}
|
||||
onSelect={() => setDialog({ kind: "delete", user })}
|
||||
>
|
||||
<Trash2 />
|
||||
{t.actions.delete}
|
||||
</DropdownMenuItem>
|
||||
{blocked ? (
|
||||
<p className="px-2 py-1.5 text-xs text-muted-foreground">{guardMessage(blocked)}</p>
|
||||
) : null}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
);
|
||||
}
|
||||
|
||||
const columns = helper.columns([
|
||||
helper.accessor("name", {
|
||||
header: ({ column }) => (
|
||||
<SortableHeader
|
||||
label={t.columns.name}
|
||||
sorted={column.getIsSorted()}
|
||||
onToggle={column.getToggleSortingHandler()}
|
||||
/>
|
||||
),
|
||||
sortFn: byTr,
|
||||
cell: ({ row }) => <NameCell user={row.original} />,
|
||||
}),
|
||||
helper.accessor("username", {
|
||||
header: ({ column }) => (
|
||||
<SortableHeader
|
||||
label={t.columns.username}
|
||||
sorted={column.getIsSorted()}
|
||||
onToggle={column.getToggleSortingHandler()}
|
||||
/>
|
||||
),
|
||||
sortFn: byTr,
|
||||
cell: ({ getValue }) => <span className="text-muted-foreground">@{getValue()}</span>,
|
||||
}),
|
||||
helper.accessor((u) => u.email ?? "", {
|
||||
id: "email",
|
||||
header: ({ column }) => (
|
||||
<SortableHeader
|
||||
label={t.columns.email}
|
||||
sorted={column.getIsSorted()}
|
||||
onToggle={column.getToggleSortingHandler()}
|
||||
/>
|
||||
),
|
||||
sortFn: byTr,
|
||||
cell: ({ getValue }) =>
|
||||
getValue() || <span className="text-muted-foreground">{t.noEmail}</span>,
|
||||
}),
|
||||
helper.accessor("role", {
|
||||
header: ({ column }) => (
|
||||
<SortableHeader
|
||||
label={t.columns.role}
|
||||
sorted={column.getIsSorted()}
|
||||
onToggle={column.getToggleSortingHandler()}
|
||||
/>
|
||||
),
|
||||
cell: ({ getValue }) => (
|
||||
<Badge variant={getValue() === "admin" ? "default" : "secondary"}>
|
||||
{tr.roles[getValue()]}
|
||||
</Badge>
|
||||
),
|
||||
}),
|
||||
helper.accessor("banned", {
|
||||
header: ({ column }) => (
|
||||
<SortableHeader
|
||||
label={t.columns.status}
|
||||
sorted={column.getIsSorted()}
|
||||
onToggle={column.getToggleSortingHandler()}
|
||||
/>
|
||||
),
|
||||
cell: ({ row }) =>
|
||||
row.original.banned ? (
|
||||
<Badge variant="destructive" title={row.original.banReason}>
|
||||
{t.status.banned}
|
||||
</Badge>
|
||||
) : (
|
||||
<Badge variant="outline" className="border-income/30 text-income">
|
||||
{t.status.active}
|
||||
</Badge>
|
||||
),
|
||||
}),
|
||||
helper.accessor("createdAt", {
|
||||
header: ({ column }) => (
|
||||
<SortableHeader
|
||||
label={t.columns.createdAt}
|
||||
sorted={column.getIsSorted()}
|
||||
onToggle={column.getToggleSortingHandler()}
|
||||
/>
|
||||
),
|
||||
cell: ({ getValue }) => <span className="tabular-nums">{formatDate(getValue())}</span>,
|
||||
}),
|
||||
helper.display({
|
||||
id: "actions",
|
||||
header: () => <span className="sr-only">{tr.common.actions}</span>,
|
||||
cell: ({ row }) => <RowActions user={row.original} />,
|
||||
}),
|
||||
]);
|
||||
|
||||
export function UsersTable({
|
||||
initialUsers,
|
||||
currentUserId,
|
||||
}: {
|
||||
initialUsers: AdminUser[];
|
||||
currentUserId: string;
|
||||
}) {
|
||||
// FAZ 3: yerel durum yerine Server Action + revalidatePath.
|
||||
const [users, setUsers] = useState(initialUsers);
|
||||
const [dialog, setDialog] = useState<DialogState>(null);
|
||||
const adminCount = users.filter((u) => u.role === "admin").length;
|
||||
|
||||
const guard = (action: AdminAction, target: AdminUser): GuardViolation | null =>
|
||||
checkAdminAction(action, { actorId: currentUserId, target, adminCount });
|
||||
|
||||
const guardMessage = (v: GuardViolation) => (v === "self" ? t.guards.self : t.guards.lastAdmin);
|
||||
|
||||
// --- Mock işlemler (FAZ 3'te Server Action'lara taşınacak; aynı ActionResult sözleşmesi) ---
|
||||
|
||||
async function createUser(values: UserCreate): Promise<ActionResult> {
|
||||
const conflicts = findUniqueConflicts(users, values);
|
||||
if (conflicts.username || conflicts.email) {
|
||||
return fail(t.errors.checkFields, {
|
||||
username: conflicts.username && t.errors.usernameTaken,
|
||||
email: conflicts.email && t.errors.emailTaken,
|
||||
});
|
||||
}
|
||||
const { password: _password, ...rest } = values;
|
||||
setUsers((prev) => [
|
||||
{
|
||||
...rest,
|
||||
id: `u_${crypto.randomUUID().slice(0, 8)}`,
|
||||
banned: false,
|
||||
createdAt: new Date().toISOString(),
|
||||
},
|
||||
...prev,
|
||||
]);
|
||||
toast.success(t.toast.created(values.name));
|
||||
return ok(undefined);
|
||||
}
|
||||
|
||||
async function updateUser(id: string, values: UserUpdate): Promise<ActionResult> {
|
||||
const target = users.find((u) => u.id === id);
|
||||
if (!target) return fail(tr.common.genericError);
|
||||
const conflicts = findUniqueConflicts(users, values, id);
|
||||
if (conflicts.username || conflicts.email) {
|
||||
return fail(t.errors.checkFields, {
|
||||
username: conflicts.username && t.errors.usernameTaken,
|
||||
email: conflicts.email && t.errors.emailTaken,
|
||||
});
|
||||
}
|
||||
const v =
|
||||
values.role !== target.role ? guard({ type: "setRole", role: values.role }, target) : null;
|
||||
if (v) return fail(guardMessage(v), { role: guardMessage(v) });
|
||||
setUsers((prev) => prev.map((u) => (u.id === id ? { ...u, ...values } : u)));
|
||||
toast.success(t.toast.updated(values.name));
|
||||
return ok(undefined);
|
||||
}
|
||||
|
||||
function setRole(user: AdminUser, role: SystemRole) {
|
||||
const v = guard({ type: "setRole", role }, user);
|
||||
if (v) return void toast.error(guardMessage(v));
|
||||
setUsers((prev) => prev.map((u) => (u.id === user.id ? { ...u, role } : u)));
|
||||
toast.success(t.toast.roleChanged(user.name));
|
||||
}
|
||||
|
||||
async function setPassword(user: AdminUser): Promise<ActionResult> {
|
||||
toast.success(t.toast.passwordSet(user.name));
|
||||
return ok(undefined);
|
||||
}
|
||||
|
||||
async function banUser(user: AdminUser, { reason }: { reason?: string }): Promise<ActionResult> {
|
||||
const v = guard({ type: "ban" }, user);
|
||||
if (v) return fail(guardMessage(v));
|
||||
setUsers((prev) =>
|
||||
prev.map((u) => (u.id === user.id ? { ...u, banned: true, banReason: reason } : u)),
|
||||
);
|
||||
toast.success(t.toast.banned(user.name));
|
||||
return ok(undefined);
|
||||
}
|
||||
|
||||
function unbanUser(user: AdminUser) {
|
||||
setUsers((prev) =>
|
||||
prev.map((u) => (u.id === user.id ? { ...u, banned: false, banReason: undefined } : u)),
|
||||
);
|
||||
toast.success(t.toast.unbanned(user.name));
|
||||
}
|
||||
|
||||
async function removeUser(user: AdminUser): Promise<ActionResult> {
|
||||
const v = guard({ type: "delete" }, user);
|
||||
if (v) return fail(guardMessage(v));
|
||||
setUsers((prev) => prev.filter((u) => u.id !== user.id));
|
||||
toast.success(t.toast.removed(user.name));
|
||||
return ok(undefined);
|
||||
}
|
||||
|
||||
const table = useTable({
|
||||
features,
|
||||
columns,
|
||||
data: users,
|
||||
// Türkçe, büyük/küçük harf ve aksan duyarsız arama (ad, kullanıcı adı, e-posta).
|
||||
globalFilterFn: (row, _columnId, filterValue) => {
|
||||
const q = String(filterValue ?? "");
|
||||
const u = row.original;
|
||||
return includesTr(u.name, q) || includesTr(u.username, q) || includesTr(u.email, q);
|
||||
},
|
||||
getColumnCanGlobalFilter: (column) => column.id !== "actions",
|
||||
initialState: {
|
||||
sorting: [{ id: "createdAt", desc: true }],
|
||||
pagination: { pageIndex: 0, pageSize: 10 },
|
||||
},
|
||||
});
|
||||
|
||||
const globalFilter = String(table.state.globalFilter ?? "");
|
||||
const pageCount = Math.max(table.getPageCount(), 1);
|
||||
const filteredCount = table.getFilteredRowModel().rows.length;
|
||||
const selected = dialog && dialog.kind !== "create" ? dialog.user : undefined;
|
||||
const close = (open: boolean) => !open && setDialog(null);
|
||||
|
||||
const rowActions: RowActionsApi = {
|
||||
currentUserId,
|
||||
guard,
|
||||
guardMessage,
|
||||
setDialog,
|
||||
setRole,
|
||||
unbanUser,
|
||||
};
|
||||
|
||||
return (
|
||||
<RowActionsContext value={rowActions}>
|
||||
<div className="flex flex-col gap-3">
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<InputGroup className="max-w-sm flex-1">
|
||||
<InputGroupAddon>
|
||||
<Search />
|
||||
</InputGroupAddon>
|
||||
<InputGroupInput
|
||||
type="search"
|
||||
value={globalFilter}
|
||||
onChange={(e) => table.setGlobalFilter(e.target.value)}
|
||||
placeholder={t.searchPlaceholder}
|
||||
aria-label={tr.common.search}
|
||||
/>
|
||||
</InputGroup>
|
||||
<Button className="ml-auto" onClick={() => setDialog({ kind: "create" })}>
|
||||
<Plus />
|
||||
{t.newUser}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<div className="overflow-hidden rounded-xl border bg-card">
|
||||
<Table>
|
||||
<TableHeader>
|
||||
{table.getHeaderGroups().map((group) => (
|
||||
<TableRow key={group.id}>
|
||||
{group.headers.map((header) => (
|
||||
<TableHead key={header.id} className={COLUMN_CLASS[header.column.id]}>
|
||||
{header.isPlaceholder ? null : <table.FlexRender header={header} />}
|
||||
</TableHead>
|
||||
))}
|
||||
</TableRow>
|
||||
))}
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{table.getRowModel().rows.length ? (
|
||||
table.getRowModel().rows.map((row) => (
|
||||
<TableRow key={row.id} className={cn(row.original.banned && "opacity-70")}>
|
||||
{row.getAllCells().map((cell) => (
|
||||
<TableCell key={cell.id} className={COLUMN_CLASS[cell.column.id]}>
|
||||
<table.FlexRender cell={cell} />
|
||||
</TableCell>
|
||||
))}
|
||||
</TableRow>
|
||||
))
|
||||
) : (
|
||||
<TableRow>
|
||||
<TableCell
|
||||
colSpan={columns.length}
|
||||
className="h-24 text-center text-muted-foreground"
|
||||
>
|
||||
{tr.common.noResults}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
)}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-wrap items-center justify-between gap-3 text-sm text-muted-foreground">
|
||||
<span>{tr.common.totalRows(filteredCount)}</span>
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="hidden sm:inline">{tr.common.rowsPerPage}</span>
|
||||
<Select
|
||||
value={String(table.state.pagination.pageSize)}
|
||||
onValueChange={(v) => table.setPageSize(Number(v))}
|
||||
>
|
||||
<SelectTrigger size="sm" aria-label={tr.common.rowsPerPage} className="w-18">
|
||||
<SelectValue>{table.state.pagination.pageSize}</SelectValue>
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{PAGE_SIZES.map((n) => (
|
||||
<SelectItem key={n} value={String(n)}>
|
||||
{n}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<span className="tabular-nums">
|
||||
{tr.common.page(table.state.pagination.pageIndex + 1, pageCount)}
|
||||
</span>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="icon-sm"
|
||||
onClick={() => table.previousPage()}
|
||||
disabled={!table.getCanPreviousPage()}
|
||||
aria-label={tr.common.previous}
|
||||
>
|
||||
<ChevronLeft />
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="icon-sm"
|
||||
onClick={() => table.nextPage()}
|
||||
disabled={!table.getCanNextPage()}
|
||||
aria-label={tr.common.next}
|
||||
>
|
||||
<ChevronRight />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<UserFormDialog
|
||||
open={dialog?.kind === "create" || dialog?.kind === "edit"}
|
||||
onOpenChange={close}
|
||||
user={dialog?.kind === "edit" ? dialog.user : undefined}
|
||||
onCreate={createUser}
|
||||
onUpdate={updateUser}
|
||||
/>
|
||||
<SetPasswordDialog
|
||||
user={selected}
|
||||
open={dialog?.kind === "password"}
|
||||
onOpenChange={close}
|
||||
onConfirm={setPassword}
|
||||
/>
|
||||
<BanUserDialog
|
||||
user={selected}
|
||||
open={dialog?.kind === "ban"}
|
||||
onOpenChange={close}
|
||||
onConfirm={banUser}
|
||||
/>
|
||||
<DeleteUserDialog
|
||||
user={selected}
|
||||
open={dialog?.kind === "delete"}
|
||||
onOpenChange={close}
|
||||
onConfirm={removeUser}
|
||||
/>
|
||||
</div>
|
||||
</RowActionsContext>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { checkAdminAction, findUniqueConflicts } from "./guards";
|
||||
|
||||
const admin = { id: "a1", role: "admin" as const };
|
||||
const user = { id: "u1", role: "user" as const };
|
||||
|
||||
describe("checkAdminAction", () => {
|
||||
it("admin kendini silemez, askıya alamaz, rolünü düşüremez", () => {
|
||||
const ctx = { actorId: "a1", target: admin, adminCount: 3 };
|
||||
expect(checkAdminAction({ type: "delete" }, ctx)).toBe("self");
|
||||
expect(checkAdminAction({ type: "ban" }, ctx)).toBe("self");
|
||||
expect(checkAdminAction({ type: "setRole", role: "user" }, ctx)).toBe("self");
|
||||
});
|
||||
|
||||
it("admin kendi bilgisini ve şifresini değiştirebilir", () => {
|
||||
const ctx = { actorId: "a1", target: admin, adminCount: 1 };
|
||||
expect(checkAdminAction({ type: "edit" }, ctx)).toBeNull();
|
||||
expect(checkAdminAction({ type: "setPassword" }, ctx)).toBeNull();
|
||||
expect(checkAdminAction({ type: "setRole", role: "admin" }, ctx)).toBeNull();
|
||||
});
|
||||
|
||||
it("son admin silinemez, askıya alınamaz, düşürülemez", () => {
|
||||
const ctx = { actorId: "x", target: admin, adminCount: 1 };
|
||||
expect(checkAdminAction({ type: "delete" }, ctx)).toBe("lastAdmin");
|
||||
expect(checkAdminAction({ type: "ban" }, ctx)).toBe("lastAdmin");
|
||||
expect(checkAdminAction({ type: "setRole", role: "user" }, ctx)).toBe("lastAdmin");
|
||||
});
|
||||
|
||||
it("birden çok admin varken başka bir admin düşürülebilir", () => {
|
||||
const ctx = { actorId: "x", target: admin, adminCount: 2 };
|
||||
expect(checkAdminAction({ type: "setRole", role: "user" }, ctx)).toBeNull();
|
||||
expect(checkAdminAction({ type: "delete" }, ctx)).toBeNull();
|
||||
});
|
||||
|
||||
it("normal kullanıcıya her işlem yapılabilir", () => {
|
||||
const ctx = { actorId: "a1", target: user, adminCount: 1 };
|
||||
for (const t of ["delete", "ban", "edit", "setPassword"] as const) {
|
||||
expect(checkAdminAction({ type: t }, ctx)).toBeNull();
|
||||
}
|
||||
expect(checkAdminAction({ type: "setRole", role: "admin" }, ctx)).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe("findUniqueConflicts", () => {
|
||||
const users = [
|
||||
{ id: "1", username: "ayse", email: "ayse@x.com" },
|
||||
{ id: "2", username: "emre" },
|
||||
];
|
||||
it("çakışan kullanıcı adı ve e-postayı bulur", () => {
|
||||
expect(findUniqueConflicts(users, { username: "ayse", email: "ayse@x.com" })).toEqual({
|
||||
username: "taken",
|
||||
email: "taken",
|
||||
});
|
||||
});
|
||||
it("düzenlenen kaydın kendisini saymaz, boş e-postayı kontrol etmez", () => {
|
||||
expect(findUniqueConflicts(users, { username: "ayse", email: "ayse@x.com" }, "1")).toEqual({});
|
||||
expect(findUniqueConflicts(users, { username: "yeni" })).toEqual({});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,52 @@
|
||||
import type { SystemRole } from "@/shared/schemas/common";
|
||||
|
||||
export type AdminAction =
|
||||
| { type: "delete" }
|
||||
| { type: "ban" }
|
||||
| { type: "setRole"; role: SystemRole }
|
||||
| { type: "edit" }
|
||||
| { type: "setPassword" };
|
||||
|
||||
export type GuardContext = {
|
||||
actorId: string;
|
||||
target: { id: string; role: SystemRole };
|
||||
/** Sistemdeki toplam admin sayısı (hedef dahil). */
|
||||
adminCount: number;
|
||||
};
|
||||
|
||||
export type GuardViolation = "self" | "lastAdmin";
|
||||
|
||||
/**
|
||||
* Admin işlem kuralları (arayüz ve sunucu aynı fonksiyonu kullanır):
|
||||
* - Admin kendini silemez, askıya alamaz ve kendi admin rolünü kaldıramaz.
|
||||
* - Sistemdeki son admin silinemez, askıya alınamaz veya rolü düşürülemez.
|
||||
*/
|
||||
export function checkAdminAction(action: AdminAction, ctx: GuardContext): GuardViolation | null {
|
||||
const isSelf = ctx.actorId === ctx.target.id;
|
||||
const removesAdmin =
|
||||
ctx.target.role === "admin" &&
|
||||
(action.type === "delete" ||
|
||||
action.type === "ban" ||
|
||||
(action.type === "setRole" && action.role !== "admin"));
|
||||
|
||||
if (isSelf && (action.type === "delete" || action.type === "ban" || removesAdmin)) {
|
||||
return "self";
|
||||
}
|
||||
if (removesAdmin && ctx.adminCount <= 1) return "lastAdmin";
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Kullanıcı adı / e-posta benzersizlik kontrolü (normalize edilmiş değerlerle). */
|
||||
export function findUniqueConflicts(
|
||||
users: ReadonlyArray<{ id: string; username: string; email?: string }>,
|
||||
values: { username: string; email?: string },
|
||||
excludeId?: string,
|
||||
): { username?: "taken"; email?: "taken" } {
|
||||
const others = users.filter((u) => u.id !== excludeId);
|
||||
return {
|
||||
...(others.some((u) => u.username === values.username) ? { username: "taken" as const } : {}),
|
||||
...(values.email && others.some((u) => u.email === values.email)
|
||||
? { email: "taken" as const }
|
||||
: {}),
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
import type { AdminUser } from "./types";
|
||||
|
||||
/** FAZ 2 GEÇİCİ: Faz 3'te Better Auth admin API'sinden gelen listeyle değiştirilecek. */
|
||||
export const MOCK_ADMIN_USERS: AdminUser[] = [
|
||||
{
|
||||
id: "u_admin",
|
||||
name: "Suphi Çakır",
|
||||
username: "suphi",
|
||||
email: "admin@butcem.local",
|
||||
role: "admin",
|
||||
banned: false,
|
||||
createdAt: "2026-05-02T08:00:00Z",
|
||||
},
|
||||
{
|
||||
id: "u_ayse",
|
||||
name: "Ayşe Çakır",
|
||||
username: "ayse",
|
||||
email: "ayse@butcem.local",
|
||||
role: "user",
|
||||
banned: false,
|
||||
createdAt: "2026-05-02T08:10:00Z",
|
||||
},
|
||||
{
|
||||
id: "u_emre",
|
||||
name: "Emre Çakır",
|
||||
username: "emre",
|
||||
role: "user",
|
||||
banned: false,
|
||||
createdAt: "2026-05-03T17:45:00Z",
|
||||
},
|
||||
{
|
||||
id: "u_zeynep",
|
||||
name: "Zeynep Çakır",
|
||||
username: "zeynep",
|
||||
role: "user",
|
||||
banned: false,
|
||||
createdAt: "2026-05-03T17:50:00Z",
|
||||
},
|
||||
{
|
||||
id: "u_fatma",
|
||||
name: "Fatma Demir",
|
||||
username: "fatma.demir",
|
||||
email: "fatma@butcem.local",
|
||||
role: "user",
|
||||
banned: false,
|
||||
createdAt: "2026-06-11T12:00:00Z",
|
||||
},
|
||||
{
|
||||
id: "u_mehmet",
|
||||
name: "Mehmet Demir",
|
||||
username: "mehmet.demir",
|
||||
email: "mehmet@butcem.local",
|
||||
role: "user",
|
||||
banned: false,
|
||||
createdAt: "2026-06-11T12:05:00Z",
|
||||
},
|
||||
{
|
||||
id: "u_ozan",
|
||||
name: "Ozan Kaya",
|
||||
username: "ozan",
|
||||
email: "ozan@butcem.local",
|
||||
role: "user",
|
||||
banned: true,
|
||||
banReason: "Eski ev arkadaşı",
|
||||
createdAt: "2026-07-20T09:30:00Z",
|
||||
},
|
||||
{
|
||||
id: "u_elif",
|
||||
name: "Elif Şahin",
|
||||
username: "elif_s",
|
||||
email: "elif@butcem.local",
|
||||
role: "user",
|
||||
banned: false,
|
||||
createdAt: "2026-08-14T19:15:00Z",
|
||||
},
|
||||
{
|
||||
id: "u_burak",
|
||||
name: "Burak Öztürk",
|
||||
username: "burak",
|
||||
email: "burak@butcem.local",
|
||||
role: "admin",
|
||||
banned: false,
|
||||
createdAt: "2026-09-01T06:40:00Z",
|
||||
},
|
||||
{
|
||||
id: "u_irem",
|
||||
name: "İrem Güneş",
|
||||
username: "irem",
|
||||
role: "user",
|
||||
banned: false,
|
||||
createdAt: "2026-09-22T15:00:00Z",
|
||||
},
|
||||
{
|
||||
id: "u_can",
|
||||
name: "Can Yıldız",
|
||||
username: "can.y",
|
||||
email: "can@butcem.local",
|
||||
role: "user",
|
||||
banned: false,
|
||||
createdAt: "2026-10-05T10:20:00Z",
|
||||
},
|
||||
{
|
||||
id: "u_selin",
|
||||
name: "Selin Aydın",
|
||||
username: "selin",
|
||||
email: "selin@butcem.local",
|
||||
role: "user",
|
||||
banned: false,
|
||||
createdAt: "2026-10-30T21:05:00Z",
|
||||
},
|
||||
];
|
||||
@@ -0,0 +1,14 @@
|
||||
import type { SystemRole } from "@/shared/schemas/common";
|
||||
|
||||
/** Admin kullanıcı listesindeki satır (Better Auth user kaydının arayüz özeti). */
|
||||
export type AdminUser = {
|
||||
id: string;
|
||||
name: string;
|
||||
username: string;
|
||||
email?: string;
|
||||
role: SystemRole;
|
||||
banned: boolean;
|
||||
banReason?: string;
|
||||
/** ISO tarih (UTC) */
|
||||
createdAt: string;
|
||||
};
|
||||
@@ -0,0 +1,13 @@
|
||||
import type { SessionUser } from "./types";
|
||||
|
||||
/**
|
||||
* FAZ 2 GEÇİCİ: Better Auth bağlanana kadar arayüzü besleyen sahte oturum.
|
||||
* Faz 3'te `requireSession()` (lib/dal.ts) ile değiştirilecek ve bu dosya silinecek.
|
||||
*/
|
||||
export const MOCK_SESSION_USER: SessionUser = {
|
||||
id: "u_admin",
|
||||
name: "Suphi Çakır",
|
||||
username: "suphi",
|
||||
email: "admin@butcem.local",
|
||||
role: "admin",
|
||||
};
|
||||
@@ -0,0 +1,11 @@
|
||||
import type { SystemRole } from "@/shared/schemas/common";
|
||||
|
||||
/** Oturumdaki kullanıcının arayüzde ihtiyaç duyulan özeti. */
|
||||
export type SessionUser = {
|
||||
id: string;
|
||||
name: string;
|
||||
username: string;
|
||||
email?: string;
|
||||
role: SystemRole;
|
||||
image?: string;
|
||||
};
|
||||
@@ -0,0 +1,16 @@
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import { tr } from "@/i18n/tr";
|
||||
|
||||
export function SummaryCardsSkeleton() {
|
||||
return (
|
||||
<div
|
||||
role="status"
|
||||
aria-label={tr.common.loading}
|
||||
className="grid grid-cols-2 gap-3 lg:grid-cols-3 xl:grid-cols-6"
|
||||
>
|
||||
{Array.from({ length: 6 }, (_, i) => (
|
||||
<Skeleton key={i} className="h-24 rounded-xl" />
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import type { HouseholdSummary } from "./types";
|
||||
|
||||
/** FAZ 2 GEÇİCİ: Faz 5'te kullanıcının üye olduğu hanelerle değiştirilecek. */
|
||||
export const MOCK_HOUSEHOLDS: HouseholdSummary[] = [
|
||||
{ id: "h_cakir", name: "Çakır Ailesi", role: "owner" },
|
||||
{ id: "h_anne", name: "Annemler", role: "viewer" },
|
||||
];
|
||||
@@ -0,0 +1,8 @@
|
||||
export const HOUSEHOLD_ROLES = ["owner", "member", "viewer"] as const;
|
||||
export type HouseholdRole = (typeof HOUSEHOLD_ROLES)[number];
|
||||
|
||||
export type HouseholdSummary = {
|
||||
id: string;
|
||||
name: string;
|
||||
role: HouseholdRole;
|
||||
};
|
||||
@@ -0,0 +1,22 @@
|
||||
import { useSyncExternalStore } from "react";
|
||||
|
||||
const MOBILE_BREAKPOINT = 768;
|
||||
const QUERY = `(max-width: ${MOBILE_BREAKPOINT - 1}px)`;
|
||||
|
||||
function subscribe(onChange: () => void) {
|
||||
const mql = window.matchMedia(QUERY);
|
||||
mql.addEventListener("change", onChange);
|
||||
return () => mql.removeEventListener("change", onChange);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ekran mobil genişlikte mi (< 768px)? Sunucuda ve hydration sırasında `false` döner,
|
||||
* ardından tarayıcı değerine geçer (effect içinde setState yok).
|
||||
*/
|
||||
export function useIsMobile() {
|
||||
return useSyncExternalStore(
|
||||
subscribe,
|
||||
() => window.matchMedia(QUERY).matches,
|
||||
() => false,
|
||||
);
|
||||
}
|
||||
@@ -1,15 +1,207 @@
|
||||
/**
|
||||
* Arayüz metinleri (tr-TR). Tüm kullanıcıya görünen metinler burada toplanır.
|
||||
* Arayüz metinleri (tr-TR). Kullanıcıya görünen tüm metinler burada toplanır.
|
||||
* Şimdilik tek dil; ileride çok dil gerekirse bu nesnenin şekli sözleşme olur.
|
||||
*/
|
||||
export const tr = {
|
||||
app: {
|
||||
name: "BÜTÇEM",
|
||||
tagline: "Aile bütçesi, birikim, ev stoğu ve akıllı alışveriş",
|
||||
setupInProgress: "Kurulum sürüyor",
|
||||
setupDescription: "Altyapı hazır. Giriş ekranı ve arayüz bir sonraki fazda eklenecek.",
|
||||
version: "Sürüm",
|
||||
},
|
||||
common: {
|
||||
save: "Kaydet",
|
||||
cancel: "Vazgeç",
|
||||
close: "Kapat",
|
||||
delete: "Sil",
|
||||
edit: "Düzenle",
|
||||
create: "Oluştur",
|
||||
search: "Ara",
|
||||
actions: "İşlemler",
|
||||
loading: "Yükleniyor…",
|
||||
comingSoon: "Yakında",
|
||||
required: "Bu alan zorunlu",
|
||||
yes: "Evet",
|
||||
no: "Hayır",
|
||||
previous: "Önceki",
|
||||
next: "Sonraki",
|
||||
noResults: "Sonuç bulunamadı.",
|
||||
page: (current: number, total: number) => `Sayfa ${current} / ${total}`,
|
||||
rowsPerPage: "Sayfa başına",
|
||||
totalRows: (n: number) => `Toplam ${n} kayıt`,
|
||||
showPassword: "Şifreyi göster",
|
||||
hidePassword: "Şifreyi gizle",
|
||||
genericError: "Beklenmeyen bir hata oluştu. Lütfen tekrar deneyin.",
|
||||
},
|
||||
theme: {
|
||||
label: "Tema",
|
||||
light: "Açık",
|
||||
dark: "Koyu",
|
||||
system: "Sistem",
|
||||
},
|
||||
nav: {
|
||||
main: "Menü",
|
||||
dashboard: "Ana sayfa",
|
||||
transactions: "İşlemler",
|
||||
accounts: "Hesaplar",
|
||||
budget: "Bütçe",
|
||||
planned: "Planlı işlemler",
|
||||
contacts: "Cari hesaplar",
|
||||
savings: "Birikim",
|
||||
stock: "Ev stoğu",
|
||||
shopping: "Alışveriş",
|
||||
reports: "Raporlar",
|
||||
settings: "Ayarlar",
|
||||
more: "Daha fazla",
|
||||
admin: "Yönetim",
|
||||
adminUsers: "Kullanıcılar",
|
||||
adminHouseholds: "Haneler",
|
||||
toggleSidebar: "Menüyü aç/kapat",
|
||||
},
|
||||
household: {
|
||||
label: "Aktif hane",
|
||||
select: "Hane seçin",
|
||||
roles: { owner: "Sahip", member: "Üye", viewer: "İzleyici" },
|
||||
},
|
||||
userMenu: {
|
||||
open: "Kullanıcı menüsü",
|
||||
profile: "Profil",
|
||||
logout: "Çıkış yap",
|
||||
loggedOut: "Çıkış yapıldı.",
|
||||
},
|
||||
roles: { admin: "Yönetici", user: "Kullanıcı" },
|
||||
quickAdd: {
|
||||
button: "Hızlı ekle",
|
||||
title: "Hızlı ekle",
|
||||
description: "Ne eklemek istiyorsunuz?",
|
||||
expense: "Gider",
|
||||
income: "Gelir",
|
||||
transfer: "Transfer",
|
||||
expenseHint: "Harcama, fatura, alışveriş",
|
||||
incomeHint: "Maaş, ek gelir, iade",
|
||||
transferHint: "Hesaplar ve cariler arası",
|
||||
notYet: "İşlem formu Faz 6'da eklenecek.",
|
||||
},
|
||||
auth: {
|
||||
loginTitle: "Giriş yap",
|
||||
loginDescription: "Hesabınıza kullanıcı adı veya e-posta ile giriş yapın.",
|
||||
identifier: "Kullanıcı adı veya e-posta",
|
||||
identifierPlaceholder: "ornek veya ornek@eposta.com",
|
||||
password: "Şifre",
|
||||
submit: "Giriş yap",
|
||||
submitting: "Giriş yapılıyor…",
|
||||
invalidCredentials: "Kullanıcı adı/e-posta veya şifre hatalı.",
|
||||
noSignUp: "Hesaplar yalnızca yönetici tarafından açılır.",
|
||||
identifierRequired: "Kullanıcı adı veya e-posta girin",
|
||||
passwordRequired: "Şifre girin",
|
||||
},
|
||||
dashboard: {
|
||||
title: "Ana sayfa",
|
||||
welcome: (name: string) => `Hoş geldin, ${name}`,
|
||||
welcomeDescription: "Bu ayın özetini burada göreceksin. Veriler sonraki fazlarda bağlanacak.",
|
||||
cards: {
|
||||
monthIncome: "Bu ay gelir",
|
||||
monthExpense: "Bu ay gider",
|
||||
monthRemaining: "Kalan",
|
||||
totalBalance: "Toplam hesap bakiyesi",
|
||||
cardDebt: "Kart borçları",
|
||||
netWorth: "Net varlık",
|
||||
},
|
||||
noData: "Henüz veri yok",
|
||||
},
|
||||
adminUsers: {
|
||||
title: "Kullanıcılar",
|
||||
description: "Kullanıcı oluşturma, rol, şifre ve erişim yönetimi.",
|
||||
newUser: "Yeni kullanıcı",
|
||||
searchPlaceholder: "Ad, kullanıcı adı veya e-posta ara…",
|
||||
columns: {
|
||||
name: "Ad soyad",
|
||||
username: "Kullanıcı adı",
|
||||
email: "E-posta",
|
||||
role: "Rol",
|
||||
status: "Durum",
|
||||
createdAt: "Oluşturulma",
|
||||
},
|
||||
status: { active: "Aktif", banned: "Askıda" },
|
||||
actions: {
|
||||
edit: "Düzenle",
|
||||
changeRole: "Rolü değiştir",
|
||||
makeAdmin: "Yönetici yap",
|
||||
makeUser: "Kullanıcı yap",
|
||||
resetPassword: "Şifre sıfırla",
|
||||
ban: "Askıya al",
|
||||
unban: "Askıyı kaldır",
|
||||
delete: "Sil",
|
||||
},
|
||||
form: {
|
||||
createTitle: "Yeni kullanıcı",
|
||||
createDescription: "Kullanıcı kendi hesabını açamaz; hesapları buradan oluşturun.",
|
||||
editTitle: "Kullanıcıyı düzenle",
|
||||
editDescription: "Ad, kullanıcı adı, e-posta ve rol bilgilerini güncelleyin.",
|
||||
name: "Ad soyad",
|
||||
username: "Kullanıcı adı",
|
||||
usernameHint: "Küçük harf, rakam, nokta, alt çizgi; 3–30 karakter.",
|
||||
email: "E-posta",
|
||||
emailHint: "İsteğe bağlı. Boş bırakılırsa giriş kullanıcı adıyla yapılır.",
|
||||
role: "Sistem rolü",
|
||||
password: "Geçici şifre",
|
||||
passwordHint: "En az 8 karakter. Kullanıcıya güvenli bir kanaldan iletin.",
|
||||
},
|
||||
password: {
|
||||
title: "Şifre sıfırla",
|
||||
description: (name: string) => `${name} için yeni bir şifre belirleyin.`,
|
||||
newPassword: "Yeni şifre",
|
||||
confirm: "Şifreyi belirle",
|
||||
},
|
||||
ban: {
|
||||
title: "Kullanıcıyı askıya al",
|
||||
description: (name: string) => `${name} giriş yapamayacak ve açık oturumları kapatılacak.`,
|
||||
reason: "Neden (isteğe bağlı)",
|
||||
confirm: "Askıya al",
|
||||
},
|
||||
remove: {
|
||||
title: "Kullanıcı silinsin mi?",
|
||||
description: (name: string) => `${name} kalıcı olarak silinecek. Bu işlem geri alınamaz.`,
|
||||
confirm: "Kalıcı olarak sil",
|
||||
},
|
||||
toast: {
|
||||
created: (name: string) => `${name} oluşturuldu.`,
|
||||
updated: (name: string) => `${name} güncellendi.`,
|
||||
roleChanged: (name: string) => `${name} için rol değiştirildi.`,
|
||||
passwordSet: (name: string) => `${name} için şifre güncellendi.`,
|
||||
banned: (name: string) => `${name} askıya alındı.`,
|
||||
unbanned: (name: string) => `${name} için askı kaldırıldı.`,
|
||||
removed: (name: string) => `${name} silindi.`,
|
||||
},
|
||||
guards: {
|
||||
self: "Kendi hesabınız için bu işlem yapılamaz.",
|
||||
lastAdmin: "Sistemdeki son yönetici silinemez veya rolü düşürülemez.",
|
||||
},
|
||||
errors: {
|
||||
usernameTaken: "Bu kullanıcı adı kullanılıyor.",
|
||||
emailTaken: "Bu e-posta adresi kullanılıyor.",
|
||||
checkFields: "Lütfen işaretli alanları düzeltin.",
|
||||
},
|
||||
you: "Siz",
|
||||
noEmail: "—",
|
||||
},
|
||||
validation: {
|
||||
nameMin: "Ad en az 2 karakter olmalı",
|
||||
nameMax: "Ad en fazla 80 karakter olabilir",
|
||||
usernameFormat: "Yalnızca küçük harf, rakam, nokta ve alt çizgi; 3–30 karakter",
|
||||
email: "Geçerli bir e-posta adresi girin",
|
||||
passwordMin: "Şifre en az 8 karakter olmalı",
|
||||
passwordMax: "Şifre en fazla 128 karakter olabilir",
|
||||
banReasonMax: "Neden en fazla 200 karakter olabilir",
|
||||
},
|
||||
errors: {
|
||||
notFoundTitle: "Sayfa bulunamadı",
|
||||
notFoundDescription: "Aradığınız sayfa taşınmış veya hiç var olmamış olabilir.",
|
||||
backHome: "Ana sayfaya dön",
|
||||
errorTitle: "Bir şeyler ters gitti",
|
||||
errorDescription: "Sayfa yüklenirken bir hata oluştu. Tekrar deneyebilirsiniz.",
|
||||
retry: "Tekrar dene",
|
||||
reference: "Hata kodu",
|
||||
},
|
||||
} as const;
|
||||
|
||||
export type Messages = typeof tr;
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* Server Action ve servis dönüş tipi (Faz 3+). Hata durumunda kullanıcıya gösterilecek
|
||||
* genel mesaj ve isteğe bağlı alan bazlı hatalar döner; iç detay asla sızdırılmaz.
|
||||
*/
|
||||
export type ActionResult<T = void> =
|
||||
| { ok: true; data: T }
|
||||
| { ok: false; error: string; fieldErrors?: Partial<Record<string, string>> };
|
||||
|
||||
export const ok = <T>(data: T): ActionResult<T> => ({ ok: true, data });
|
||||
export const fail = (
|
||||
error: string,
|
||||
fieldErrors?: Partial<Record<string, string>>,
|
||||
): ActionResult<never> => ({
|
||||
ok: false,
|
||||
error,
|
||||
fieldErrors,
|
||||
});
|
||||
@@ -0,0 +1,29 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { formatDate, formatDateTime, formatMoney } from "./format";
|
||||
|
||||
// Intl çıktısındaki boşluklar (ör. U+00A0) ortama göre değişebilir; karşılaştırmada normalleştir.
|
||||
const norm = (s: string) => s.replace(/\s/g, " ");
|
||||
|
||||
describe("formatMoney", () => {
|
||||
it("kuruşu TL olarak Türkçe biçimde gösterir", () => {
|
||||
expect(norm(formatMoney(125050))).toBe("₺1.250,50");
|
||||
expect(norm(formatMoney(0))).toBe("₺0,00");
|
||||
expect(norm(formatMoney(-9999))).toBe("-₺99,99");
|
||||
});
|
||||
|
||||
it("tamsayı olmayan tutarı reddeder", () => {
|
||||
expect(() => formatMoney(12.5)).toThrow(TypeError);
|
||||
});
|
||||
});
|
||||
|
||||
describe("formatDate", () => {
|
||||
it("İstanbul saatine göre gün sınırını uygular", () => {
|
||||
// 31.12.2026 21:30 UTC = 01.01.2027 00:30 İstanbul (UTC+3)
|
||||
expect(formatDate("2026-12-31T21:30:00Z")).toBe("01.01.2027");
|
||||
expect(formatDate("2026-12-31T20:59:00Z")).toBe("31.12.2026");
|
||||
});
|
||||
|
||||
it("tarih-saat biçimi", () => {
|
||||
expect(norm(formatDateTime("2026-11-05T07:05:00Z"))).toBe("05.11.2026 10:05");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* Görüntüleme biçimleri (tr-TR, Europe/Istanbul). Sunucu ve istemci aynı sonucu üretir
|
||||
* çünkü yerel ayar ve saat dilimi her zaman açıkça verilir (hydration uyumsuzluğu olmaz).
|
||||
*/
|
||||
export const LOCALE = "tr-TR";
|
||||
export const TIME_ZONE = "Europe/Istanbul";
|
||||
|
||||
const moneyFmt = new Intl.NumberFormat(LOCALE, { style: "currency", currency: "TRY" });
|
||||
|
||||
/** Kuruş cinsinden tamsayı tutarı TL olarak biçimlendirir: 125050 → "₺1.250,50". */
|
||||
export function formatMoney(amountMinor: number): string {
|
||||
if (!Number.isSafeInteger(amountMinor)) {
|
||||
throw new TypeError(`amountMinor tamsayı olmalı: ${amountMinor}`);
|
||||
}
|
||||
return moneyFmt.format(amountMinor / 100);
|
||||
}
|
||||
|
||||
const dateFmt = new Intl.DateTimeFormat(LOCALE, {
|
||||
timeZone: TIME_ZONE,
|
||||
day: "2-digit",
|
||||
month: "2-digit",
|
||||
year: "numeric",
|
||||
});
|
||||
|
||||
const dateTimeFmt = new Intl.DateTimeFormat(LOCALE, {
|
||||
timeZone: TIME_ZONE,
|
||||
day: "2-digit",
|
||||
month: "2-digit",
|
||||
year: "numeric",
|
||||
hour: "2-digit",
|
||||
minute: "2-digit",
|
||||
});
|
||||
|
||||
/** UTC tarihi İstanbul saatine göre "dd.MM.yyyy" biçiminde gösterir. */
|
||||
export function formatDate(date: Date | string): string {
|
||||
return dateFmt.format(new Date(date));
|
||||
}
|
||||
|
||||
/** UTC tarihi İstanbul saatine göre "dd.MM.yyyy HH:mm" biçiminde gösterir. */
|
||||
export function formatDateTime(date: Date | string): string {
|
||||
return dateTimeFmt.format(new Date(date));
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { z } from "zod";
|
||||
import { tr } from "../../i18n/tr";
|
||||
|
||||
/** Giriş formu: kullanıcı adı veya e-posta + şifre. Biçim kontrolü sunucuda yapılır. */
|
||||
export const loginSchema = z.object({
|
||||
identifier: z.string().trim().min(1, tr.auth.identifierRequired),
|
||||
password: z.string().min(1, tr.auth.passwordRequired),
|
||||
});
|
||||
|
||||
export type LoginInput = z.infer<typeof loginSchema>;
|
||||
@@ -0,0 +1,36 @@
|
||||
import { z } from "zod";
|
||||
import { tr } from "../../i18n/tr";
|
||||
|
||||
const v = tr.validation;
|
||||
|
||||
/** Sistem rolleri (Better Auth admin plugin). */
|
||||
export const SYSTEM_ROLES = ["admin", "user"] as const;
|
||||
export const systemRoleSchema = z.enum(SYSTEM_ROLES);
|
||||
export type SystemRole = z.infer<typeof systemRoleSchema>;
|
||||
|
||||
export const USERNAME_PATTERN = /^[a-z0-9._]{3,30}$/;
|
||||
|
||||
export const nameSchema = z.string().trim().min(2, v.nameMin).max(80, v.nameMax);
|
||||
|
||||
/** Kullanıcı adı küçük harfe çevrilir; Türkçe büyük İ/I sorununu önlemek için tr-TR kullanılır. */
|
||||
export const usernameSchema = z
|
||||
.string()
|
||||
.trim()
|
||||
.transform((s) => s.toLocaleLowerCase("tr-TR"))
|
||||
.pipe(z.string().regex(USERNAME_PATTERN, v.usernameFormat));
|
||||
|
||||
export const emailSchema = z.string().trim().toLowerCase().pipe(z.email(v.email));
|
||||
|
||||
/** Boş bırakılabilen e-posta: "" → undefined. */
|
||||
export const optionalEmailSchema = z
|
||||
.string()
|
||||
.trim()
|
||||
.transform((s) => (s === "" ? undefined : s.toLowerCase()))
|
||||
.pipe(z.email(v.email).optional());
|
||||
|
||||
export const passwordSchema = z.string().min(8, v.passwordMin).max(128, v.passwordMax);
|
||||
|
||||
/** Girilen değer e-posta mı (giriş sırasında e-posta/kullanıcı adı yöntemini seçmek için)? */
|
||||
export function looksLikeEmail(value: string): boolean {
|
||||
return value.includes("@");
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { loginSchema } from "./auth";
|
||||
import { looksLikeEmail, usernameSchema } from "./common";
|
||||
import { banUserSchema, userCreateSchema, userUpdateSchema } from "./user";
|
||||
|
||||
const base = {
|
||||
name: "Ayşe Yılmaz",
|
||||
username: "ayse",
|
||||
email: "",
|
||||
role: "user",
|
||||
password: "gizli-1234",
|
||||
};
|
||||
|
||||
describe("usernameSchema", () => {
|
||||
it("küçük harfe çevirir ve boşlukları kırpar (Türkçe İ dahil)", () => {
|
||||
expect(usernameSchema.parse(" AYSE.K ")).toBe("ayse.k");
|
||||
expect(usernameSchema.parse("Ali_2")).toBe("ali_2");
|
||||
});
|
||||
|
||||
it("Türkçe karakter, boşluk ve kısa değerleri reddeder", () => {
|
||||
for (const bad of ["ayşe", "ali veli", "ab", "a".repeat(31), "ali-veli"]) {
|
||||
expect(usernameSchema.safeParse(bad).success, bad).toBe(false);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("userCreateSchema", () => {
|
||||
it("boş e-postayı undefined yapar", () => {
|
||||
const out = userCreateSchema.parse(base);
|
||||
expect(out.email).toBeUndefined();
|
||||
expect(out.name).toBe("Ayşe Yılmaz");
|
||||
});
|
||||
|
||||
it("e-postayı küçük harfe çevirir ve doğrular", () => {
|
||||
expect(userCreateSchema.parse({ ...base, email: " Ayse@Ornek.COM " }).email).toBe(
|
||||
"ayse@ornek.com",
|
||||
);
|
||||
expect(userCreateSchema.safeParse({ ...base, email: "gecersiz" }).success).toBe(false);
|
||||
});
|
||||
|
||||
it("kısa şifreyi ve geçersiz rolü reddeder", () => {
|
||||
expect(userCreateSchema.safeParse({ ...base, password: "1234567" }).success).toBe(false);
|
||||
expect(userCreateSchema.safeParse({ ...base, role: "owner" }).success).toBe(false);
|
||||
});
|
||||
|
||||
it("güncelleme şemasında şifre yoktur", () => {
|
||||
const { password: _password, ...rest } = base;
|
||||
expect(userUpdateSchema.parse(rest)).not.toHaveProperty("password");
|
||||
});
|
||||
});
|
||||
|
||||
describe("banUserSchema", () => {
|
||||
it("boş nedeni undefined yapar, uzun nedeni reddeder", () => {
|
||||
expect(banUserSchema.parse({ reason: " " }).reason).toBeUndefined();
|
||||
expect(banUserSchema.safeParse({ reason: "x".repeat(201) }).success).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("loginSchema", () => {
|
||||
it("boş alanları Türkçe mesajla reddeder", () => {
|
||||
const r = loginSchema.safeParse({ identifier: " ", password: "" });
|
||||
expect(r.success).toBe(false);
|
||||
expect(r.error?.issues.map((i) => i.message)).toEqual([
|
||||
"Kullanıcı adı veya e-posta girin",
|
||||
"Şifre girin",
|
||||
]);
|
||||
});
|
||||
|
||||
it("e-posta / kullanıcı adı ayrımı", () => {
|
||||
expect(looksLikeEmail("ayse@ornek.com")).toBe(true);
|
||||
expect(looksLikeEmail("ayse")).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,39 @@
|
||||
import { z } from "zod";
|
||||
import { tr } from "../../i18n/tr";
|
||||
import {
|
||||
nameSchema,
|
||||
optionalEmailSchema,
|
||||
passwordSchema,
|
||||
systemRoleSchema,
|
||||
usernameSchema,
|
||||
} from "./common";
|
||||
|
||||
/** Admin: yeni kullanıcı. E-posta isteğe bağlı (çocuklar vb. için kullanıcı adıyla giriş). */
|
||||
export const userCreateSchema = z.object({
|
||||
name: nameSchema,
|
||||
username: usernameSchema,
|
||||
email: optionalEmailSchema,
|
||||
role: systemRoleSchema,
|
||||
password: passwordSchema,
|
||||
});
|
||||
|
||||
/** Admin: kullanıcı bilgisi güncelleme (şifre ayrı akışta). */
|
||||
export const userUpdateSchema = userCreateSchema.omit({ password: true });
|
||||
|
||||
export const setPasswordSchema = z.object({ password: passwordSchema });
|
||||
|
||||
export const banUserSchema = z.object({
|
||||
reason: z
|
||||
.string()
|
||||
.trim()
|
||||
.max(200, tr.validation.banReasonMax)
|
||||
.transform((s) => (s === "" ? undefined : s))
|
||||
.optional(),
|
||||
});
|
||||
|
||||
export type UserCreateInput = z.input<typeof userCreateSchema>;
|
||||
export type UserCreate = z.output<typeof userCreateSchema>;
|
||||
export type UserUpdateInput = z.input<typeof userUpdateSchema>;
|
||||
export type UserUpdate = z.output<typeof userUpdateSchema>;
|
||||
export type SetPasswordInput = z.input<typeof setPasswordSchema>;
|
||||
export type BanUserInput = z.input<typeof banUserSchema>;
|
||||
@@ -0,0 +1,38 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { compareTr, foldTr, includesTr } from "./search";
|
||||
|
||||
describe("foldTr", () => {
|
||||
it("Türkçe harfleri ve büyük/küçük farkını normalize eder", () => {
|
||||
expect(foldTr("İrem")).toBe("irem");
|
||||
expect(foldTr("IŞIK")).toBe("isik");
|
||||
expect(foldTr("Ayşe Çağrı Öztürk Ünal")).toBe("ayse cagri ozturk unal");
|
||||
});
|
||||
});
|
||||
|
||||
describe("includesTr", () => {
|
||||
it("aksansız ve büyük harfli aramayla eşleşir", () => {
|
||||
expect(includesTr("İrem Güneş", "irem")).toBe(true);
|
||||
expect(includesTr("İrem Güneş", "GUNES")).toBe(true);
|
||||
expect(includesTr("Ayşe", "ayse")).toBe(true);
|
||||
expect(includesTr("Ayşe", "mehmet")).toBe(false);
|
||||
});
|
||||
|
||||
it("boş arama her şeyle eşleşir, boş değer hiçbir aramayla eşleşmez", () => {
|
||||
expect(includesTr("x", " ")).toBe(true);
|
||||
expect(includesTr(undefined, "a")).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("compareTr", () => {
|
||||
it("Türk alfabesine göre sıralar", () => {
|
||||
expect(["Zeynep", "Çiğdem", "Can", "Şule", "Selin", "İrem", "Ilgın"].sort(compareTr)).toEqual([
|
||||
"Can",
|
||||
"Çiğdem",
|
||||
"Ilgın",
|
||||
"İrem",
|
||||
"Selin",
|
||||
"Şule",
|
||||
"Zeynep",
|
||||
]);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* Türkçe arama normalizasyonu: büyük/küçük harf ve aksan farkını yok sayar.
|
||||
* "İrem" ↔ "irem", "IŞIK" ↔ "isik", "Ayşe" ↔ "ayse", "Çağrı" ↔ "cagri".
|
||||
*/
|
||||
export function foldTr(value: string): string {
|
||||
return value
|
||||
.toLocaleLowerCase("tr-TR")
|
||||
.replace(/ı/g, "i")
|
||||
.normalize("NFD")
|
||||
.replace(/\p{M}/gu, "")
|
||||
.trim();
|
||||
}
|
||||
|
||||
/** `haystack` içinde `needle` (normalize edilmiş) geçiyor mu? */
|
||||
export function includesTr(haystack: string | undefined | null, needle: string): boolean {
|
||||
if (!needle.trim()) return true;
|
||||
return haystack ? foldTr(haystack).includes(foldTr(needle)) : false;
|
||||
}
|
||||
|
||||
const collator = new Intl.Collator("tr-TR", { sensitivity: "base" });
|
||||
|
||||
/** Türkçe alfabetik sıralama karşılaştırıcısı (Ç, Ğ, İ, Ö, Ş, Ü doğru yerde). */
|
||||
export function compareTr(a: string, b: string): number {
|
||||
return collator.compare(a, b);
|
||||
}
|
||||