From a1d059a83846be4467bc11a5c47559e70bb653ad Mon Sep 17 00:00:00 2001 From: Jelaletdin12 Date: Tue, 12 May 2026 23:16:27 +0500 Subject: [PATCH] added some settings page --- package-lock.json | 601 +++++++++++++++++- package.json | 3 + src/app/router/index.tsx | 74 +++ src/features/loanTypes/api/loanTypesApi.ts | 169 +++++ .../loanTypes/components/loanTypesForm.tsx | 268 ++++++++ src/features/loanTypes/hooks/useLoanTypes.ts | 97 +++ .../api/requiredDocumentsApi.ts | 163 +++++ .../components/requiredDocumentsForm.tsx | 311 +++++++++ .../hooks/useRequiredDocuments.ts | 96 +++ src/layouts/DashboardLayout.tsx | 4 +- src/lib/i18n/locales/tk.json | 27 +- src/pages/settings/loan/loanTypes/index.tsx | 219 +++++++ .../settings/loan/loanTypesCreate/index.tsx | 20 + .../settings/loan/loanTypesEdit/index.tsx | 47 ++ .../settings/loan/loanTypesView/index.tsx | 206 ++++++ .../settings/loan/requiredDocuments/index.tsx | 138 ++++ .../loan/requiredDocumentsCreate/index.tsx | 16 + .../loan/requiredDocumentsEdit/index.tsx | 47 ++ .../loan/requiredDocumentsView/index.tsx | 117 ++++ 19 files changed, 2612 insertions(+), 11 deletions(-) create mode 100644 src/features/loanTypes/api/loanTypesApi.ts create mode 100644 src/features/loanTypes/components/loanTypesForm.tsx create mode 100644 src/features/loanTypes/hooks/useLoanTypes.ts create mode 100644 src/features/requiredDocuments/api/requiredDocumentsApi.ts create mode 100644 src/features/requiredDocuments/components/requiredDocumentsForm.tsx create mode 100644 src/features/requiredDocuments/hooks/useRequiredDocuments.ts create mode 100644 src/pages/settings/loan/loanTypes/index.tsx create mode 100644 src/pages/settings/loan/loanTypesCreate/index.tsx create mode 100644 src/pages/settings/loan/loanTypesEdit/index.tsx create mode 100644 src/pages/settings/loan/loanTypesView/index.tsx create mode 100644 src/pages/settings/loan/requiredDocuments/index.tsx create mode 100644 src/pages/settings/loan/requiredDocumentsCreate/index.tsx create mode 100644 src/pages/settings/loan/requiredDocumentsEdit/index.tsx create mode 100644 src/pages/settings/loan/requiredDocumentsView/index.tsx diff --git a/package-lock.json b/package-lock.json index b5489ce..c2c5893 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,6 +12,9 @@ "@fontsource-variable/inter": "^5.2.8", "@tanstack/react-query": "^5.100.8", "@tanstack/react-table": "^8.21.3", + "@tiptap/extension-link": "^3.23.2", + "@tiptap/react": "^3.23.2", + "@tiptap/starter-kit": "^3.23.2", "axios": "^1.15.2", "class-variance-authority": "^0.7.1", "clsx": "^2.1.1", @@ -809,6 +812,7 @@ "resolved": "https://registry.npmjs.org/@floating-ui/dom/-/dom-1.7.6.tgz", "integrity": "sha512-9gZSAI5XM36880PPMm//9dfiEngYoC6Am2izES1FF406YFsjvyBMmeJ2g4SAju3xWwtuynNRFL2s9hgxpLI5SQ==", "license": "MIT", + "peer": true, "dependencies": { "@floating-ui/core": "^1.7.5", "@floating-ui/utils": "^0.2.11" @@ -3434,6 +3438,438 @@ "url": "https://github.com/sponsors/tannerlinsley" } }, + "node_modules/@tiptap/core": { + "version": "3.23.2", + "resolved": "https://registry.npmjs.org/@tiptap/core/-/core-3.23.2.tgz", + "integrity": "sha512-yjv2N7gaQMbIVfsSZHBMscLoybgetcTraXsSMrELAerl/jfRipg5S1dBXMFvgRy8Kh48+TGoH+5nqshxdOEGoQ==", + "license": "MIT", + "peer": true, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/pm": "3.23.2" + } + }, + "node_modules/@tiptap/extension-blockquote": { + "version": "3.23.2", + "resolved": "https://registry.npmjs.org/@tiptap/extension-blockquote/-/extension-blockquote-3.23.2.tgz", + "integrity": "sha512-BBN22/nUErRzUr1HI/Q4iPFBNavWoNC5Fx0KXp9oDOCCrCvj55rtGwLn2dB3r4vLfhjYvhEZ38wN+r7Y9RhORA==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/core": "3.23.2" + } + }, + "node_modules/@tiptap/extension-bold": { + "version": "3.23.2", + "resolved": "https://registry.npmjs.org/@tiptap/extension-bold/-/extension-bold-3.23.2.tgz", + "integrity": "sha512-onPFP260enNkjMGhR7sDSqaF80A4sgvMZ/VZLxp7zGa6DAfcuN4PyUQhZN61KmYgbUdr+qrAAMx+tPuid22F4g==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/core": "3.23.2" + } + }, + "node_modules/@tiptap/extension-bubble-menu": { + "version": "3.23.2", + "resolved": "https://registry.npmjs.org/@tiptap/extension-bubble-menu/-/extension-bubble-menu-3.23.2.tgz", + "integrity": "sha512-S0LZg6EMdkr5CiYAGmOwzuNPd2T18ZR5pWrgHHHZjt0IFqU01tBJa3zLzC1Vd7noPCec64ygW9S8+p8CHBgOIA==", + "license": "MIT", + "optional": true, + "dependencies": { + "@floating-ui/dom": "^1.0.0" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/core": "3.23.2", + "@tiptap/pm": "3.23.2" + } + }, + "node_modules/@tiptap/extension-bullet-list": { + "version": "3.23.2", + "resolved": "https://registry.npmjs.org/@tiptap/extension-bullet-list/-/extension-bullet-list-3.23.2.tgz", + "integrity": "sha512-jhvu1qa8F53r//6DrLdA2OkTbRgY73NkQL51Ruozzi+JrfVIo3IfaTNRq01BXO5qcvNH7P/aDBF5cByvuiUMzQ==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/extension-list": "3.23.2" + } + }, + "node_modules/@tiptap/extension-code": { + "version": "3.23.2", + "resolved": "https://registry.npmjs.org/@tiptap/extension-code/-/extension-code-3.23.2.tgz", + "integrity": "sha512-5yHYavvBEkxgWL6DCPYNHujxBXF7c812MFNoU62ljNJjIYDc2Mu8ftOie/ajNJbMLqwSVzCuGfG9swEuEKxY5g==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/core": "3.23.2" + } + }, + "node_modules/@tiptap/extension-code-block": { + "version": "3.23.2", + "resolved": "https://registry.npmjs.org/@tiptap/extension-code-block/-/extension-code-block-3.23.2.tgz", + "integrity": "sha512-oWwjsLi+m7zHTqM0kYnnogjS3vFENCaLk3ue/1XE9ccpZlmmPzmK70hodB/UPylFJmgr3g726rhxViYv9LRS7A==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/core": "3.23.2", + "@tiptap/pm": "3.23.2" + } + }, + "node_modules/@tiptap/extension-document": { + "version": "3.23.2", + "resolved": "https://registry.npmjs.org/@tiptap/extension-document/-/extension-document-3.23.2.tgz", + "integrity": "sha512-Ff/MAaWPzFtb7nhPG6ETdu7/OqkD6cAmJfViBAiRqh9PPULH98fGDaMBm3TGa1s3XB7hGO7c/xVKxEdjYij5rg==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/core": "3.23.2" + } + }, + "node_modules/@tiptap/extension-dropcursor": { + "version": "3.23.2", + "resolved": "https://registry.npmjs.org/@tiptap/extension-dropcursor/-/extension-dropcursor-3.23.2.tgz", + "integrity": "sha512-T7pVfIF5uDj043CDJlurNoMAmXPy36EjBz/YQVYrVMSSUbvUlOaL3xxoDODRmir29jVrmCROjaKwVExqooQTqQ==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/extensions": "3.23.2" + } + }, + "node_modules/@tiptap/extension-floating-menu": { + "version": "3.23.2", + "resolved": "https://registry.npmjs.org/@tiptap/extension-floating-menu/-/extension-floating-menu-3.23.2.tgz", + "integrity": "sha512-1rfxx5X52h44jSS9R1fUx8sOaRpNq8CM0IR3EdjpthVvaRZ9XD1tKX4h5EcwGFqNiwtWXxNne2mV7ZJuH2UYsQ==", + "license": "MIT", + "optional": true, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@floating-ui/dom": "^1.0.0", + "@tiptap/core": "3.23.2", + "@tiptap/pm": "3.23.2" + } + }, + "node_modules/@tiptap/extension-gapcursor": { + "version": "3.23.2", + "resolved": "https://registry.npmjs.org/@tiptap/extension-gapcursor/-/extension-gapcursor-3.23.2.tgz", + "integrity": "sha512-I3LKYVwyxRaiVaJxss98QWOXzZZrHmsJD3RgAZ0Uoguu3pL29Krn2tXfwp4FAd9NG79wdQHj20c+XuqJLNkAbw==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/extensions": "3.23.2" + } + }, + "node_modules/@tiptap/extension-hard-break": { + "version": "3.23.2", + "resolved": "https://registry.npmjs.org/@tiptap/extension-hard-break/-/extension-hard-break-3.23.2.tgz", + "integrity": "sha512-3p00oC2caRAVtkOweJ9IjTgjhzm34R9tNyMCykzMRygC8CdO08Jv2JKvUaOeMVVmWZI+O9wkGUpaA2Drg6pY4g==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/core": "3.23.2" + } + }, + "node_modules/@tiptap/extension-heading": { + "version": "3.23.2", + "resolved": "https://registry.npmjs.org/@tiptap/extension-heading/-/extension-heading-3.23.2.tgz", + "integrity": "sha512-ldQh38ZWTIedSY6XsOkn1ULtk+mD/mezLogrvcVv8neez0qM/S25vyMZKqP7i2/x4i4ds1JYIJLw9y3HX/B69Q==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/core": "3.23.2" + } + }, + "node_modules/@tiptap/extension-horizontal-rule": { + "version": "3.23.2", + "resolved": "https://registry.npmjs.org/@tiptap/extension-horizontal-rule/-/extension-horizontal-rule-3.23.2.tgz", + "integrity": "sha512-LbLACqe/OiTdYIq3zbsY7Ue7WOP+mYTGufNDfs8rSGcUbWI2GwUwoGRrTPBbLIesnuCdH6FyMB60Tg/HzjKaYw==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/core": "3.23.2", + "@tiptap/pm": "3.23.2" + } + }, + "node_modules/@tiptap/extension-italic": { + "version": "3.23.2", + "resolved": "https://registry.npmjs.org/@tiptap/extension-italic/-/extension-italic-3.23.2.tgz", + "integrity": "sha512-pauWOkom8riyZoIGn8I8uFE//uRgE6kL46Pd6PdSd5Wt6w/ao/le9Ju2Ln947NGjz/6whaDiFnBrkSbZEAhpmw==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/core": "3.23.2" + } + }, + "node_modules/@tiptap/extension-link": { + "version": "3.23.2", + "resolved": "https://registry.npmjs.org/@tiptap/extension-link/-/extension-link-3.23.2.tgz", + "integrity": "sha512-h0D3Lwom0hGDsbpZ6tW0+DRKgBP0qSl4rO/iBfGk3Krb2CoyEn1yII3pSTd1PwAld7bHt/buURi6DWudQsIhgg==", + "license": "MIT", + "dependencies": { + "linkifyjs": "^4.3.2" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/core": "3.23.2", + "@tiptap/pm": "3.23.2" + } + }, + "node_modules/@tiptap/extension-list": { + "version": "3.23.2", + "resolved": "https://registry.npmjs.org/@tiptap/extension-list/-/extension-list-3.23.2.tgz", + "integrity": "sha512-tRbbjpOPrY4ApIHtn3ctnKIhkkioewMsZa5gJzqVB47LJFNyzLXLo/aID4sJRKTIMi1wd1fA9TiBKPe6KqczPA==", + "license": "MIT", + "peer": true, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/core": "3.23.2", + "@tiptap/pm": "3.23.2" + } + }, + "node_modules/@tiptap/extension-list-item": { + "version": "3.23.2", + "resolved": "https://registry.npmjs.org/@tiptap/extension-list-item/-/extension-list-item-3.23.2.tgz", + "integrity": "sha512-I9Yed0mmBE6AAhc4Cc5UhZLZUMCft9XdPkdBM/wjcjpLwdMhdzelVQXEhNDyPfRkA1TTGs5VHlc6twjCPCTgLg==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/extension-list": "3.23.2" + } + }, + "node_modules/@tiptap/extension-list-keymap": { + "version": "3.23.2", + "resolved": "https://registry.npmjs.org/@tiptap/extension-list-keymap/-/extension-list-keymap-3.23.2.tgz", + "integrity": "sha512-aE4PzCy+OWXXFc8UsrrYjcfEbyXCh8f7LuGgFPl8jf0JjgIK0FHmzWDg3912zWb5Ww66AF2j0KJzTB9NFOMWlw==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/extension-list": "3.23.2" + } + }, + "node_modules/@tiptap/extension-ordered-list": { + "version": "3.23.2", + "resolved": "https://registry.npmjs.org/@tiptap/extension-ordered-list/-/extension-ordered-list-3.23.2.tgz", + "integrity": "sha512-ZhMejT4jXfOEECqI60AVBzULl8AVN8BXk/9vjVnJHxBtcQxW+tIu5GHVZ4DPaCfTX7mH+hsceFMhQ2BvV7qvbg==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/extension-list": "3.23.2" + } + }, + "node_modules/@tiptap/extension-paragraph": { + "version": "3.23.2", + "resolved": "https://registry.npmjs.org/@tiptap/extension-paragraph/-/extension-paragraph-3.23.2.tgz", + "integrity": "sha512-UzHx5zOi9fjhC9TAqHeD7BV5eJIA3t65pa2Mq8b54V9nrIg1yAlgiafU0WDWoom11TF+IWxz5JBsjlW0/P/VeQ==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/core": "3.23.2" + } + }, + "node_modules/@tiptap/extension-strike": { + "version": "3.23.2", + "resolved": "https://registry.npmjs.org/@tiptap/extension-strike/-/extension-strike-3.23.2.tgz", + "integrity": "sha512-m1BN3EXwYagzVdReGoI7McvuZFyolFwuXLgzU6c+RN7E+u+K68EY+2U3pJI5ee8UgPYGW4eBs/3BT/5k+0so3Q==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/core": "3.23.2" + } + }, + "node_modules/@tiptap/extension-text": { + "version": "3.23.2", + "resolved": "https://registry.npmjs.org/@tiptap/extension-text/-/extension-text-3.23.2.tgz", + "integrity": "sha512-Ny4FC+BivfwACTuJO3QPe+BXtVFfzWQVBcfhlFlA7xTaeBktFeBavH2cEyXR8Qbez3Wio/Hn+bibT4d44EBLyg==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/core": "3.23.2" + } + }, + "node_modules/@tiptap/extension-underline": { + "version": "3.23.2", + "resolved": "https://registry.npmjs.org/@tiptap/extension-underline/-/extension-underline-3.23.2.tgz", + "integrity": "sha512-HdPX1nZarOF8UkDccu6gBy6brZd4vDFCa5Mz1liw3B3D6UBiC+8vzE1YGHtggO+KEBBQYf4GgjT3qqIgOcsTEQ==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/core": "3.23.2" + } + }, + "node_modules/@tiptap/extensions": { + "version": "3.23.2", + "resolved": "https://registry.npmjs.org/@tiptap/extensions/-/extensions-3.23.2.tgz", + "integrity": "sha512-kRHQ3nSbAfkFdxj9FtDdr4hpREndGgWFA6ZEAwlLeGUxf8QYTpuF9zb2yxdBPBlTc5+JsbPcskNt+u1PazGKYw==", + "license": "MIT", + "peer": true, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/core": "3.23.2", + "@tiptap/pm": "3.23.2" + } + }, + "node_modules/@tiptap/pm": { + "version": "3.23.2", + "resolved": "https://registry.npmjs.org/@tiptap/pm/-/pm-3.23.2.tgz", + "integrity": "sha512-1kvsBqGNu2ZJ0P/lkxN0pAMqSyUcpkMIzE4xwGUIyAiD0pZV6dr+OCMwGWOTLllSyrn91xI5K7OLk3pYeCPKqA==", + "license": "MIT", + "peer": true, + "dependencies": { + "prosemirror-changeset": "^2.3.0", + "prosemirror-commands": "^1.6.2", + "prosemirror-dropcursor": "^1.8.1", + "prosemirror-gapcursor": "^1.3.2", + "prosemirror-history": "^1.4.1", + "prosemirror-keymap": "^1.2.2", + "prosemirror-model": "^1.24.1", + "prosemirror-schema-list": "^1.5.0", + "prosemirror-state": "^1.4.3", + "prosemirror-tables": "^1.6.4", + "prosemirror-transform": "^1.10.2", + "prosemirror-view": "^1.38.1" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + } + }, + "node_modules/@tiptap/react": { + "version": "3.23.2", + "resolved": "https://registry.npmjs.org/@tiptap/react/-/react-3.23.2.tgz", + "integrity": "sha512-qfl70xRDQbwov8y5QvK+EiYk6JyoyzUimNtOmLSfeun2NjQwv67hW1iQ+c3geDbcwfUY5+h3XYMy1Lm+Bt46NQ==", + "license": "MIT", + "dependencies": { + "@types/use-sync-external-store": "^0.0.6", + "fast-equals": "^5.3.3", + "use-sync-external-store": "^1.4.0" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "optionalDependencies": { + "@tiptap/extension-bubble-menu": "^3.23.2", + "@tiptap/extension-floating-menu": "^3.23.2" + }, + "peerDependencies": { + "@tiptap/core": "3.23.2", + "@tiptap/pm": "3.23.2", + "@types/react": "^17.0.0 || ^18.0.0 || ^19.0.0", + "@types/react-dom": "^17.0.0 || ^18.0.0 || ^19.0.0", + "react": "^17.0.0 || ^18.0.0 || ^19.0.0", + "react-dom": "^17.0.0 || ^18.0.0 || ^19.0.0" + } + }, + "node_modules/@tiptap/starter-kit": { + "version": "3.23.2", + "resolved": "https://registry.npmjs.org/@tiptap/starter-kit/-/starter-kit-3.23.2.tgz", + "integrity": "sha512-t0o//bLmlUW/3j9ke1wIrrKkvfVYcBiC/cowCUNwN/YQx9Bc3S++yInkR6hat4qI4+O49+NRknVeaF/Sp247QA==", + "license": "MIT", + "dependencies": { + "@tiptap/core": "^3.23.2", + "@tiptap/extension-blockquote": "^3.23.2", + "@tiptap/extension-bold": "^3.23.2", + "@tiptap/extension-bullet-list": "^3.23.2", + "@tiptap/extension-code": "^3.23.2", + "@tiptap/extension-code-block": "^3.23.2", + "@tiptap/extension-document": "^3.23.2", + "@tiptap/extension-dropcursor": "^3.23.2", + "@tiptap/extension-gapcursor": "^3.23.2", + "@tiptap/extension-hard-break": "^3.23.2", + "@tiptap/extension-heading": "^3.23.2", + "@tiptap/extension-horizontal-rule": "^3.23.2", + "@tiptap/extension-italic": "^3.23.2", + "@tiptap/extension-link": "^3.23.2", + "@tiptap/extension-list": "^3.23.2", + "@tiptap/extension-list-item": "^3.23.2", + "@tiptap/extension-list-keymap": "^3.23.2", + "@tiptap/extension-ordered-list": "^3.23.2", + "@tiptap/extension-paragraph": "^3.23.2", + "@tiptap/extension-strike": "^3.23.2", + "@tiptap/extension-text": "^3.23.2", + "@tiptap/extension-underline": "^3.23.2", + "@tiptap/extensions": "^3.23.2", + "@tiptap/pm": "^3.23.2" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + } + }, "node_modules/@ts-morph/common": { "version": "0.27.0", "resolved": "https://registry.npmjs.org/@ts-morph/common/-/common-0.27.0.tgz", @@ -3554,7 +3990,6 @@ "version": "19.2.14", "resolved": "https://registry.npmjs.org/@types/react/-/react-19.2.14.tgz", "integrity": "sha512-ilcTH/UniCkMdtexkoCN0bI7pMcJDvmQFPvuPvmEaYA/NSfFTAgdUSLAoVjaRJm7+6PvcM+q1zYOwS4wTYMF9w==", - "devOptional": true, "license": "MIT", "peer": true, "dependencies": { @@ -3565,7 +4000,6 @@ "version": "19.2.3", "resolved": "https://registry.npmjs.org/@types/react-dom/-/react-dom-19.2.3.tgz", "integrity": "sha512-jp2L/eY6fn+KgVVQAOqYItbF0VY/YApe5Mz2F0aykSO8gx31bYCZyvSeYxCHKvzHG5eZjc+zyaS5BrBWya2+kQ==", - "devOptional": true, "license": "MIT", "peer": true, "peerDependencies": { @@ -4555,7 +4989,6 @@ "version": "3.2.3", "resolved": "https://registry.npmjs.org/csstype/-/csstype-3.2.3.tgz", "integrity": "sha512-z1HGKcYy2xA8AGQfwrn0PAy+PB7X/GSj3UVJW9qKyn43xWa+gl5nXmU4qqLMRzWVLFC8KusUX8T/0kCiOYpAIQ==", - "devOptional": true, "license": "MIT" }, "node_modules/d3-array": { @@ -5351,6 +5784,15 @@ "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", "license": "MIT" }, + "node_modules/fast-equals": { + "version": "5.4.0", + "resolved": "https://registry.npmjs.org/fast-equals/-/fast-equals-5.4.0.tgz", + "integrity": "sha512-jt2DW/aNFNwke7AUd+Z+e6pz39KO5rzdbbFCg2sGafS4mk13MI7Z8O5z9cADNn5lhGODIgLwug6TZO2ctf7kcw==", + "license": "MIT", + "engines": { + "node": ">=6.0.0" + } + }, "node_modules/fast-glob": { "version": "3.3.3", "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.3.3.tgz", @@ -6734,6 +7176,12 @@ "integrity": "sha512-7ylylesZQ/PV29jhEDl3Ufjo6ZX7gCqJr5F7PKrqc93v7fzSymt1BpwEU8nAUXs8qzzvqhbjhK5QZg6Mt/HkBg==", "license": "MIT" }, + "node_modules/linkifyjs": { + "version": "4.3.2", + "resolved": "https://registry.npmjs.org/linkifyjs/-/linkifyjs-4.3.2.tgz", + "integrity": "sha512-NT1CJtq3hHIreOianA8aSXn6Cw0JzYOuDQbOrSPe7gqFnCpKP++MQe3ODgO3oh2GJFORkAAdqredOa60z63GbA==", + "license": "MIT" + }, "node_modules/locate-path": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-6.0.0.tgz", @@ -7261,6 +7709,12 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/orderedmap": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/orderedmap/-/orderedmap-2.1.1.tgz", + "integrity": "sha512-TvAWxi0nDe1j/rtMcWcIj94+Ffe6n7zhow33h40SKxmsmozs6dz/e+EajymfoFcHd7sxNn8yHM8839uixMOV6g==", + "license": "MIT" + }, "node_modules/outvariant": { "version": "1.4.3", "resolved": "https://registry.npmjs.org/outvariant/-/outvariant-1.4.3.tgz", @@ -7516,6 +7970,135 @@ "node": ">=6" } }, + "node_modules/prosemirror-changeset": { + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/prosemirror-changeset/-/prosemirror-changeset-2.4.1.tgz", + "integrity": "sha512-96WBLhOaYhJ+kPhLg3uW359Tz6I/MfcrQfL4EGv4SrcqKEMC1gmoGrXHecPE8eOwTVCJ4IwgfzM8fFad25wNfw==", + "license": "MIT", + "dependencies": { + "prosemirror-transform": "^1.0.0" + } + }, + "node_modules/prosemirror-commands": { + "version": "1.7.1", + "resolved": "https://registry.npmjs.org/prosemirror-commands/-/prosemirror-commands-1.7.1.tgz", + "integrity": "sha512-rT7qZnQtx5c0/y/KlYaGvtG411S97UaL6gdp6RIZ23DLHanMYLyfGBV5DtSnZdthQql7W+lEVbpSfwtO8T+L2w==", + "license": "MIT", + "dependencies": { + "prosemirror-model": "^1.0.0", + "prosemirror-state": "^1.0.0", + "prosemirror-transform": "^1.10.2" + } + }, + "node_modules/prosemirror-dropcursor": { + "version": "1.8.2", + "resolved": "https://registry.npmjs.org/prosemirror-dropcursor/-/prosemirror-dropcursor-1.8.2.tgz", + "integrity": "sha512-CCk6Gyx9+Tt2sbYk5NK0nB1ukHi2ryaRgadV/LvyNuO3ena1payM2z6Cg0vO1ebK8cxbzo41ku2DE5Axj1Zuiw==", + "license": "MIT", + "dependencies": { + "prosemirror-state": "^1.0.0", + "prosemirror-transform": "^1.1.0", + "prosemirror-view": "^1.1.0" + } + }, + "node_modules/prosemirror-gapcursor": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/prosemirror-gapcursor/-/prosemirror-gapcursor-1.4.1.tgz", + "integrity": "sha512-pMdYaEnjNMSwl11yjEGtgTmLkR08m/Vl+Jj443167p9eB3HVQKhYCc4gmHVDsLPODfZfjr/MmirsdyZziXbQKw==", + "license": "MIT", + "dependencies": { + "prosemirror-keymap": "^1.0.0", + "prosemirror-model": "^1.0.0", + "prosemirror-state": "^1.0.0", + "prosemirror-view": "^1.0.0" + } + }, + "node_modules/prosemirror-history": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/prosemirror-history/-/prosemirror-history-1.5.0.tgz", + "integrity": "sha512-zlzTiH01eKA55UAf1MEjtssJeHnGxO0j4K4Dpx+gnmX9n+SHNlDqI2oO1Kv1iPN5B1dm5fsljCfqKF9nFL6HRg==", + "license": "MIT", + "dependencies": { + "prosemirror-state": "^1.2.2", + "prosemirror-transform": "^1.0.0", + "prosemirror-view": "^1.31.0", + "rope-sequence": "^1.3.0" + } + }, + "node_modules/prosemirror-keymap": { + "version": "1.2.3", + "resolved": "https://registry.npmjs.org/prosemirror-keymap/-/prosemirror-keymap-1.2.3.tgz", + "integrity": "sha512-4HucRlpiLd1IPQQXNqeo81BGtkY8Ai5smHhKW9jjPKRc2wQIxksg7Hl1tTI2IfT2B/LgX6bfYvXxEpJl7aKYKw==", + "license": "MIT", + "dependencies": { + "prosemirror-state": "^1.0.0", + "w3c-keyname": "^2.2.0" + } + }, + "node_modules/prosemirror-model": { + "version": "1.25.4", + "resolved": "https://registry.npmjs.org/prosemirror-model/-/prosemirror-model-1.25.4.tgz", + "integrity": "sha512-PIM7E43PBxKce8OQeezAs9j4TP+5yDpZVbuurd1h5phUxEKIu+G2a+EUZzIC5nS1mJktDJWzbqS23n1tsAf5QA==", + "license": "MIT", + "dependencies": { + "orderedmap": "^2.0.0" + } + }, + "node_modules/prosemirror-schema-list": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/prosemirror-schema-list/-/prosemirror-schema-list-1.5.1.tgz", + "integrity": "sha512-927lFx/uwyQaGwJxLWCZRkjXG0p48KpMj6ueoYiu4JX05GGuGcgzAy62dfiV8eFZftgyBUvLx76RsMe20fJl+Q==", + "license": "MIT", + "dependencies": { + "prosemirror-model": "^1.0.0", + "prosemirror-state": "^1.0.0", + "prosemirror-transform": "^1.7.3" + } + }, + "node_modules/prosemirror-state": { + "version": "1.4.4", + "resolved": "https://registry.npmjs.org/prosemirror-state/-/prosemirror-state-1.4.4.tgz", + "integrity": "sha512-6jiYHH2CIGbCfnxdHbXZ12gySFY/fz/ulZE333G6bPqIZ4F+TXo9ifiR86nAHpWnfoNjOb3o5ESi7J8Uz1jXHw==", + "license": "MIT", + "dependencies": { + "prosemirror-model": "^1.0.0", + "prosemirror-transform": "^1.0.0", + "prosemirror-view": "^1.27.0" + } + }, + "node_modules/prosemirror-tables": { + "version": "1.8.5", + "resolved": "https://registry.npmjs.org/prosemirror-tables/-/prosemirror-tables-1.8.5.tgz", + "integrity": "sha512-V/0cDCsHKHe/tfWkeCmthNUcEp1IVO3p6vwN8XtwE9PZQLAZJigbw3QoraAdfJPir4NKJtNvOB8oYGKRl+t0Dw==", + "license": "MIT", + "dependencies": { + "prosemirror-keymap": "^1.2.3", + "prosemirror-model": "^1.25.4", + "prosemirror-state": "^1.4.4", + "prosemirror-transform": "^1.10.5", + "prosemirror-view": "^1.41.4" + } + }, + "node_modules/prosemirror-transform": { + "version": "1.12.0", + "resolved": "https://registry.npmjs.org/prosemirror-transform/-/prosemirror-transform-1.12.0.tgz", + "integrity": "sha512-GxboyN4AMIsoHNtz5uf2r2Ru551i5hWeCMD6E2Ib4Eogqoub0NflniaBPVQ4MrGE5yZ8JV9tUHg9qcZTTrcN4w==", + "license": "MIT", + "dependencies": { + "prosemirror-model": "^1.21.0" + } + }, + "node_modules/prosemirror-view": { + "version": "1.41.8", + "resolved": "https://registry.npmjs.org/prosemirror-view/-/prosemirror-view-1.41.8.tgz", + "integrity": "sha512-TnKDdohEatgyZNGCDWIdccOHXhYloJwbwU+phw/a23KBvJIR9lWQWW7WHHK3vBdOLDNuF7TaX98GObUZOWkOnA==", + "license": "MIT", + "dependencies": { + "prosemirror-model": "^1.20.0", + "prosemirror-state": "^1.0.0", + "prosemirror-transform": "^1.1.0" + } + }, "node_modules/proxy-addr": { "version": "2.0.7", "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz", @@ -8084,6 +8667,12 @@ "node_modules/root": { "resolved": "git+ssh://git@github.com/tanstack/react-query.git#9800c8f1a3f7907956410c23426a26d981e7d694" }, + "node_modules/rope-sequence": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/rope-sequence/-/rope-sequence-1.3.4.tgz", + "integrity": "sha512-UT5EDe2cu2E/6O4igUr5PSFs23nvvukicWHx6GnOPlHAiiYbzNuCRQCuiUdHJQcqKalLKlrYJnjY0ySGsXNQXQ==", + "license": "MIT" + }, "node_modules/router": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/router/-/router-2.2.0.tgz", @@ -9047,6 +9636,12 @@ "node": ">=0.10.0" } }, + "node_modules/w3c-keyname": { + "version": "2.2.8", + "resolved": "https://registry.npmjs.org/w3c-keyname/-/w3c-keyname-2.2.8.tgz", + "integrity": "sha512-dpojBhNsCNN7T82Tm7k26A6G9ML3NkhDsnw9n/eoxSRlVBB4CEtIQ/KTCLI2Fwf3ataSXRhYFkQi3SlnFwPvPQ==", + "license": "MIT" + }, "node_modules/web-streams-polyfill": { "version": "3.3.3", "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.3.3.tgz", diff --git a/package.json b/package.json index 820e4f0..3d53708 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,9 @@ "@fontsource-variable/inter": "^5.2.8", "@tanstack/react-query": "^5.100.8", "@tanstack/react-table": "^8.21.3", + "@tiptap/extension-link": "^3.23.2", + "@tiptap/react": "^3.23.2", + "@tiptap/starter-kit": "^3.23.2", "axios": "^1.15.2", "class-variance-authority": "^0.7.1", "clsx": "^2.1.1", diff --git a/src/app/router/index.tsx b/src/app/router/index.tsx index 11a5298..dfd92dd 100644 --- a/src/app/router/index.tsx +++ b/src/app/router/index.tsx @@ -137,6 +137,16 @@ const PermissionCreatePage = lazy(() => import("@/pages/settings/users/permissio const PermissionsViewPage = lazy(() => import("@/pages/settings/users/permissionsView")); const PermissionEditPage = lazy(() => import("@/pages/settings/users/permissionsEdit")); +const LoanTypesPage = lazy(() => import("@/pages/settings/loan/loanTypes")); +const LoanTypeCreatePage = lazy(() => import("@/pages/settings/loan/loanTypesCreate")); +const LoanTypesViewPage = lazy(() => import("@/pages/settings/loan/loanTypesView")); +const LoanTypeEditPage = lazy(() => import("@/pages/settings/loan/loanTypesEdit")); + +const RequiredDocumentsPage = lazy(() => import("@/pages/settings/loan/requiredDocuments")); +const RequiredDocumentCreatePage = lazy(() => import("@/pages/settings/loan/requiredDocumentsCreate")); +const RequiredDocumentsViewPage = lazy(() => import("@/pages/settings/loan/requiredDocumentsView")); +const RequiredDocumentEditPage = lazy(() => import("@/pages/settings/loan/requiredDocumentsEdit")); + function AuthGuard() { const isAuthenticated = useAuthStore((s) => s.isAuthenticated); if (!isAuthenticated) return ; @@ -753,6 +763,70 @@ export const router = createBrowserRouter([ ), }, + { + path: "/settings/loan/loan-types", + element: ( + }> + + + ), + }, + { + path: "/settings/loan/loan-types/create", + element: ( + }> + + + ), + }, + { + path: "/settings/loan/loan-types/:id", + element: ( + }> + + + ), + }, + { + path: "/settings/loan/loan-types/:id/edit", + element: ( + }> + + + ), + }, + { + path: "/settings/loan/required-documents", + element: ( + }> + + + ), + }, + { + path: "/settings/loan/required-documents/create", + element: ( + }> + + + ), + }, + { + path: "/settings/loan/required-documents/:id", + element: ( + }> + + + ), + }, + { + path: "/settings/loan/required-documents/:id/edit", + element: ( + }> + + + ), + }, ], }, ], diff --git a/src/features/loanTypes/api/loanTypesApi.ts b/src/features/loanTypes/api/loanTypesApi.ts new file mode 100644 index 0000000..bf5c500 --- /dev/null +++ b/src/features/loanTypes/api/loanTypesApi.ts @@ -0,0 +1,169 @@ +// features/loanTypes/api/loanTypesApi.ts + +export interface LoanTypeTranslation { + tk: string + ru: string + en: string +} + +export interface LoanType { + id: number + name: LoanTypeTranslation + tax: number + loanTerm: number + notes: LoanTypeTranslation | null + isActive: boolean + createdAt: string + updatedAt: string +} + +export interface LoanTypeListParams { + page?: number + perPage?: number + search?: string +} + +export interface LoanTypeListResponse { + data: LoanType[] + total: number + page: number + perPage: number + totalPages: number +} + +export interface CreateLoanTypePayload { + name: LoanTypeTranslation + tax: number + loanTerm: number + notes: LoanTypeTranslation | null + isActive: boolean +} + +export type UpdateLoanTypePayload = CreateLoanTypePayload + +// ─── Mock Data ──────────────────────────────────────────────────────────────── + +const MOCK_LOAN_TYPES: LoanType[] = [ + { + id: 5, + name: { tk: 'Talyp karzy', ru: 'Студенческий кредит', en: 'Student Loan' }, + tax: 1, + loanTerm: 30, + notes: { tk: 'Bellik', ru: 'Примечание', en: 'Note' }, + isActive: true, + createdAt: '2026-01-10T08:00:00Z', + updatedAt: '2026-03-15T10:30:00Z', + }, + { + id: 4, + name: { + tk: 'Üpjünçiligine girew emlägi bolan sarp ediş karzy', + ru: 'Потребительский кредит под залог имущества', + en: 'Consumer Loan Secured by Property', + }, + tax: 1, + loanTerm: 30, + notes: null, + isActive: true, + createdAt: '2026-01-08T09:00:00Z', + updatedAt: '2026-02-20T11:00:00Z', + }, + { + id: 3, + name: { tk: 'Kiçi göwrümli karzlar', ru: 'Микрокредиты', en: 'Micro Loans' }, + tax: 1, + loanTerm: 30, + notes: null, + isActive: true, + createdAt: '2026-01-05T07:00:00Z', + updatedAt: '2026-01-05T07:00:00Z', + }, + { + id: 2, + name: { + tk: 'Üpjünçiligine zamunlyk bolan sarp ediş karzy', + ru: 'Потребительский кредит под поручительство', + en: 'Consumer Loan with Guarantor', + }, + tax: 1, + loanTerm: 30, + notes: null, + isActive: true, + createdAt: '2026-01-03T06:00:00Z', + updatedAt: '2026-01-03T06:00:00Z', + }, + { + id: 1, + name: { tk: 'Ýaş çatynjalara', ru: 'Молодожёнам', en: 'Newlyweds Loan' }, + tax: 1, + loanTerm: 30, + notes: null, + isActive: true, + createdAt: '2026-01-01T00:00:00Z', + updatedAt: '2026-01-01T00:00:00Z', + }, +] + +let _mockStore: LoanType[] = [...MOCK_LOAN_TYPES] +let _nextId = 6 + +const delay = (ms = 400) => new Promise((res) => setTimeout(res, ms)) + +// ─── API Functions ──────────────────────────────────────────────────────────── + +export async function fetchLoanTypes(params: LoanTypeListParams = {}): Promise { + await delay() + const { page = 1, perPage = 25, search = '' } = params + + const filtered = search.trim() + ? _mockStore.filter((lt) => + lt.name.tk.toLowerCase().includes(search.toLowerCase()) || + lt.name.ru.toLowerCase().includes(search.toLowerCase()) || + lt.name.en.toLowerCase().includes(search.toLowerCase()) + ) + : _mockStore + + const sorted = [...filtered].sort((a, b) => b.id - a.id) + const start = (page - 1) * perPage + const data = sorted.slice(start, start + perPage) + + return { + data, + total: filtered.length, + page, + perPage, + totalPages: Math.max(1, Math.ceil(filtered.length / perPage)), + } +} + +export async function fetchLoanTypeById(id: number): Promise { + await delay() + const found = _mockStore.find((lt) => lt.id === id) + if (!found) throw new Error(`LoanType with id=${id} not found`) + return { ...found } +} + +export async function createLoanType(payload: CreateLoanTypePayload): Promise { + await delay() + const newItem: LoanType = { + id: _nextId++, + ...payload, + createdAt: new Date().toISOString(), + updatedAt: new Date().toISOString(), + } + _mockStore = [newItem, ..._mockStore] + return { ...newItem } +} + +export async function updateLoanType(id: number, payload: UpdateLoanTypePayload): Promise { + await delay() + const idx = _mockStore.findIndex((lt) => lt.id === id) + if (idx === -1) throw new Error(`LoanType with id=${id} not found`) + _mockStore[idx] = { ..._mockStore[idx], ...payload, updatedAt: new Date().toISOString() } + return { ..._mockStore[idx] } +} + +export async function deleteLoanType(id: number): Promise { + await delay() + _mockStore = _mockStore.filter((lt) => lt.id !== id) +} \ No newline at end of file diff --git a/src/features/loanTypes/components/loanTypesForm.tsx b/src/features/loanTypes/components/loanTypesForm.tsx new file mode 100644 index 0000000..fbd3b19 --- /dev/null +++ b/src/features/loanTypes/components/loanTypesForm.tsx @@ -0,0 +1,268 @@ +// features/loanTypes/components/LoanTypeForm.tsx + +import { useState, useEffect } from 'react' +import { useNavigate } from 'react-router-dom' +import { useTranslation } from 'react-i18next' +import { FormInput } from '@/components/formInput' +import { Button } from '@/components/ui/button' +import { Label } from '@/components/ui/label' +import { Checkbox } from '@/components/ui/checkbox' +import { useCreateLoanType, useUpdateLoanType } from '../hooks/useLoanTypes' +import type { LoanType, CreateLoanTypePayload } from '../api/loanTypesApi' + +// ─── Types ──────────────────────────────────────────────────────────────────── + +type FormMode = 'create' | 'edit' + +interface LoanTypeFormProps { + mode: FormMode + initialData?: LoanType + loanTypeId?: number +} + +interface FormErrors { + nameTk?: string + nameRu?: string + nameEn?: string + tax?: string + loanTerm?: string +} + +// ─── Language Tab ───────────────────────────────────────────────────────────── + +type Lang = 'tk' | 'ru' | 'en' + +const LANG_TABS: { key: Lang; label: string }[] = [ + { key: 'tk', label: 'Türkmen' }, + { key: 'ru', label: 'Русский' }, + { key: 'en', label: 'English' }, +] + +// ─── Validation ─────────────────────────────────────────────────────────────── + +function validate( + nameTk: string, + nameRu: string, + nameEn: string, + tax: string, + loanTerm: string, + t: (key: string, fallback: string) => string +): FormErrors { + const errors: FormErrors = {} + if (!nameTk.trim()) errors.nameTk = t('validation.required', 'Hökmany meýdan') + if (!nameRu.trim()) errors.nameRu = t('validation.required', 'Hökmany meýdan') + if (!nameEn.trim()) errors.nameEn = t('validation.required', 'Hökmany meýdan') + if (!tax || Number(tax) <= 0) errors.tax = t('validation.positiveNumber', 'Oňyn san gerek') + if (!loanTerm || Number(loanTerm) <= 0) errors.loanTerm = t('validation.positiveNumber', 'Oňyn san gerek') + return errors +} + +// ─── LoanTypeForm ───────────────────────────────────────────────────────────── + +export function LoanTypeForm({ mode, initialData, loanTypeId }: LoanTypeFormProps) { + const { t } = useTranslation() + const navigate = useNavigate() + + const createMutation = useCreateLoanType() + const updateMutation = useUpdateLoanType(loanTypeId ?? 0) + + const isPending = createMutation.isPending || updateMutation.isPending + + // ── State ────────────────────────────────────────────────────────────────── + const [activeLang, setActiveLang] = useState('tk') + const [nameTk, setNameTk] = useState('') + const [nameRu, setNameRu] = useState('') + const [nameEn, setNameEn] = useState('') + const [notesTk, setNotesTk] = useState('') + const [notesRu, setNotesRu] = useState('') + const [notesEn, setNotesEn] = useState('') + const [tax, setTax] = useState('') + const [loanTerm, setLoanTerm] = useState('') + const [isActive, setIsActive] = useState(true) + const [errors, setErrors] = useState({}) + + // ── Populate on edit ─────────────────────────────────────────────────────── + useEffect(() => { + if (mode === 'edit' && initialData) { + setNameTk(initialData.name.tk) + setNameRu(initialData.name.ru) + setNameEn(initialData.name.en) + setNotesTk(initialData.notes?.tk ?? '') + setNotesRu(initialData.notes?.ru ?? '') + setNotesEn(initialData.notes?.en ?? '') + setTax(String(initialData.tax)) + setLoanTerm(String(initialData.loanTerm)) + setIsActive(initialData.isActive) + } + }, [mode, initialData]) + + // ── Submit ───────────────────────────────────────────────────────────────── + const handleSubmit = async () => { + const validationErrors = validate(nameTk, nameRu, nameEn, tax, loanTerm, t) + if (Object.keys(validationErrors).length > 0) { + setErrors(validationErrors) + return + } + setErrors({}) + + const payload: CreateLoanTypePayload = { + name: { tk: nameTk.trim(), ru: nameRu.trim(), en: nameEn.trim() }, + tax: Number(tax), + loanTerm: Number(loanTerm), + notes: + notesTk.trim() || notesRu.trim() || notesEn.trim() + ? { tk: notesTk.trim(), ru: notesRu.trim(), en: notesEn.trim() } + : null, + isActive, + } + + if (mode === 'create') { + const result = await createMutation.mutateAsync(payload) + navigate(`/resources/loan-types/${result.id}`) + } else { + await updateMutation.mutateAsync(payload) + navigate(`/resources/loan-types/${loanTypeId}`) + } + } + + const handleCancel = () => navigate('/resources/loan-types') + + // ── Name fields per lang ─────────────────────────────────────────────────── + const nameFields: Record void; error?: string }> = { + tk: { value: nameTk, onChange: setNameTk, error: errors.nameTk }, + ru: { value: nameRu, onChange: setNameRu, error: errors.nameRu }, + en: { value: nameEn, onChange: setNameEn, error: errors.nameEn }, + } + + const notesFields: Record void }> = { + tk: { value: notesTk, onChange: setNotesTk }, + ru: { value: notesRu, onChange: setNotesRu }, + en: { value: notesEn, onChange: setNotesEn }, + } + + // ───────────────────────────────────────────────────────────────────────── + + return ( +
+ {/* Language tabs row */} +
+ {LANG_TABS.map((tab) => ( + + ))} +
+ + {/* Form card */} +
+ {/* Ady */} +
+ + {t('loanTypes.fields.name', 'Ady')} + * + + +
+ + {/* Salgyt */} +
+ + {t('loanTypes.fields.tax', 'Salgyt')} + * + + +
+ + {/* Karz möhleti */} +
+ + {t('loanTypes.fields.loanTerm', 'Karz möhleti')} + * + + +
+ + {/* Bellikler */} +
+ + {t('loanTypes.fields.notes', 'Bellikler')} + + +
+ + {/* Işjeň */} +
+ + {t('loanTypes.fields.isActive', 'Işjeň')} + +
+ + +
+
+
+ + {/* Actions */} +
+ + +
+
+ ) +} \ No newline at end of file diff --git a/src/features/loanTypes/hooks/useLoanTypes.ts b/src/features/loanTypes/hooks/useLoanTypes.ts new file mode 100644 index 0000000..56e6ae7 --- /dev/null +++ b/src/features/loanTypes/hooks/useLoanTypes.ts @@ -0,0 +1,97 @@ +// features/loanTypes/hooks/useLoanTypes.ts + +import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query' +import { toast } from 'sonner' +import { useTranslation } from 'react-i18next' +import { + fetchLoanTypes, + fetchLoanTypeById, + createLoanType, + updateLoanType, + deleteLoanType, + type LoanTypeListParams, + type CreateLoanTypePayload, + type UpdateLoanTypePayload, +} from '../api/loanTypesApi' + +// ─── Query Keys ─────────────────────────────────────────────────────────────── + +export const loanTypeKeys = { + all: () => ['loanTypes'] as const, + list: (params: LoanTypeListParams) => ['loanTypes', 'list', params] as const, + detail: (id: number) => ['loanTypes', 'detail', id] as const, +} + +// ─── useGetLoanTypes ────────────────────────────────────────────────────────── + +export function useGetLoanTypes(params: LoanTypeListParams = {}) { + return useQuery({ + queryKey: loanTypeKeys.list(params), + queryFn: () => fetchLoanTypes(params), + placeholderData: (prev) => prev, + }) +} + +// ─── useGetLoanTypeById ─────────────────────────────────────────────────────── + +export function useGetLoanTypeById(id: number | undefined) { + return useQuery({ + queryKey: loanTypeKeys.detail(id!), + queryFn: () => fetchLoanTypeById(id!), + enabled: !!id, + }) +} + +// ─── useCreateLoanType ──────────────────────────────────────────────────────── + +export function useCreateLoanType() { + const queryClient = useQueryClient() + const { t } = useTranslation() + + return useMutation({ + mutationFn: (payload: CreateLoanTypePayload) => createLoanType(payload), + onSuccess: () => { + queryClient.invalidateQueries({ queryKey: loanTypeKeys.all() }) + toast.success(t('loanTypes.toast.created', 'Karz görnüşi üstünlikli döredildi')) + }, + onError: (error: Error) => { + toast.error(error.message || t('loanTypes.toast.createError', 'Döretmek başartmady')) + }, + }) +} + +// ─── useUpdateLoanType ──────────────────────────────────────────────────────── + +export function useUpdateLoanType(id: number) { + const queryClient = useQueryClient() + const { t } = useTranslation() + + return useMutation({ + mutationFn: (payload: UpdateLoanTypePayload) => updateLoanType(id, payload), + onSuccess: () => { + queryClient.invalidateQueries({ queryKey: loanTypeKeys.all() }) + toast.success(t('loanTypes.toast.updated', 'Karz görnüşi üstünlikli täzelendi')) + }, + onError: (error: Error) => { + toast.error(error.message || t('loanTypes.toast.updateError', 'Täzelemek başartmady')) + }, + }) +} + +// ─── useDeleteLoanType ──────────────────────────────────────────────────────── + +export function useDeleteLoanType() { + const queryClient = useQueryClient() + const { t } = useTranslation() + + return useMutation({ + mutationFn: (id: number) => deleteLoanType(id), + onSuccess: () => { + queryClient.invalidateQueries({ queryKey: loanTypeKeys.all() }) + toast.success(t('loanTypes.toast.deleted', 'Karz görnüşi üstünlikli pozuldy')) + }, + onError: (error: Error) => { + toast.error(error.message || t('loanTypes.toast.deleteError', 'Pozmak başartmady')) + }, + }) +} \ No newline at end of file diff --git a/src/features/requiredDocuments/api/requiredDocumentsApi.ts b/src/features/requiredDocuments/api/requiredDocumentsApi.ts new file mode 100644 index 0000000..bade0a0 --- /dev/null +++ b/src/features/requiredDocuments/api/requiredDocumentsApi.ts @@ -0,0 +1,163 @@ +// ─── Types ──────────────────────────────────────────────────────────────────── + +export interface LoanDocumentTranslation { + tk: string + ru: string + en: string +} + +export interface LoanDocument { + id: number + name: LoanDocumentTranslation + description: LoanDocumentTranslation + createdAt: string + updatedAt: string +} + +export interface LoanDocumentPayload { + name: LoanDocumentTranslation + description: LoanDocumentTranslation +} + +export interface PaginatedResponse { + data: T[] + total: number + page: number + perPage: number + totalPages: number +} + +export interface ListParams { + page?: number + perPage?: number + search?: string +} + +// ─── Mock Data ──────────────────────────────────────────────────────────────── + +const MOCK_LOAN_DOCUMENTS: LoanDocument[] = [ + { + id: 1, + name: { + tk: 'Hormatly müşderi! Siziň ýüztutmaňyz kanagatlandyryldy!', + ru: 'Уважаемый клиент! Ваше обращение удовлетворено!', + en: 'Dear customer! Your request has been approved!', + }, + description: { + tk: 'Siziň karz sargydyňyz üstünlikli kabul edildi we tassyklandy.', + ru: 'Ваша заявка на кредит успешно принята и подтверждена.', + en: 'Your loan application has been successfully received and confirmed.', + }, + createdAt: '2026-01-15T10:30:00Z', + updatedAt: '2026-01-15T10:30:00Z', + }, + { + id: 2, + name: { + tk: 'Hormatly müşderi! Siziň ýüztutmaňyz kanagatlandyrylmady!', + ru: 'Уважаемый клиент! Ваше обращение не удовлетворено!', + en: 'Dear customer! Your request has been rejected!', + }, + description: { + tk: 'Siziň bank kart maglumatlaryňyz tapylmandygy sebäpli Siziň ýüztutmaňyz kanagatlandyrylmady! Bank kartyňyz boýunça hyzmat ediji bankyňyza ýüz tutmagyňyzy Sizden haýyş edýäris.', + ru: 'Ваше обращение не удовлетворено в связи с тем, что данные вашей банковской карты не найдены! Просим вас обратиться в банк, обслуживающий вашу банковскую карту.', + en: 'Your request has been rejected because your bank card information was not found! We kindly ask you to contact the bank that services your card.', + }, + createdAt: '2026-02-20T14:15:00Z', + updatedAt: '2026-03-10T09:00:00Z', + }, + { + id: 3, + name: { + tk: 'Karz resminama talap edilýär', + ru: 'Требуется документ для кредита', + en: 'Loan document required', + }, + description: { + tk: 'Karz almak üçin zerur resminamalary tabşyrmagyňyzy haýyş edýäris.', + ru: 'Просим вас предоставить необходимые документы для получения кредита.', + en: 'Please submit the required documents to obtain the loan.', + }, + createdAt: '2026-03-05T08:00:00Z', + updatedAt: '2026-03-05T08:00:00Z', + }, +] + +let mockStore = [...MOCK_LOAN_DOCUMENTS] +let nextId = mockStore.length + 1 + +// ─── Simulated delay ────────────────────────────────────────────────────────── + +const delay = (ms = 400) => new Promise((r) => setTimeout(r, ms)) + +// ─── API Functions ──────────────────────────────────────────────────────────── + +export async function fetchLoanDocuments( + params: ListParams = {} +): Promise> { + await delay() + const { page = 1, perPage = 10, search = '' } = params + + let filtered = mockStore + if (search.trim()) { + const q = search.toLowerCase() + filtered = mockStore.filter( + (d) => + d.name.tk.toLowerCase().includes(q) || + d.name.ru.toLowerCase().includes(q) || + d.name.en.toLowerCase().includes(q) + ) + } + + const total = filtered.length + const totalPages = Math.ceil(total / perPage) + const start = (page - 1) * perPage + const data = filtered.slice(start, start + perPage) + + return { data, total, page, perPage, totalPages } +} + +export async function fetchLoanDocumentById(id: number): Promise { + await delay() + const doc = mockStore.find((d) => d.id === id) + if (!doc) throw new Error(`LoanDocument with id ${id} not found`) + return { ...doc } +} + +export async function createLoanDocument( + payload: LoanDocumentPayload +): Promise { + await delay(600) + const now = new Date().toISOString() + const newDoc: LoanDocument = { + id: nextId++, + ...payload, + createdAt: now, + updatedAt: now, + } + mockStore = [newDoc, ...mockStore] + return { ...newDoc } +} + +export async function updateLoanDocument( + id: number, + payload: LoanDocumentPayload +): Promise { + await delay(600) + const index = mockStore.findIndex((d) => d.id === id) + if (index === -1) throw new Error(`LoanDocument with id ${id} not found`) + const updated: LoanDocument = { + ...mockStore[index], + ...payload, + updatedAt: new Date().toISOString(), + } + mockStore = mockStore.map((d) => (d.id === id ? updated : d)) + return { ...updated } +} + +export async function deleteLoanDocument(id: number): Promise { + await delay(400) + const exists = mockStore.some((d) => d.id === id) + if (!exists) throw new Error(`LoanDocument with id ${id} not found`) + mockStore = mockStore.filter((d) => d.id !== id) +} \ No newline at end of file diff --git a/src/features/requiredDocuments/components/requiredDocumentsForm.tsx b/src/features/requiredDocuments/components/requiredDocumentsForm.tsx new file mode 100644 index 0000000..a3bd53d --- /dev/null +++ b/src/features/requiredDocuments/components/requiredDocumentsForm.tsx @@ -0,0 +1,311 @@ +import { useState, useEffect } from 'react' +import { useNavigate } from 'react-router-dom' +import { useTranslation } from 'react-i18next' +import { useEditor, EditorContent } from '@tiptap/react' +import StarterKit from '@tiptap/starter-kit' +import Link from '@tiptap/extension-link' +import { + Bold, + Italic, + Strikethrough, + Link2, + Heading2, + Quote, + Code, + List, + ListOrdered, + Minus, + WrapText, + Paperclip, + Type, +} from 'lucide-react' +import { cn } from '@/lib/utils' +import { FormInput } from '@/components/formInput' +import { Button } from '@/components/ui/button' +import { useCreateRequiredDocument, useUpdateRequiredDocument } from '../hooks/useRequiredDocuments' +import type { LoanDocument, LoanDocumentPayload, LoanDocumentTranslation } from '../api/requiredDocumentsApi' + +// ─── Types ──────────────────────────────────────────────────────────────────── + +type Locale = 'tk' | 'ru' | 'en' + +interface RequiredDocumentFormProps { + mode: 'create' | 'edit' + initialData?: LoanDocument + requiredDocumentId?: number +} + +// ─── Lang tabs ──────────────────────────────────────────────────────────────── + +const LOCALES: { code: Locale; label: string }[] = [ + { code: 'tk', label: 'Türkmen' }, + { code: 'ru', label: 'Русский' }, + { code: 'en', label: 'English' }, +] + +// ─── Tiptap Toolbar ─────────────────────────────────────────────────────────── + +interface RichTextToolbarProps { + editor: ReturnType +} + +function RichTextToolbar({ editor }: RichTextToolbarProps) { + if (!editor) return null + + const tools = [ + { icon: Bold, action: () => editor.chain().focus().toggleBold().run(), active: editor.isActive('bold'), title: 'Bold' }, + { icon: Italic, action: () => editor.chain().focus().toggleItalic().run(), active: editor.isActive('italic'), title: 'Italic' }, + { icon: Strikethrough, action: () => editor.chain().focus().toggleStrike().run(), active: editor.isActive('strike'), title: 'Strike' }, + { icon: Link2, action: () => { + const url = prompt('URL giriziň:') + if (url) editor.chain().focus().setLink({ href: url }).run() + }, active: editor.isActive('link'), title: 'Link' }, + { icon: Heading2, action: () => editor.chain().focus().toggleHeading({ level: 2 }).run(), active: editor.isActive('heading', { level: 2 }), title: 'H2' }, + { icon: Quote, action: () => editor.chain().focus().toggleBlockquote().run(), active: editor.isActive('blockquote'), title: 'Quote' }, + { icon: Code, action: () => editor.chain().focus().toggleCode().run(), active: editor.isActive('code'), title: 'Code' }, + { icon: List, action: () => editor.chain().focus().toggleBulletList().run(), active: editor.isActive('bulletList'), title: 'Bullet List' }, + { icon: ListOrdered, action: () => editor.chain().focus().toggleOrderedList().run(), active: editor.isActive('orderedList'), title: 'Ordered List' }, + { icon: Minus, action: () => editor.chain().focus().setHorizontalRule().run(), active: false, title: 'Divider' }, + { icon: WrapText, action: () => editor.chain().focus().setHardBreak().run(), active: false, title: 'Hard Break' }, + { icon: Paperclip, action: () => {}, active: false, title: 'Attachment' }, + { icon: Type, action: () => editor.chain().focus().clearNodes().unsetAllMarks().run(), active: false, title: 'Clear format' }, + ] + + return ( +
+ {tools.map(({ icon: Icon, action, active, title }) => ( + + ))} +
+ ) +} + +// ─── RichTextEditor ─────────────────────────────────────────────────────────── + +interface RichTextEditorProps { + value: string + onChange: (html: string) => void + error?: string +} + +function RichTextEditor({ value, onChange, error }: RichTextEditorProps) { + const editor = useEditor({ + extensions: [StarterKit, Link.configure({ openOnClick: false })], + content: value, + onUpdate: ({ editor }) => onChange(editor.getHTML()), + }) + + // Sync external value changes (e.g. tab switch) + useEffect(() => { + if (editor && editor.getHTML() !== value) { + editor.commands.setContent(value, { emitUpdate: false }) + } + }, [value, editor]) + + return ( +
+ + + {error && ( +

+ + {error} +

+ )} +
+ ) +} + +// ─── LangTabs ──────────────────────────────────────────────────────────────── + +interface LangTabsProps { + active: Locale + onChange: (locale: Locale) => void +} + +function LangTabs({ active, onChange }: LangTabsProps) { + return ( +
+ {LOCALES.map(({ code, label }) => ( + + ))} +
+ ) +} + +// ─── Empty translation ──────────────────────────────────────────────────────── + +const emptyTranslation = (): LoanDocumentTranslation => ({ tk: '', ru: '', en: '' }) + +// ─── RequiredDocumentForm ───────────────────────────────────────────────────────── + +export function RequiredDocumentForm({ mode, initialData, requiredDocumentId }: RequiredDocumentFormProps) { + const { t } = useTranslation() + const navigate = useNavigate() + + // Per-field locale tabs + const [nameLang, setNameLang] = useState('tk') + const [descLang, setDescLang] = useState('tk') + + // Form state + const [name, setName] = useState( + initialData?.name ?? emptyTranslation() + ) + const [description, setDescription] = useState( + initialData?.description ?? emptyTranslation() + ) + + // Errors + const [errors, setErrors] = useState>>({}) + + // Sync initial data on edit mode load + useEffect(() => { + if (initialData) { + setName(initialData.name) + setDescription(initialData.description) + } + }, [initialData]) + + const createMutation = useCreateRequiredDocument() + const updateMutation = useUpdateRequiredDocument(requiredDocumentId ?? 0) + + const isPending = createMutation.isPending || updateMutation.isPending + + // ── Validation ────────────────────────────────────────────────────────────── + + const validate = (): boolean => { + const errs: typeof errors = {} + LOCALES.forEach(({ code }) => { + if (!name[code].trim()) { + errs[`name_${code}`] = t('validation.required', 'Bu meýdan hökmany') + } + if (!description[code].replace(/<[^>]*>/g, '').trim()) { + errs[`desc_${code}`] = t('validation.required', 'Bu meýdan hökmany') + } + }) + setErrors(errs) + return Object.keys(errs).length === 0 + } + + // ── Submit ────────────────────────────────────────────────────────────────── + + const handleSubmit = async (e: React.FormEvent) => { + e.preventDefault() + if (!validate()) return + + const payload: LoanDocumentPayload = { name, description } + + if (mode === 'create') { + await createMutation.mutateAsync(payload) + navigate('/settings/loan/loan-documents') + } else { + await updateMutation.mutateAsync(payload) + navigate('/settings/loan/loan-documents') + } + } + + const submitLabel = + mode === 'create' + ? t('loanDocuments.form.create', 'Karz gerekli resminamalary döretiň') + : t('loanDocuments.form.update', 'Karz gerekli resminamalary täzele') + + return ( +
+
+ + {/* ── Name field ──────────────────────────────────────────────────── */} +
+ +
+ + setName((prev) => ({ ...prev, [nameLang]: val }))} + placeholder={t('loanDocuments.fields.namePlaceholder', 'Ady')} + error={errors[`name_${nameLang}`]} + /> + {/* Show errors for other locales as hints */} + {LOCALES.filter((l) => l.code !== nameLang && errors[`name_${l.code}`]).map(({ code, label }) => ( +

+ {label}: {errors[`name_${code}`]} +

+ ))} +
+
+ + {/* ── Description field ────────────────────────────────────────────── */} +
+ +
+ + setDescription((prev) => ({ ...prev, [descLang]: val }))} + error={errors[`desc_${descLang}`]} + /> + {LOCALES.filter((l) => l.code !== descLang && errors[`desc_${l.code}`]).map(({ code, label }) => ( +

+ {label}: {errors[`desc_${code}`]} +

+ ))} +
+
+
+ + {/* ── Actions ──────────────────────────────────────────────────────────── */} +
+ + +
+
+ ) +} \ No newline at end of file diff --git a/src/features/requiredDocuments/hooks/useRequiredDocuments.ts b/src/features/requiredDocuments/hooks/useRequiredDocuments.ts new file mode 100644 index 0000000..f7576ca --- /dev/null +++ b/src/features/requiredDocuments/hooks/useRequiredDocuments.ts @@ -0,0 +1,96 @@ +import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query' +import { toast } from 'sonner' +import { useTranslation } from 'react-i18next' +import { + fetchLoanDocuments, + fetchLoanDocumentById, + createLoanDocument, + updateLoanDocument, + deleteLoanDocument, + type ListParams, + type LoanDocumentPayload, +} from '../api/requiredDocumentsApi' + +// ─── Query Keys ─────────────────────────────────────────────────────────────── + +export const requiredDocumentsKeys = { + all: ['requiredDocuments'] as const, + lists: () => [...requiredDocumentsKeys.all, 'list'] as const, + list: (params: ListParams) => [...requiredDocumentsKeys.lists(), params] as const, + details: () => [...requiredDocumentsKeys.all, 'detail'] as const, + detail: (id: number) => [...requiredDocumentsKeys.details(), id] as const, +} + +// ─── useGetLoanDocuments ────────────────────────────────────────────────────── + +export function useGetRequiredDocuments(params: ListParams) { + return useQuery({ + queryKey: requiredDocumentsKeys.list(params), + queryFn: () => fetchLoanDocuments(params), + }) +} + +// ─── useGetLoanDocumentById ─────────────────────────────────────────────────── + +export function useGetRequiredDocumentById(id: number) { + return useQuery({ + queryKey: requiredDocumentsKeys.detail(id), + queryFn: () => fetchLoanDocumentById(id), + enabled: !!id, + }) +} + +// ─── useCreateLoanDocument ──────────────────────────────────────────────────── + +export function useCreateRequiredDocument() { + const queryClient = useQueryClient() + const { t } = useTranslation() + + return useMutation({ + mutationFn: (payload: LoanDocumentPayload) => createLoanDocument(payload), + onSuccess: () => { + queryClient.invalidateQueries({ queryKey: requiredDocumentsKeys.lists() }) + toast.success(t('loanDocuments.toast.created', 'Resminama üstünlikli döredildi!')) + }, + onError: () => { + toast.error(t('loanDocuments.toast.createError', 'Resminama döredilende ýalňyşlyk ýüze çykdy!')) + }, + }) +} + +// ─── useUpdateLoanDocument ──────────────────────────────────────────────────── + +export function useUpdateRequiredDocument(id: number) { + const queryClient = useQueryClient() + const { t } = useTranslation() + + return useMutation({ + mutationFn: (payload: LoanDocumentPayload) => updateLoanDocument(id, payload), + onSuccess: () => { + queryClient.invalidateQueries({ queryKey: requiredDocumentsKeys.lists() }) + queryClient.invalidateQueries({ queryKey: requiredDocumentsKeys.detail(id) }) + toast.success(t('loanDocuments.toast.updated', 'Resminama üstünlikli täzelendi!')) + }, + onError: () => { + toast.error(t('loanDocuments.toast.updateError', 'Resminama täzelenende ýalňyşlyk ýüze çykdy!')) + }, + }) +} + +// ─── useDeleteLoanDocument ──────────────────────────────────────────────────── + +export function useDeleteRequiredDocument() { + const queryClient = useQueryClient() + const { t } = useTranslation() + + return useMutation({ + mutationFn: (id: number) => deleteLoanDocument(id), + onSuccess: () => { + queryClient.invalidateQueries({ queryKey: requiredDocumentsKeys.lists() }) + toast.success(t('loanDocuments.toast.deleted', 'Resminama üstünlikli öçürildi!')) + }, + onError: () => { + toast.error(t('loanDocuments.toast.deleteError', 'Resminama öçürilende ýalňyşlyk ýüze çykdy!')) + }, + }) +} \ No newline at end of file diff --git a/src/layouts/DashboardLayout.tsx b/src/layouts/DashboardLayout.tsx index 2d8f627..ee7b238 100644 --- a/src/layouts/DashboardLayout.tsx +++ b/src/layouts/DashboardLayout.tsx @@ -378,11 +378,11 @@ function AppSidebar() { items: [ { title: t("Loan types", "Karz görnüşleri"), - url: "/settings/loan/types", + url: "/settings/loan/loan-types", }, { title: t("Required Documents", "Gerekli resminamalar"), - url: "/settings/loan/documents", + url: "/settings/loan/required-documents", }, ], }, diff --git a/src/lib/i18n/locales/tk.json b/src/lib/i18n/locales/tk.json index 47f843b..f3173b0 100644 --- a/src/lib/i18n/locales/tk.json +++ b/src/lib/i18n/locales/tk.json @@ -403,10 +403,25 @@ "loanOrderStatus.RED_EDILDI": "RED EDILDI", "loanOrderStatus.IŞLENÝÄR": "IŞLENÝÄR", "Dashboards": "Dolandyryş panelleri", -"Card Issuance Reasons": "Kartyň çykarylmagynyň sebäpleri", -"Locale Manager": "Locale dolandyryjy", -"Resources": "Çeşmeler", -"Currency rates": "Walýuta kurslary", -"Loan balance": "Karzyň galyndysy" - + "Card Issuance Reasons": "Kartyň çykarylmagynyň sebäpleri", + "Locale Manager": "Locale dolandyryjy", + "Resources": "Çeşmeler", + "Currency rates": "Walýuta kurslary", + "Loan balance": "Karzyň galyndysy", + "loanDocuments.title": "Karz gerekli resminamalary", + "loanDocuments.createBtn": "Karz gerekli resminamalary dörediň", + "loanDocuments.editTitle": "Karz gerekli resminamalary redaktirle", + "loanDocuments.columns.name": "ADY", + "loanDocuments.deleteConfirm": "Bu resminamany öçürmek isleýärsiňizmi?", + "loanDocuments.form.create": "Karz gerekli resminamalary döretiň", + "loanDocuments.form.update": "Karz gerekli resminamalary täzele", + "loanDocuments.fields.name": "Ady", + "loanDocuments.fields.namePlaceholder": "Ady", + "loanDocuments.fields.description": "Yazgy", + "loanDocuments.toast.created": "Resminama üstünlikli döredildi!", + "loanDocuments.toast.createError": "Resminama döredilende ýalňyşlyk ýüze çykdy!", + "loanDocuments.toast.updated": "Resminama üstünlikli täzelendi!", + "loanDocuments.toast.updateError": "Resminama täzelenende ýalňyşlyk ýüze çykdy!", + "loanDocuments.toast.deleted": "Resminama üstünlikli öçürildi!", + "loanDocuments.toast.deleteError": "Resminama öçürilende ýalňyşlyk ýüze çykdy!" } \ No newline at end of file diff --git a/src/pages/settings/loan/loanTypes/index.tsx b/src/pages/settings/loan/loanTypes/index.tsx new file mode 100644 index 0000000..3f2ca97 --- /dev/null +++ b/src/pages/settings/loan/loanTypes/index.tsx @@ -0,0 +1,219 @@ +// pages/LoanTypesListPage.tsx + +import { useState } from 'react' +import { useNavigate } from 'react-router-dom' +import { useTranslation } from 'react-i18next' +import { Eye, Pencil, Trash2, CheckCircle2, XCircle } from 'lucide-react' +import { DataTable, type ColumnDef } from '@/components/dataTable' +import { DataTableToolbar } from '@/components/dataTableToolbar' +import { useGetLoanTypes, useDeleteLoanType } from '@/features/loanTypes/hooks/useLoanTypes' +import type { LoanType } from '@/features/loanTypes/api/loanTypesApi' +import { + AlertDialog, + AlertDialogAction, + AlertDialogCancel, + AlertDialogContent, + AlertDialogDescription, + AlertDialogFooter, + AlertDialogHeader, + AlertDialogTitle, +} from '@/components/ui/alert-dialog' + +// ─── Column definitions ─────────────────────────────────────────────────────── + +function useLoanTypeColumns( + onView: (id: number) => void, + onEdit: (id: number) => void, + onDelete: (id: number) => void +): ColumnDef[] { + const { t, i18n } = useTranslation() + const lang = (i18n.language ?? 'tk') as 'tk' | 'ru' | 'en' + + return [ + { + accessorKey: 'id', + header: 'ID', + size: 60, + cell: ({ row }) => ( + {row.original.id} + ), + }, + { + accessorKey: 'name', + header: t('loanTypes.columns.name', 'ADY'), + cell: ({ row }) => ( + {row.original.name[lang]} + ), + }, + { + accessorKey: 'tax', + header: t('loanTypes.columns.tax', 'SALGYT'), + size: 90, + cell: ({ row }) => ( + {row.original.tax} + ), + }, + { + accessorKey: 'loanTerm', + header: t('loanTypes.columns.loanTerm', 'KARZ MÖHLETI'), + size: 130, + cell: ({ row }) => ( + {row.original.loanTerm} + ), + }, + { + accessorKey: 'notes', + header: t('loanTypes.columns.notes', 'BELLIKLER'), + cell: ({ row }) => { + const notes = row.original.notes + return ( + + {notes ? notes[lang] || '—' : '—'} + + ) + }, + }, + { + accessorKey: 'isActive', + header: t('loanTypes.columns.isActive', 'IŞJEŇ'), + size: 80, + cell: ({ row }) => + row.original.isActive ? ( + + ) : ( + + ), + }, + { + id: 'actions', + header: '', + size: 120, + enableSorting: false, + cell: ({ row }) => ( +
+ + + +
+ ), + }, + ] +} + +// ─── LoanTypesListPage ──────────────────────────────────────────────────────── + +export default function LoanTypesListPage() { + const { t } = useTranslation() + const navigate = useNavigate() + + const [page, setPage] = useState(1) + const [perPage] = useState(25) + const [search, setSearch] = useState('') + const [deleteId, setDeleteId] = useState(null) + + const [columnVisibility, setColumnVisibility] = useState>({}) + const [columnOrder, setColumnOrder] = useState([]) + + const { data, isLoading } = useGetLoanTypes({ page, perPage, search }) + const deleteMutation = useDeleteLoanType() + + const handleView = (id: number) => navigate(`/settings/loan/loan-types/${id}`) + const handleEdit = (id: number) => navigate(`/settings/loan/loan-types/${id}/edit`) + const handleDelete = (id: number) => setDeleteId(id) + + const confirmDelete = async () => { + if (deleteId === null) return + await deleteMutation.mutateAsync(deleteId) + setDeleteId(null) + } + + const columns = useLoanTypeColumns(handleView, handleEdit, handleDelete) + + const columnMeta = columns + .filter((c) => c.id !== 'actions' && 'accessorKey' in c) + .map((c) => ({ + id: 'accessorKey' in c ? String(c.accessorKey) : String(c.id), + label: typeof c.header === 'string' ? c.header : String(c.id ?? ''), + })) + + return ( +
+ + +

