From f834f29e531d1be628cf5729b923428f5bc6388b Mon Sep 17 00:00:00 2001 From: Jelaletdin12 Date: Sun, 3 May 2026 23:12:11 +0500 Subject: [PATCH] added loan pages --- PROJECT_STANDARDS.md | 77 + index.html | 2 +- package-lock.json | 75 +- package.json | 1 + src/App.css | 184 - src/app/router/index.tsx | 109 +- src/assets/icon.svg | 3013 +++++++++++++++++ src/components/dataTable.tsx | 456 +++ src/components/dataTableToolbar.tsx | 393 +++ src/components/tableButton.tsx | 36 + src/components/tableSearch.tsx | 40 + src/components/ui/button-variants.ts | 2 +- src/components/ui/input.tsx | 2 +- src/components/ui/sidebar.tsx | 2 +- src/components/ui/statusBadge.tsx | 33 + src/components/ui/table.tsx | 114 + src/components/ui/tooltip.tsx | 2 +- src/features/auth/api/authApi.ts | 4 +- .../api/loanOrderMobilesApi.ts | 105 + .../hooks/useLoanOrderMobiles.ts | 42 + src/features/loanOrders/api/loanOrdersApi.ts | 162 + .../components/loanOrderStatusBadge.tsx | 25 + .../loanOrders/hooks/useLoanOrders.ts | 70 + .../api/loanPaidOffLettersApi.ts | 84 + .../hooks/useLoanPaidOffLetters.ts | 43 + .../loanRemaining/api/loanRemainingApi.ts | 83 + .../loanRemaining/hooks/useLoanRemaining.ts | 42 + src/index.css | 43 +- src/layouts/AuthLayout.tsx | 126 - src/layouts/DashboardLayout.tsx | 500 +++ .../use-mobile.ts => lib/hooks/useMobile.ts} | 0 src/lib/hooks/useOutsideClick.ts | 17 + src/lib/i18n/locales/en.json | 412 ++- src/lib/i18n/locales/ru.json | 412 ++- src/lib/i18n/locales/tk.json | 412 ++- src/pages/dashboard/index.tsx | 96 +- src/pages/loanOrderMobiles/index.tsx | 306 ++ src/pages/loanOrders/index.tsx | 297 ++ src/pages/loanPaidOffLetters/index.tsx | 293 ++ src/pages/loanRemaining/index.tsx | 189 ++ src/pages/login/index.tsx | 286 +- 41 files changed, 7942 insertions(+), 648 deletions(-) create mode 100644 PROJECT_STANDARDS.md create mode 100644 src/assets/icon.svg create mode 100644 src/components/dataTable.tsx create mode 100644 src/components/dataTableToolbar.tsx create mode 100644 src/components/tableButton.tsx create mode 100644 src/components/tableSearch.tsx create mode 100644 src/components/ui/statusBadge.tsx create mode 100644 src/components/ui/table.tsx create mode 100644 src/features/loanOrderMobiles/api/loanOrderMobilesApi.ts create mode 100644 src/features/loanOrderMobiles/hooks/useLoanOrderMobiles.ts create mode 100644 src/features/loanOrders/api/loanOrdersApi.ts create mode 100644 src/features/loanOrders/components/loanOrderStatusBadge.tsx create mode 100644 src/features/loanOrders/hooks/useLoanOrders.ts create mode 100644 src/features/loanPaidOffLetters/api/loanPaidOffLettersApi.ts create mode 100644 src/features/loanPaidOffLetters/hooks/useLoanPaidOffLetters.ts create mode 100644 src/features/loanRemaining/api/loanRemainingApi.ts create mode 100644 src/features/loanRemaining/hooks/useLoanRemaining.ts delete mode 100644 src/layouts/AuthLayout.tsx create mode 100644 src/layouts/DashboardLayout.tsx rename src/{hooks/use-mobile.ts => lib/hooks/useMobile.ts} (100%) create mode 100644 src/lib/hooks/useOutsideClick.ts create mode 100644 src/pages/loanOrderMobiles/index.tsx create mode 100644 src/pages/loanOrders/index.tsx create mode 100644 src/pages/loanPaidOffLetters/index.tsx create mode 100644 src/pages/loanRemaining/index.tsx diff --git a/PROJECT_STANDARDS.md b/PROJECT_STANDARDS.md new file mode 100644 index 0000000..48d69c1 --- /dev/null +++ b/PROJECT_STANDARDS.md @@ -0,0 +1,77 @@ +# Proje Geliştirme Standartları ve AI/Agent Rehberi (TBBank Admin) + +Bu doküman, projenin büyümesiyle yapının bozulmaması ve projede çalışacak olan yapay zeka (AI) asistanlarının / agent'ların mimariyi karıştırmaması için hazırlanmıştır. Geliştirme yaparken aşağıdaki kurallara **kesinlikle** uyulmalıdır. + +## 1. Temel Teknoloji Yığını ve Kullanım Yerleri + +- **State Management:** `zustand` + - **Path:** `src/app/store/` (Örn: `authStore.ts`, `themeStore.ts`, `i18nStore.ts`) + - Sadece global state (kullanıcı oturumu, tema, dil vb.) için kullanılmalıdır. Component içi basit stateler için `useState` kullanın. + +- **Data Fetching & Caching:** `@tanstack/react-query` + - **Path:** `src/features/[feature-name]/hooks/` (Örn: `src/features/auth/hooks/useLogin.ts`) + - Bütün API istekleri custom hook'lar içerisine sarmalanmalı ve doğrudan component içinde `useQuery` veya `useMutation` yazılmamalıdır. + +- **HTTP Client:** `axios` + - **Path:** `src/lib/api/client.ts` + - Tüm istekler merkezi axios instance'ı üzerinden yapılmalıdır. Interceptor'lar (token ekleme, hata yakalama vb.) bu dosyada yönetilir. + +## 2. Kullanıcı Deneyimi (UX) ve UI Kuralları + +- **Smooth UX:** + - Yükleme durumları (loading states) her zaman gösterilmelidir (`src/components/ui/spinner.tsx` veya `skeleton.tsx`). + - İşlem beklerken butonlar `disabled` duruma geçmelidir. + - Geçişler ve animasyonlar pürüzsüz olmalıdır. + +- **Bildirimler (Toast):** `sonner` + - **Path:** `import { toast } from 'sonner'` (Bileşen Provider'ı: `src/components/ui/sonner.tsx`) + - Her başarılı `mutation` (ekleme/güncelleme/silme) işleminden sonra **kesinlikle** başarı mesajı (`toast.success()`) gösterilmelidir. + - Hatalı işlemlerde **kesinlikle** hata mesajı (`toast.error()`) gösterilmelidir. + +- **Tema (Light / Dark Mode):** + - Projede açık ve koyu tema desteği zorunludur. + - Ui component olarak shadcn ui kullanilmaktadir. + - Renklendirmeler Tailwind CSS sınıfları ile yapılmalıdır (Örn: `bg-white dark:bg-gray-900`). + - Tema durumu `src/app/store/themeStore.ts` (veya proje yapısına göre `next-themes`) üzerinden kontrol edilmektedir. + +- **Çoklu Dil Desteği (i18n):** + - **Path:** `src/lib/i18n/` ve çeviri dosyaları `src/lib/i18n/locales/` + - Desteklenen diller: İngilizce (`en`), Rusça (`ru`), Türkmence (`tk`). + - Arayüzde hard-coded metin (string) yazmak **yasaktır**. Tüm metinler çeviri dosyalarından `useTranslation` kancası ile çekilmelidir. + +## 3. Kod Kalitesi ve TypeScript Kuralları + +- **Kesinlikle `any` Kullanımı Yasaktır!** + - Proje genelinde `any` tipi kullanmak kesinlikle yasaktır (`eslint` kurallarıyla da desteklenmelidir). + - Tipler tam olarak bilinmiyorsa `unknown` kullanılmalı veya uygun `interface` / `type` tanımlamaları yapılmalıdır. + - Tüm API yanıtları, payload'lar ve component propları için mutlaka tip tanımlamaları oluşturulmalıdır. + +- **Clean Code (Temiz Kod):** + - Modüler yapı (Feature-Sliced Design) korunmalıdır. Her özellik kendi klasöründe (`src/features/[feature-name]/`) api, hooks, components olarak ayrılmalıdır. + - Fonksiyonlar tek bir iş yapmalı (Single Responsibility). + - İsimlendirmeler açıklayıcı olmalı (Örn: `handleData` yerine `submitLoginForm`). + +## 4. Dosya Yapısı Özeti +```text +src/ +├── app/ # Global provider'lar, store'lar ve router konfigürasyonları +├── assets/ # Görseller, fontlar vb. statik dosyalar +├── components/ # Global ve UI bileşenleri (shadcn vb. ortak bileşenler) +├── features/ # Özellik bazlı modüller (auth, dashboard, users vb.) +│ └── [feature]/ +│ ├── api/ # Feature'a özel axios istek fonksiyonları +│ ├── hooks/ # Feature'a özel React Query hook'ları (useQuery, useMutation) +│ └── components/# Feature'a özel bileşenler +├── hooks/ # Global custom hook'lar +├── layouts/ # Sayfa düzenleri (DashboardLayout, AuthLayout vb.) +├── lib/ # API client, i18n ayarları ve utils (yardımcı fonksiyonlar) +└── pages/ # Router tarafından çağrılan ana sayfalar +``` + +## AI / Agent İçin Katı Talimatlar (System Instructions) +1. Yeni bir bileşen veya özellik ekleneceğinde her zaman önce `src/features/` altına eklenip eklenmeyeceğini değerlendir. +2. UI bileşeni oluştururken önce `src/components/ui/` dizininde mevcut bir yapı olup olmadığını kontrol et. +3. Asla `any` tipi tanımlama. TypeScript hatalarını doğru tipler (interface/type) yazarak çöz. +4. Mutation'lardan (POST, PUT, DELETE) sonra `onSuccess` ve `onError` bloklarında mutlaka `sonner` ile bildirim göster. +5. Kullanıcıya dönen her metni `i18n` dosyalarına ekle ve `t('anahtar')` şeklinde çağır. Hard-coded string kullanma. +6. Kod yazarken temiz, okunabilir ve modüler bir yaklaşım benimse. diff --git a/index.html b/index.html index ff3cf15..d079fa2 100644 --- a/index.html +++ b/index.html @@ -2,7 +2,7 @@ - + tbbank-admin diff --git a/package-lock.json b/package-lock.json index 9b750c6..c69d15a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,7 @@ "dependencies": { "@fontsource-variable/geist": "^5.2.8", "@tanstack/react-query": "^5.100.8", + "@tanstack/react-table": "^8.21.3", "axios": "^1.15.2", "class-variance-authority": "^0.7.1", "clsx": "^2.1.1", @@ -89,6 +90,7 @@ "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.29.0.tgz", "integrity": "sha512-CGOfOJqWjg2qW/Mb6zNsDm+u5vFQ8DxXfbM09z69p5Z6+mE1ikP2jUXw+j42Pf1XTYED2Rni5f95npYeuwMDQA==", "license": "MIT", + "peer": true, "dependencies": { "@babel/code-frame": "^7.29.0", "@babel/generator": "^7.29.0", @@ -644,29 +646,6 @@ "@noble/ciphers": "^1.0.0" } }, - "node_modules/@emnapi/core": { - "version": "1.10.0", - "resolved": "https://registry.npmjs.org/@emnapi/core/-/core-1.10.0.tgz", - "integrity": "sha512-yq6OkJ4p82CAfPl0u9mQebQHKPJkY7WrIuk205cTYnYe+k2Z8YBh11FrbRG/H6ihirqcacOgl2BIO8oyMQLeXw==", - "dev": true, - "license": "MIT", - "optional": true, - "dependencies": { - "@emnapi/wasi-threads": "1.2.1", - "tslib": "^2.4.0" - } - }, - "node_modules/@emnapi/runtime": { - "version": "1.10.0", - "resolved": "https://registry.npmjs.org/@emnapi/runtime/-/runtime-1.10.0.tgz", - "integrity": "sha512-ewvYlk86xUoGI0zQRNq/mC+16R1QeDlKQy21Ki3oSYXNgLb45GV1P6A0M+/s6nyCuNDqe5VpaY84BzXGwVbwFA==", - "dev": true, - "license": "MIT", - "optional": true, - "dependencies": { - "tslib": "^2.4.0" - } - }, "node_modules/@emnapi/wasi-threads": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/@emnapi/wasi-threads/-/wasi-threads-1.2.1.tgz", @@ -1167,6 +1146,7 @@ "resolved": "https://registry.npmjs.org/@noble/ciphers/-/ciphers-1.3.0.tgz", "integrity": "sha512-2I0gnIVPtfnMw9ee9h1dJG7tp81+8Ob3OJb3Mv37rx5L40/b0i7djjCVvGOVqc9AEIQyvyu1i6ypKdFw8R8gQw==", "license": "MIT", + "peer": true, "engines": { "node": "^14.21.3 || >=16" }, @@ -3345,6 +3325,39 @@ "react": "^18 || ^19" } }, + "node_modules/@tanstack/react-table": { + "version": "8.21.3", + "resolved": "https://registry.npmjs.org/@tanstack/react-table/-/react-table-8.21.3.tgz", + "integrity": "sha512-5nNMTSETP4ykGegmVkhjcS8tTLW6Vl4axfEGQN3v0zdHYbK4UfoqfPChclTrJ4EoK9QynqAu9oUf8VEmrpZ5Ww==", + "license": "MIT", + "dependencies": { + "@tanstack/table-core": "8.21.3" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/tannerlinsley" + }, + "peerDependencies": { + "react": ">=16.8", + "react-dom": ">=16.8" + } + }, + "node_modules/@tanstack/table-core": { + "version": "8.21.3", + "resolved": "https://registry.npmjs.org/@tanstack/table-core/-/table-core-8.21.3.tgz", + "integrity": "sha512-ldZXEhOBb8Is7xLs01fR3YEc3DERiz5silj8tnGkFZytt1abEvl/GhUmCE0PMLaMPTa3Jk4HbKmRlHmu+gCftg==", + "license": "MIT", + "engines": { + "node": ">=12" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/tannerlinsley" + } + }, "node_modules/@ts-morph/common": { "version": "0.27.0", "resolved": "https://registry.npmjs.org/@ts-morph/common/-/common-0.27.0.tgz", @@ -3393,6 +3406,7 @@ "resolved": "https://registry.npmjs.org/@types/node/-/node-24.12.2.tgz", "integrity": "sha512-A1sre26ke7HDIuY/M23nd9gfB+nrmhtYyMINbjI1zHJxYteKR6qSMX56FsmjMcDb3SMcjJg5BiRRgOCC/yBD0g==", "license": "MIT", + "peer": true, "dependencies": { "undici-types": "~7.16.0" } @@ -3403,6 +3417,7 @@ "integrity": "sha512-ilcTH/UniCkMdtexkoCN0bI7pMcJDvmQFPvuPvmEaYA/NSfFTAgdUSLAoVjaRJm7+6PvcM+q1zYOwS4wTYMF9w==", "devOptional": true, "license": "MIT", + "peer": true, "dependencies": { "csstype": "^3.2.2" } @@ -3413,6 +3428,7 @@ "integrity": "sha512-jp2L/eY6fn+KgVVQAOqYItbF0VY/YApe5Mz2F0aykSO8gx31bYCZyvSeYxCHKvzHG5eZjc+zyaS5BrBWya2+kQ==", "devOptional": true, "license": "MIT", + "peer": true, "peerDependencies": { "@types/react": "^19.2.0" } @@ -3483,6 +3499,7 @@ "integrity": "sha512-HDQH9O/47Dxi1ceDhBXdaldtf/WV9yRYMjbjCuNk3qnaTD564qwv61Y7+gTxwxRKzSrgO5uhtw584igXVuuZkA==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@typescript-eslint/scope-manager": "8.59.1", "@typescript-eslint/types": "8.59.1", @@ -3726,6 +3743,7 @@ "integrity": "sha512-UVJyE9MttOsBQIDKw1skb9nAwQuR5wuGD3+82K6JgJlm/Y+KI92oNsMNGZCYdDsVtRHSak0pcV5Dno5+4jh9sw==", "dev": true, "license": "MIT", + "peer": true, "bin": { "acorn": "bin/acorn" }, @@ -4007,6 +4025,7 @@ } ], "license": "MIT", + "peer": true, "dependencies": { "baseline-browser-mapping": "^2.10.12", "caniuse-lite": "^1.0.30001782", @@ -4714,6 +4733,7 @@ "integrity": "sha512-XbEXaRva5cF0ZQB8w6MluHA0kZZfV2DuCMJ3ozyEOHLwDpZX2Lmm/7Pp0xdJmI0GL1W05VH5VwIFHEm1Vcw2gw==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@eslint-community/eslint-utils": "^4.8.0", "@eslint-community/regexpp": "^4.12.2", @@ -4964,6 +4984,7 @@ "resolved": "https://registry.npmjs.org/express/-/express-5.2.1.tgz", "integrity": "sha512-hIS4idWWai69NezIdRt2xFVofaF4j+6INOpJlVOLDO8zXGpUVEVzIYk12UUi2JzjEzWL3IOAxcTubgz9Po0yXw==", "license": "MIT", + "peer": true, "dependencies": { "accepts": "^2.0.0", "body-parser": "^2.2.1", @@ -5629,6 +5650,7 @@ "resolved": "https://registry.npmjs.org/hono/-/hono-4.12.16.tgz", "integrity": "sha512-jN0ZewiNAWSe5khM3EyCmBb250+b40wWbwNILNfEvq84VREWwOIkuUsFONk/3i3nqkz7Oe1PcpM2mwQEK2L9Kg==", "license": "MIT", + "peer": true, "engines": { "node": ">=16.9.0" } @@ -5703,6 +5725,7 @@ } ], "license": "MIT", + "peer": true, "peerDependencies": { "typescript": "^5 || ^6" }, @@ -7081,6 +7104,7 @@ } ], "license": "MIT", + "peer": true, "dependencies": { "nanoid": "^3.3.11", "picocolors": "^1.1.1", @@ -7342,6 +7366,7 @@ "resolved": "https://registry.npmjs.org/react/-/react-19.2.5.tgz", "integrity": "sha512-llUJLzz1zTUBrskt2pwZgLq59AemifIftw4aB7JxOqf1HY2FDaGDxgwpAPVzHU1kdWabH7FauP4i1oEeer2WCA==", "license": "MIT", + "peer": true, "engines": { "node": ">=0.10.0" } @@ -7351,6 +7376,7 @@ "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-19.2.5.tgz", "integrity": "sha512-J5bAZz+DXMMwW/wV3xzKke59Af6CHY7G4uYLN1OvBcKEsWOs4pQExj86BBKamxl/Ik5bx9whOrvBlSDfWzgSag==", "license": "MIT", + "peer": true, "dependencies": { "scheduler": "^0.27.0" }, @@ -8276,6 +8302,7 @@ "integrity": "sha512-y2TvuxSZPDyQakkFRPZHKFm+KKVqIisdg9/CZwm9ftvKXLP8NRWj38/ODjNbr43SsoXqNuAisEf1GdCxqWcdBw==", "devOptional": true, "license": "Apache-2.0", + "peer": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" @@ -8488,6 +8515,7 @@ "integrity": "sha512-rZuUu9j6J5uotLDs+cAA4O5H4K1SfPliUlQwqa6YEwSrWDZzP4rhm00oJR5snMewjxF5V/K3D4kctsUTsIU9Mw==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "lightningcss": "^1.32.0", "picomatch": "^4.0.4", @@ -8811,6 +8839,7 @@ "resolved": "https://registry.npmjs.org/zod/-/zod-4.4.2.tgz", "integrity": "sha512-IynmDyxsEsb9RKzO3J9+4SxXnl2FTFSzNBaKKaMV6tsSk0rw9gYw9gs+JFCq/qk2LCZ78KDwyj+Z289TijSkUw==", "license": "MIT", + "peer": true, "funding": { "url": "https://github.com/sponsors/colinhacks" } diff --git a/package.json b/package.json index e6268dd..b8497c6 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "dependencies": { "@fontsource-variable/geist": "^5.2.8", "@tanstack/react-query": "^5.100.8", + "@tanstack/react-table": "^8.21.3", "axios": "^1.15.2", "class-variance-authority": "^0.7.1", "clsx": "^2.1.1", diff --git a/src/App.css b/src/App.css index f90339d..e69de29 100644 --- a/src/App.css +++ b/src/App.css @@ -1,184 +0,0 @@ -.counter { - font-size: 16px; - padding: 5px 10px; - border-radius: 5px; - color: var(--accent); - background: var(--accent-bg); - border: 2px solid transparent; - transition: border-color 0.3s; - margin-bottom: 24px; - - &:hover { - border-color: var(--accent-border); - } - &:focus-visible { - outline: 2px solid var(--accent); - outline-offset: 2px; - } -} - -.hero { - position: relative; - - .base, - .framework, - .vite { - inset-inline: 0; - margin: 0 auto; - } - - .base { - width: 170px; - position: relative; - z-index: 0; - } - - .framework, - .vite { - position: absolute; - } - - .framework { - z-index: 1; - top: 34px; - height: 28px; - transform: perspective(2000px) rotateZ(300deg) rotateX(44deg) rotateY(39deg) - scale(1.4); - } - - .vite { - z-index: 0; - top: 107px; - height: 26px; - width: auto; - transform: perspective(2000px) rotateZ(300deg) rotateX(40deg) rotateY(39deg) - scale(0.8); - } -} - -#center { - display: flex; - flex-direction: column; - gap: 25px; - place-content: center; - place-items: center; - flex-grow: 1; - - @media (max-width: 1024px) { - padding: 32px 20px 24px; - gap: 18px; - } -} - -#next-steps { - display: flex; - border-top: 1px solid var(--border); - text-align: left; - - & > div { - flex: 1 1 0; - padding: 32px; - @media (max-width: 1024px) { - padding: 24px 20px; - } - } - - .icon { - margin-bottom: 16px; - width: 22px; - height: 22px; - } - - @media (max-width: 1024px) { - flex-direction: column; - text-align: center; - } -} - -#docs { - border-right: 1px solid var(--border); - - @media (max-width: 1024px) { - border-right: none; - border-bottom: 1px solid var(--border); - } -} - -#next-steps ul { - list-style: none; - padding: 0; - display: flex; - gap: 8px; - margin: 32px 0 0; - - .logo { - height: 18px; - } - - a { - color: var(--text-h); - font-size: 16px; - border-radius: 6px; - background: var(--social-bg); - display: flex; - padding: 6px 12px; - align-items: center; - gap: 8px; - text-decoration: none; - transition: box-shadow 0.3s; - - &:hover { - box-shadow: var(--shadow); - } - .button-icon { - height: 18px; - width: 18px; - } - } - - @media (max-width: 1024px) { - margin-top: 20px; - flex-wrap: wrap; - justify-content: center; - - li { - flex: 1 1 calc(50% - 8px); - } - - a { - width: 100%; - justify-content: center; - box-sizing: border-box; - } - } -} - -#spacer { - height: 88px; - border-top: 1px solid var(--border); - @media (max-width: 1024px) { - height: 48px; - } -} - -.ticks { - position: relative; - width: 100%; - - &::before, - &::after { - content: ''; - position: absolute; - top: -4.5px; - border: 5px solid transparent; - } - - &::before { - left: 0; - border-left-color: var(--border); - } - &::after { - right: 0; - border-right-color: var(--border); - } -} diff --git a/src/app/router/index.tsx b/src/app/router/index.tsx index 9310bf2..4cb68a3 100644 --- a/src/app/router/index.tsx +++ b/src/app/router/index.tsx @@ -1,38 +1,35 @@ -import { lazy, Suspense } from 'react' -import { createBrowserRouter, Navigate, Outlet } from 'react-router-dom' -import { useAuthStore } from '../store/authStore' -import { Spinner } from '@/components/ui/spinner' +import { lazy, Suspense } from "react"; +import { createBrowserRouter, Navigate, Outlet } from "react-router-dom"; +import { useAuthStore } from "../store/authStore"; +import { Spinner } from "@/components/ui/spinner"; +import { DashboardLayout } from "@/layouts/DashboardLayout"; -const LoginPage = lazy(() => import('@/pages/login')) -const DashboardPage = lazy(() => import('@/pages/dashboard')) +const LoginPage = lazy(() => import("@/pages/login")); +const DashboardPage = lazy(() => import("@/pages/dashboard")); +const LoanOrdersPage = lazy(() => import("@/pages/loanOrders")); +const LoanOrderMobilesPage = lazy(() => import("@/pages/loanOrderMobiles")); +const LoanRemainingPage = lazy(() => import("@/pages/loanRemaining")); +const LoanPaidOffLettersPage = lazy(() => import("@/pages/loanPaidOffLetters")); function AuthGuard() { - const isAuthenticated = useAuthStore((s) => s.isAuthenticated) - - if (!isAuthenticated) { - return - } - - return + const isAuthenticated = useAuthStore((s) => s.isAuthenticated); + if (!isAuthenticated) return ; + return ; } function PublicGuard() { - const isAuthenticated = useAuthStore((s) => s.isAuthenticated) - - if (isAuthenticated) { - return - } - - return + const isAuthenticated = useAuthStore((s) => s.isAuthenticated); + if (isAuthenticated) return ; + return ; } function PageLoader() { return ( -
- +
+
- ) + ); } export const router = createBrowserRouter([ @@ -40,7 +37,7 @@ export const router = createBrowserRouter([ element: , children: [ { - path: '/login', + path: "/login", element: ( }> @@ -53,21 +50,61 @@ export const router = createBrowserRouter([ element: , children: [ { - path: '/dashboard', - element: ( - }> - - - ), - }, - { - path: '/', - element: , + element: , + children: [ + { + path: "/dashboard", + element: ( + }> + + + ), + }, + + { path: "/", element: }, + + // ── KARZ BÖLÜMI ────────────────────────────────────────────────── + { + path: "/resources/loan-orders", + element: ( + }> + + + ), + }, + { + // Sidebar: /resources/loan-order-mobiles + path: "/resources/loan-order-mobiles", + element: ( + }> + + + ), + }, + { + // Sidebar: /resources/loan-remaining + path: "/resources/loan-remaining", + element: ( + }> + + + ), + }, + { + // Sidebar: /resources/loan-paid-off-letters + path: "/resources/loan-paid-off-letters", + element: ( + }> + + + ), + }, + ], }, ], }, { - path: '*', + path: "*", element: , }, -]) +]); diff --git a/src/assets/icon.svg b/src/assets/icon.svg new file mode 100644 index 0000000..689797a --- /dev/null +++ b/src/assets/icon.svg @@ -0,0 +1,3013 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/components/dataTable.tsx b/src/components/dataTable.tsx new file mode 100644 index 0000000..4d501ed --- /dev/null +++ b/src/components/dataTable.tsx @@ -0,0 +1,456 @@ +import { useRef, useState } from 'react' +import { + flexRender, + getCoreRowModel, + useReactTable, + type ColumnDef, + type VisibilityState, + type RowSelectionState, + type SortingState, + getSortedRowModel, +} from '@tanstack/react-table' +import { + Table, + TableBody, + TableCell, + TableHead, + TableHeader, + TableRow, +} from '@/components/ui/table' +import { Checkbox } from '@/components/ui/checkbox' +import { + Pagination, + PaginationContent, + PaginationEllipsis, + PaginationItem, + PaginationLink, + PaginationNext, + PaginationPrevious, +} from '@/components/ui/pagination' +import { cn } from '@/lib/utils' +import { useOutsideClick } from '@/lib/hooks/useOutsideClick' +import { ChevronDown } from 'lucide-react' + +export type { ColumnDef } + +// ─── Pagination ─────────────────────────────────────────────────────────────── + +interface DataTablePaginationProps { + currentPage: number + totalPages: number + onPageChange: (page: number) => void +} + +function DataTablePagination({ + currentPage, + totalPages, + onPageChange, +}: DataTablePaginationProps) { + if (totalPages <= 1) return null + + const getPages = (): (number | 'ellipsis')[] => { + if (totalPages <= 7) return Array.from({ length: totalPages }, (_, i) => i + 1) + + const pages: (number | 'ellipsis')[] = [1] + + if (currentPage > 3) pages.push('ellipsis') + + const start = Math.max(2, currentPage - 1) + const end = Math.min(totalPages - 1, currentPage + 1) + + for (let i = start; i <= end; i++) pages.push(i) + + if (currentPage < totalPages - 2) pages.push('ellipsis') + + pages.push(totalPages) + return pages + } + + return ( + + + + { + e.preventDefault() + if (currentPage > 1) onPageChange(currentPage - 1) + }} + className={cn(currentPage === 1 && 'pointer-events-none opacity-40')} + /> + + + {getPages().map((page, i) => + page === 'ellipsis' ? ( + + + + ) : ( + + { + e.preventDefault() + onPageChange(page) + }} + > + {page} + + + ) + )} + + + { + e.preventDefault() + if (currentPage < totalPages) onPageChange(currentPage + 1) + }} + className={cn(currentPage === totalPages && 'pointer-events-none opacity-40')} + /> + + + + ) +} + +// ─── Select All Dropdown ────────────────────────────────────────────────────── + +interface SelectAllDropdownProps { + isAllPageSelected: boolean + isSomePageSelected: boolean + isAllTotalSelected: boolean + totalCount: number + pageCount: number + onSelectPage: (checked: boolean) => void + onSelectAll: () => void + onClearAll: () => void +} + +function SelectAllDropdown({ + isAllPageSelected, + isSomePageSelected, + isAllTotalSelected, + totalCount, + pageCount, + onSelectPage, + onSelectAll, + onClearAll, +}: SelectAllDropdownProps) { + const [open, setOpen] = useState(false) + const ref = useRef(null) + useOutsideClick(ref, () => setOpen(false)) + + const checkboxChecked = isAllPageSelected || (isSomePageSelected && 'indeterminate') + + return ( +
+ onSelectPage(!!value)} + aria-label="Select all on page" + /> + + + {open && ( +
+ + + {(isAllPageSelected || isAllTotalSelected || isSomePageSelected) && ( + <> +
+ + + )} +
+ )} +
+ ) +} + +// ─── DataTable ──────────────────────────────────────────────────────────────── + +interface DataTableProps { + columns: ColumnDef[] + data: TData[] + isLoading?: boolean + columnVisibility?: VisibilityState + onColumnVisibilityChange?: (visibility: VisibilityState) => void + columnOrder?: string[] + onColumnOrderChange?: (order: string[]) => void + enableRowSelection?: boolean + onRowSelectionChange?: (rows: TData[]) => void + getRowId?: (row: TData) => string + + // Pagination — server-side + currentPage?: number + totalPages?: number + totalCount?: number + onPageChange?: (page: number) => void +} + +export function DataTable({ + columns, + data, + isLoading = false, + columnVisibility, + onColumnVisibilityChange, + columnOrder, + onColumnOrderChange, + enableRowSelection = false, + onRowSelectionChange, + getRowId, + currentPage = 1, + totalPages = 1, + totalCount, + onPageChange, +}: DataTableProps) { + const [sorting, setSorting] = useState([]) + const [rowSelection, setRowSelection] = useState({}) + // Tracks whether ALL records (across pages) are logically selected + const [allTotalSelected, setAllTotalSelected] = useState(false) + + const resolvedTotalCount = totalCount ?? data.length + + // ── Build selection column ────────────────────────────────────────────────── + const selectionColumn: ColumnDef = { + id: 'select', + header: ({ table }) => ( +
+ { + table.toggleAllPageRowsSelected(checked) + if (!checked) setAllTotalSelected(false) + }} + onSelectAll={() => { + table.toggleAllPageRowsSelected(true) + setAllTotalSelected(true) + }} + onClearAll={() => { + table.toggleAllPageRowsSelected(false) + setAllTotalSelected(false) + }} + /> +
+ ), + cell: ({ row }) => ( + row.toggleSelected(!!value)} + aria-label="Select row" + onClick={(e) => e.stopPropagation()} + /> + ), + enableSorting: false, + enableHiding: false, + size: 48, + } + + const allColumns: ColumnDef[] = enableRowSelection + ? [selectionColumn, ...columns] + : columns + + const effectiveColumnOrder: string[] = enableRowSelection + ? columnOrder && columnOrder.length > 0 + ? columnOrder[0] === 'select' + ? columnOrder + : ['select', ...columnOrder.filter((id) => id !== 'select')] + : [] + : (columnOrder ?? []) + + const table = useReactTable({ + data, + columns: allColumns, + state: { + sorting, + rowSelection, + columnVisibility: columnVisibility ?? {}, + columnOrder: effectiveColumnOrder, + }, + getRowId, + enableRowSelection, + onRowSelectionChange: (updater) => { + const newSelection = + typeof updater === 'function' ? updater(rowSelection) : updater + setRowSelection(newSelection) + // If deselecting anything, clear allTotalSelected + if (Object.keys(newSelection).length < data.length) { + setAllTotalSelected(false) + } + if (onRowSelectionChange) { + const selectedRows = data.filter((_, index) => + newSelection[getRowId ? getRowId(data[index]) : String(index)] + ) + onRowSelectionChange(selectedRows) + } + }, + onSortingChange: setSorting, + onColumnVisibilityChange: (updater) => { + if (!onColumnVisibilityChange) return + const next = + typeof updater === 'function' ? updater(columnVisibility ?? {}) : updater + onColumnVisibilityChange(next) + }, + onColumnOrderChange: (updater) => { + if (!onColumnOrderChange) return + const next = + typeof updater === 'function' ? updater(columnOrder ?? []) : updater + onColumnOrderChange(next) + }, + getCoreRowModel: getCoreRowModel(), + getSortedRowModel: getSortedRowModel(), + }) + + // ── Selection banner ──────────────────────────────────────────────────────── + const selectedCount = Object.keys(rowSelection).length + const showBanner = enableRowSelection && (selectedCount > 0 || allTotalSelected) + + return ( +
+ {/* Selection banner */} + {showBanner && ( +
+ + {allTotalSelected + ? `All ${resolvedTotalCount} records selected` + : `${selectedCount} row${selectedCount !== 1 ? 's' : ''} selected`} + + +
+ )} + + {/* Table */} +
+ + + {table.getHeaderGroups().map((headerGroup) => ( + + {headerGroup.headers.map((header) => ( + + {header.isPlaceholder + ? null + : flexRender(header.column.columnDef.header, header.getContext())} + + ))} + + ))} + + + {isLoading ? ( + Array.from({ length: 7 }).map((_, i) => ( + + {allColumns.map((_, j) => ( + +
+ + ))} + + )) + ) : table.getRowModel().rows.length === 0 ? ( + + + No data found + + + ) : ( + table.getRowModel().rows.map((row) => ( + + {row.getVisibleCells().map((cell) => ( + + {flexRender(cell.column.columnDef.cell, cell.getContext())} + + ))} + + )) + )} + +
+
+ + {/* Pagination */} + {onPageChange && ( + { + // Clear selection on page change (server-side pattern) + if (!allTotalSelected) { + table.toggleAllPageRowsSelected(false) + setRowSelection({}) + } + onPageChange(page) + }} + /> + )} +
+ ) +} \ No newline at end of file diff --git a/src/components/dataTableToolbar.tsx b/src/components/dataTableToolbar.tsx new file mode 100644 index 0000000..8a78e64 --- /dev/null +++ b/src/components/dataTableToolbar.tsx @@ -0,0 +1,393 @@ +import { useRef, useState } from 'react' +import { useTranslation } from 'react-i18next' +import { SlidersHorizontal, Clock, Filter, ChevronDown, X, GripVertical } from 'lucide-react' +import type { VisibilityState } from '@tanstack/react-table' +import { useOutsideClick } from '@/lib/hooks/useOutsideClick' +import { cn } from '@/lib/utils' +import { TableSearchInput } from '@/components/tableSearch' +import { TableActionButton } from '@/components/tableButton' + +// ─── Types ──────────────────────────────────────────────────────────────────── + +export interface ColumnMeta { + id: string + label: string +} + +export interface FilterField { + id: string + label: string + options: { value: string; label: string }[] +} + +export interface ActiveFilter { + fieldId: string + value: string +} + +interface DataTableToolbarProps { + searchValue: string + onSearchChange: (value: string) => void + searchPlaceholder?: string + + columns: ColumnMeta[] + columnVisibility: VisibilityState + onColumnVisibilityChange: (visibility: VisibilityState) => void + columnOrder: string[] + onColumnOrderChange: (order: string[]) => void + + filterFields?: FilterField[] + activeFilters?: ActiveFilter[] + onFilterChange?: (fieldId: string, value: string) => void + onFilterReset?: () => void + + perPageOptions?: number[] + perPage?: number + onPerPageChange?: (value: number) => void + + actionLabel?: string + onAction?: () => void + + hideSearch?: boolean + hideAction?: boolean +} + +// ─── Toggle Columns Dropdown ────────────────────────────────────────────────── + +interface ToggleColumnsDropdownProps { + columns: ColumnMeta[] + columnVisibility: VisibilityState + onColumnVisibilityChange: (visibility: VisibilityState) => void + columnOrder: string[] + onColumnOrderChange: (order: string[]) => void +} + +function ToggleColumnsDropdown({ + columns, + columnVisibility, + onColumnVisibilityChange, + columnOrder, + onColumnOrderChange, +}: ToggleColumnsDropdownProps) { + const { t } = useTranslation() + const [open, setOpen] = useState(false) + const ref = useRef(null) + const dragIdRef = useRef(null) + const [dragOverId, setDragOverId] = useState(null) + + useOutsideClick(ref, () => setOpen(false)) + + const isVisible = (id: string) => + columnVisibility[id] === undefined ? true : columnVisibility[id] + + const toggle = (id: string) => { + onColumnVisibilityChange({ ...columnVisibility, [id]: !isVisible(id) }) + } + + // columnOrder'a göre sırala; columnOrder'da olmayan kolonları sona at + const orderedColumns = [...columns].sort((a, b) => { + const ai = columnOrder.indexOf(a.id) + const bi = columnOrder.indexOf(b.id) + if (ai === -1 && bi === -1) return 0 + if (ai === -1) return 1 + if (bi === -1) return -1 + return ai - bi + }) + + const handleDragStart = (id: string) => { + dragIdRef.current = id + } + + const handleDragOver = (e: React.DragEvent, id: string) => { + e.preventDefault() + if (dragIdRef.current !== id) setDragOverId(id) + } + + const handleDrop = (targetId: string) => { + const sourceId = dragIdRef.current + if (!sourceId || sourceId === targetId) return + + const next = [...columnOrder] + const from = next.indexOf(sourceId) + const to = next.indexOf(targetId) + + // columnOrder'da yoksa ekle + const safeFrom = from === -1 ? next.length : from + const safeTo = to === -1 ? next.length : to + + next.splice(safeFrom, 1) + next.splice(safeTo, 0, sourceId) + onColumnOrderChange(next) + + dragIdRef.current = null + setDragOverId(null) + } + + const handleDragEnd = () => { + dragIdRef.current = null + setDragOverId(null) + } + + return ( +
+ + + {open && ( +
+

+ {t('table.toggleColumns', 'Toggle Columns')} +

+ {orderedColumns.map((col) => ( +
handleDragStart(col.id)} + onDragOver={(e) => handleDragOver(e, col.id)} + onDrop={() => handleDrop(col.id)} + onDragEnd={handleDragEnd} + className={cn( + 'flex items-center gap-2.5 px-3 py-1.5 transition-colors cursor-default', + 'hover:bg-muted/40', + dragOverId === col.id && 'bg-primary/10 border-l-2 border-primary' + )} + > + + toggle(col.id)} + className="w-4 h-4 rounded cursor-pointer accent-primary" + /> + +
+ ))} +
+ )} +
+ ) +} + +// ─── Date Filter Button ─────────────────────────────────────────────────────── + +function DateFilterButton() { + return ( + + ) +} + +// ─── Filter Dropdown ────────────────────────────────────────────────────────── + +interface FilterDropdownProps { + filterFields: FilterField[] + activeFilters: ActiveFilter[] + onFilterChange: (fieldId: string, value: string) => void + onFilterReset: () => void + perPageOptions?: number[] + perPage?: number + onPerPageChange?: (value: number) => void +} + +function FilterDropdown({ + filterFields, + activeFilters, + onFilterChange, + onFilterReset, + perPageOptions = [10, 25, 50, 100], + perPage = 25, + onPerPageChange, +}: FilterDropdownProps) { + const { t } = useTranslation() + const [open, setOpen] = useState(false) + const ref = useRef(null) + useOutsideClick(ref, () => setOpen(false)) + + const activeCount = activeFilters.filter((f) => f.value !== '').length + const hasActive = activeCount > 0 + + const getActiveValue = (fieldId: string) => + activeFilters.find((f) => f.fieldId === fieldId)?.value ?? '' + + return ( +
+ + + {open && ( +
+
+

+ {t('table.filters', 'Filters')} +

+ {hasActive && ( + + )} +
+ +
+ {filterFields.map((field) => ( +
+ + +
+ ))} + + {onPerPageChange && ( +
+ + +
+ )} +
+
+ )} +
+ ) +} + +// ─── DataTableToolbar ───────────────────────────────────────────────────────── + +export function DataTableToolbar({ + searchValue, + onSearchChange, + searchPlaceholder, + columns, + columnVisibility, + onColumnVisibilityChange, + columnOrder, + onColumnOrderChange, + filterFields = [], + activeFilters = [], + onFilterChange, + onFilterReset, + perPageOptions, + perPage, + onPerPageChange, + actionLabel, + onAction, + hideSearch = false, + hideAction = false, +}: DataTableToolbarProps) { + return ( +
+ {!hideSearch && ( + + )} + +
+ + + + + {filterFields.length > 0 && onFilterChange && onFilterReset && ( + + )} + + {!hideAction && actionLabel && onAction && ( + + )} +
+
+ ) +} \ No newline at end of file diff --git a/src/components/tableButton.tsx b/src/components/tableButton.tsx new file mode 100644 index 0000000..14552dd --- /dev/null +++ b/src/components/tableButton.tsx @@ -0,0 +1,36 @@ +import { Plus } from 'lucide-react' +import { Button } from '@/components/ui/button' +import { cn } from '@/lib/utils' + +interface TableActionButtonProps { + label: string + onClick: () => void + icon?: React.ReactNode + disabled?: boolean + className?: string + variant?: 'primary' | 'destructive' | 'secondary' +} + +export function TableActionButton({ + label, + onClick, + icon, + disabled = false, + className, + variant = 'primary', +}: TableActionButtonProps) { + return ( + + ) +} \ No newline at end of file diff --git a/src/components/tableSearch.tsx b/src/components/tableSearch.tsx new file mode 100644 index 0000000..f4a77be --- /dev/null +++ b/src/components/tableSearch.tsx @@ -0,0 +1,40 @@ +import { Search } from 'lucide-react' +import { useTranslation } from 'react-i18next' +import { cn } from '@/lib/utils' + +interface TableSearchInputProps { + value: string + onChange: (value: string) => void + placeholder?: string + className?: string +} + +export function TableSearchInput({ + value, + onChange, + placeholder, + className, +}: TableSearchInputProps) { + const { t } = useTranslation() + + return ( +
+ + onChange(e.target.value)} + placeholder={placeholder ?? t('table.search', 'Search...')} + className={cn( + 'h-9 w-64 rounded-md border border-border bg-background pl-9 pr-3', + 'text-sm text-foreground placeholder:text-muted-foreground', + 'focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent', + 'transition-colors' + )} + /> +
+ ) +} \ No newline at end of file diff --git a/src/components/ui/button-variants.ts b/src/components/ui/button-variants.ts index 8a78a81..5ac3ffa 100644 --- a/src/components/ui/button-variants.ts +++ b/src/components/ui/button-variants.ts @@ -1,7 +1,7 @@ import { cva } from "class-variance-authority" export const buttonVariants = cva( - "group/button inline-flex shrink-0 items-center justify-center rounded-lg border border-transparent bg-clip-padding text-sm font-medium whitespace-nowrap transition-all outline-none select-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 active:not-aria-[haspopup]:translate-y-px disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 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", + "group/button inline-flex shrink-0 cursor-pointer items-center justify-center rounded-md border border-transparent bg-clip-padding text-sm font-medium whitespace-nowrap transition-all outline-none select-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 active:not-aria-[haspopup]:translate-y-px disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 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", { variants: { variant: { diff --git a/src/components/ui/input.tsx b/src/components/ui/input.tsx index d763cd9..ad5d042 100644 --- a/src/components/ui/input.tsx +++ b/src/components/ui/input.tsx @@ -8,7 +8,7 @@ function Input({ className, type, ...props }: React.ComponentProps<"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", + "h-8 w-full min-w-0 rounded-md 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} diff --git a/src/components/ui/sidebar.tsx b/src/components/ui/sidebar.tsx index 74fe88f..abaa0fe 100644 --- a/src/components/ui/sidebar.tsx +++ b/src/components/ui/sidebar.tsx @@ -4,7 +4,7 @@ import * as React from "react" import { cva, type VariantProps } from "class-variance-authority" import { Slot } from "radix-ui" -import { useIsMobile } from "@/hooks/use-mobile" +import { useIsMobile } from "@/lib/hooks/useMobile" import { cn } from "@/lib/utils" import { Button } from "@/components/ui/button" import { Input } from "@/components/ui/input" diff --git a/src/components/ui/statusBadge.tsx b/src/components/ui/statusBadge.tsx new file mode 100644 index 0000000..58a9cf4 --- /dev/null +++ b/src/components/ui/statusBadge.tsx @@ -0,0 +1,33 @@ +import { cn } from '@/lib/utils' + +export type StatusBadgeVariant = 'warning' | 'success' | 'error' | 'info' | 'default' + +interface StatusBadgeProps { + label: string + variant: StatusBadgeVariant + icon?: React.ElementType + className?: string +} + +const VARIANT_STYLES: Record = { + warning: 'bg-amber-500/15 text-amber-500 border-amber-500/30', + success: 'bg-emerald-500/15 text-emerald-500 border-emerald-500/30', + error: 'bg-red-500/15 text-red-500 border-red-500/30', + info: 'bg-blue-500/15 text-blue-500 border-blue-500/30', + default: 'bg-muted/50 text-muted-foreground border-border', +} + +export function StatusBadge({ label, variant, icon: Icon, className }: StatusBadgeProps) { + return ( + + {Icon && } + {label} + + ) +} \ No newline at end of file diff --git a/src/components/ui/table.tsx b/src/components/ui/table.tsx new file mode 100644 index 0000000..ac9585e --- /dev/null +++ b/src/components/ui/table.tsx @@ -0,0 +1,114 @@ +import * as React from "react" + +import { cn } from "@/lib/utils" + +function Table({ className, ...props }: React.ComponentProps<"table">) { + return ( +
+ + + ) +} + +function TableHeader({ className, ...props }: React.ComponentProps<"thead">) { + return ( + + ) +} + +function TableBody({ className, ...props }: React.ComponentProps<"tbody">) { + return ( + + ) +} + +function TableFooter({ className, ...props }: React.ComponentProps<"tfoot">) { + return ( + tr]:last:border-b-0", + className + )} + {...props} + /> + ) +} + +function TableRow({ className, ...props }: React.ComponentProps<"tr">) { + return ( + + ) +} + +function TableHead({ className, ...props }: React.ComponentProps<"th">) { + return ( +
+ ) +} + +function TableCell({ className, ...props }: React.ComponentProps<"td">) { + return ( + + ) +} + +function TableCaption({ + className, + ...props +}: React.ComponentProps<"caption">) { + return ( +
+ ) +} + +export { + Table, + TableHeader, + TableBody, + TableFooter, + TableHead, + TableRow, + TableCell, + TableCaption, +} diff --git a/src/components/ui/tooltip.tsx b/src/components/ui/tooltip.tsx index bb1ea52..545cafa 100644 --- a/src/components/ui/tooltip.tsx +++ b/src/components/ui/tooltip.tsx @@ -48,7 +48,7 @@ function TooltipContent({ {...props} > {children} - + ) diff --git a/src/features/auth/api/authApi.ts b/src/features/auth/api/authApi.ts index 5f4777a..0471b63 100644 --- a/src/features/auth/api/authApi.ts +++ b/src/features/auth/api/authApi.ts @@ -13,8 +13,8 @@ export interface LoginResponse { // Mock credentials const MOCK_USERS: Array<{ email: string; password: string; user: AuthUser; token: string }> = [ { - email: 'admin@tbbank.tm', - password: 'Admin123!', + email: 'jelaletdin', + password: '123', token: 'mock-jwt-token-admin-xyz123', user: { id: '1', diff --git a/src/features/loanOrderMobiles/api/loanOrderMobilesApi.ts b/src/features/loanOrderMobiles/api/loanOrderMobilesApi.ts new file mode 100644 index 0000000..e51f0c1 --- /dev/null +++ b/src/features/loanOrderMobiles/api/loanOrderMobilesApi.ts @@ -0,0 +1,105 @@ +import { apiClient } from '@/lib/api/client' + +// ─── Types ───────────────────────────────────────────────────────────────────── + +export type LoanOrderMobileStatus = + | 'GARAŞYLÝAR' + | 'KANAGATLANDYRYLAN' + | 'RED_EDILDI' + | 'IŞLENÝÄR' + +export interface LoanOrderMobile { + id: string + loanType: string + createdAt: string + region: string + branch: string + firstName: string + lastName: string + phone: string + status: LoanOrderMobileStatus +} + +export interface LoanOrderMobileListParams { + search?: string + region?: string + status?: LoanOrderMobileStatus + branch?: string + archived?: string + page?: number + perPage?: number +} + +export interface PaginatedResponse { + data: T[] + total: number +} + +// ─── Mock Data ───────────────────────────────────────────────────────────────── + +const USE_MOCK = true // gerçek API hazır olunca false yap + +const MOCK_DATA: LoanOrderMobile[] = [ + { id: 'LOM-0001', loanType: 'Sarp etmek karzy', createdAt: '2025-01-15 09:42', region: 'Aşgabat', branch: 'Merkezi', firstName: 'Oraz', lastName: 'Annaýew', phone: '+99361123456', status: 'GARAŞYLÝAR' }, + { id: 'LOM-0002', loanType: 'Awtoulag karzy', createdAt: '2025-01-18 11:05', region: 'Ahal', branch: 'Änew', firstName: 'Merjen', lastName: 'Hudaýewa', phone: '+99362234567', status: 'KANAGATLANDYRYLAN' }, + { id: 'LOM-0003', loanType: 'Ipoteka karzy', createdAt: '2025-01-20 14:30', region: 'Balkan', branch: 'Türkmenbaşy', firstName: 'Serdar', lastName: 'Durdyýew', phone: '+99363345678', status: 'IŞLENÝÄR' }, + { id: 'LOM-0004', loanType: 'Telekeçilik karzy', createdAt: '2025-01-22 08:15', region: 'Lebap', branch: 'Türkmenabat', firstName: 'Aýna', lastName: 'Meredowa', phone: '+99365456789', status: 'RED_EDILDI' }, + { id: 'LOM-0005', loanType: 'Sarp etmek karzy', createdAt: '2025-01-25 16:00', region: 'Mary', branch: 'Mary', firstName: 'Begmyrat',lastName: 'Oraz', phone: '+99366567890', status: 'GARAŞYLÝAR' }, + { id: 'LOM-0006', loanType: 'Bilim karzy', createdAt: '2025-01-28 10:20', region: 'Daşoguz', branch: 'Daşoguz', firstName: 'Gülälek', lastName: 'Saparowa', phone: '+99361678901', status: 'KANAGATLANDYRYLAN' }, + { id: 'LOM-0007', loanType: 'Awtoulag karzy', createdAt: '2025-02-01 13:45', region: 'Aşgabat', branch: 'Çoganly', firstName: 'Myrat', lastName: 'Ataýew', phone: '+99362789012', status: 'IŞLENÝÄR' }, + { id: 'LOM-0008', loanType: 'Ipoteka karzy', createdAt: '2025-02-03 09:00', region: 'Ahal', branch: 'Tejen', firstName: 'Ogulnur', lastName: 'Berdiýewa', phone: '+99363890123', status: 'GARAŞYLÝAR' }, + { id: 'LOM-0009', loanType: 'Telekeçilik karzy', createdAt: '2025-02-05 15:30', region: 'Balkan', branch: 'Balkanabat', firstName: 'Döwlet', lastName: 'Çaryýew', phone: '+99364901234', status: 'RED_EDILDI' }, + { id: 'LOM-0010', loanType: 'Sarp etmek karzy', createdAt: '2025-02-08 11:15', region: 'Lebap', branch: 'Farap', firstName: 'Maral', lastName: 'Ýollyýewa', phone: '+99365012345', status: 'KANAGATLANDYRYLAN' }, + { id: 'LOM-0011', loanType: 'Bilim karzy', createdAt: '2025-02-10 08:45', region: 'Mary', branch: 'Baýramaly', firstName: 'Nurmuhammet', lastName: 'Garaýew', phone: '+99366123456', status: 'GARAŞYLÝAR' }, + { id: 'LOM-0012', loanType: 'Awtoulag karzy', createdAt: '2025-02-12 14:00', region: 'Daşoguz', branch: 'Köneürgenç', firstName: 'Şemşat', lastName: 'Jumaýewa', phone: '+99361234567', status: 'IŞLENÝÄR' }, +] + +function applyMockFilters( + params: LoanOrderMobileListParams, +): PaginatedResponse { + let result = [...MOCK_DATA] + + if (params.search) { + const q = params.search.toLowerCase() + result = result.filter( + (r) => + r.firstName.toLowerCase().includes(q) || + r.lastName.toLowerCase().includes(q) || + r.phone.includes(q) || + r.id.toLowerCase().includes(q), + ) + } + if (params.region) result = result.filter((r) => r.region === params.region) + if (params.status) result = result.filter((r) => r.status === params.status) + if (params.branch) result = result.filter((r) => r.branch === params.branch) + + const total = result.length + const page = params.page ?? 1 + const perPage = params.perPage ?? 25 + const start = (page - 1) * perPage + + return { data: result.slice(start, start + perPage), total } +} + +// ─── API Functions ───────────────────────────────────────────────────────────── + +export async function fetchLoanOrderMobiles( + params: LoanOrderMobileListParams, +): Promise> { + if (USE_MOCK) return applyMockFilters(params) + + const { data } = await apiClient.get>( + '/loan-order-mobiles', + { params }, + ) + return data +} + +export async function deleteLoanOrderMobile(id: string): Promise { + if (USE_MOCK) { + const idx = MOCK_DATA.findIndex((r) => r.id === id) + if (idx !== -1) MOCK_DATA.splice(idx, 1) + return + } + await apiClient.delete(`/loan-order-mobiles/${id}`) +} \ No newline at end of file diff --git a/src/features/loanOrderMobiles/hooks/useLoanOrderMobiles.ts b/src/features/loanOrderMobiles/hooks/useLoanOrderMobiles.ts new file mode 100644 index 0000000..45dd969 --- /dev/null +++ b/src/features/loanOrderMobiles/hooks/useLoanOrderMobiles.ts @@ -0,0 +1,42 @@ +import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query' +import { toast } from 'sonner' +import { useTranslation } from 'react-i18next' + +import { + fetchLoanOrderMobiles, + deleteLoanOrderMobile, + type LoanOrderMobileListParams, +} from '../api/loanOrderMobilesApi' + +// ─── Query keys ──────────────────────────────────────────────────────────────── + +export const loanOrderMobileKeys = { + all: ['loanOrderMobiles'] as const, + lists: () => [...loanOrderMobileKeys.all, 'list'] as const, + list: (params: LoanOrderMobileListParams) => [...loanOrderMobileKeys.lists(), params] as const, +} + +// ─── Hooks ───────────────────────────────────────────────────────────────────── + +export function useLoanOrderMobiles(params: LoanOrderMobileListParams) { + return useQuery({ + queryKey: loanOrderMobileKeys.list(params), + queryFn: () => fetchLoanOrderMobiles(params), + }) +} + +export function useDeleteLoanOrderMobile() { + const queryClient = useQueryClient() + const { t } = useTranslation() + + return useMutation({ + mutationFn: (id: string) => deleteLoanOrderMobile(id), + onSuccess: () => { + queryClient.invalidateQueries({ queryKey: loanOrderMobileKeys.lists() }) + toast.success(t('loanOrderMobiles.deleteSuccess', 'Sargyt üstünlikli pozuldy')) + }, + onError: () => { + toast.error(t('loanOrderMobiles.deleteError', 'Pozmak başartmady, gaýtadan synanyşyň')) + }, + }) +} \ No newline at end of file diff --git a/src/features/loanOrders/api/loanOrdersApi.ts b/src/features/loanOrders/api/loanOrdersApi.ts new file mode 100644 index 0000000..b34de26 --- /dev/null +++ b/src/features/loanOrders/api/loanOrdersApi.ts @@ -0,0 +1,162 @@ +import { apiClient } from '@/lib/api/client' + +const MOCK_DATA: LoanOrder[] = [ + { + id: 'L-1001', + loanType: 'Ipoteka karzy', + createdAt: '2024-03-20 10:30', + region: 'Aşgabat', + branch: 'Merkezi şahamça', + firstName: 'Aman', + lastName: 'Amanow', + phone: '+993 65 112233', + status: 'GARAŞYLÝAR', + }, + { + id: 'L-1002', + loanType: 'Sarp ediş karzy', + createdAt: '2024-03-19 14:15', + region: 'Mary', + branch: 'Mary-1 şahamçasy', + firstName: 'Oguljan', + lastName: 'Berdiýewa', + phone: '+993 61 445566', + status: 'IŞLENÝÄR', + }, + { + id: 'L-1003', + loanType: 'Biznes karzy', + createdAt: '2024-03-18 09:00', + region: 'Lebap', + branch: 'Türkmenabat şahamçasy', + firstName: 'Myrat', + lastName: 'Hallyýew', + phone: '+993 64 778899', + status: 'KANAGATLANDYRYLAN', + }, + { + id: 'L-1004', + loanType: 'Talyp karzy', + createdAt: '2024-03-17 16:45', + region: 'Balkan', + branch: 'Türkmenbaşy şahamçasy', + firstName: 'Jeren', + lastName: 'Saparowa', + phone: '+993 62 001122', + status: 'RED_EDILDI', + }, + { + id: 'L-1005', + loanType: 'Awtoulag karzy', + createdAt: '2024-03-16 11:20', + region: 'Daşoguz', + branch: 'Daşoguz-2 şahamçasy', + firstName: 'Döwlet', + lastName: 'Meredow', + phone: '+993 63 334455', + status: 'GARAŞYLÝAR', + } +]; + +// ─── Types ─────────────────────────────────────────────────────────────────── + +export type LoanOrderStatus = + | 'GARAŞYLÝAR' + | 'KANAGATLANDYRYLAN' + | 'RED_EDILDI' + | 'IŞLENÝÄR' + +export interface LoanOrder { + id: string + loanType: string + createdAt: string + region: string + branch: string + firstName: string + lastName: string + phone: string + status: LoanOrderStatus +} + +export interface LoanOrdersParams { + search?: string + region?: string + status?: LoanOrderStatus | '' + branch?: string + archived?: string + page?: number + perPage?: number +} + +export interface LoanOrdersResponse { + data: LoanOrder[] + total: number + page: number + perPage: number +} + +export interface CreateLoanOrderPayload { + loanType: string + region: string + branch: string + firstName: string + lastName: string + phone: string +} + +// ─── API Functions ──────────────────────────────────────────────────────────── + +export async function fetchLoanOrders( + params: LoanOrdersParams +): Promise { + // Hakyky API ýok wagty simulator (800ms garaşdyrýar) + await new Promise((resolve) => setTimeout(resolve, 800)); + + // Gözleg (search) logic-ni simulirlemek (optional) + const filtered = MOCK_DATA.filter(item => + !params.search || + item.firstName.toLowerCase().includes(params.search.toLowerCase()) || + item.id.toLowerCase().includes(params.search.toLowerCase()) + ); + + return { + data: filtered, + total: filtered.length, + page: params.page || 1, + perPage: params.perPage || 25, + };} + +// export async function fetchLoanOrders( +// params: LoanOrdersParams +// ): Promise { +// const { data } = await apiClient.get( +// '/resources/loan-orders', +// { params } +// ) +// return data +// } + +export async function createLoanOrder( + payload: CreateLoanOrderPayload +): Promise { + const { data } = await apiClient.post( + '/resources/loan-orders', + payload + ) + return data +} + +export async function updateLoanOrder( + id: string, + payload: Partial +): Promise { + const { data } = await apiClient.put( + `/resources/loan-orders/${id}`, + payload + ) + return data +} + +export async function deleteLoanOrder(id: string): Promise { + await apiClient.delete(`/resources/loan-orders/${id}`) +} \ No newline at end of file diff --git a/src/features/loanOrders/components/loanOrderStatusBadge.tsx b/src/features/loanOrders/components/loanOrderStatusBadge.tsx new file mode 100644 index 0000000..8b9b190 --- /dev/null +++ b/src/features/loanOrders/components/loanOrderStatusBadge.tsx @@ -0,0 +1,25 @@ +import { AlertCircle, CheckCircle2, XCircle, Loader2 } from 'lucide-react' +import { StatusBadge, type StatusBadgeVariant } from '@/components/ui/statusBadge' +import type { LoanOrderStatus } from '../api/loanOrdersApi' + +interface LoanOrderStatusConfig { + label: string + variant: StatusBadgeVariant + icon: React.ElementType +} + +const STATUS_CONFIG: Record = { + GARAŞYLÝAR: { label: 'GARAŞYLÝAR', variant: 'warning', icon: AlertCircle }, + KANAGATLANDYRYLAN: { label: 'KANAGATLANDYRYLAN', variant: 'success', icon: CheckCircle2 }, + RED_EDILDI: { label: 'RED EDILDI', variant: 'error', icon: XCircle }, + IŞLENÝÄR: { label: 'IŞLENÝÄR', variant: 'info', icon: Loader2 }, +} + +interface LoanOrderStatusBadgeProps { + status: LoanOrderStatus +} + +export function LoanOrderStatusBadge({ status }: LoanOrderStatusBadgeProps) { + const config = STATUS_CONFIG[status] + return +} \ No newline at end of file diff --git a/src/features/loanOrders/hooks/useLoanOrders.ts b/src/features/loanOrders/hooks/useLoanOrders.ts new file mode 100644 index 0000000..6a3474d --- /dev/null +++ b/src/features/loanOrders/hooks/useLoanOrders.ts @@ -0,0 +1,70 @@ +import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query' +import { toast } from 'sonner' +import { useTranslation } from 'react-i18next' +import { + fetchLoanOrders, + createLoanOrder, + updateLoanOrder, + deleteLoanOrder, + type LoanOrdersParams, + type CreateLoanOrderPayload, +} from '../api/loanOrdersApi' + +const LOAN_ORDERS_KEY = 'loan-orders' + +export function useLoanOrders(params: LoanOrdersParams) { + return useQuery({ + queryKey: [LOAN_ORDERS_KEY, params], + queryFn: () => fetchLoanOrders(params), + placeholderData: (prev) => prev, + }) +} + +export function useCreateLoanOrder() { + const { t } = useTranslation() + const queryClient = useQueryClient() + + return useMutation({ + mutationFn: (payload: CreateLoanOrderPayload) => createLoanOrder(payload), + onSuccess: () => { + queryClient.invalidateQueries({ queryKey: [LOAN_ORDERS_KEY] }) + toast.success(t('loanOrders.createSuccess', 'Karz sargyt üstünlikli döredildi')) + }, + onError: () => { + toast.error(t('loanOrders.createError', 'Karz sargyt döretmekde säwlik ýüze çykdy')) + }, + }) +} + +export function useUpdateLoanOrder() { + const { t } = useTranslation() + const queryClient = useQueryClient() + + return useMutation({ + mutationFn: ({ id, payload }: { id: string; payload: Partial }) => + updateLoanOrder(id, payload), + onSuccess: () => { + queryClient.invalidateQueries({ queryKey: [LOAN_ORDERS_KEY] }) + toast.success(t('loanOrders.updateSuccess', 'Karz sargyt üstünlikli üýtgedildi')) + }, + onError: () => { + toast.error(t('loanOrders.updateError', 'Karz sargyt üýtgetmekde säwlik ýüze çykdy')) + }, + }) +} + +export function useDeleteLoanOrder() { + const { t } = useTranslation() + const queryClient = useQueryClient() + + return useMutation({ + mutationFn: (id: string) => deleteLoanOrder(id), + onSuccess: () => { + queryClient.invalidateQueries({ queryKey: [LOAN_ORDERS_KEY] }) + toast.success(t('loanOrders.deleteSuccess', 'Karz sargyt üstünlikli pozuldy')) + }, + onError: () => { + toast.error(t('loanOrders.deleteError', 'Karz sargyt pozmakda säwlik ýüze çykdy')) + }, + }) +} \ No newline at end of file diff --git a/src/features/loanPaidOffLetters/api/loanPaidOffLettersApi.ts b/src/features/loanPaidOffLetters/api/loanPaidOffLettersApi.ts new file mode 100644 index 0000000..aaaf872 --- /dev/null +++ b/src/features/loanPaidOffLetters/api/loanPaidOffLettersApi.ts @@ -0,0 +1,84 @@ +import { apiClient } from '@/lib/api/client' + +// ─── Types ───────────────────────────────────────────────────────────────────── + +export interface LoanPaidOffLetter { + id: number + passportSeries: string + passportNumber: string + loanAccount: string + issuedAt: string +} + +export interface LoanPaidOffLetterListParams { + search?: string + page?: number + perPage?: number +} + +export interface PaginatedResponse { + data: T[] + total: number +} + +// ─── Mock Data ───────────────────────────────────────────────────────────────── + +const USE_MOCK = true + +const MOCK_DATA: LoanPaidOffLetter[] = [ + { id: 1, passportSeries: 'TM', passportNumber: 'A123456', loanAccount: 'LOAN-2024-001', issuedAt: '2025-01-10' }, + { id: 2, passportSeries: 'TM', passportNumber: 'B234567', loanAccount: 'LOAN-2024-002', issuedAt: '2025-01-14' }, + { id: 3, passportSeries: 'TM', passportNumber: 'C345678', loanAccount: 'LOAN-2024-003', issuedAt: '2025-01-17' }, + { id: 4, passportSeries: 'TM', passportNumber: 'D456789', loanAccount: 'LOAN-2023-115', issuedAt: '2025-01-20' }, + { id: 5, passportSeries: 'TM', passportNumber: 'E567890', loanAccount: 'LOAN-2023-116', issuedAt: '2025-01-23' }, + { id: 6, passportSeries: 'TM', passportNumber: 'F678901', loanAccount: 'LOAN-2024-044', issuedAt: '2025-01-27' }, + { id: 7, passportSeries: 'TM', passportNumber: 'G789012', loanAccount: 'LOAN-2024-055', issuedAt: '2025-02-01' }, + { id: 8, passportSeries: 'TM', passportNumber: 'H890123', loanAccount: 'LOAN-2024-066', issuedAt: '2025-02-05' }, + { id: 9, passportSeries: 'TM', passportNumber: 'I901234', loanAccount: 'LOAN-2024-077', issuedAt: '2025-02-09' }, + { id: 10, passportSeries: 'TM', passportNumber: 'J012345', loanAccount: 'LOAN-2024-088', issuedAt: '2025-02-12' }, +] + +function applyMockFilters( + params: LoanPaidOffLetterListParams, +): PaginatedResponse { + let result = [...MOCK_DATA] + + if (params.search) { + const q = params.search.toLowerCase() + result = result.filter( + (r) => + r.passportNumber.toLowerCase().includes(q) || + r.loanAccount.toLowerCase().includes(q), + ) + } + + const total = result.length + const page = params.page ?? 1 + const perPage = params.perPage ?? 25 + const start = (page - 1) * perPage + + return { data: result.slice(start, start + perPage), total } +} + +// ─── API Functions ───────────────────────────────────────────────────────────── + +export async function fetchLoanPaidOffLetters( + params: LoanPaidOffLetterListParams, +): Promise> { + if (USE_MOCK) return applyMockFilters(params) + + const { data } = await apiClient.get>( + '/loan-paid-off-letter-orders', + { params }, + ) + return data +} + +export async function deleteLoanPaidOffLetter(id: number): Promise { + if (USE_MOCK) { + const idx = MOCK_DATA.findIndex((r) => r.id === id) + if (idx !== -1) MOCK_DATA.splice(idx, 1) + return + } + await apiClient.delete(`/loan-paid-off-letter-orders/${id}`) +} \ No newline at end of file diff --git a/src/features/loanPaidOffLetters/hooks/useLoanPaidOffLetters.ts b/src/features/loanPaidOffLetters/hooks/useLoanPaidOffLetters.ts new file mode 100644 index 0000000..3c8e3a4 --- /dev/null +++ b/src/features/loanPaidOffLetters/hooks/useLoanPaidOffLetters.ts @@ -0,0 +1,43 @@ +import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query' +import { toast } from 'sonner' +import { useTranslation } from 'react-i18next' + +import { + fetchLoanPaidOffLetters, + deleteLoanPaidOffLetter, + type LoanPaidOffLetterListParams, +} from '../api/loanPaidOffLettersApi' + +// ─── Query keys ──────────────────────────────────────────────────────────────── + +export const loanPaidOffLetterKeys = { + all: ['loanPaidOffLetters'] as const, + lists: () => [...loanPaidOffLetterKeys.all, 'list'] as const, + list: (params: LoanPaidOffLetterListParams) => + [...loanPaidOffLetterKeys.lists(), params] as const, +} + +// ─── Hooks ───────────────────────────────────────────────────────────────────── + +export function useLoanPaidOffLetters(params: LoanPaidOffLetterListParams) { + return useQuery({ + queryKey: loanPaidOffLetterKeys.list(params), + queryFn: () => fetchLoanPaidOffLetters(params), + }) +} + +export function useDeleteLoanPaidOffLetter() { + const queryClient = useQueryClient() + const { t } = useTranslation() + + return useMutation({ + mutationFn: (id: number) => deleteLoanPaidOffLetter(id), + onSuccess: () => { + queryClient.invalidateQueries({ queryKey: loanPaidOffLetterKeys.lists() }) + toast.success(t('loanPaidOffLetters.deleteSuccess', 'Güwanama üstünlikli pozuldy')) + }, + onError: () => { + toast.error(t('loanPaidOffLetters.deleteError', 'Pozmak başartmady, gaýtadan synanyşyň')) + }, + }) +} \ No newline at end of file diff --git a/src/features/loanRemaining/api/loanRemainingApi.ts b/src/features/loanRemaining/api/loanRemainingApi.ts new file mode 100644 index 0000000..c23dfd2 --- /dev/null +++ b/src/features/loanRemaining/api/loanRemainingApi.ts @@ -0,0 +1,83 @@ +import { apiClient } from '@/lib/api/client' + +// ─── Types ───────────────────────────────────────────────────────────────────── + +export interface LoanRemaining { + id: number + passportSeries: string + passportNumber: string + loanAccount: string +} + +export interface LoanRemainingListParams { + search?: string + page?: number + perPage?: number +} + +export interface PaginatedResponse { + data: T[] + total: number +} + +// ─── Mock Data ───────────────────────────────────────────────────────────────── + +const USE_MOCK = true + +const MOCK_DATA: LoanRemaining[] = [ + { id: 1, passportSeries: 'TM', passportNumber: 'A111111', loanAccount: 'NOVA-2024-001' }, + { id: 2, passportSeries: 'TM', passportNumber: 'B222222', loanAccount: 'NOVA-2024-002' }, + { id: 3, passportSeries: 'TM', passportNumber: 'C333333', loanAccount: 'NOVA-2023-078' }, + { id: 4, passportSeries: 'TM', passportNumber: 'D444444', loanAccount: 'NOVA-2023-079' }, + { id: 5, passportSeries: 'TM', passportNumber: 'E555555', loanAccount: 'NOVA-2024-033' }, + { id: 6, passportSeries: 'TM', passportNumber: 'F666666', loanAccount: 'NOVA-2024-034' }, + { id: 7, passportSeries: 'TM', passportNumber: 'G777777', loanAccount: 'NOVA-2024-051' }, + { id: 8, passportSeries: 'TM', passportNumber: 'H888888', loanAccount: 'NOVA-2024-052' }, + { id: 9, passportSeries: 'TM', passportNumber: 'I999999', loanAccount: 'NOVA-2024-063' }, + { id: 10, passportSeries: 'TM', passportNumber: 'J000000', loanAccount: 'NOVA-2024-064' }, +] + +function applyMockFilters( + params: LoanRemainingListParams, +): PaginatedResponse { + let result = [...MOCK_DATA] + + if (params.search) { + const q = params.search.toLowerCase() + result = result.filter( + (r) => + r.passportNumber.toLowerCase().includes(q) || + r.loanAccount.toLowerCase().includes(q), + ) + } + + const total = result.length + const page = params.page ?? 1 + const perPage = params.perPage ?? 25 + const start = (page - 1) * perPage + + return { data: result.slice(start, start + perPage), total } +} + +// ─── API Functions ───────────────────────────────────────────────────────────── + +export async function fetchLoanRemaining( + params: LoanRemainingListParams, +): Promise> { + if (USE_MOCK) return applyMockFilters(params) + + const { data } = await apiClient.get>( + '/nova-loan-remaining-orders', + { params }, + ) + return data +} + +export async function deleteLoanRemaining(id: number): Promise { + if (USE_MOCK) { + const idx = MOCK_DATA.findIndex((r) => r.id === id) + if (idx !== -1) MOCK_DATA.splice(idx, 1) + return + } + await apiClient.delete(`/nova-loan-remaining-orders/${id}`) +} \ No newline at end of file diff --git a/src/features/loanRemaining/hooks/useLoanRemaining.ts b/src/features/loanRemaining/hooks/useLoanRemaining.ts new file mode 100644 index 0000000..aed1875 --- /dev/null +++ b/src/features/loanRemaining/hooks/useLoanRemaining.ts @@ -0,0 +1,42 @@ +import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query' +import { toast } from 'sonner' +import { useTranslation } from 'react-i18next' + +import { + fetchLoanRemaining, + deleteLoanRemaining, + type LoanRemainingListParams, +} from '../api/loanRemainingApi' + +// ─── Query keys ──────────────────────────────────────────────────────────────── + +export const loanRemainingKeys = { + all: ['loanRemaining'] as const, + lists: () => [...loanRemainingKeys.all, 'list'] as const, + list: (params: LoanRemainingListParams) => [...loanRemainingKeys.lists(), params] as const, +} + +// ─── Hooks ───────────────────────────────────────────────────────────────────── + +export function useLoanRemaining(params: LoanRemainingListParams) { + return useQuery({ + queryKey: loanRemainingKeys.list(params), + queryFn: () => fetchLoanRemaining(params), + }) +} + +export function useDeleteLoanRemaining() { + const queryClient = useQueryClient() + const { t } = useTranslation() + + return useMutation({ + mutationFn: (id: number) => deleteLoanRemaining(id), + onSuccess: () => { + queryClient.invalidateQueries({ queryKey: loanRemainingKeys.lists() }) + toast.success(t('loanRemaining.deleteSuccess', 'Ýazgy üstünlikli pozuldy')) + }, + onError: () => { + toast.error(t('loanRemaining.deleteError', 'Pozmak başartmady, gaýtadan synanyşyň')) + }, + }) +} \ No newline at end of file diff --git a/src/index.css b/src/index.css index fb3d497..fbca959 100644 --- a/src/index.css +++ b/src/index.css @@ -148,49 +148,12 @@ body { margin: 0; } -h1, -h2 { - font-family: var(--heading); - font-weight: 500; - color: var(--text-h); -} -h1 { - font-size: 56px; - letter-spacing: -1.68px; - margin: 32px 0; - @media (max-width: 1024px) { - font-size: 36px; - margin: 20px 0; - } -} -h2 { - font-size: 24px; - line-height: 118%; - letter-spacing: -0.24px; - margin: 0 0 8px; - @media (max-width: 1024px) { - font-size: 20px; - } -} -p { - margin: 0; -} -code, -.counter { - font-family: var(--mono); - display: inline-flex; - border-radius: 4px; - color: var(--text-h); -} -code { - font-size: 15px; - line-height: 135%; - padding: 4px 8px; - background: var(--code-bg); -} + + + @theme inline { --font-heading: var(--font-sans); diff --git a/src/layouts/AuthLayout.tsx b/src/layouts/AuthLayout.tsx deleted file mode 100644 index 07ebf31..0000000 --- a/src/layouts/AuthLayout.tsx +++ /dev/null @@ -1,126 +0,0 @@ -import type { ReactNode } from 'react' -import { useTranslation } from 'react-i18next' -import { useThemeStore } from '@/app/store/themeStore' -import { useI18nStore } from '@/app/store/i18nStore' -import type { SupportedLanguage } from '@/lib/i18n' - -const LANG_LABELS: Record = { - en: 'EN', - ru: 'RU', - tk: 'TK', -} - -interface AuthLayoutProps { - children: ReactNode -} - -export function AuthLayout({ children }: AuthLayoutProps) { - const { t } = useTranslation() - const { theme, toggleTheme } = useThemeStore() - const { language, setLanguage } = useI18nStore() - - return ( -
- - {/* Animated Background */} -