+ {t('loanTypes.title', 'Karz görnüşleri')} +

+ + { setSearch(v); setPage(1) }} + searchPlaceholder={t('common.search', 'Gözlemek')} + columns={columnMeta} + columnVisibility={columnVisibility} + onColumnVisibilityChange={setColumnVisibility} + columnOrder={columnOrder} + onColumnOrderChange={setColumnOrder} + actionLabel={t('loanTypes.actions.create', 'Karz görnüşi dörediň')} + onAction={() => navigate('/settings/loan/loan-types/create')} + /> + + + columns={columns} + data={data?.data ?? []} + isLoading={isLoading} + columnVisibility={columnVisibility} + onColumnVisibilityChange={setColumnVisibility} + columnOrder={columnOrder} + onColumnOrderChange={setColumnOrder} + enableRowSelection + getRowId={(row) => String(row.id)} + currentPage={page} + totalPages={data?.totalPages ?? 1} + totalCount={data?.total} + onPageChange={setPage} + /> + + {/* Delete confirmation dialog */} + !open && setDeleteId(null)}> + + + {t('loanTypes.deleteDialog.title', 'Pozmak')} + + {t('loanTypes.deleteDialog.description', 'Bu karz görnüşini pozmak isleýärsiňizmi? Bu amal yzyna gaýtarylyp bilinmez.')} + + + + + {t('common.cancel', 'Ýatyr')} + + + {deleteMutation.isPending ? t('common.deleting', 'Pozulýar...') : t('common.delete', 'Pozmak')} + + + + +
+ ) +} \ No newline at end of file diff --git a/src/pages/settings/loan/loanTypesCreate/index.tsx b/src/pages/settings/loan/loanTypesCreate/index.tsx new file mode 100644 index 0000000..b214cb2 --- /dev/null +++ b/src/pages/settings/loan/loanTypesCreate/index.tsx @@ -0,0 +1,20 @@ +// pages/LoanTypeCreatePage.tsx + +import { useTranslation } from 'react-i18next' +import { LoanTypeForm } from '@/features/loanTypes/components/loanTypesForm' + +export default function LoanTypeCreatePage() { + const { t } = useTranslation() + + return ( +
+ + +

+ {t('loanTypes.actions.create', 'Karz görnüşi dörediň')} +

+ + +
+ ) +} \ No newline at end of file diff --git a/src/pages/settings/loan/loanTypesEdit/index.tsx b/src/pages/settings/loan/loanTypesEdit/index.tsx new file mode 100644 index 0000000..04484ad --- /dev/null +++ b/src/pages/settings/loan/loanTypesEdit/index.tsx @@ -0,0 +1,47 @@ +// pages/LoanTypeEditPage.tsx + +import { useParams } from 'react-router-dom' +import { useTranslation } from 'react-i18next' +import { LoanTypeForm } from '@/features/loanTypes/components/loanTypesForm' +import { useGetLoanTypeById } from '@/features/loanTypes/hooks/useLoanTypes' +import { Skeleton } from '@/components/ui/skeleton' + +export default function LoanTypeEditPage() { + const { t } = useTranslation() + const { id } = useParams<{ id: string }>() + const loanTypeId = Number(id) + + const { data, isLoading, isError } = useGetLoanTypeById(loanTypeId) + + return ( +
+ +

+ {isLoading + ? t('common.loading', 'Ýüklenýär...') + : `${t('loanTypes.editTitle', 'Karz görnüşi redaktirle')}: ${data?.name.tk ?? ''}`} +

+ + {isLoading ? ( +
+ {Array.from({ length: 5 }).map((_, i) => ( +
+ + +
+ ))} +
+ ) : isError ? ( +
+ {t('common.error', 'Ýalňyşlyk ýüze çykdy')} +
+ ) : ( + + )} +
+ ) +} \ No newline at end of file diff --git a/src/pages/settings/loan/loanTypesView/index.tsx b/src/pages/settings/loan/loanTypesView/index.tsx new file mode 100644 index 0000000..9cc0e27 --- /dev/null +++ b/src/pages/settings/loan/loanTypesView/index.tsx @@ -0,0 +1,206 @@ +// pages/LoanTypeViewPage.tsx + +import { useState } from 'react' +import { useNavigate, useParams } from 'react-router-dom' +import { useTranslation } from 'react-i18next' +import { Pencil, Trash2, CheckCircle2, XCircle } from 'lucide-react' +import { Button } from '@/components/ui/button' +import { Skeleton } from '@/components/ui/skeleton' +import { + AlertDialog, + AlertDialogAction, + AlertDialogCancel, + AlertDialogContent, + AlertDialogDescription, + AlertDialogFooter, + AlertDialogHeader, + AlertDialogTitle, +} from '@/components/ui/alert-dialog' +import { Section, InfoRow } from '@/components/viewPageComponents' +import { useGetLoanTypeById, useDeleteLoanType } from '@/features/loanTypes/hooks/useLoanTypes' + +// ─── LoanTypeViewPage ───────────────────────────────────────────────────────── + +export default function LoanTypeViewPage() { + const { t, i18n } = useTranslation() + const navigate = useNavigate() + const { id } = useParams<{ id: string }>() + const loanTypeId = Number(id) + + const [showDeleteDialog, setShowDeleteDialog] = useState(false) + + const { data, isLoading, isError } = useGetLoanTypeById(loanTypeId) + const deleteMutation = useDeleteLoanType() + + const lang = (i18n.language ?? 'tk') as 'tk' | 'ru' | 'en' + + const handleDelete = async () => { + await deleteMutation.mutateAsync(loanTypeId) + navigate('/resources/loan-types') + } + + // ── Skeleton ─────────────────────────────────────────────────────────────── + if (isLoading) { + return ( +
+ + +
+ {Array.from({ length: 5 }).map((_, i) => ( +
+ + +
+ ))} +
+
+ ) + } + + // ── Error ────────────────────────────────────────────────────────────────── + if (isError || !data) { + return ( +
+ {t('common.error', 'Ýalňyşlyk ýüze çykdy')} +
+ ) + } + + // ── View ─────────────────────────────────────────────────────────────────── + return ( +
+ {/* Breadcrumb */} +
+ navigate('/resources')} + > + {t('nav.resources', 'Resurslar')} + + / + navigate('/resources/loan-types')} + > + {t('loanTypes.title', 'Karz görnüşleri')} + + / + + {t('loanTypes.viewTitle', 'Karz görnüşi giňişleýin')}: {data.name[lang]} + +
+ + {/* Page header */} +
+

+ {t('loanTypes.viewTitle', 'Karz görnüşi giňişleýin')}: {data.name[lang]} +

+
+ + +
+
+ + {/* Detail section */} +
+ + + {/* Multilingual name rows */} +
+ + {t('loanTypes.fields.name', 'Ady')} + +
+
+ TK + {data.name.tk} +
+
+ RU + {data.name.ru} +
+
+ EN + {data.name.en} +
+
+
+ + + + + +
+ + {t('loanTypes.fields.notes', 'Bellikler')} + + + {data.notes ? data.notes[lang] || '—' : '—'} + +
+ +
+ + {t('loanTypes.fields.isActive', 'Işjeň')} + + {data.isActive ? ( + + ) : ( + + )} +
+
+ + {/* Delete dialog */} + + + + {t('loanTypes.deleteDialog.title', 'Pozmak')} + + {t( + 'loanTypes.deleteDialog.description', + 'Bu karz görnüşini pozmak isleýärsiňizmi? Bu amal yzyna gaýtarylyp bilinmez.' + )} + + + + + {t('common.cancel', 'Ýatyr')} + + + {deleteMutation.isPending + ? t('common.deleting', 'Pozulýar...') + : t('common.delete', 'Pozmak')} + + + + +
+ ) +} \ No newline at end of file diff --git a/src/pages/settings/loan/requiredDocuments/index.tsx b/src/pages/settings/loan/requiredDocuments/index.tsx new file mode 100644 index 0000000..3190649 --- /dev/null +++ b/src/pages/settings/loan/requiredDocuments/index.tsx @@ -0,0 +1,138 @@ +import { useState } from 'react' +import { useNavigate } from 'react-router-dom' +import { useTranslation } from 'react-i18next' +import { Eye, Pencil, Trash2 } from 'lucide-react' +import { DataTable, type ColumnDef } from '@/components/dataTable' +import { DataTableToolbar } from '@/components/dataTableToolbar' +import { useGetRequiredDocuments, useDeleteRequiredDocument } from '@/features/requiredDocuments/hooks/useRequiredDocuments' +import type { LoanDocument } from '@/features/requiredDocuments/api/requiredDocumentsApi' +import type { VisibilityState } from '@tanstack/react-table' + +// ─── Column visibility defaults ─────────────────────────────────────────────── + +const DEFAULT_VISIBILITY: VisibilityState = {} +const DEFAULT_ORDER = ['id', 'name', 'actions'] + +export default function RequiredDocumentsListPage() { + const { t } = useTranslation() + const navigate = useNavigate() + + // ── Table state ───────────────────────────────────────────────────────────── + const [search, setSearch] = useState('') + const [page, setPage] = useState(1) + const [perPage] = useState(10) + const [columnVisibility, setColumnVisibility] = useState(DEFAULT_VISIBILITY) + const [columnOrder, setColumnOrder] = useState(DEFAULT_ORDER) + + // ── Data ──────────────────────────────────────────────────────────────────── + const { data, isLoading } = useGetRequiredDocuments({ page, perPage, search }) + const deleteMutation = useDeleteRequiredDocument() + + const handleDelete = (id: number) => { + if (window.confirm(t('loanDocuments.deleteConfirm', 'Bu resminamany öçürmek isleýärsiňizmi?'))) { + deleteMutation.mutate(id) + } + } + + // ── Columns ───────────────────────────────────────────────────────────────── + const columns: ColumnDef[] = [ + { + id: 'id', + accessorKey: 'id', + header: 'ID', + size: 72, + cell: ({ row }) => ( + navigate(`/settings/loan/required-documents/${row.original.id}`)} + > + {row.original.id} + + ), + }, + { + id: 'name', + header: t('loanDocuments.columns.name', 'ADY'), + accessorFn: (row) => row.name.tk, + cell: ({ row }) => ( + {row.original.name.tk} + ), + }, + { + id: 'actions', + header: '', + size: 100, + enableSorting: false, + cell: ({ row }) => ( +
+ + + +
+ ), + }, + ] + + const columnMetas = columns + .filter((c) => c.id !== 'actions' && c.id !== 'select') + .map((c) => ({ id: c.id as string, label: typeof c.header === 'string' ? c.header : c.id as string })) + + return ( +
+ {/* Page heading */} +

+ {t('loanDocuments.title', 'Karz gerekli resminamalary')} +

+ + {/* Toolbar */} + { setSearch(v); setPage(1) }} + searchPlaceholder={t('common.search', 'Gözlemek')} + columns={columnMetas} + columnVisibility={columnVisibility} + onColumnVisibilityChange={setColumnVisibility} + columnOrder={columnOrder} + onColumnOrderChange={setColumnOrder} + actionLabel={t('loanDocuments.createBtn', 'Karz gerekli resminamalary döretiň')} + onAction={() => navigate('/settings/loan/required-documents/create')} + /> + + {/* Table */} + String(row.id)} + enableRowSelection + currentPage={page} + totalPages={data?.totalPages ?? 1} + totalCount={data?.total} + onPageChange={setPage} + /> +
+ ) +} \ No newline at end of file diff --git a/src/pages/settings/loan/requiredDocumentsCreate/index.tsx b/src/pages/settings/loan/requiredDocumentsCreate/index.tsx new file mode 100644 index 0000000..ed45d11 --- /dev/null +++ b/src/pages/settings/loan/requiredDocumentsCreate/index.tsx @@ -0,0 +1,16 @@ +import { useTranslation } from 'react-i18next' +import { RequiredDocumentForm } from '@/features/requiredDocuments/components/requiredDocumentsForm' + +export default function RequiredDocumentsCreatePage() { + const { t } = useTranslation() + + return ( +
+

+ {t('loanDocuments.createBtn', 'Karz gerekli resminamalary dörediň')} +

+ + +
+ ) +} diff --git a/src/pages/settings/loan/requiredDocumentsEdit/index.tsx b/src/pages/settings/loan/requiredDocumentsEdit/index.tsx new file mode 100644 index 0000000..4826b0c --- /dev/null +++ b/src/pages/settings/loan/requiredDocumentsEdit/index.tsx @@ -0,0 +1,47 @@ +import { useParams } from 'react-router-dom' +import { useTranslation } from 'react-i18next' +import { RequiredDocumentForm } from '@/features/requiredDocuments/components/requiredDocumentsForm' +import { useGetRequiredDocumentById } from '@/features/requiredDocuments/hooks/useRequiredDocuments' +import { Skeleton } from '@/components/ui/skeleton' + +export default function RequiredDocumentsEditPage() { + const { t } = useTranslation() + const { id } = useParams<{ id: string }>() + const documentId = Number(id) + + const { data, isLoading, isError } = useGetRequiredDocumentById(documentId) + + return ( +
+

+ {isLoading + ? t('common.loading', 'Ýüklenýär...') + : `${t('loanDocuments.editTitle', 'Karz gerekli resminamalary redaktirle')}: ${data?.name.tk ?? ''}`} +

+ + {isLoading ? ( +
+ {Array.from({ length: 2 }).map((_, i) => ( +
+ +
+ + +
+
+ ))} +
+ ) : isError ? ( +
+ {t('common.error', 'Ýalňyşlyk ýüze çykdy')} +
+ ) : ( + + )} +
+ ) +} diff --git a/src/pages/settings/loan/requiredDocumentsView/index.tsx b/src/pages/settings/loan/requiredDocumentsView/index.tsx new file mode 100644 index 0000000..b87a3d4 --- /dev/null +++ b/src/pages/settings/loan/requiredDocumentsView/index.tsx @@ -0,0 +1,117 @@ +import { useParams, useNavigate } from 'react-router-dom' +import { useTranslation } from 'react-i18next' +import { Pencil, Trash2 } from 'lucide-react' +import { Button } from '@/components/ui/button' +import { Section, InfoRow } from '@/components/viewPageComponents' +import { useGetRequiredDocumentById, useDeleteRequiredDocument } from '@/features/requiredDocuments/hooks/useRequiredDocuments' + +export default function RequiredDocumentsViewPage() { + const { id } = useParams<{ id: string }>() + const navigate = useNavigate() + const { t } = useTranslation() + + const docId = Number(id) + const { data, isLoading } = useGetRequiredDocumentById(docId) + const deleteMutation = useDeleteRequiredDocument() + + const handleDelete = async () => { + if (window.confirm(t('loanDocuments.deleteConfirm', 'Bu resminamany öçürmek isleýärsiňizmi?'))) { + await deleteMutation.mutateAsync(docId) + navigate('/settings/loan/loan-documents') + } + } + + if (isLoading) { + return ( +
+ {Array.from({ length: 3 }).map((_, i) => ( +
+ ))} +
+ ) + } + + if (!data) { + return ( +
+ {t('common.notFound', 'Maglumat tapylmady')} +
+ ) + } + + return ( +
+ {/* Page heading */} +
+

+ {t('loanDocuments.viewTitle', 'Karz gerekli resminamalary giňişleýin')}: {data.name.tk} +

+
+ + +
+
+ + {/* Main info */} +
+ + + {/* Name — multilingual */} +
+ + {t('loanDocuments.fields.name', 'Ady')} + +
+ {(['tk', 'ru', 'en'] as const).map((lang) => ( +
+ + {lang === 'tk' ? 'Türkmen' : lang === 'ru' ? 'Русский' : 'English'} + + {data.name[lang] || '—'} +
+ ))} +
+
+ + {/* Description — multilingual */} +
+ + {t('loanDocuments.fields.description', 'Yazgy')} + +
+ {(['tk', 'ru', 'en'] as const).map((lang) => ( +
+ + {lang === 'tk' ? 'Türkmen' : lang === 'ru' ? 'Русский' : 'English'} + + {data.description[lang] ? ( +
+ ) : ( + — + )} +
+ ))} +
+
+
+
+ ) +} \ No newline at end of file