improves steppbar, and phone validation, added formatter
This commit is contained in:
1 parent
7258b82265
commit
3472738fb1
27 files changed
+6958
-5363
No files matched your search
@@ -0,0 +1 @@
|
|||||||
|
npx lint-staged
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"*.{js,jsx,ts,tsx}": [
|
||||||
|
"eslint --fix",
|
||||||
|
"prettier --write"
|
||||||
|
],
|
||||||
|
"*.{css,scss,md,json,html}": [
|
||||||
|
"prettier --write"
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
node_modules/
|
||||||
|
dist/
|
||||||
|
build/
|
||||||
|
.env
|
||||||
|
.env.*
|
||||||
|
public/
|
||||||
|
*.png
|
||||||
|
*.jpg
|
||||||
|
*.jpeg
|
||||||
|
*.svg
|
||||||
|
*.gif
|
||||||
|
*.woff
|
||||||
|
*.woff2
|
||||||
|
*.ttf
|
||||||
|
*.eot
|
||||||
+11
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"printWidth": 140,
|
||||||
|
"tabWidth": 2,
|
||||||
|
"useTabs": false,
|
||||||
|
"semi": true,
|
||||||
|
"singleQuote": false,
|
||||||
|
"trailingComma": "all",
|
||||||
|
"bracketSpacing": true,
|
||||||
|
"arrowParens": "always",
|
||||||
|
"endOfLine": "auto"
|
||||||
|
}
|
||||||
+12
-15
@@ -1,22 +1,19 @@
|
|||||||
import js from '@eslint/js'
|
import js from "@eslint/js";
|
||||||
import globals from 'globals'
|
import globals from "globals";
|
||||||
import reactHooks from 'eslint-plugin-react-hooks'
|
import reactHooks from "eslint-plugin-react-hooks";
|
||||||
import reactRefresh from 'eslint-plugin-react-refresh'
|
import reactRefresh from "eslint-plugin-react-refresh";
|
||||||
import tseslint from 'typescript-eslint'
|
import tseslint from "typescript-eslint";
|
||||||
import { defineConfig, globalIgnores } from 'eslint/config'
|
import { defineConfig, globalIgnores } from "eslint/config";
|
||||||
|
import eslintConfigPrettier from "eslint-config-prettier";
|
||||||
|
|
||||||
export default defineConfig([
|
export default defineConfig([
|
||||||
globalIgnores(['dist']),
|
globalIgnores(["dist"]),
|
||||||
{
|
{
|
||||||
files: ['**/*.{ts,tsx}'],
|
files: ["**/*.{ts,tsx}"],
|
||||||
extends: [
|
extends: [js.configs.recommended, tseslint.configs.recommended, reactHooks.configs.flat.recommended, reactRefresh.configs.vite],
|
||||||
js.configs.recommended,
|
|
||||||
tseslint.configs.recommended,
|
|
||||||
reactHooks.configs.flat.recommended,
|
|
||||||
reactRefresh.configs.vite,
|
|
||||||
],
|
|
||||||
languageOptions: {
|
languageOptions: {
|
||||||
globals: globals.browser,
|
globals: globals.browser,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
])
|
eslintConfigPrettier,
|
||||||
|
]);
|
||||||
Generated
+368
@@ -50,10 +50,14 @@
|
|||||||
"@vitejs/plugin-react": "^6.0.1",
|
"@vitejs/plugin-react": "^6.0.1",
|
||||||
"autoprefixer": "^10.5.0",
|
"autoprefixer": "^10.5.0",
|
||||||
"eslint": "^10.2.1",
|
"eslint": "^10.2.1",
|
||||||
|
"eslint-config-prettier": "^10.1.8",
|
||||||
"eslint-plugin-react-hooks": "^7.1.1",
|
"eslint-plugin-react-hooks": "^7.1.1",
|
||||||
"eslint-plugin-react-refresh": "^0.5.2",
|
"eslint-plugin-react-refresh": "^0.5.2",
|
||||||
"globals": "^17.5.0",
|
"globals": "^17.5.0",
|
||||||
|
"husky": "^9.1.7",
|
||||||
|
"lint-staged": "^16.4.0",
|
||||||
"postcss": "^8.5.13",
|
"postcss": "^8.5.13",
|
||||||
|
"prettier": "^3.8.3",
|
||||||
"tailwindcss": "^4.2.4",
|
"tailwindcss": "^4.2.4",
|
||||||
"typescript": "~6.0.2",
|
"typescript": "~6.0.2",
|
||||||
"typescript-eslint": "^8.58.2",
|
"typescript-eslint": "^8.58.2",
|
||||||
@@ -4459,6 +4463,22 @@
|
|||||||
"integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==",
|
"integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==",
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
|
"node_modules/ansi-escapes": {
|
||||||
|
"version": "7.3.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-7.3.0.tgz",
|
||||||
|
"integrity": "sha512-BvU8nYgGQBxcmMuEeUEmNTvrMVjJNSH7RgW24vXexN4Ven6qCvy4TntnvlnwnMLTVlcRQQdbRY8NKnaIoeWDNg==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"environment": "^1.0.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=18"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/sponsors/sindresorhus"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/ansi-regex": {
|
"node_modules/ansi-regex": {
|
||||||
"version": "6.2.2",
|
"version": "6.2.2",
|
||||||
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.2.2.tgz",
|
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.2.2.tgz",
|
||||||
@@ -4805,6 +4825,40 @@
|
|||||||
"url": "https://github.com/sponsors/sindresorhus"
|
"url": "https://github.com/sponsors/sindresorhus"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/cli-truncate": {
|
||||||
|
"version": "5.2.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/cli-truncate/-/cli-truncate-5.2.0.tgz",
|
||||||
|
"integrity": "sha512-xRwvIOMGrfOAnM1JYtqQImuaNtDEv9v6oIYAs4LIHwTiKee8uwvIi363igssOC0O5U04i4AlENs79LQLu9tEMw==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"slice-ansi": "^8.0.0",
|
||||||
|
"string-width": "^8.2.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=20"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/sponsors/sindresorhus"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/cli-truncate/node_modules/string-width": {
|
||||||
|
"version": "8.2.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/string-width/-/string-width-8.2.1.tgz",
|
||||||
|
"integrity": "sha512-IIaP0g3iy9Cyy18w3M9YcaDudujEAVHKt3a3QJg1+sr/oX96TbaGUubG0hJyCjCBThFH+tFpcIyoUHUn1ogaLA==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"get-east-asian-width": "^1.5.0",
|
||||||
|
"strip-ansi": "^7.1.2"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=20"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/sponsors/sindresorhus"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/cli-width": {
|
"node_modules/cli-width": {
|
||||||
"version": "4.1.0",
|
"version": "4.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/cli-width/-/cli-width-4.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/cli-width/-/cli-width-4.1.0.tgz",
|
||||||
@@ -4902,6 +4956,13 @@
|
|||||||
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
|
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
|
"node_modules/colorette": {
|
||||||
|
"version": "2.0.20",
|
||||||
|
"resolved": "https://registry.npmjs.org/colorette/-/colorette-2.0.20.tgz",
|
||||||
|
"integrity": "sha512-IfEDxwoWIjkeXL1eXcDiow4UbKjhLdq6/EuSVR9GMN7KVH3r9gQ83e73hsz1Nd1T3ijd5xv1wcWRYO+D6kCI2w==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
"node_modules/combined-stream": {
|
"node_modules/combined-stream": {
|
||||||
"version": "1.0.8",
|
"version": "1.0.8",
|
||||||
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
|
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
|
||||||
@@ -5419,6 +5480,19 @@
|
|||||||
"node": ">=6"
|
"node": ">=6"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/environment": {
|
||||||
|
"version": "1.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/environment/-/environment-1.1.0.tgz",
|
||||||
|
"integrity": "sha512-xUtoPkMggbz0MPyPiIWr1Kp4aeWJjDZ6SMvURhimjdZgsRuDplF5/s9hcgGhyXMhs+6vpnuoiZ2kFiu3FMnS8Q==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=18"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/sponsors/sindresorhus"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/error-ex": {
|
"node_modules/error-ex": {
|
||||||
"version": "1.3.4",
|
"version": "1.3.4",
|
||||||
"resolved": "https://registry.npmjs.org/error-ex/-/error-ex-1.3.4.tgz",
|
"resolved": "https://registry.npmjs.org/error-ex/-/error-ex-1.3.4.tgz",
|
||||||
@@ -5567,6 +5641,22 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/eslint-config-prettier": {
|
||||||
|
"version": "10.1.8",
|
||||||
|
"resolved": "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-10.1.8.tgz",
|
||||||
|
"integrity": "sha512-82GZUjRS0p/jganf6q1rEO25VSoHH0hKPCTrgillPjdI/3bgBhAE1QzHrHTizjpRvy6pGAvKjDJtk2pF9NDq8w==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"bin": {
|
||||||
|
"eslint-config-prettier": "bin/cli.js"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://opencollective.com/eslint-config-prettier"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"eslint": ">=7.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/eslint-plugin-react-hooks": {
|
"node_modules/eslint-plugin-react-hooks": {
|
||||||
"version": "7.1.1",
|
"version": "7.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/eslint-plugin-react-hooks/-/eslint-plugin-react-hooks-7.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/eslint-plugin-react-hooks/-/eslint-plugin-react-hooks-7.1.1.tgz",
|
||||||
@@ -6502,6 +6592,22 @@
|
|||||||
"node": ">=18.18.0"
|
"node": ">=18.18.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/husky": {
|
||||||
|
"version": "9.1.7",
|
||||||
|
"resolved": "https://registry.npmjs.org/husky/-/husky-9.1.7.tgz",
|
||||||
|
"integrity": "sha512-5gs5ytaNjBrh5Ow3zrvdUUY+0VxIuWVL4i9irt6friV+BqdCfmV11CQTWMiBYWHbXhco+J1kHfTOUkePhCDvMA==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"bin": {
|
||||||
|
"husky": "bin.js"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=18"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/sponsors/typicode"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/i18next": {
|
"node_modules/i18next": {
|
||||||
"version": "26.0.8",
|
"version": "26.0.8",
|
||||||
"resolved": "https://registry.npmjs.org/i18next/-/i18next-26.0.8.tgz",
|
"resolved": "https://registry.npmjs.org/i18next/-/i18next-26.0.8.tgz",
|
||||||
@@ -7231,6 +7337,79 @@
|
|||||||
"integrity": "sha512-NT1CJtq3hHIreOianA8aSXn6Cw0JzYOuDQbOrSPe7gqFnCpKP++MQe3ODgO3oh2GJFORkAAdqredOa60z63GbA==",
|
"integrity": "sha512-NT1CJtq3hHIreOianA8aSXn6Cw0JzYOuDQbOrSPe7gqFnCpKP++MQe3ODgO3oh2GJFORkAAdqredOa60z63GbA==",
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
|
"node_modules/lint-staged": {
|
||||||
|
"version": "16.4.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/lint-staged/-/lint-staged-16.4.0.tgz",
|
||||||
|
"integrity": "sha512-lBWt8hujh/Cjysw5GYVmZpFHXDCgZzhrOm8vbcUdobADZNOK/bRshr2kM3DfgrrtR1DQhfupW9gnIXOfiFi+bw==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"commander": "^14.0.3",
|
||||||
|
"listr2": "^9.0.5",
|
||||||
|
"picomatch": "^4.0.3",
|
||||||
|
"string-argv": "^0.3.2",
|
||||||
|
"tinyexec": "^1.0.4",
|
||||||
|
"yaml": "^2.8.2"
|
||||||
|
},
|
||||||
|
"bin": {
|
||||||
|
"lint-staged": "bin/lint-staged.js"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=20.17"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://opencollective.com/lint-staged"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/listr2": {
|
||||||
|
"version": "9.0.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/listr2/-/listr2-9.0.5.tgz",
|
||||||
|
"integrity": "sha512-ME4Fb83LgEgwNw96RKNvKV4VTLuXfoKudAmm2lP8Kk87KaMK0/Xrx/aAkMWmT8mDb+3MlFDspfbCs7adjRxA2g==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"cli-truncate": "^5.0.0",
|
||||||
|
"colorette": "^2.0.20",
|
||||||
|
"eventemitter3": "^5.0.1",
|
||||||
|
"log-update": "^6.1.0",
|
||||||
|
"rfdc": "^1.4.1",
|
||||||
|
"wrap-ansi": "^9.0.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=20.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/listr2/node_modules/ansi-styles": {
|
||||||
|
"version": "6.2.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-6.2.3.tgz",
|
||||||
|
"integrity": "sha512-4Dj6M28JB+oAH8kFkTLUo+a2jwOFkuqb3yucU0CANcRRUbxS0cP0nZYCGjcc3BNXwRIsUVmDGgzawme7zvJHvg==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/chalk/ansi-styles?sponsor=1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/listr2/node_modules/wrap-ansi": {
|
||||||
|
"version": "9.0.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-9.0.2.tgz",
|
||||||
|
"integrity": "sha512-42AtmgqjV+X1VpdOfyTGOYRi0/zsoLqtXQckTmqTeybT+BDIbM/Guxo7x3pE2vtpr1ok6xRqM9OpBe+Jyoqyww==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"ansi-styles": "^6.2.1",
|
||||||
|
"string-width": "^7.0.0",
|
||||||
|
"strip-ansi": "^7.1.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=18"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/chalk/wrap-ansi?sponsor=1"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/locate-path": {
|
"node_modules/locate-path": {
|
||||||
"version": "6.0.0",
|
"version": "6.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/locate-path/-/locate-path-6.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/locate-path/-/locate-path-6.0.0.tgz",
|
||||||
@@ -7275,6 +7454,90 @@
|
|||||||
"url": "https://github.com/sponsors/sindresorhus"
|
"url": "https://github.com/sponsors/sindresorhus"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/log-update": {
|
||||||
|
"version": "6.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/log-update/-/log-update-6.1.0.tgz",
|
||||||
|
"integrity": "sha512-9ie8ItPR6tjY5uYJh8K/Zrv/RMZ5VOlOWvtZdEHYSTFKZfIBPQa9tOAEeAWhd+AnIneLJ22w5fjOYtoutpWq5w==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"ansi-escapes": "^7.0.0",
|
||||||
|
"cli-cursor": "^5.0.0",
|
||||||
|
"slice-ansi": "^7.1.0",
|
||||||
|
"strip-ansi": "^7.1.0",
|
||||||
|
"wrap-ansi": "^9.0.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=18"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/sponsors/sindresorhus"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/log-update/node_modules/ansi-styles": {
|
||||||
|
"version": "6.2.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-6.2.3.tgz",
|
||||||
|
"integrity": "sha512-4Dj6M28JB+oAH8kFkTLUo+a2jwOFkuqb3yucU0CANcRRUbxS0cP0nZYCGjcc3BNXwRIsUVmDGgzawme7zvJHvg==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/chalk/ansi-styles?sponsor=1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/log-update/node_modules/is-fullwidth-code-point": {
|
||||||
|
"version": "5.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-5.1.0.tgz",
|
||||||
|
"integrity": "sha512-5XHYaSyiqADb4RnZ1Bdad6cPp8Toise4TzEjcOYDHZkTCbKgiUl7WTUCpNWHuxmDt91wnsZBc9xinNzopv3JMQ==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"get-east-asian-width": "^1.3.1"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=18"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/sponsors/sindresorhus"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/log-update/node_modules/slice-ansi": {
|
||||||
|
"version": "7.1.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/slice-ansi/-/slice-ansi-7.1.2.tgz",
|
||||||
|
"integrity": "sha512-iOBWFgUX7caIZiuutICxVgX1SdxwAVFFKwt1EvMYYec/NWO5meOJ6K5uQxhrYBdQJne4KxiqZc+KptFOWFSI9w==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"ansi-styles": "^6.2.1",
|
||||||
|
"is-fullwidth-code-point": "^5.0.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=18"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/chalk/slice-ansi?sponsor=1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/log-update/node_modules/wrap-ansi": {
|
||||||
|
"version": "9.0.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-9.0.2.tgz",
|
||||||
|
"integrity": "sha512-42AtmgqjV+X1VpdOfyTGOYRi0/zsoLqtXQckTmqTeybT+BDIbM/Guxo7x3pE2vtpr1ok6xRqM9OpBe+Jyoqyww==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"ansi-styles": "^6.2.1",
|
||||||
|
"string-width": "^7.0.0",
|
||||||
|
"strip-ansi": "^7.1.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=18"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/chalk/wrap-ansi?sponsor=1"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/lru-cache": {
|
"node_modules/lru-cache": {
|
||||||
"version": "5.1.1",
|
"version": "5.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-5.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-5.1.1.tgz",
|
||||||
@@ -7981,6 +8244,22 @@
|
|||||||
"node": ">= 0.8.0"
|
"node": ">= 0.8.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/prettier": {
|
||||||
|
"version": "3.8.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/prettier/-/prettier-3.8.3.tgz",
|
||||||
|
"integrity": "sha512-7igPTM53cGHMW8xWuVTydi2KO233VFiTNyF5hLJqpilHfmn8C8gPf+PS7dUT64YcXFbiMGZxS9pCSxL/Dxm/Jw==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"bin": {
|
||||||
|
"prettier": "bin/prettier.cjs"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=14"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/prettier/prettier?sponsor=1"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/pretty-ms": {
|
"node_modules/pretty-ms": {
|
||||||
"version": "9.3.0",
|
"version": "9.3.0",
|
||||||
"resolved": "https://registry.npmjs.org/pretty-ms/-/pretty-ms-9.3.0.tgz",
|
"resolved": "https://registry.npmjs.org/pretty-ms/-/pretty-ms-9.3.0.tgz",
|
||||||
@@ -8683,6 +8962,13 @@
|
|||||||
"node": ">=0.10.0"
|
"node": ">=0.10.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/rfdc": {
|
||||||
|
"version": "1.4.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/rfdc/-/rfdc-1.4.1.tgz",
|
||||||
|
"integrity": "sha512-q1b3N5QkRUWUl7iyylaaj3kOpIT0N2i9MqIEQXP73GVsN9cw3fdx8X63cEmWhJGi2PPCF23Ijp7ktmd39rawIA==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
"node_modules/rolldown": {
|
"node_modules/rolldown": {
|
||||||
"version": "1.0.0-rc.17",
|
"version": "1.0.0-rc.17",
|
||||||
"resolved": "https://registry.npmjs.org/rolldown/-/rolldown-1.0.0-rc.17.tgz",
|
"resolved": "https://registry.npmjs.org/rolldown/-/rolldown-1.0.0-rc.17.tgz",
|
||||||
@@ -9037,6 +9323,52 @@
|
|||||||
"integrity": "sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg==",
|
"integrity": "sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg==",
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
|
"node_modules/slice-ansi": {
|
||||||
|
"version": "8.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/slice-ansi/-/slice-ansi-8.0.0.tgz",
|
||||||
|
"integrity": "sha512-stxByr12oeeOyY2BlviTNQlYV5xOj47GirPr4yA1hE9JCtxfQN0+tVbkxwCtYDQWhEKWFHsEK48ORg5jrouCAg==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"ansi-styles": "^6.2.3",
|
||||||
|
"is-fullwidth-code-point": "^5.1.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=20"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/chalk/slice-ansi?sponsor=1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/slice-ansi/node_modules/ansi-styles": {
|
||||||
|
"version": "6.2.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-6.2.3.tgz",
|
||||||
|
"integrity": "sha512-4Dj6M28JB+oAH8kFkTLUo+a2jwOFkuqb3yucU0CANcRRUbxS0cP0nZYCGjcc3BNXwRIsUVmDGgzawme7zvJHvg==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/chalk/ansi-styles?sponsor=1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/slice-ansi/node_modules/is-fullwidth-code-point": {
|
||||||
|
"version": "5.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-5.1.0.tgz",
|
||||||
|
"integrity": "sha512-5XHYaSyiqADb4RnZ1Bdad6cPp8Toise4TzEjcOYDHZkTCbKgiUl7WTUCpNWHuxmDt91wnsZBc9xinNzopv3JMQ==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"get-east-asian-width": "^1.3.1"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=18"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/sponsors/sindresorhus"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/sonner": {
|
"node_modules/sonner": {
|
||||||
"version": "2.0.7",
|
"version": "2.0.7",
|
||||||
"resolved": "https://registry.npmjs.org/sonner/-/sonner-2.0.7.tgz",
|
"resolved": "https://registry.npmjs.org/sonner/-/sonner-2.0.7.tgz",
|
||||||
@@ -9092,6 +9424,16 @@
|
|||||||
"integrity": "sha512-vMgjE/GGEPEFnhFub6pa4FmJBRBVOLpIII2hvCZ8Kzb7K0hlHo7mQv6xYrBvCL2LtAIBwFUK8wvuJgTVSQ5MFQ==",
|
"integrity": "sha512-vMgjE/GGEPEFnhFub6pa4FmJBRBVOLpIII2hvCZ8Kzb7K0hlHo7mQv6xYrBvCL2LtAIBwFUK8wvuJgTVSQ5MFQ==",
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
|
"node_modules/string-argv": {
|
||||||
|
"version": "0.3.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/string-argv/-/string-argv-0.3.2.tgz",
|
||||||
|
"integrity": "sha512-aqD2Q0144Z+/RqG52NeHEkZauTAUWJO8c6yTftGJKO3Tja5tUgIfmIl6kExvhtxSDP7fXB6DvzkfMpCd/F3G+Q==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.6.19"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/string-width": {
|
"node_modules/string-width": {
|
||||||
"version": "7.2.0",
|
"version": "7.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/string-width/-/string-width-7.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/string-width/-/string-width-7.2.0.tgz",
|
||||||
@@ -9211,6 +9553,16 @@
|
|||||||
"integrity": "sha512-+FbBPE1o9QAYvviau/qC5SE3caw21q3xkvWKBtja5vgqOWIHHJ3ioaq1VPfn/Szqctz2bU/oYeKd9/z5BL+PVg==",
|
"integrity": "sha512-+FbBPE1o9QAYvviau/qC5SE3caw21q3xkvWKBtja5vgqOWIHHJ3ioaq1VPfn/Szqctz2bU/oYeKd9/z5BL+PVg==",
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
|
"node_modules/tinyexec": {
|
||||||
|
"version": "1.2.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/tinyexec/-/tinyexec-1.2.4.tgz",
|
||||||
|
"integrity": "sha512-SHf/r48b7vOrjve9PxJo3MN5v5yuyjHvdUcrQffT3WXMUfnGmHDVbC4k3sHJaJTgZCwpUplIaAo5ANtMyp3YHg==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=18"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/tinyglobby": {
|
"node_modules/tinyglobby": {
|
||||||
"version": "0.2.16",
|
"version": "0.2.16",
|
||||||
"resolved": "https://registry.npmjs.org/tinyglobby/-/tinyglobby-0.2.16.tgz",
|
"resolved": "https://registry.npmjs.org/tinyglobby/-/tinyglobby-0.2.16.tgz",
|
||||||
@@ -9829,6 +10181,22 @@
|
|||||||
"integrity": "sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g==",
|
"integrity": "sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g==",
|
||||||
"license": "ISC"
|
"license": "ISC"
|
||||||
},
|
},
|
||||||
|
"node_modules/yaml": {
|
||||||
|
"version": "2.9.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/yaml/-/yaml-2.9.0.tgz",
|
||||||
|
"integrity": "sha512-2AvhNX3mb8zd6Zy7INTtSpl1F15HW6Wnqj0srWlkKLcpYl/gMIMJiyuGq2KeI2YFxUPjdlB+3Lc10seMLtL4cA==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "ISC",
|
||||||
|
"bin": {
|
||||||
|
"yaml": "bin.mjs"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 14.6"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/sponsors/eemeli"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/yargs": {
|
"node_modules/yargs": {
|
||||||
"version": "17.7.2",
|
"version": "17.7.2",
|
||||||
"resolved": "https://registry.npmjs.org/yargs/-/yargs-17.7.2.tgz",
|
"resolved": "https://registry.npmjs.org/yargs/-/yargs-17.7.2.tgz",
|
||||||
|
|||||||
+7
-1
@@ -7,7 +7,9 @@
|
|||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
"build": "tsc -b && vite build",
|
"build": "tsc -b && vite build",
|
||||||
"lint": "eslint .",
|
"lint": "eslint .",
|
||||||
"preview": "vite preview"
|
"format": "prettier --write .",
|
||||||
|
"preview": "vite preview",
|
||||||
|
"prepare": "husky"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@fontsource-variable/geist": "^5.2.8",
|
"@fontsource-variable/geist": "^5.2.8",
|
||||||
@@ -52,10 +54,14 @@
|
|||||||
"@vitejs/plugin-react": "^6.0.1",
|
"@vitejs/plugin-react": "^6.0.1",
|
||||||
"autoprefixer": "^10.5.0",
|
"autoprefixer": "^10.5.0",
|
||||||
"eslint": "^10.2.1",
|
"eslint": "^10.2.1",
|
||||||
|
"eslint-config-prettier": "^10.1.8",
|
||||||
"eslint-plugin-react-hooks": "^7.1.1",
|
"eslint-plugin-react-hooks": "^7.1.1",
|
||||||
"eslint-plugin-react-refresh": "^0.5.2",
|
"eslint-plugin-react-refresh": "^0.5.2",
|
||||||
"globals": "^17.5.0",
|
"globals": "^17.5.0",
|
||||||
|
"husky": "^9.1.7",
|
||||||
|
"lint-staged": "^16.4.0",
|
||||||
"postcss": "^8.5.13",
|
"postcss": "^8.5.13",
|
||||||
|
"prettier": "^3.8.3",
|
||||||
"tailwindcss": "^4.2.4",
|
"tailwindcss": "^4.2.4",
|
||||||
"typescript": "~6.0.2",
|
"typescript": "~6.0.2",
|
||||||
"typescript-eslint": "^8.58.2",
|
"typescript-eslint": "^8.58.2",
|
||||||
|
|||||||
+239
-245
@@ -1,95 +1,94 @@
|
|||||||
import { useState, useRef, useEffect } from 'react'
|
import { useState, useRef, useEffect } from "react";
|
||||||
import * as CollapsiblePrimitive from '@radix-ui/react-collapsible'
|
import * as CollapsiblePrimitive from "@radix-ui/react-collapsible";
|
||||||
import { Check, ChevronsUpDown, Search, X, Eye, EyeOff, Upload, Hash } from 'lucide-react'
|
import { Check, ChevronsUpDown, Search, X, Eye, EyeOff, Upload, Hash } from "lucide-react";
|
||||||
|
|
||||||
import { cn } from '@/lib/utils'
|
import { cn } from "@/lib/utils";
|
||||||
import { Input } from '@/components/ui/input'
|
import { Input } from "@/components/ui/input";
|
||||||
import { Textarea } from '@/components/ui/textarea'
|
import { Textarea } from "@/components/ui/textarea";
|
||||||
import { Button } from '@/components/ui/button'
|
import { Button } from "@/components/ui/button";
|
||||||
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover'
|
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
|
||||||
import { Calendar } from '@/components/ui/calendar'
|
import { Calendar } from "@/components/ui/calendar";
|
||||||
import { format, parse, isValid } from 'date-fns'
|
import { format, parse, isValid } from "date-fns";
|
||||||
import { CalendarIcon } from 'lucide-react'
|
import { CalendarIcon } from "lucide-react";
|
||||||
|
|
||||||
// ─── Collapsible aliases ──────────────────────────────────────────────────────
|
// ─── Collapsible aliases ──────────────────────────────────────────────────────
|
||||||
|
|
||||||
const Collapsible = CollapsiblePrimitive.Root
|
const Collapsible = CollapsiblePrimitive.Root;
|
||||||
const CollapsibleTrigger = CollapsiblePrimitive.Trigger
|
const CollapsibleTrigger = CollapsiblePrimitive.Trigger;
|
||||||
const CollapsibleContent = CollapsiblePrimitive.Content
|
const CollapsibleContent = CollapsiblePrimitive.Content;
|
||||||
|
|
||||||
// ─── Types ────────────────────────────────────────────────────────────────────
|
// ─── Types ────────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
export type FormInputType =
|
export type FormInputType =
|
||||||
| 'text'
|
| "text"
|
||||||
| 'number'
|
| "number"
|
||||||
| 'phone'
|
| "phone"
|
||||||
| 'email'
|
| "email"
|
||||||
| 'password'
|
| "password"
|
||||||
| 'date'
|
| "date"
|
||||||
| 'select'
|
| "select"
|
||||||
| 'searchable-select'
|
| "searchable-select"
|
||||||
| 'file'
|
| "file"
|
||||||
| 'textarea'
|
| "textarea";
|
||||||
|
|
||||||
export interface SelectOption {
|
export interface SelectOption {
|
||||||
value: string
|
value: string;
|
||||||
label: string
|
label: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface FormInputProps {
|
export interface FormInputProps {
|
||||||
type?: FormInputType
|
type?: FormInputType;
|
||||||
label?: string
|
label?: string;
|
||||||
value?: string
|
value?: string;
|
||||||
onChange?: (value: string) => void
|
onChange?: (value: string) => void;
|
||||||
placeholder?: string
|
placeholder?: string;
|
||||||
error?: string
|
error?: string;
|
||||||
required?: boolean
|
required?: boolean;
|
||||||
disabled?: boolean
|
disabled?: boolean;
|
||||||
options?: SelectOption[]
|
options?: SelectOption[];
|
||||||
accept?: string
|
accept?: string;
|
||||||
onFileChange?: (file: File | null) => void
|
onFileChange?: (file: File | null) => void;
|
||||||
fileValue?: File | null
|
fileValue?: File | null;
|
||||||
className?: string
|
className?: string;
|
||||||
phonePrefix?: string
|
phonePrefix?: string;
|
||||||
rows?: number
|
rows?: number;
|
||||||
name?: string
|
name?: string;
|
||||||
readOnly?: boolean
|
readOnly?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ─── FieldLabel ───────────────────────────────────────────────────────────────
|
// ─── FieldLabel ───────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
function FieldLabel({ label, required }: { label?: string; required?: boolean }) {
|
function FieldLabel({ label, required }: { label?: string; required?: boolean }) {
|
||||||
if (!label) return null
|
if (!label) return null;
|
||||||
return (
|
return (
|
||||||
<label className="block text-xs font-semibold text-muted-foreground uppercase tracking-wider mb-1.5 select-none">
|
<label className="block text-xs font-semibold text-muted-foreground uppercase tracking-wider mb-1.5 select-none">
|
||||||
{label}
|
{label}
|
||||||
{required && <span className="text-destructive ml-0.5">*</span>}
|
{required && <span className="text-destructive ml-0.5">*</span>}
|
||||||
</label>
|
</label>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ─── ErrorMsg ─────────────────────────────────────────────────────────────────
|
// ─── ErrorMsg ─────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
function ErrorMsg({ error }: { error?: string }) {
|
function ErrorMsg({ error }: { error?: string }) {
|
||||||
if (!error) return null
|
if (!error) return null;
|
||||||
return (
|
return (
|
||||||
<p className="mt-1.5 text-xs text-destructive font-medium flex items-center gap-1.5">
|
<p className="mt-1.5 text-xs text-destructive font-medium flex items-center gap-1.5">
|
||||||
<span className="inline-block w-1 h-1 rounded-full bg-destructive shrink-0" />
|
<span className="inline-block w-1 h-1 rounded-full bg-destructive shrink-0" />
|
||||||
{error}
|
{error}
|
||||||
</p>
|
</p>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ─── error border helper ──────────────────────────────────────────────────────
|
// ─── error border helper ──────────────────────────────────────────────────────
|
||||||
|
|
||||||
const withError = (error?: string) =>
|
const withError = (error?: string) => (error ? "border-destructive focus-visible:ring-destructive/30" : "");
|
||||||
error ? 'border-destructive focus-visible:ring-destructive/30' : ''
|
|
||||||
|
|
||||||
// ─── TextInput ────────────────────────────────────────────────────────────────
|
// ─── TextInput ────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
function TextInput({
|
function TextInput({
|
||||||
type = 'text',
|
type = "text",
|
||||||
value = '',
|
value = "",
|
||||||
onChange,
|
onChange,
|
||||||
placeholder,
|
placeholder,
|
||||||
error,
|
error,
|
||||||
@@ -101,11 +100,11 @@ function TextInput({
|
|||||||
readOnly,
|
readOnly,
|
||||||
rows = 3,
|
rows = 3,
|
||||||
}: FormInputProps) {
|
}: FormInputProps) {
|
||||||
const [showPass, setShowPass] = useState(false)
|
const [showPass, setShowPass] = useState(false);
|
||||||
|
|
||||||
const isPassword = type === 'password'
|
const isPassword = type === "password";
|
||||||
const isTextarea = type === 'textarea'
|
const isTextarea = type === "textarea";
|
||||||
const isNumber = type === 'number'
|
const isNumber = type === "number";
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={className}>
|
<div className={className}>
|
||||||
@@ -121,35 +120,26 @@ function TextInput({
|
|||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
readOnly={readOnly}
|
readOnly={readOnly}
|
||||||
rows={rows}
|
rows={rows}
|
||||||
className={cn('resize-none', withError(error))}
|
className={cn("resize-none", withError(error))}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<Input
|
<Input
|
||||||
name={name}
|
name={name}
|
||||||
type={
|
type={isPassword ? (showPass ? "text" : "password") : isNumber ? "number" : type === "email" ? "email" : "text"}
|
||||||
isPassword ? (showPass ? 'text' : 'password')
|
|
||||||
: isNumber ? 'number'
|
|
||||||
: type === 'email' ? 'email'
|
|
||||||
: 'text'
|
|
||||||
}
|
|
||||||
min={isNumber ? 0 : undefined}
|
min={isNumber ? 0 : undefined}
|
||||||
value={value}
|
value={value}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
if (isNumber) {
|
if (isNumber) {
|
||||||
const num = e.target.value
|
const num = e.target.value;
|
||||||
if (num === '' || Number(num) >= 0) onChange?.(num)
|
if (num === "" || Number(num) >= 0) onChange?.(num);
|
||||||
} else {
|
} else {
|
||||||
onChange?.(e.target.value)
|
onChange?.(e.target.value);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
placeholder={placeholder}
|
placeholder={placeholder}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
readOnly={readOnly}
|
readOnly={readOnly}
|
||||||
className={cn(
|
className={cn(isPassword && "pr-10", isNumber && "pr-10", withError(error))}
|
||||||
isPassword && 'pr-10',
|
|
||||||
isNumber && 'pr-10',
|
|
||||||
withError(error),
|
|
||||||
)}
|
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
@@ -164,43 +154,48 @@ function TextInput({
|
|||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{isNumber && (
|
{isNumber && <Hash size={14} className="absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground pointer-events-none" />}
|
||||||
<Hash
|
|
||||||
size={14}
|
|
||||||
className="absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground pointer-events-none"
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<ErrorMsg error={error} />
|
<ErrorMsg error={error} />
|
||||||
</div>
|
</div>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ─── PhoneInput ───────────────────────────────────────────────────────────────
|
// ─── PhoneInput ───────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
function PhoneInput({
|
function PhoneInput({
|
||||||
value = '',
|
value = "",
|
||||||
onChange,
|
onChange,
|
||||||
placeholder = '61 111213',
|
placeholder = "61 097651",
|
||||||
error,
|
error,
|
||||||
disabled,
|
disabled,
|
||||||
required,
|
required,
|
||||||
label,
|
label,
|
||||||
className,
|
className,
|
||||||
phonePrefix = '+993',
|
phonePrefix = "+993",
|
||||||
}: FormInputProps) {
|
}: FormInputProps) {
|
||||||
|
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
|
const digits = e.target.value.replace(/\D/g, "").slice(0, 8);
|
||||||
|
|
||||||
|
if (digits.length <= 2) {
|
||||||
|
onChange?.(digits);
|
||||||
|
} else {
|
||||||
|
onChange?.(`${digits.slice(0, 2)} ${digits.slice(2)}`);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={className}>
|
<div className={className}>
|
||||||
<FieldLabel label={label} required={required} />
|
<FieldLabel label={label} required={required} />
|
||||||
|
|
||||||
<div
|
<div
|
||||||
className={cn(
|
className={cn(
|
||||||
'flex h-8 w-full rounded-md border bg-background overflow-hidden',
|
"flex h-8 w-full rounded-md border bg-background overflow-hidden",
|
||||||
'ring-offset-background transition-colors duration-150',
|
"ring-offset-background transition-colors duration-150",
|
||||||
'focus-within:outline-none focus-within:ring-1 focus-within:ring-ring focus-within:ring-offset-0',
|
"focus-within:outline-none focus-within:ring-1 focus-within:ring-ring focus-within:ring-offset-0",
|
||||||
error ? 'border-destructive focus-within:ring-destructive/30' : 'border-input',
|
error ? "border-destructive focus-within:ring-destructive/30" : "border-input",
|
||||||
disabled && 'opacity-50 cursor-not-allowed',
|
disabled && "opacity-50 cursor-not-allowed",
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<div className="flex items-center px-3 bg-muted/50 border-r border-input text-sm font-medium text-muted-foreground shrink-0 select-none">
|
<div className="flex items-center px-3 bg-muted/50 border-r border-input text-sm font-medium text-muted-foreground shrink-0 select-none">
|
||||||
@@ -209,7 +204,7 @@ function PhoneInput({
|
|||||||
<input
|
<input
|
||||||
type="tel"
|
type="tel"
|
||||||
value={value}
|
value={value}
|
||||||
onChange={(e) => onChange?.(e.target.value.replace(/[^\d\s-]/g, ''))}
|
onChange={handleChange}
|
||||||
placeholder={placeholder}
|
placeholder={placeholder}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
className="flex-1 h-full px-3 bg-transparent text-sm text-foreground placeholder:text-muted-foreground/50 focus:outline-none disabled:cursor-not-allowed"
|
className="flex-1 h-full px-3 bg-transparent text-sm text-foreground placeholder:text-muted-foreground/50 focus:outline-none disabled:cursor-not-allowed"
|
||||||
@@ -218,31 +213,22 @@ function PhoneInput({
|
|||||||
|
|
||||||
<ErrorMsg error={error} />
|
<ErrorMsg error={error} />
|
||||||
</div>
|
</div>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ─── DateInput (shadcn Popover + Calendar) ───────────────────────────────────
|
// ─── DateInput (shadcn Popover + Calendar) ───────────────────────────────────
|
||||||
|
|
||||||
function DateInput({
|
function DateInput({ value = "", onChange, error, disabled, required, label, className, placeholder = "Sene saýlaň" }: FormInputProps) {
|
||||||
value = '',
|
const [open, setOpen] = useState(false);
|
||||||
onChange,
|
|
||||||
error,
|
|
||||||
disabled,
|
|
||||||
required,
|
|
||||||
label,
|
|
||||||
className,
|
|
||||||
placeholder = 'Sene saýlaň',
|
|
||||||
}: FormInputProps) {
|
|
||||||
const [open, setOpen] = useState(false)
|
|
||||||
|
|
||||||
// value is stored as 'yyyy-MM-dd' string
|
// value is stored as 'yyyy-MM-dd' string
|
||||||
const parsed = value ? parse(value, 'yyyy-MM-dd', new Date()) : undefined
|
const parsed = value ? parse(value, "yyyy-MM-dd", new Date()) : undefined;
|
||||||
const selected = parsed && isValid(parsed) ? parsed : undefined
|
const selected = parsed && isValid(parsed) ? parsed : undefined;
|
||||||
|
|
||||||
const handleSelect = (day: Date | undefined) => {
|
const handleSelect = (day: Date | undefined) => {
|
||||||
onChange?.(day ? format(day, 'yyyy-MM-dd') : '')
|
onChange?.(day ? format(day, "yyyy-MM-dd") : "");
|
||||||
setOpen(false)
|
setOpen(false);
|
||||||
}
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={className}>
|
<div className={className}>
|
||||||
@@ -254,15 +240,15 @@ function DateInput({
|
|||||||
type="button"
|
type="button"
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
className={cn(
|
className={cn(
|
||||||
'flex h-8 w-full items-center justify-between rounded-md border bg-background px-3 py-2',
|
"flex h-8 w-full items-center justify-between rounded-md border bg-background px-3 py-2",
|
||||||
'text-sm ring-offset-background transition-colors duration-150',
|
"text-sm ring-offset-background transition-colors duration-150",
|
||||||
'focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-0',
|
"focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-0",
|
||||||
'disabled:cursor-not-allowed disabled:opacity-50',
|
"disabled:cursor-not-allowed disabled:opacity-50",
|
||||||
error ? 'border-destructive' : 'border-input',
|
error ? "border-destructive" : "border-input",
|
||||||
!selected && 'text-muted-foreground/60',
|
!selected && "text-muted-foreground/60",
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<span>{selected ? format(selected, 'dd.MM.yyyy') : placeholder}</span>
|
<span>{selected ? format(selected, "dd.MM.yyyy") : placeholder}</span>
|
||||||
<CalendarIcon size={15} className="text-muted-foreground shrink-0" />
|
<CalendarIcon size={15} className="text-muted-foreground shrink-0" />
|
||||||
</button>
|
</button>
|
||||||
</PopoverTrigger>
|
</PopoverTrigger>
|
||||||
@@ -282,42 +268,39 @@ function DateInput({
|
|||||||
|
|
||||||
<ErrorMsg error={error} />
|
<ErrorMsg error={error} />
|
||||||
</div>
|
</div>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ─── SelectInput ──────────────────────────────────────────────────────────────
|
// ─── SelectInput ──────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
// ─── SelectInput ──────────────────────────────────────────────────────────────
|
|
||||||
// Artık Collapsible tabanlı — SearchableSelect ile aynı mekanizma
|
|
||||||
|
|
||||||
function SelectInput({
|
function SelectInput({
|
||||||
value = '',
|
value = "",
|
||||||
onChange,
|
onChange,
|
||||||
options = [],
|
options = [],
|
||||||
placeholder = '—',
|
placeholder = "—",
|
||||||
error,
|
error,
|
||||||
disabled,
|
disabled,
|
||||||
required,
|
required,
|
||||||
label,
|
label,
|
||||||
className,
|
className,
|
||||||
}: FormInputProps) {
|
}: FormInputProps) {
|
||||||
const [open, setOpen] = useState(false)
|
const [open, setOpen] = useState(false);
|
||||||
|
|
||||||
const selected = options.find((o) => o.value === value)
|
const selected = options.find((o) => o.value === value);
|
||||||
|
|
||||||
const handleSelect = (val: string) => {
|
const handleSelect = (val: string) => {
|
||||||
onChange?.(val)
|
onChange?.(val);
|
||||||
setOpen(false)
|
setOpen(false);
|
||||||
}
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={cn('relative', className)}>
|
<div className={cn("relative", className)}>
|
||||||
<FieldLabel label={label} required={required} />
|
<FieldLabel label={label} required={required} />
|
||||||
|
|
||||||
<Collapsible
|
<Collapsible
|
||||||
open={open}
|
open={open}
|
||||||
onOpenChange={(next) => {
|
onOpenChange={(next) => {
|
||||||
if (!disabled) setOpen(next)
|
if (!disabled) setOpen(next);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<CollapsibleTrigger asChild>
|
<CollapsibleTrigger asChild>
|
||||||
@@ -325,23 +308,20 @@ function SelectInput({
|
|||||||
type="button"
|
type="button"
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
className={cn(
|
className={cn(
|
||||||
'flex h-8 w-full items-center justify-between rounded-md border bg-background px-3 py-2',
|
"flex h-8 w-full items-center justify-between rounded-md border bg-background px-3 py-2",
|
||||||
'text-sm ring-offset-background transition-colors duration-150',
|
"text-sm ring-offset-background transition-colors duration-150",
|
||||||
'focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-0',
|
"focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-0",
|
||||||
'disabled:cursor-not-allowed disabled:opacity-50',
|
"disabled:cursor-not-allowed disabled:opacity-50",
|
||||||
error ? 'border-destructive' : 'border-input',
|
error ? "border-destructive" : "border-input",
|
||||||
open && !error && 'ring-2 ring-ring ring-offset-0 border-transparent',
|
open && !error && "ring-2 ring-ring ring-offset-0 border-transparent",
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<span className={cn('truncate text-left', !selected && 'text-muted-foreground/60')}>
|
<span className={cn("truncate text-left", !selected && "text-muted-foreground/60")}>
|
||||||
{selected ? selected.label : placeholder}
|
{selected ? selected.label : placeholder}
|
||||||
</span>
|
</span>
|
||||||
<ChevronsUpDown
|
<ChevronsUpDown
|
||||||
size={14}
|
size={14}
|
||||||
className={cn(
|
className={cn("text-muted-foreground transition-transform duration-200 shrink-0", open && "text-foreground")}
|
||||||
'text-muted-foreground transition-transform duration-200 shrink-0',
|
|
||||||
open && 'text-foreground',
|
|
||||||
)}
|
|
||||||
/>
|
/>
|
||||||
</button>
|
</button>
|
||||||
</CollapsibleTrigger>
|
</CollapsibleTrigger>
|
||||||
@@ -349,22 +329,25 @@ function SelectInput({
|
|||||||
<CollapsibleContent className="mt-1 rounded-md border border-border bg-card shadow-lg overflow-hidden">
|
<CollapsibleContent className="mt-1 rounded-md border border-border bg-card shadow-lg overflow-hidden">
|
||||||
<div className="max-h-52 overflow-y-auto py-1">
|
<div className="max-h-52 overflow-y-auto py-1">
|
||||||
{options.map((opt) => {
|
{options.map((opt) => {
|
||||||
const isSelected = opt.value === value
|
const isSelected = opt.value === value;
|
||||||
return (
|
return (
|
||||||
<button
|
<button
|
||||||
key={opt.value}
|
key={opt.value}
|
||||||
type="button"
|
type="button"
|
||||||
onMouseDown={(e) => { e.preventDefault(); handleSelect(opt.value) }}
|
onMouseDown={(e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
handleSelect(opt.value);
|
||||||
|
}}
|
||||||
className={cn(
|
className={cn(
|
||||||
'flex items-center justify-between w-full text-left px-3 py-2 text-sm transition-colors',
|
"flex items-center justify-between w-full text-left px-3 py-2 text-sm transition-colors",
|
||||||
'hover:bg-accent hover:text-accent-foreground',
|
"hover:bg-accent hover:text-accent-foreground",
|
||||||
isSelected && 'text-primary font-medium bg-primary/10',
|
isSelected && "text-primary font-medium bg-primary/10",
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<span>{opt.label}</span>
|
<span>{opt.label}</span>
|
||||||
{isSelected && <Check size={13} className="text-primary shrink-0" />}
|
{isSelected && <Check size={13} className="text-primary shrink-0" />}
|
||||||
</button>
|
</button>
|
||||||
)
|
);
|
||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
</CollapsibleContent>
|
</CollapsibleContent>
|
||||||
@@ -372,7 +355,7 @@ function SelectInput({
|
|||||||
|
|
||||||
<ErrorMsg error={error} />
|
<ErrorMsg error={error} />
|
||||||
</div>
|
</div>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ─── SearchableSelect ─────────────────────────────────────────────────────────
|
// ─── SearchableSelect ─────────────────────────────────────────────────────────
|
||||||
@@ -381,67 +364,76 @@ function SelectInput({
|
|||||||
// firing before the selection is registered.
|
// firing before the selection is registered.
|
||||||
|
|
||||||
function SearchableSelect({
|
function SearchableSelect({
|
||||||
value = '',
|
value = "",
|
||||||
onChange,
|
onChange,
|
||||||
options = [],
|
options = [],
|
||||||
placeholder = 'Saýlamak üçin basyň',
|
placeholder = "Saýlamak üçin basyň",
|
||||||
error,
|
error,
|
||||||
disabled,
|
disabled,
|
||||||
required,
|
required,
|
||||||
label,
|
label,
|
||||||
className,
|
className,
|
||||||
}: FormInputProps) {
|
}: FormInputProps) {
|
||||||
const [open, setOpen] = useState(false)
|
const [open, setOpen] = useState(false);
|
||||||
const [query, setQuery] = useState('')
|
const [query, setQuery] = useState("");
|
||||||
const searchRef = useRef<HTMLInputElement>(null)
|
const searchRef = useRef<HTMLInputElement>(null);
|
||||||
|
|
||||||
const selected = options.find((o) => o.value === value)
|
const selected = options.find((o) => o.value === value);
|
||||||
const filtered = query.trim()
|
const filtered = query.trim() ? options.filter((o) => o.label.toLowerCase().includes(query.toLowerCase())) : options;
|
||||||
? options.filter((o) => o.label.toLowerCase().includes(query.toLowerCase()))
|
|
||||||
: options
|
|
||||||
|
|
||||||
const openDropdown = () => {
|
const openDropdown = () => {
|
||||||
setOpen(true)
|
setOpen(true);
|
||||||
// Focus search after Collapsible animation frame
|
// Focus search after Collapsible animation frame
|
||||||
requestAnimationFrame(() => searchRef.current?.focus())
|
requestAnimationFrame(() => searchRef.current?.focus());
|
||||||
}
|
};
|
||||||
|
|
||||||
const closeDropdown = () => {
|
const closeDropdown = () => {
|
||||||
setOpen(false)
|
setOpen(false);
|
||||||
setQuery('')
|
setQuery("");
|
||||||
}
|
};
|
||||||
|
|
||||||
const handleSelect = (val: string) => {
|
const handleSelect = (val: string) => {
|
||||||
onChange?.(val)
|
onChange?.(val);
|
||||||
closeDropdown()
|
closeDropdown();
|
||||||
}
|
};
|
||||||
|
|
||||||
const handleClear = (e: React.MouseEvent) => {
|
const handleClear = (e: React.MouseEvent) => {
|
||||||
e.preventDefault()
|
e.preventDefault();
|
||||||
e.stopPropagation()
|
e.stopPropagation();
|
||||||
onChange?.('')
|
onChange?.("");
|
||||||
}
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={cn('relative', className)}>
|
<div className={cn("relative", className)}>
|
||||||
<FieldLabel label={label} required={required} />
|
<FieldLabel label={label} required={required} />
|
||||||
|
|
||||||
<Collapsible open={open} onOpenChange={(next) => { if (!disabled) { if (next) { openDropdown() } else { closeDropdown() } } }}>
|
<Collapsible
|
||||||
|
open={open}
|
||||||
|
onOpenChange={(next) => {
|
||||||
|
if (!disabled) {
|
||||||
|
if (next) {
|
||||||
|
openDropdown();
|
||||||
|
} else {
|
||||||
|
closeDropdown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
{/* Trigger */}
|
{/* Trigger */}
|
||||||
<CollapsibleTrigger asChild>
|
<CollapsibleTrigger asChild>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
className={cn(
|
className={cn(
|
||||||
'flex h-8 w-full items-center justify-between rounded-md border bg-background px-3 py-2',
|
"flex h-8 w-full items-center justify-between rounded-md border bg-background px-3 py-2",
|
||||||
'text-sm ring-offset-background transition-colors duration-150',
|
"text-sm ring-offset-background transition-colors duration-150",
|
||||||
'focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-0',
|
"focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-0",
|
||||||
'disabled:cursor-not-allowed disabled:opacity-50',
|
"disabled:cursor-not-allowed disabled:opacity-50",
|
||||||
error ? 'border-destructive' : 'border-input',
|
error ? "border-destructive" : "border-input",
|
||||||
open && !error && 'ring-2 ring-ring ring-offset-0 border-transparent',
|
open && !error && "ring-2 ring-ring ring-offset-0 border-transparent",
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<span className={cn('truncate text-left', !selected && 'text-muted-foreground/60')}>
|
<span className={cn("truncate text-left", !selected && "text-muted-foreground/60")}>
|
||||||
{selected ? selected.label : placeholder}
|
{selected ? selected.label : placeholder}
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
@@ -458,10 +450,7 @@ function SearchableSelect({
|
|||||||
)}
|
)}
|
||||||
<ChevronsUpDown
|
<ChevronsUpDown
|
||||||
size={14}
|
size={14}
|
||||||
className={cn(
|
className={cn("text-muted-foreground transition-transform duration-200 shrink-0", open && "text-foreground")}
|
||||||
'text-muted-foreground transition-transform duration-200 shrink-0',
|
|
||||||
open && 'text-foreground',
|
|
||||||
)}
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</button>
|
</button>
|
||||||
@@ -484,7 +473,7 @@ function SearchableSelect({
|
|||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
tabIndex={-1}
|
tabIndex={-1}
|
||||||
onMouseDown={() => setQuery('')}
|
onMouseDown={() => setQuery("")}
|
||||||
className="text-muted-foreground hover:text-foreground transition-colors"
|
className="text-muted-foreground hover:text-foreground transition-colors"
|
||||||
>
|
>
|
||||||
<X size={12} />
|
<X size={12} />
|
||||||
@@ -495,27 +484,28 @@ function SearchableSelect({
|
|||||||
{/* Options */}
|
{/* Options */}
|
||||||
<div className="max-h-52 overflow-y-auto py-1">
|
<div className="max-h-52 overflow-y-auto py-1">
|
||||||
{filtered.length === 0 ? (
|
{filtered.length === 0 ? (
|
||||||
<p className="px-3 py-4 text-sm text-muted-foreground text-center">
|
<p className="px-3 py-4 text-sm text-muted-foreground text-center">Netije tapylmady</p>
|
||||||
Netije tapylmady
|
|
||||||
</p>
|
|
||||||
) : (
|
) : (
|
||||||
filtered.map((opt) => {
|
filtered.map((opt) => {
|
||||||
const isSelected = opt.value === value
|
const isSelected = opt.value === value;
|
||||||
return (
|
return (
|
||||||
<button
|
<button
|
||||||
key={opt.value}
|
key={opt.value}
|
||||||
type="button"
|
type="button"
|
||||||
onMouseDown={(e) => { e.preventDefault(); handleSelect(opt.value) }}
|
onMouseDown={(e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
handleSelect(opt.value);
|
||||||
|
}}
|
||||||
className={cn(
|
className={cn(
|
||||||
'flex items-center justify-between w-full text-left px-3 py-2 text-sm transition-colors',
|
"flex items-center justify-between w-full text-left px-3 py-2 text-sm transition-colors",
|
||||||
'hover:bg-accent hover:text-accent-foreground',
|
"hover:bg-accent hover:text-accent-foreground",
|
||||||
isSelected && 'text-primary font-medium bg-primary/10',
|
isSelected && "text-primary font-medium bg-primary/10",
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<span>{opt.label}</span>
|
<span>{opt.label}</span>
|
||||||
{isSelected && <Check size={13} className="text-primary shrink-0" />}
|
{isSelected && <Check size={13} className="text-primary shrink-0" />}
|
||||||
</button>
|
</button>
|
||||||
)
|
);
|
||||||
})
|
})
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
@@ -524,50 +514,56 @@ function SearchableSelect({
|
|||||||
|
|
||||||
<ErrorMsg error={error} />
|
<ErrorMsg error={error} />
|
||||||
</div>
|
</div>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ─── FileInput ────────────────────────────────────────────────────────────────
|
// ─── FileInput ────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
// ─── FileInput ────────────────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
function FileInput({
|
function FileInput({
|
||||||
label,
|
label,
|
||||||
required,
|
required,
|
||||||
error,
|
error,
|
||||||
disabled,
|
disabled,
|
||||||
accept = 'image/*',
|
accept = "image/*",
|
||||||
onFileChange,
|
onFileChange,
|
||||||
fileValue,
|
fileValue,
|
||||||
className,
|
className,
|
||||||
placeholder = 'Faýl saýlaň ýa-da salmak üçin basyň',
|
placeholder = "Faýl saýlaň ýa-da salmak üçin basyň",
|
||||||
}: FormInputProps) {
|
}: FormInputProps) {
|
||||||
const inputRef = useRef<HTMLInputElement>(null)
|
const inputRef = useRef<HTMLInputElement>(null);
|
||||||
const [dragOver, setDragOver] = useState(false)
|
const [dragOver, setDragOver] = useState(false);
|
||||||
const [preview, setPreview] = useState<string | null>(null)
|
const [preview, setPreview] = useState<string | null>(null);
|
||||||
|
|
||||||
// fileValue prop'u değişince preview'i güncelle + memory leak önle
|
// fileValue prop'u değişince preview'i güncelle + memory leak önle
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (fileValue?.type.startsWith('image/')) {
|
let url: string | null = null;
|
||||||
const url = URL.createObjectURL(fileValue)
|
let timer: ReturnType<typeof setTimeout>;
|
||||||
setPreview(url)
|
|
||||||
return () => URL.revokeObjectURL(url)
|
if (fileValue?.type.startsWith("image/")) {
|
||||||
|
url = URL.createObjectURL(fileValue);
|
||||||
|
timer = setTimeout(() => setPreview(url!), 0);
|
||||||
|
} else {
|
||||||
|
timer = setTimeout(() => setPreview(null), 0);
|
||||||
}
|
}
|
||||||
setPreview(null)
|
|
||||||
}, [fileValue])
|
return () => {
|
||||||
|
if (timer) clearTimeout(timer);
|
||||||
|
if (url) URL.revokeObjectURL(url);
|
||||||
|
};
|
||||||
|
}, [fileValue]);
|
||||||
|
|
||||||
// handleFile sadece onFileChange'i çağırıyor — preview useEffect hallediyor
|
// handleFile sadece onFileChange'i çağırıyor — preview useEffect hallediyor
|
||||||
const handleFile = (file: File | null) => {
|
const handleFile = (file: File | null) => {
|
||||||
onFileChange?.(file)
|
onFileChange?.(file);
|
||||||
}
|
};
|
||||||
|
|
||||||
const handleDrop = (e: React.DragEvent) => {
|
const handleDrop = (e: React.DragEvent) => {
|
||||||
e.preventDefault()
|
e.preventDefault();
|
||||||
setDragOver(false)
|
setDragOver(false);
|
||||||
handleFile(e.dataTransfer.files[0] ?? null)
|
handleFile(e.dataTransfer.files[0] ?? null);
|
||||||
}
|
};
|
||||||
|
|
||||||
const isImage = fileValue?.type.startsWith('image/')
|
const isImage = fileValue?.type.startsWith("image/");
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={className}>
|
<div className={className}>
|
||||||
@@ -577,38 +573,38 @@ function FileInput({
|
|||||||
role="button"
|
role="button"
|
||||||
tabIndex={disabled ? -1 : 0}
|
tabIndex={disabled ? -1 : 0}
|
||||||
onClick={() => !disabled && inputRef.current?.click()}
|
onClick={() => !disabled && inputRef.current?.click()}
|
||||||
onKeyDown={(e) => e.key === 'Enter' && !disabled && inputRef.current?.click()}
|
onKeyDown={(e) => e.key === "Enter" && !disabled && inputRef.current?.click()}
|
||||||
onDragOver={(e) => { e.preventDefault(); setDragOver(true) }}
|
onDragOver={(e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
setDragOver(true);
|
||||||
|
}}
|
||||||
onDragLeave={() => setDragOver(false)}
|
onDragLeave={() => setDragOver(false)}
|
||||||
onDrop={handleDrop}
|
onDrop={handleDrop}
|
||||||
className={cn(
|
className={cn(
|
||||||
'relative flex flex-col items-center justify-center',
|
"relative flex flex-col items-center justify-center",
|
||||||
'min-h-[88px] rounded-md border-2 border-dashed cursor-pointer select-none',
|
"min-h-[88px] rounded-md border-2 border-dashed cursor-pointer select-none",
|
||||||
'transition-all duration-200',
|
"transition-all duration-200",
|
||||||
'focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-2',
|
"focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-2",
|
||||||
dragOver && 'border-primary bg-primary/5 scale-[1.01]',
|
dragOver && "border-primary bg-primary/5 scale-[1.01]",
|
||||||
error ? 'border-destructive/60' : 'border-border',
|
error ? "border-destructive/60" : "border-border",
|
||||||
!dragOver && !error && 'hover:border-primary/50 hover:bg-muted/20',
|
!dragOver && !error && "hover:border-primary/50 hover:bg-muted/20",
|
||||||
disabled && 'opacity-50 cursor-not-allowed pointer-events-none',
|
disabled && "opacity-50 cursor-not-allowed pointer-events-none",
|
||||||
fileValue && isImage && '!border-solid !border-border overflow-hidden',
|
fileValue && isImage && "!border-solid !border-border overflow-hidden",
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{fileValue && isImage && preview ? (
|
{fileValue && isImage && preview ? (
|
||||||
<>
|
<>
|
||||||
<img
|
<img src={preview} alt="preview" className="w-full max-h-56 object-contain bg-muted/30 p-2" />
|
||||||
src={preview}
|
|
||||||
alt="preview"
|
|
||||||
className="w-full max-h-56 object-contain bg-muted/30 p-2"
|
|
||||||
/>
|
|
||||||
<div className="w-full flex items-center justify-between px-3 py-2 bg-muted/40 border-t border-border">
|
<div className="w-full flex items-center justify-between px-3 py-2 bg-muted/40 border-t border-border">
|
||||||
<span className="text-xs text-muted-foreground truncate max-w-[200px]">
|
<span className="text-xs text-muted-foreground truncate max-w-[200px]">{fileValue.name}</span>
|
||||||
{fileValue.name}
|
|
||||||
</span>
|
|
||||||
<Button
|
<Button
|
||||||
type="button"
|
type="button"
|
||||||
size="icon"
|
size="icon"
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
onClick={(e) => { e.stopPropagation(); handleFile(null) }}
|
onClick={(e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
handleFile(null);
|
||||||
|
}}
|
||||||
className="h-6 w-6 shrink-0 text-destructive hover:text-destructive hover:bg-destructive/10"
|
className="h-6 w-6 shrink-0 text-destructive hover:text-destructive hover:bg-destructive/10"
|
||||||
>
|
>
|
||||||
<X size={13} />
|
<X size={13} />
|
||||||
@@ -620,12 +616,13 @@ function FileInput({
|
|||||||
<div className="w-8 h-8 rounded-md bg-primary/10 flex items-center justify-center">
|
<div className="w-8 h-8 rounded-md bg-primary/10 flex items-center justify-center">
|
||||||
<Upload size={14} className="text-primary" />
|
<Upload size={14} className="text-primary" />
|
||||||
</div>
|
</div>
|
||||||
<p className="text-xs font-medium text-foreground text-center truncate max-w-[180px]">
|
<p className="text-xs font-medium text-foreground text-center truncate max-w-[180px]">{fileValue.name}</p>
|
||||||
{fileValue.name}
|
|
||||||
</p>
|
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={(e) => { e.stopPropagation(); handleFile(null) }}
|
onClick={(e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
handleFile(null);
|
||||||
|
}}
|
||||||
className="text-xs text-destructive hover:text-destructive/80 transition-colors"
|
className="text-xs text-destructive hover:text-destructive/80 transition-colors"
|
||||||
>
|
>
|
||||||
Aýyr
|
Aýyr
|
||||||
@@ -636,9 +633,7 @@ function FileInput({
|
|||||||
<div className="w-8 h-8 rounded-md bg-muted flex items-center justify-center">
|
<div className="w-8 h-8 rounded-md bg-muted flex items-center justify-center">
|
||||||
<Upload size={14} className="text-muted-foreground" />
|
<Upload size={14} className="text-muted-foreground" />
|
||||||
</div>
|
</div>
|
||||||
<p className="text-xs text-muted-foreground text-center leading-relaxed">
|
<p className="text-xs text-muted-foreground text-center leading-relaxed">{placeholder}</p>
|
||||||
{placeholder}
|
|
||||||
</p>
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
@@ -654,20 +649,19 @@ function FileInput({
|
|||||||
|
|
||||||
<ErrorMsg error={error} />
|
<ErrorMsg error={error} />
|
||||||
</div>
|
</div>
|
||||||
)
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ─── FormInput (router) ───────────────────────────────────────────────────────
|
// ─── FormInput (router) ───────────────────────────────────────────────────────
|
||||||
|
|
||||||
export function FormInput(props: FormInputProps) {
|
export function FormInput(props: FormInputProps) {
|
||||||
const { type = 'text' } = props
|
const { type = "text" } = props;
|
||||||
|
|
||||||
if (type === 'phone') return <PhoneInput {...props} />
|
if (type === "phone") return <PhoneInput {...props} />;
|
||||||
if (type === 'date') return <DateInput {...props} />
|
if (type === "date") return <DateInput {...props} />;
|
||||||
if (type === 'select') return <SelectInput {...props} />
|
if (type === "select") return <SelectInput {...props} />;
|
||||||
if (type === 'searchable-select') return <SearchableSelect {...props} />
|
if (type === "searchable-select") return <SearchableSelect {...props} />;
|
||||||
if (type === 'file') return <FileInput {...props} />
|
if (type === "file") return <FileInput {...props} />;
|
||||||
if (type === 'textarea') return <TextInput {...props} type="textarea" />
|
if (type === "textarea") return <TextInput {...props} type="textarea" />;
|
||||||
return <TextInput {...props} />
|
return <TextInput {...props} />;
|
||||||
}
|
}
|
||||||
+138
-86
@@ -1,9 +1,5 @@
|
|||||||
import {
|
import { useRef, useEffect } from "react";
|
||||||
type LucideIcon,
|
import { type LucideIcon, ChevronRight, Check, AlertTriangle } from "lucide-react";
|
||||||
ChevronRight,
|
|
||||||
Check,
|
|
||||||
AlertTriangle,
|
|
||||||
} from "lucide-react";
|
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import type { StepStatus } from "./stepBar";
|
import type { StepStatus } from "./stepBar";
|
||||||
|
|
||||||
@@ -21,95 +17,151 @@ interface StepBarCardsProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function StepBarCards({ steps, onGoTo }: StepBarCardsProps) {
|
export function StepBarCards({ steps, onGoTo }: StepBarCardsProps) {
|
||||||
return (
|
const wrapRef = useRef<HTMLDivElement>(null);
|
||||||
<nav
|
const isDragging = useRef(false);
|
||||||
role="tablist"
|
const startX = useRef(0);
|
||||||
aria-label="Form adımları"
|
const scrollX = useRef(0);
|
||||||
className={cn(
|
const moved = useRef(false);
|
||||||
"flex items-center gap-2 overflow-x-auto",
|
|
||||||
"[&::-webkit-scrollbar]:hidden [-ms-overflow-style:none] [scrollbar-width:none]",
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
{steps.map((step, i) => {
|
|
||||||
const Icon = step.icon;
|
|
||||||
const isActive = step.status === "active";
|
|
||||||
const isDone = step.status === "done";
|
|
||||||
const isError = step.status === "error";
|
|
||||||
const isIdle = step.status === "idle";
|
|
||||||
const reachable = !isIdle || (i > 0 && steps[i - 1].status === "done");
|
|
||||||
|
|
||||||
return (
|
// Auto-scroll active step to center
|
||||||
<div key={step.id} className="flex items-center gap-2 shrink-0">
|
useEffect(() => {
|
||||||
<button
|
const wrap = wrapRef.current;
|
||||||
type="button"
|
if (!wrap) return;
|
||||||
role="tab"
|
const active = wrap.querySelector<HTMLElement>('[aria-current="step"]');
|
||||||
aria-selected={isActive}
|
if (!active) return;
|
||||||
aria-current={isActive ? "step" : undefined}
|
const wrapRect = wrap.getBoundingClientRect();
|
||||||
disabled={!reachable}
|
const btnRect = active.getBoundingClientRect();
|
||||||
onClick={() => reachable && onGoTo(i)}
|
wrap.scrollTo({
|
||||||
className={cn(
|
left: wrap.scrollLeft + (btnRect.left - wrapRect.left) - wrapRect.width / 2 + btnRect.width / 2,
|
||||||
"group flex items-center gap-3 rounded-lg px-3 py-2.5 transition-all duration-200",
|
behavior: "smooth",
|
||||||
"outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background",
|
});
|
||||||
"disabled:cursor-not-allowed disabled:opacity-40",
|
}, [steps]);
|
||||||
reachable && !isActive && "hover:bg-muted/40 cursor-pointer",
|
|
||||||
isActive && "bg-muted/60",
|
// Mouse drag-to-scroll
|
||||||
)}
|
useEffect(() => {
|
||||||
>
|
const wrap = wrapRef.current;
|
||||||
{/* Icon disc */}
|
if (!wrap) return;
|
||||||
<span
|
|
||||||
|
const onDown = (e: MouseEvent) => {
|
||||||
|
isDragging.current = true;
|
||||||
|
moved.current = false;
|
||||||
|
startX.current = e.pageX - wrap.offsetLeft;
|
||||||
|
scrollX.current = wrap.scrollLeft;
|
||||||
|
wrap.style.cursor = "grabbing";
|
||||||
|
};
|
||||||
|
|
||||||
|
const onUp = () => {
|
||||||
|
isDragging.current = false;
|
||||||
|
wrap.style.cursor = "grab";
|
||||||
|
};
|
||||||
|
|
||||||
|
const onMove = (e: MouseEvent) => {
|
||||||
|
if (!isDragging.current) return;
|
||||||
|
e.preventDefault();
|
||||||
|
const dist = e.pageX - wrap.offsetLeft - startX.current;
|
||||||
|
if (Math.abs(dist) > 4) moved.current = true;
|
||||||
|
wrap.scrollLeft = scrollX.current - dist;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Block click after a real drag so step navigation doesn't fire
|
||||||
|
const onClickCapture = (e: MouseEvent) => {
|
||||||
|
if (moved.current) {
|
||||||
|
e.stopPropagation();
|
||||||
|
moved.current = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
wrap.addEventListener("mousedown", onDown);
|
||||||
|
wrap.addEventListener("mouseup", onUp);
|
||||||
|
wrap.addEventListener("mouseleave", onUp);
|
||||||
|
wrap.addEventListener("mousemove", onMove);
|
||||||
|
wrap.addEventListener("click", onClickCapture, true);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
wrap.removeEventListener("mousedown", onDown);
|
||||||
|
wrap.removeEventListener("mouseup", onUp);
|
||||||
|
wrap.removeEventListener("mouseleave", onUp);
|
||||||
|
wrap.removeEventListener("mousemove", onMove);
|
||||||
|
wrap.removeEventListener("click", onClickCapture, true);
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
ref={wrapRef}
|
||||||
|
style={{ cursor: "grab" }}
|
||||||
|
className="overflow-x-auto [&::-webkit-scrollbar]:hidden [-ms-overflow-style:none] [scrollbar-width:none]"
|
||||||
|
>
|
||||||
|
<nav role="tablist" aria-label="Form adımları" className="flex items-center gap-2 w-max">
|
||||||
|
{steps.map((step, i) => {
|
||||||
|
const Icon = step.icon;
|
||||||
|
const isActive = step.status === "active";
|
||||||
|
const isDone = step.status === "done";
|
||||||
|
const isError = step.status === "error";
|
||||||
|
const isIdle = step.status === "idle";
|
||||||
|
const reachable = !isIdle || (i > 0 && steps[i - 1].status === "done");
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div key={step.id} className="flex items-center gap-2 shrink-0">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
role="tab"
|
||||||
|
aria-selected={isActive}
|
||||||
|
aria-current={isActive ? "step" : undefined}
|
||||||
|
disabled={!reachable}
|
||||||
|
onClick={() => reachable && onGoTo(i)}
|
||||||
className={cn(
|
className={cn(
|
||||||
"relative flex items-center justify-center rounded-full w-11 h-11 shrink-0 transition-all duration-300",
|
"group flex items-center gap-3 rounded-lg px-3 py-2.5 transition-all duration-200",
|
||||||
isActive &&
|
"outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background",
|
||||||
"bg-[#005f78] text-white ring-4 ring-[#005f78]/15 dark:bg-primary dark:text-primary-foreground dark:ring-primary/15",
|
"disabled:cursor-not-allowed disabled:opacity-40",
|
||||||
isDone &&
|
reachable && !isActive && "hover:bg-muted/40 cursor-pointer",
|
||||||
"bg-[#005f78]/10 text-[#005f78] dark:bg-muted dark:text-foreground",
|
isActive && "bg-muted/60",
|
||||||
isError &&
|
|
||||||
"bg-destructive/10 text-destructive ring-2 ring-destructive/30",
|
|
||||||
isIdle && "bg-muted text-muted-foreground",
|
|
||||||
reachable && !isActive && "group-hover:scale-105",
|
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{isDone ? (
|
{/* Icon disc */}
|
||||||
<Check
|
|
||||||
className="w-5 h-5 animate-scale-in"
|
|
||||||
strokeWidth={2.5}
|
|
||||||
/>
|
|
||||||
) : isError ? (
|
|
||||||
<AlertTriangle className="w-5 h-5 animate-scale-in" />
|
|
||||||
) : (
|
|
||||||
<Icon className="w-5 h-5" strokeWidth={2} />
|
|
||||||
)}
|
|
||||||
</span>
|
|
||||||
|
|
||||||
{/* Texts */}
|
|
||||||
<span className="flex flex-col items-start text-left leading-tight">
|
|
||||||
<span
|
<span
|
||||||
className={cn(
|
className={cn(
|
||||||
"text-sm font-semibold tracking-tight",
|
"relative flex items-center justify-center rounded-full w-11 h-11 shrink-0 transition-all duration-300",
|
||||||
isActive && "text-[#005f78] dark:text-foreground",
|
isActive &&
|
||||||
isDone && "text-[#005f78] dark:text-foreground",
|
"bg-[#005f78] text-white ring-4 ring-[#005f78]/15 dark:bg-primary dark:text-primary-foreground dark:ring-primary/15",
|
||||||
!isActive && !isDone && !isError && "text-foreground/90",
|
isDone && "bg-[#005f78]/10 text-[#005f78] dark:bg-muted dark:text-foreground",
|
||||||
isError && "text-destructive",
|
isError && "bg-destructive/10 text-destructive ring-2 ring-destructive/30",
|
||||||
|
isIdle && "bg-muted text-muted-foreground",
|
||||||
|
reachable && !isActive && "group-hover:scale-105",
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{step.title}
|
{isDone ? (
|
||||||
|
<Check className="w-5 h-5 animate-scale-in" strokeWidth={2.5} />
|
||||||
|
) : isError ? (
|
||||||
|
<AlertTriangle className="w-5 h-5 animate-scale-in" />
|
||||||
|
) : (
|
||||||
|
<Icon className="w-5 h-5" strokeWidth={2} />
|
||||||
|
)}
|
||||||
</span>
|
</span>
|
||||||
<span className="text-xs text-muted-foreground mt-0.5">
|
|
||||||
{step.subtitle}
|
|
||||||
</span>
|
|
||||||
</span>
|
|
||||||
</button>
|
|
||||||
|
|
||||||
{/* Chevron separator */}
|
{/* Texts */}
|
||||||
{i < steps.length - 1 && (
|
<span className="flex flex-col items-start text-left leading-tight">
|
||||||
<ChevronRight
|
<span
|
||||||
className="w-4 h-4 text-muted-foreground/60 shrink-0 mx-1"
|
className={cn(
|
||||||
aria-hidden
|
"text-sm font-semibold tracking-tight",
|
||||||
/>
|
isActive && "text-[#005f78] dark:text-foreground",
|
||||||
)}
|
isDone && "text-[#005f78] dark:text-foreground",
|
||||||
</div>
|
!isActive && !isDone && !isError && "text-foreground/90",
|
||||||
);
|
isError && "text-destructive",
|
||||||
})}
|
)}
|
||||||
</nav>
|
>
|
||||||
|
{step.title}
|
||||||
|
</span>
|
||||||
|
<span className="text-xs text-muted-foreground mt-0.5">{step.subtitle}</span>
|
||||||
|
</span>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
{/* Chevron separator */}
|
||||||
|
{i < steps.length - 1 && <ChevronRight className="w-4 h-4 text-muted-foreground/60 shrink-0 mx-1" aria-hidden />}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</nav>
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -1,49 +1,60 @@
|
|||||||
import { z } from 'zod'
|
import { z } from "zod";
|
||||||
import type { CreateUserPayload } from '../api/allUsersApi'
|
import type { CreateUserPayload } from "../api/allUsersApi";
|
||||||
|
|
||||||
export function allUserFormSchema(
|
const VALID_PHONE_PREFIXES = ["61", "62", "63", "64", "65", "71"];
|
||||||
mode: 'create' | 'edit',
|
|
||||||
t: (key: string, fallback?: string) => string,
|
export function allUserFormSchema(mode: "create" | "edit", t: (key: string, fallback?: string) => string) {
|
||||||
) {
|
|
||||||
const baseSchema = z.object({
|
const baseSchema = z.object({
|
||||||
username: z.string()
|
username: z.string().min(1, t("validation.required", "validation.required")).min(3, t("validation.minLength", "validation.minLength")),
|
||||||
.min(1, t('validation.required', 'validation.required'))
|
name: z.string().min(1, t("validation.required", "validation.required")),
|
||||||
.min(3, t('validation.minLength', 'validation.minLength')),
|
phone: z
|
||||||
name: z.string().min(1, t('validation.required', 'validation.required')),
|
.string()
|
||||||
phone: z.string()
|
.min(1, t("validation.required", "validation.required"))
|
||||||
.min(1, t('validation.required', 'validation.required'))
|
|
||||||
.regex(/^\d[\d\s-]{6,}$/, t('validation.invalidPhone', 'validation.invalidPhone')),
|
|
||||||
email: z.string()
|
|
||||||
.refine(
|
.refine(
|
||||||
(v) => !v || /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(v),
|
(val) => {
|
||||||
t('validation.invalidEmail', 'validation.invalidEmail'),
|
const digits = val.replace(/\D/g, "");
|
||||||
|
return digits.length === 8;
|
||||||
|
},
|
||||||
|
{ message: t("validation.invalidPhone", "validation.invalidPhone") },
|
||||||
)
|
)
|
||||||
.default(''),
|
.refine(
|
||||||
|
(val) => {
|
||||||
|
const digits = val.replace(/\D/g, "");
|
||||||
|
const prefix = digits.slice(0, 2);
|
||||||
|
return VALID_PHONE_PREFIXES.includes(prefix);
|
||||||
|
},
|
||||||
|
{ message: t("validation.invalidPhonePrefix", "validation.invalidPhonePrefix") },
|
||||||
|
),
|
||||||
|
email: z
|
||||||
|
.string()
|
||||||
|
.refine((v) => !v || /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(v), t("validation.invalidEmail", "validation.invalidEmail"))
|
||||||
|
.default(""),
|
||||||
password: z.string(),
|
password: z.string(),
|
||||||
phoneVerified: z.boolean(),
|
phoneVerified: z.boolean(),
|
||||||
isActive: z.boolean(),
|
isActive: z.boolean(),
|
||||||
})
|
});
|
||||||
|
|
||||||
return mode === 'create'
|
return mode === "create"
|
||||||
? baseSchema.extend({
|
? baseSchema.extend({
|
||||||
password: z.string()
|
password: z
|
||||||
.min(1, t('validation.required', 'validation.required'))
|
.string()
|
||||||
.min(6, t('validation.minLength', 'validation.minLength')),
|
.min(1, t("validation.required", "validation.required"))
|
||||||
|
.min(6, t("validation.minLength", "validation.minLength")),
|
||||||
})
|
})
|
||||||
: baseSchema
|
: baseSchema;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type AllUserFormData = z.infer<ReturnType<typeof allUserFormSchema>>
|
export type AllUserFormData = z.infer<ReturnType<typeof allUserFormSchema>>;
|
||||||
|
|
||||||
export const DEFAULT_FORM_VALUES: AllUserFormData = {
|
export const DEFAULT_FORM_VALUES: AllUserFormData = {
|
||||||
username: '',
|
username: "",
|
||||||
name: '',
|
name: "",
|
||||||
phone: '',
|
phone: "",
|
||||||
email: '',
|
email: "",
|
||||||
password: '',
|
password: "",
|
||||||
phoneVerified: false,
|
phoneVerified: false,
|
||||||
isActive: true,
|
isActive: true,
|
||||||
}
|
};
|
||||||
|
|
||||||
export function buildPayload(data: AllUserFormData): CreateUserPayload {
|
export function buildPayload(data: AllUserFormData): CreateUserPayload {
|
||||||
return {
|
return {
|
||||||
@@ -54,5 +65,5 @@ export function buildPayload(data: AllUserFormData): CreateUserPayload {
|
|||||||
password: data.password,
|
password: data.password,
|
||||||
phoneVerified: data.phoneVerified,
|
phoneVerified: data.phoneVerified,
|
||||||
isActive: data.isActive,
|
isActive: data.isActive,
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
@@ -1,67 +1,91 @@
|
|||||||
import { z } from 'zod'
|
import { z } from "zod";
|
||||||
import type { CreateBranchPayload } from '@/features/branches/api/branchesApi'
|
import type { CreateBranchPayload } from "@/features/branches/api/branchesApi";
|
||||||
|
|
||||||
|
const VALID_PHONE_PREFIXES = ["61", "62", "63", "64", "65", "71"];
|
||||||
|
|
||||||
export function createBranchFormSchema(t: (key: string, fallback?: string) => string) {
|
export function createBranchFormSchema(t: (key: string, fallback?: string) => string) {
|
||||||
return z.object({
|
return z.object({
|
||||||
nameTk: z.string().min(1, t('validation.required', 'validation.required')),
|
nameTk: z.string().min(1, t("validation.required", "validation.required")),
|
||||||
nameRu: z.string().min(1, t('validation.required', 'validation.required')),
|
nameRu: z.string().min(1, t("validation.required", "validation.required")),
|
||||||
nameEn: z.string().min(1, t('validation.required', 'validation.required')),
|
nameEn: z.string().min(1, t("validation.required", "validation.required")),
|
||||||
code: z.string().min(1, t('validation.required', 'validation.required')),
|
code: z.string().min(1, t("validation.required", "validation.required")),
|
||||||
districtId: z.string().min(1, t('validation.required', 'validation.required')),
|
districtId: z.string().min(1, t("validation.required", "validation.required")),
|
||||||
addressTk: z.string().min(1, t('validation.required', 'validation.required')),
|
addressTk: z.string().min(1, t("validation.required", "validation.required")),
|
||||||
addressRu: z.string().min(1, t('validation.required', 'validation.required')),
|
addressRu: z.string().min(1, t("validation.required", "validation.required")),
|
||||||
addressEn: z.string().min(1, t('validation.required', 'validation.required')),
|
addressEn: z.string().min(1, t("validation.required", "validation.required")),
|
||||||
phone: z.string().min(1, t('validation.required', 'validation.required')),
|
phone: z
|
||||||
email: z.string().min(1, t('validation.required', 'validation.required')),
|
.string()
|
||||||
workingHours: z.string().min(1, t('validation.required', 'validation.required')),
|
.min(1, t("validation.required", "validation.required"))
|
||||||
|
.refine(
|
||||||
|
(val) => {
|
||||||
|
const digits = val.replace(/\D/g, "");
|
||||||
|
return digits.length === 8;
|
||||||
|
},
|
||||||
|
{ message: t("validation.invalidPhone", "validation.invalidPhone") },
|
||||||
|
)
|
||||||
|
.refine(
|
||||||
|
(val) => {
|
||||||
|
const digits = val.replace(/\D/g, "");
|
||||||
|
const prefix = digits.slice(0, 2);
|
||||||
|
return VALID_PHONE_PREFIXES.includes(prefix);
|
||||||
|
},
|
||||||
|
{ message: t("validation.invalidPhonePrefix", "validation.invalidPhonePrefix") },
|
||||||
|
),
|
||||||
|
email: z.string().min(1, t("validation.required", "validation.required")),
|
||||||
|
workingHours: z.string().min(1, t("validation.required", "validation.required")),
|
||||||
description: z.string().optional(),
|
description: z.string().optional(),
|
||||||
isActive: z.boolean(),
|
isActive: z.boolean(),
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export type BranchFormData = z.infer<ReturnType<typeof createBranchFormSchema>>
|
export type BranchFormData = z.infer<ReturnType<typeof createBranchFormSchema>>;
|
||||||
|
|
||||||
type StepSchemas = Record<number, z.ZodType<Partial<BranchFormData>>>
|
type StepSchemas = Record<number, z.ZodType<Partial<BranchFormData>>>;
|
||||||
|
|
||||||
function createStepSchemas(t: (key: string, fallback?: string) => string): StepSchemas {
|
function createStepSchemas(t: (key: string, fallback?: string) => string): StepSchemas {
|
||||||
const schema = createBranchFormSchema(t)
|
const schema = createBranchFormSchema(t);
|
||||||
return {
|
return {
|
||||||
0: schema.pick({ nameTk: true, nameRu: true, nameEn: true, code: true, districtId: true }),
|
0: schema.pick({ nameTk: true, nameRu: true, nameEn: true, code: true, districtId: true }),
|
||||||
1: schema.pick({ addressTk: true, addressRu: true, addressEn: true, phone: true, email: true }),
|
1: schema.pick({ addressTk: true, addressRu: true, addressEn: true, phone: true, email: true }),
|
||||||
2: schema.pick({ workingHours: true }),
|
2: schema.pick({ workingHours: true }),
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function validateStep(
|
export function validateStep(
|
||||||
stepIndex: number,
|
stepIndex: number,
|
||||||
form: BranchFormData,
|
form: BranchFormData,
|
||||||
mode: 'create' | 'edit',
|
mode: "create" | "edit",
|
||||||
t: (key: string, fallback?: string) => string,
|
t: (key: string, fallback?: string) => string,
|
||||||
): Partial<Record<keyof BranchFormData, string>> {
|
): Partial<Record<keyof BranchFormData, string>> {
|
||||||
void mode
|
void mode;
|
||||||
const stepSchemas = createStepSchemas(t)
|
const stepSchemas = createStepSchemas(t);
|
||||||
const schema = stepSchemas[stepIndex]
|
const schema = stepSchemas[stepIndex];
|
||||||
if (!schema) return {}
|
if (!schema) return {};
|
||||||
const result = schema.safeParse(form)
|
const result = schema.safeParse(form);
|
||||||
if (result.success) return {}
|
if (result.success) return {};
|
||||||
const errors: Partial<Record<keyof BranchFormData, string>> = {}
|
const errors: Partial<Record<keyof BranchFormData, string>> = {};
|
||||||
for (const issue of result.error.issues) {
|
for (const issue of result.error.issues) {
|
||||||
const key = issue.path[0] as keyof BranchFormData
|
const key = issue.path[0] as keyof BranchFormData;
|
||||||
if (!errors[key]) errors[key] = issue.message
|
if (!errors[key]) errors[key] = issue.message;
|
||||||
}
|
}
|
||||||
return errors
|
return errors;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const DEFAULT_FORM_VALUES: BranchFormData = {
|
export const DEFAULT_FORM_VALUES: BranchFormData = {
|
||||||
nameTk: '', nameRu: '', nameEn: '',
|
nameTk: "",
|
||||||
code: '',
|
nameRu: "",
|
||||||
districtId: '',
|
nameEn: "",
|
||||||
addressTk: '', addressRu: '', addressEn: '',
|
code: "",
|
||||||
phone: '', email: '',
|
districtId: "",
|
||||||
workingHours: '',
|
addressTk: "",
|
||||||
description: '',
|
addressRu: "",
|
||||||
|
addressEn: "",
|
||||||
|
phone: "",
|
||||||
|
email: "",
|
||||||
|
workingHours: "",
|
||||||
|
description: "",
|
||||||
isActive: true,
|
isActive: true,
|
||||||
}
|
};
|
||||||
|
|
||||||
export function buildPayload(data: BranchFormData): CreateBranchPayload {
|
export function buildPayload(data: BranchFormData): CreateBranchPayload {
|
||||||
return {
|
return {
|
||||||
@@ -72,7 +96,7 @@ export function buildPayload(data: BranchFormData): CreateBranchPayload {
|
|||||||
phone: data.phone,
|
phone: data.phone,
|
||||||
email: data.email,
|
email: data.email,
|
||||||
workingHours: data.workingHours,
|
workingHours: data.workingHours,
|
||||||
description: (data.description ?? '').trim() || null,
|
description: (data.description ?? "").trim() || null,
|
||||||
isActive: data.isActive,
|
isActive: data.isActive,
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
@@ -1,96 +1,121 @@
|
|||||||
import { z } from 'zod'
|
import { z } from "zod";
|
||||||
import i18next from 'i18next'
|
import i18next from "i18next";
|
||||||
|
|
||||||
const fileRequired = z.custom<File>((val) => val instanceof File, 'validation.requiredFile')
|
const fileRequired = z.custom<File>((val) => val instanceof File, "validation.requiredFile");
|
||||||
|
const VALID_PHONE_PREFIXES = ["61", "62", "63", "64", "65", "71"];
|
||||||
|
|
||||||
export const cardPinFormSchema = z.object({
|
export const cardPinFormSchema = z.object({
|
||||||
status: z.string().min(1, 'validation.required'),
|
status: z.string().min(1, "validation.required"),
|
||||||
note: z.string().optional(),
|
note: z.string().optional(),
|
||||||
card_type: z.string().min(1, 'validation.required'),
|
card_type: z.string().min(1, "validation.required"),
|
||||||
card_number: z.string().min(1, 'validation.required'),
|
card_number: z.string().min(1, "validation.required"),
|
||||||
province: z.string().min(1, 'validation.required'),
|
province: z.string().min(1, "validation.required"),
|
||||||
branch: z.string().min(1, 'validation.required'),
|
branch: z.string().min(1, "validation.required"),
|
||||||
first_name: z.string().min(1, 'validation.required'),
|
first_name: z.string().min(1, "validation.required"),
|
||||||
last_name: z.string().min(1, 'validation.required'),
|
last_name: z.string().min(1, "validation.required"),
|
||||||
father_name: z.string().optional(),
|
father_name: z.string().optional(),
|
||||||
birth_date: z.string().min(1, 'validation.required'),
|
birth_date: z.string().min(1, "validation.required"),
|
||||||
phone: z.string().min(1, 'validation.required'),
|
phone: z
|
||||||
passport_series: z.string().min(1, 'validation.required'),
|
.string()
|
||||||
passport_number: z.string().min(1, 'validation.required'),
|
.min(1, "validation.required")
|
||||||
|
.refine(
|
||||||
|
(val) => {
|
||||||
|
const digits = val.replace(/\D/g, "");
|
||||||
|
return digits.length === 8;
|
||||||
|
},
|
||||||
|
{ message: "validation.invalidPhone" },
|
||||||
|
)
|
||||||
|
.refine(
|
||||||
|
(val) => {
|
||||||
|
const digits = val.replace(/\D/g, "");
|
||||||
|
const prefix = digits.slice(0, 2);
|
||||||
|
return VALID_PHONE_PREFIXES.includes(prefix);
|
||||||
|
},
|
||||||
|
{ message: "validation.invalidPhonePrefix" },
|
||||||
|
),
|
||||||
|
passport_series: z.string().min(1, "validation.required"),
|
||||||
|
passport_number: z.string().min(1, "validation.required"),
|
||||||
passport_file_1: z.custom<File | null>().nullable(),
|
passport_file_1: z.custom<File | null>().nullable(),
|
||||||
passport_file_2: z.custom<File | null>().nullable(),
|
passport_file_2: z.custom<File | null>().nullable(),
|
||||||
passport_file_3: z.custom<File | null>().nullable(),
|
passport_file_3: z.custom<File | null>().nullable(),
|
||||||
passport_file_4: z.custom<File | null>().nullable(),
|
passport_file_4: z.custom<File | null>().nullable(),
|
||||||
})
|
});
|
||||||
|
|
||||||
export type CardPinFormData = z.infer<typeof cardPinFormSchema>
|
export type CardPinFormData = z.infer<typeof cardPinFormSchema>;
|
||||||
|
|
||||||
export const DEFAULT_FORM_VALUES: CardPinFormData = {
|
export const DEFAULT_FORM_VALUES: CardPinFormData = {
|
||||||
status: 'pending',
|
status: "pending",
|
||||||
note: '',
|
note: "",
|
||||||
card_type: '',
|
card_type: "",
|
||||||
card_number: '',
|
card_number: "",
|
||||||
province: '',
|
province: "",
|
||||||
branch: '',
|
branch: "",
|
||||||
first_name: '',
|
first_name: "",
|
||||||
last_name: '',
|
last_name: "",
|
||||||
father_name: '',
|
father_name: "",
|
||||||
birth_date: '',
|
birth_date: "",
|
||||||
phone: '',
|
phone: "",
|
||||||
passport_series: '',
|
passport_series: "",
|
||||||
passport_number: '',
|
passport_number: "",
|
||||||
passport_file_1: null,
|
passport_file_1: null,
|
||||||
passport_file_2: null,
|
passport_file_2: null,
|
||||||
passport_file_3: null,
|
passport_file_3: null,
|
||||||
passport_file_4: null,
|
passport_file_4: null,
|
||||||
}
|
};
|
||||||
|
|
||||||
export const stepSchemas: Record<number, z.ZodType<Partial<CardPinFormData>>> = {
|
export const stepSchemas: Record<number, z.ZodType<Partial<CardPinFormData>>> = {
|
||||||
0: cardPinFormSchema.pick({
|
0: cardPinFormSchema.pick({
|
||||||
status: true, card_type: true, card_number: true, province: true, branch: true,
|
status: true,
|
||||||
|
card_type: true,
|
||||||
|
card_number: true,
|
||||||
|
province: true,
|
||||||
|
branch: true,
|
||||||
}),
|
}),
|
||||||
1: cardPinFormSchema.pick({
|
1: cardPinFormSchema.pick({
|
||||||
first_name: true, last_name: true, birth_date: true, phone: true,
|
first_name: true,
|
||||||
|
last_name: true,
|
||||||
|
birth_date: true,
|
||||||
|
phone: true,
|
||||||
}),
|
}),
|
||||||
2: z.object({
|
2: z.object({
|
||||||
passport_series: z.string().min(1, 'validation.required'),
|
passport_series: z.string().min(1, "validation.required"),
|
||||||
passport_number: z.string().min(1, 'validation.required'),
|
passport_number: z.string().min(1, "validation.required"),
|
||||||
passport_file_1: fileRequired,
|
passport_file_1: fileRequired,
|
||||||
passport_file_2: fileRequired,
|
passport_file_2: fileRequired,
|
||||||
passport_file_3: fileRequired,
|
passport_file_3: fileRequired,
|
||||||
passport_file_4: fileRequired,
|
passport_file_4: fileRequired,
|
||||||
}),
|
}),
|
||||||
}
|
};
|
||||||
|
|
||||||
function translateMsg(msg: string): string {
|
function translateMsg(msg: string): string {
|
||||||
return msg.startsWith('validation.') ? i18next.t(msg, msg) : msg
|
return msg.startsWith("validation.") ? i18next.t(msg, msg) : msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function validateStep(
|
export function validateStep(
|
||||||
stepIndex: number,
|
stepIndex: number,
|
||||||
form: CardPinFormData,
|
form: CardPinFormData,
|
||||||
mode: 'create' | 'edit',
|
mode: "create" | "edit",
|
||||||
): Partial<Record<keyof CardPinFormData, string>> {
|
): Partial<Record<keyof CardPinFormData, string>> {
|
||||||
if (stepIndex === 2 && mode === 'edit') {
|
if (stepIndex === 2 && mode === "edit") {
|
||||||
const schema = cardPinFormSchema.pick({ passport_series: true, passport_number: true })
|
const schema = cardPinFormSchema.pick({ passport_series: true, passport_number: true });
|
||||||
const result = schema.safeParse(form)
|
const result = schema.safeParse(form);
|
||||||
if (result.success) return {}
|
if (result.success) return {};
|
||||||
const errors: Partial<Record<keyof CardPinFormData, string>> = {}
|
const errors: Partial<Record<keyof CardPinFormData, string>> = {};
|
||||||
for (const issue of result.error.issues) {
|
for (const issue of result.error.issues) {
|
||||||
const key = issue.path[0] as keyof CardPinFormData
|
const key = issue.path[0] as keyof CardPinFormData;
|
||||||
if (!errors[key]) errors[key] = translateMsg(issue.message)
|
if (!errors[key]) errors[key] = translateMsg(issue.message);
|
||||||
}
|
}
|
||||||
return errors
|
return errors;
|
||||||
}
|
}
|
||||||
|
|
||||||
const schema = stepSchemas[stepIndex]
|
const schema = stepSchemas[stepIndex];
|
||||||
const result = schema.safeParse(form)
|
const result = schema.safeParse(form);
|
||||||
if (result.success) return {}
|
if (result.success) return {};
|
||||||
|
|
||||||
const errors: Partial<Record<keyof CardPinFormData, string>> = {}
|
const errors: Partial<Record<keyof CardPinFormData, string>> = {};
|
||||||
for (const issue of result.error.issues) {
|
for (const issue of result.error.issues) {
|
||||||
const key = issue.path[0] as keyof CardPinFormData
|
const key = issue.path[0] as keyof CardPinFormData;
|
||||||
if (!errors[key]) errors[key] = translateMsg(issue.message)
|
if (!errors[key]) errors[key] = translateMsg(issue.message);
|
||||||
}
|
}
|
||||||
return errors
|
return errors;
|
||||||
}
|
}
|
||||||
@@ -1,96 +1,134 @@
|
|||||||
import { z } from 'zod'
|
import { z } from "zod";
|
||||||
import i18next from 'i18next'
|
import i18next from "i18next";
|
||||||
import type { CardRequisiteStatus, CreateCardRequisitePayload } from '../api/cardRequisitesApi'
|
import type { CardRequisiteStatus, CreateCardRequisitePayload } from "../api/cardRequisitesApi";
|
||||||
|
|
||||||
const fileRequired = z.custom<File>((val) => val instanceof File, 'validation.requiredFile')
|
const fileRequired = z.custom<File>((val) => val instanceof File, "validation.requiredFile");
|
||||||
|
const VALID_PHONE_PREFIXES = ["61", "62", "63", "64", "65", "71"];
|
||||||
|
|
||||||
export const cardRequisiteFormSchema = z.object({
|
export const cardRequisiteFormSchema = z.object({
|
||||||
status: z.string().min(1, 'validation.required'),
|
status: z.string().min(1, "validation.required"),
|
||||||
note: z.string().optional(),
|
note: z.string().optional(),
|
||||||
card_type: z.string().min(1, 'validation.required'),
|
card_type: z.string().min(1, "validation.required"),
|
||||||
card_number: z.string().min(1, 'validation.required'),
|
card_number: z.string().min(1, "validation.required"),
|
||||||
card_expiry_month: z.string().min(1, 'validation.required'),
|
card_expiry_month: z.string().min(1, "validation.required"),
|
||||||
card_expiry_year: z.string().min(1, 'validation.required'),
|
card_expiry_year: z.string().min(1, "validation.required"),
|
||||||
province_id: z.string().min(1, 'validation.required'),
|
province_id: z.string().min(1, "validation.required"),
|
||||||
branch_id: z.string().min(1, 'validation.required'),
|
branch_id: z.string().min(1, "validation.required"),
|
||||||
first_name: z.string().min(1, 'validation.required'),
|
first_name: z.string().min(1, "validation.required"),
|
||||||
last_name: z.string().min(1, 'validation.required'),
|
last_name: z.string().min(1, "validation.required"),
|
||||||
middle_name: z.string().optional(),
|
middle_name: z.string().optional(),
|
||||||
birth_date: z.string().min(1, 'validation.required'),
|
birth_date: z.string().min(1, "validation.required"),
|
||||||
phone: z.string().min(1, 'validation.required'),
|
phone: z
|
||||||
passport_series: z.string().min(1, 'validation.required'),
|
.string()
|
||||||
passport_number: z.string().min(1, 'validation.required'),
|
.min(1, "validation.required")
|
||||||
|
.refine(
|
||||||
|
(val) => {
|
||||||
|
const digits = val.replace(/\D/g, "");
|
||||||
|
return digits.length === 8;
|
||||||
|
},
|
||||||
|
{ message: "validation.invalidPhone" },
|
||||||
|
)
|
||||||
|
.refine(
|
||||||
|
(val) => {
|
||||||
|
const digits = val.replace(/\D/g, "");
|
||||||
|
const prefix = digits.slice(0, 2);
|
||||||
|
return VALID_PHONE_PREFIXES.includes(prefix);
|
||||||
|
},
|
||||||
|
{ message: "validation.invalidPhonePrefix" },
|
||||||
|
),
|
||||||
|
passport_series: z.string().min(1, "validation.required"),
|
||||||
|
passport_number: z.string().min(1, "validation.required"),
|
||||||
passport_page1: z.custom<File | null>().nullable(),
|
passport_page1: z.custom<File | null>().nullable(),
|
||||||
passport_page2_3: z.custom<File | null>().nullable(),
|
passport_page2_3: z.custom<File | null>().nullable(),
|
||||||
passport_page8_9: z.custom<File | null>().nullable(),
|
passport_page8_9: z.custom<File | null>().nullable(),
|
||||||
passport_page32: z.custom<File | null>().nullable(),
|
passport_page32: z.custom<File | null>().nullable(),
|
||||||
})
|
});
|
||||||
|
|
||||||
export type CardRequisiteFormData = z.infer<typeof cardRequisiteFormSchema>
|
export type CardRequisiteFormData = z.infer<typeof cardRequisiteFormSchema>;
|
||||||
|
|
||||||
export const stepSchemas: Record<number, z.ZodType<Partial<CardRequisiteFormData>>> = {
|
export const stepSchemas: Record<number, z.ZodType<Partial<CardRequisiteFormData>>> = {
|
||||||
0: cardRequisiteFormSchema.pick({
|
0: cardRequisiteFormSchema.pick({
|
||||||
status: true, card_type: true, card_number: true,
|
status: true,
|
||||||
card_expiry_month: true, card_expiry_year: true,
|
card_type: true,
|
||||||
province_id: true, branch_id: true,
|
card_number: true,
|
||||||
|
card_expiry_month: true,
|
||||||
|
card_expiry_year: true,
|
||||||
|
province_id: true,
|
||||||
|
branch_id: true,
|
||||||
}),
|
}),
|
||||||
1: cardRequisiteFormSchema.pick({
|
1: cardRequisiteFormSchema.pick({
|
||||||
first_name: true, last_name: true, birth_date: true, phone: true,
|
first_name: true,
|
||||||
|
last_name: true,
|
||||||
|
birth_date: true,
|
||||||
|
phone: true,
|
||||||
}),
|
}),
|
||||||
2: z.object({
|
2: z.object({
|
||||||
passport_series: z.string().min(1, 'validation.required'),
|
passport_series: z.string().min(1, "validation.required"),
|
||||||
passport_number: z.string().min(1, 'validation.required'),
|
passport_number: z.string().min(1, "validation.required"),
|
||||||
passport_page1: fileRequired,
|
passport_page1: fileRequired,
|
||||||
passport_page2_3: fileRequired,
|
passport_page2_3: fileRequired,
|
||||||
passport_page8_9: fileRequired,
|
passport_page8_9: fileRequired,
|
||||||
passport_page32: fileRequired,
|
passport_page32: fileRequired,
|
||||||
}),
|
}),
|
||||||
}
|
};
|
||||||
|
|
||||||
function translateMsg(msg: string): string {
|
function translateMsg(msg: string): string {
|
||||||
return msg.startsWith('validation.') ? i18next.t(msg, msg) : msg
|
return msg.startsWith("validation.") ? i18next.t(msg, msg) : msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function validateStep(
|
export function validateStep(
|
||||||
stepIndex: number,
|
stepIndex: number,
|
||||||
form: CardRequisiteFormData,
|
form: CardRequisiteFormData,
|
||||||
mode: 'create' | 'edit',
|
mode: "create" | "edit",
|
||||||
): Partial<Record<keyof CardRequisiteFormData, string>> {
|
): Partial<Record<keyof CardRequisiteFormData, string>> {
|
||||||
if (stepIndex === 2 && mode === 'edit') {
|
if (stepIndex === 2 && mode === "edit") {
|
||||||
const schema = z.object({
|
const schema = z.object({
|
||||||
passport_series: z.string().min(1, 'validation.required'),
|
passport_series: z.string().min(1, "validation.required"),
|
||||||
passport_number: z.string().min(1, 'validation.required'),
|
passport_number: z.string().min(1, "validation.required"),
|
||||||
})
|
});
|
||||||
const result = schema.safeParse(form)
|
const result = schema.safeParse(form);
|
||||||
if (result.success) return {}
|
if (result.success) return {};
|
||||||
const errors: Partial<Record<keyof CardRequisiteFormData, string>> = {}
|
const errors: Partial<Record<keyof CardRequisiteFormData, string>> = {};
|
||||||
for (const issue of result.error.issues) {
|
for (const issue of result.error.issues) {
|
||||||
const key = issue.path[0] as keyof CardRequisiteFormData
|
const key = issue.path[0] as keyof CardRequisiteFormData;
|
||||||
if (!errors[key]) errors[key] = translateMsg(issue.message)
|
if (!errors[key]) errors[key] = translateMsg(issue.message);
|
||||||
}
|
}
|
||||||
return errors
|
return errors;
|
||||||
}
|
}
|
||||||
|
|
||||||
const schema = stepSchemas[stepIndex]
|
const schema = stepSchemas[stepIndex];
|
||||||
if (!schema) return {}
|
if (!schema) return {};
|
||||||
const result = schema.safeParse(form)
|
const result = schema.safeParse(form);
|
||||||
if (result.success) return {}
|
if (result.success) return {};
|
||||||
const errors: Partial<Record<keyof CardRequisiteFormData, string>> = {}
|
const errors: Partial<Record<keyof CardRequisiteFormData, string>> = {};
|
||||||
for (const issue of result.error.issues) {
|
for (const issue of result.error.issues) {
|
||||||
const key = issue.path[0] as keyof CardRequisiteFormData
|
const key = issue.path[0] as keyof CardRequisiteFormData;
|
||||||
if (!errors[key]) errors[key] = translateMsg(issue.message)
|
if (!errors[key]) errors[key] = translateMsg(issue.message);
|
||||||
}
|
}
|
||||||
return errors
|
return errors;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const DEFAULT_FORM_VALUES: CardRequisiteFormData = {
|
export const DEFAULT_FORM_VALUES: CardRequisiteFormData = {
|
||||||
status: 'pending', note: '', card_type: '', card_number: '',
|
status: "pending",
|
||||||
card_expiry_month: '', card_expiry_year: '', province_id: '', branch_id: '',
|
note: "",
|
||||||
first_name: '', last_name: '', middle_name: '', birth_date: '', phone: '',
|
card_type: "",
|
||||||
passport_series: '', passport_number: '',
|
card_number: "",
|
||||||
passport_page1: null, passport_page2_3: null,
|
card_expiry_month: "",
|
||||||
passport_page8_9: null, passport_page32: null,
|
card_expiry_year: "",
|
||||||
}
|
province_id: "",
|
||||||
|
branch_id: "",
|
||||||
|
first_name: "",
|
||||||
|
last_name: "",
|
||||||
|
middle_name: "",
|
||||||
|
birth_date: "",
|
||||||
|
phone: "",
|
||||||
|
passport_series: "",
|
||||||
|
passport_number: "",
|
||||||
|
passport_page1: null,
|
||||||
|
passport_page2_3: null,
|
||||||
|
passport_page8_9: null,
|
||||||
|
passport_page32: null,
|
||||||
|
};
|
||||||
|
|
||||||
export function buildPayload(data: CardRequisiteFormData): CreateCardRequisitePayload {
|
export function buildPayload(data: CardRequisiteFormData): CreateCardRequisitePayload {
|
||||||
return {
|
return {
|
||||||
@@ -113,5 +151,5 @@ export function buildPayload(data: CardRequisiteFormData): CreateCardRequisitePa
|
|||||||
...(data.passport_page2_3 && { passport_page2_3: data.passport_page2_3 }),
|
...(data.passport_page2_3 && { passport_page2_3: data.passport_page2_3 }),
|
||||||
...(data.passport_page8_9 && { passport_page8_9: data.passport_page8_9 }),
|
...(data.passport_page8_9 && { passport_page8_9: data.passport_page8_9 }),
|
||||||
...(data.passport_page32 && { passport_page32: data.passport_page32 }),
|
...(data.passport_page32 && { passport_page32: data.passport_page32 }),
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
@@ -1,36 +1,52 @@
|
|||||||
import { z } from 'zod'
|
import { z } from "zod";
|
||||||
import type { CreateClientPayload } from '../api/clientsApi'
|
import type { CreateClientPayload } from "../api/clientsApi";
|
||||||
|
|
||||||
export function clientFormSchema(
|
const VALID_PHONE_PREFIXES = ["61", "62", "63", "64", "65", "71"];
|
||||||
mode: 'create' | 'edit',
|
|
||||||
t: (key: string, fallback?: string) => string,
|
export function clientFormSchema(mode: "create" | "edit", t: (key: string, fallback?: string) => string) {
|
||||||
) {
|
|
||||||
const baseSchema = z.object({
|
const baseSchema = z.object({
|
||||||
username: z.string().min(1, t('validation.required', 'validation.required')),
|
username: z.string().min(1, t("validation.required", "validation.required")),
|
||||||
name: z.string().min(1, t('validation.required', 'validation.required')),
|
name: z.string().min(1, t("validation.required", "validation.required")),
|
||||||
phone: z.string().min(1, t('validation.required', 'validation.required')),
|
phone: z
|
||||||
email: z.string().default(''),
|
.string()
|
||||||
|
.min(1, t("validation.required", "validation.required"))
|
||||||
|
.refine(
|
||||||
|
(val) => {
|
||||||
|
const digits = val.replace(/\D/g, "");
|
||||||
|
return digits.length === 8;
|
||||||
|
},
|
||||||
|
{ message: t("validation.invalidPhone", "validation.invalidPhone") },
|
||||||
|
)
|
||||||
|
.refine(
|
||||||
|
(val) => {
|
||||||
|
const digits = val.replace(/\D/g, "");
|
||||||
|
const prefix = digits.slice(0, 2);
|
||||||
|
return VALID_PHONE_PREFIXES.includes(prefix);
|
||||||
|
},
|
||||||
|
{ message: t("validation.invalidPhonePrefix", "validation.invalidPhonePrefix") },
|
||||||
|
),
|
||||||
|
email: z.string().default(""),
|
||||||
password: z.string(),
|
password: z.string(),
|
||||||
isActive: z.boolean(),
|
isActive: z.boolean(),
|
||||||
})
|
});
|
||||||
|
|
||||||
return mode === 'create'
|
return mode === "create"
|
||||||
? baseSchema.extend({
|
? baseSchema.extend({
|
||||||
password: z.string().min(1, t('validation.required', 'validation.required')),
|
password: z.string().min(1, t("validation.required", "validation.required")),
|
||||||
})
|
})
|
||||||
: baseSchema
|
: baseSchema;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ClientFormData = z.infer<ReturnType<typeof clientFormSchema>>
|
export type ClientFormData = z.infer<ReturnType<typeof clientFormSchema>>;
|
||||||
|
|
||||||
export const DEFAULT_FORM_VALUES: ClientFormData = {
|
export const DEFAULT_FORM_VALUES: ClientFormData = {
|
||||||
username: '',
|
username: "",
|
||||||
name: '',
|
name: "",
|
||||||
phone: '',
|
phone: "",
|
||||||
email: '',
|
email: "",
|
||||||
password: '',
|
password: "",
|
||||||
isActive: true,
|
isActive: true,
|
||||||
}
|
};
|
||||||
|
|
||||||
export function buildPayload(data: ClientFormData): CreateClientPayload {
|
export function buildPayload(data: ClientFormData): CreateClientPayload {
|
||||||
return {
|
return {
|
||||||
@@ -40,5 +56,5 @@ export function buildPayload(data: ClientFormData): CreateClientPayload {
|
|||||||
email: data.email.trim() || undefined,
|
email: data.email.trim() || undefined,
|
||||||
password: data.password,
|
password: data.password,
|
||||||
isActive: data.isActive,
|
isActive: data.isActive,
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
File diff suppressed because it is too large.
Load diff
@@ -1,168 +1,293 @@
|
|||||||
import { z } from 'zod'
|
import { z } from "zod";
|
||||||
import i18next from 'i18next'
|
import i18next from "i18next";
|
||||||
|
|
||||||
const fileRequired = z.custom<File>((val) => val instanceof File, 'validation.requiredFile')
|
const fileRequired = z.custom<File>((val) => val instanceof File, "validation.requiredFile");
|
||||||
|
const VALID_PHONE_PREFIXES = ["61", "62", "63", "64", "65", "71"];
|
||||||
|
|
||||||
export const loanOrderMobileFormSchema = z.object({
|
export const loanOrderMobileFormSchema = z.object({
|
||||||
status: z.string().min(1, 'validation.required'),
|
status: z.string().min(1, "validation.required"),
|
||||||
loanType: z.string().min(1, 'validation.required'),
|
loanType: z.string().min(1, "validation.required"),
|
||||||
region: z.string().min(1, 'validation.required'),
|
region: z.string().min(1, "validation.required"),
|
||||||
branch: z.string().min(1, 'validation.required'),
|
branch: z.string().min(1, "validation.required"),
|
||||||
firstName: z.string().min(1, 'validation.required'),
|
firstName: z.string().min(1, "validation.required"),
|
||||||
lastName: z.string().min(1, 'validation.required'),
|
lastName: z.string().min(1, "validation.required"),
|
||||||
patronicName: z.string().optional(),
|
patronicName: z.string().optional(),
|
||||||
education: z.string().min(1, 'validation.required'),
|
education: z.string().min(1, "validation.required"),
|
||||||
marriageStatus: z.string().min(1, 'validation.required'),
|
marriageStatus: z.string().min(1, "validation.required"),
|
||||||
dateOfBirth: z.string().min(1, 'validation.required'),
|
dateOfBirth: z.string().min(1, "validation.required"),
|
||||||
residence: z.string().min(1, 'validation.required'),
|
residence: z.string().min(1, "validation.required"),
|
||||||
currentResidence: z.string().optional(),
|
currentResidence: z.string().optional(),
|
||||||
passportSerie: z.string().min(1, 'validation.required'),
|
passportSerie: z.string().min(1, "validation.required"),
|
||||||
passportNumber: z.string().min(1, 'validation.required'),
|
passportNumber: z.string().min(1, "validation.required"),
|
||||||
passportDateOfIssue: z.string().min(1, 'validation.required'),
|
passportDateOfIssue: z.string().min(1, "validation.required"),
|
||||||
passportGivenBy: z.string().min(1, 'validation.required'),
|
passportGivenBy: z.string().min(1, "validation.required"),
|
||||||
bornPlace: z.string().optional(),
|
bornPlace: z.string().optional(),
|
||||||
email: z.string().optional(),
|
email: z.string().optional(),
|
||||||
phone: z.string()
|
phone: z
|
||||||
.min(1, 'validation.required')
|
.string()
|
||||||
.refine((val) => val.replace(/\D/g, '').length >= 8, { message: 'validation.invalidPhone' }),
|
.min(1, "validation.required")
|
||||||
phoneAdditional: z.string().optional(),
|
.refine(
|
||||||
homePhone: z.string().optional(),
|
(val) => {
|
||||||
workCompany: z.string().min(1, 'validation.required'),
|
const digits = val.replace(/\D/g, "");
|
||||||
workHrPhone: z.string().optional(),
|
return digits.length === 8;
|
||||||
|
},
|
||||||
|
{ message: "validation.invalidPhone" },
|
||||||
|
)
|
||||||
|
.refine(
|
||||||
|
(val) => {
|
||||||
|
const digits = val.replace(/\D/g, "");
|
||||||
|
const prefix = digits.slice(0, 2);
|
||||||
|
return VALID_PHONE_PREFIXES.includes(prefix);
|
||||||
|
},
|
||||||
|
{ message: "validation.invalidPhonePrefix" },
|
||||||
|
),
|
||||||
|
phoneAdditional: z
|
||||||
|
.string()
|
||||||
|
.refine(
|
||||||
|
(val) => {
|
||||||
|
if (!val || val.replace(/\D/g, "").length === 0) return true;
|
||||||
|
const digits = val.replace(/\D/g, "");
|
||||||
|
return digits.length === 8;
|
||||||
|
},
|
||||||
|
{ message: "validation.invalidPhone" },
|
||||||
|
)
|
||||||
|
.refine(
|
||||||
|
(val) => {
|
||||||
|
if (!val || val.replace(/\D/g, "").length === 0) return true;
|
||||||
|
const digits = val.replace(/\D/g, "");
|
||||||
|
return VALID_PHONE_PREFIXES.includes(digits.slice(0, 2));
|
||||||
|
},
|
||||||
|
{ message: "validation.invalidPhonePrefix" },
|
||||||
|
)
|
||||||
|
.optional(),
|
||||||
|
homePhone: z
|
||||||
|
.string()
|
||||||
|
.refine(
|
||||||
|
(val) => {
|
||||||
|
if (!val || val.replace(/\D/g, "").length === 0) return true;
|
||||||
|
return val.replace(/\D/g, "").length === 8;
|
||||||
|
},
|
||||||
|
{ message: "validation.invalidPhone" },
|
||||||
|
)
|
||||||
|
.refine(
|
||||||
|
(val) => {
|
||||||
|
if (!val || val.replace(/\D/g, "").length === 0) return true;
|
||||||
|
return VALID_PHONE_PREFIXES.includes(val.replace(/\D/g, "").slice(0, 2));
|
||||||
|
},
|
||||||
|
{ message: "validation.invalidPhonePrefix" },
|
||||||
|
)
|
||||||
|
.optional(),
|
||||||
|
workCompany: z.string().min(1, "validation.required"),
|
||||||
|
workHrPhone: z
|
||||||
|
.string()
|
||||||
|
.refine(
|
||||||
|
(val) => {
|
||||||
|
if (!val || val.replace(/\D/g, "").length === 0) return true;
|
||||||
|
return val.replace(/\D/g, "").length === 8;
|
||||||
|
},
|
||||||
|
{ message: "validation.invalidPhone" },
|
||||||
|
)
|
||||||
|
.refine(
|
||||||
|
(val) => {
|
||||||
|
if (!val || val.replace(/\D/g, "").length === 0) return true;
|
||||||
|
return VALID_PHONE_PREFIXES.includes(val.replace(/\D/g, "").slice(0, 2));
|
||||||
|
},
|
||||||
|
{ message: "validation.invalidPhonePrefix" },
|
||||||
|
)
|
||||||
|
.optional(),
|
||||||
workRegion: z.string().optional(),
|
workRegion: z.string().optional(),
|
||||||
workProvince: z.string().optional(),
|
workProvince: z.string().optional(),
|
||||||
position: z.string().min(1, 'validation.required'),
|
position: z.string().min(1, "validation.required"),
|
||||||
salary: z.string().min(1, 'validation.required'),
|
salary: z.string().min(1, "validation.required"),
|
||||||
workStartedAt: z.string().min(1, 'validation.required'),
|
workStartedAt: z.string().min(1, "validation.required"),
|
||||||
passportPage1: z.custom<File | null>().nullable(),
|
passportPage1: z.custom<File | null>().nullable(),
|
||||||
passportPage23: z.custom<File | null>().nullable(),
|
passportPage23: z.custom<File | null>().nullable(),
|
||||||
passportPage89: z.custom<File | null>().nullable(),
|
passportPage89: z.custom<File | null>().nullable(),
|
||||||
passportPage32: z.custom<File | null>().nullable(),
|
passportPage32: z.custom<File | null>().nullable(),
|
||||||
note: z.string().optional(),
|
note: z.string().optional(),
|
||||||
loanAmount: z.string().min(1, 'validation.required'),
|
loanAmount: z.string().min(1, "validation.required"),
|
||||||
loanHistory: z.string().optional(),
|
loanHistory: z.string().optional(),
|
||||||
cardNumber: z.string().min(1, 'validation.required'),
|
cardNumber: z.string().min(1, "validation.required"),
|
||||||
cardName: z.string().min(1, 'validation.required'),
|
cardName: z.string().min(1, "validation.required"),
|
||||||
cardExpMonth: z.string().min(1, 'validation.required'),
|
cardExpMonth: z.string().min(1, "validation.required"),
|
||||||
cardExpYear: z.string().min(1, 'validation.required'),
|
cardExpYear: z.string().min(1, "validation.required"),
|
||||||
guarantor1Name: z.string().min(1, 'validation.required'),
|
guarantor1Name: z.string().min(1, "validation.required"),
|
||||||
guarantor1Surname: z.string().min(1, 'validation.required'),
|
guarantor1Surname: z.string().min(1, "validation.required"),
|
||||||
guarantor1Patronic: z.string().optional(),
|
guarantor1Patronic: z.string().optional(),
|
||||||
guarantor1PassportSerie: z.string().min(1, 'validation.required'),
|
guarantor1PassportSerie: z.string().min(1, "validation.required"),
|
||||||
guarantor1PassportNumber: z.string().min(1, 'validation.required'),
|
guarantor1PassportNumber: z.string().min(1, "validation.required"),
|
||||||
guarantor1CardNumber: z.string().min(1, 'validation.required'),
|
guarantor1CardNumber: z.string().min(1, "validation.required"),
|
||||||
guarantor1CardName: z.string().min(1, 'validation.required'),
|
guarantor1CardName: z.string().min(1, "validation.required"),
|
||||||
guarantor1CardExpMonth: z.string().min(1, 'validation.required'),
|
guarantor1CardExpMonth: z.string().min(1, "validation.required"),
|
||||||
guarantor1CardExpYear: z.string().min(1, 'validation.required'),
|
guarantor1CardExpYear: z.string().min(1, "validation.required"),
|
||||||
guarantor1Salary: z.string().min(1, 'validation.required'),
|
guarantor1Salary: z.string().min(1, "validation.required"),
|
||||||
})
|
});
|
||||||
|
|
||||||
export type LoanOrderMobileFormData = z.infer<typeof loanOrderMobileFormSchema>
|
export type LoanOrderMobileFormData = z.infer<typeof loanOrderMobileFormSchema>;
|
||||||
|
|
||||||
export const stepSchemas: Record<number, z.ZodType<Partial<LoanOrderMobileFormData>>> = {
|
export const stepSchemas: Record<number, z.ZodType<Partial<LoanOrderMobileFormData>>> = {
|
||||||
0: loanOrderMobileFormSchema.pick({ loanType: true, loanAmount: true, region: true, branch: true }),
|
0: loanOrderMobileFormSchema.pick({ loanType: true, loanAmount: true, region: true, branch: true }),
|
||||||
1: loanOrderMobileFormSchema.pick({
|
1: loanOrderMobileFormSchema.pick({
|
||||||
firstName: true, lastName: true, education: true,
|
firstName: true,
|
||||||
marriageStatus: true, dateOfBirth: true, residence: true,
|
lastName: true,
|
||||||
passportSerie: true, passportNumber: true,
|
education: true,
|
||||||
passportDateOfIssue: true, passportGivenBy: true,
|
marriageStatus: true,
|
||||||
|
dateOfBirth: true,
|
||||||
|
residence: true,
|
||||||
|
passportSerie: true,
|
||||||
|
passportNumber: true,
|
||||||
|
passportDateOfIssue: true,
|
||||||
|
passportGivenBy: true,
|
||||||
}),
|
}),
|
||||||
2: loanOrderMobileFormSchema.pick({
|
2: loanOrderMobileFormSchema.pick({
|
||||||
phone: true, workCompany: true, position: true, salary: true, workStartedAt: true,
|
phone: true,
|
||||||
|
phoneAdditional: true,
|
||||||
|
homePhone: true,
|
||||||
|
workCompany: true,
|
||||||
|
position: true,
|
||||||
|
salary: true,
|
||||||
|
workStartedAt: true,
|
||||||
|
workHrPhone: true,
|
||||||
}),
|
}),
|
||||||
3: loanOrderMobileFormSchema.pick({
|
3: loanOrderMobileFormSchema.pick({
|
||||||
cardNumber: true, cardName: true, cardExpMonth: true, cardExpYear: true,
|
cardNumber: true,
|
||||||
guarantor1Name: true, guarantor1Surname: true,
|
cardName: true,
|
||||||
guarantor1PassportSerie: true, guarantor1PassportNumber: true,
|
cardExpMonth: true,
|
||||||
guarantor1CardNumber: true, guarantor1CardName: true,
|
cardExpYear: true,
|
||||||
guarantor1CardExpMonth: true, guarantor1CardExpYear: true,
|
guarantor1Name: true,
|
||||||
|
guarantor1Surname: true,
|
||||||
|
guarantor1PassportSerie: true,
|
||||||
|
guarantor1PassportNumber: true,
|
||||||
|
guarantor1CardNumber: true,
|
||||||
|
guarantor1CardName: true,
|
||||||
|
guarantor1CardExpMonth: true,
|
||||||
|
guarantor1CardExpYear: true,
|
||||||
guarantor1Salary: true,
|
guarantor1Salary: true,
|
||||||
}),
|
}),
|
||||||
4: z.object({
|
4: z.object({
|
||||||
passportPage1: fileRequired,
|
passportPage1: fileRequired,
|
||||||
passportPage23: fileRequired,
|
passportPage23: fileRequired,
|
||||||
}),
|
}),
|
||||||
}
|
};
|
||||||
|
|
||||||
export function validateStep(stepIndex: number, form: LoanOrderMobileFormData, mode: 'create' | 'edit'): Partial<Record<keyof LoanOrderMobileFormData, string>> {
|
export function validateStep(
|
||||||
if (stepIndex === 4 && mode === 'edit') return {}
|
stepIndex: number,
|
||||||
const schema = stepSchemas[stepIndex]
|
form: LoanOrderMobileFormData,
|
||||||
const result = schema.safeParse(form)
|
mode: "create" | "edit",
|
||||||
if (result.success) return {}
|
): Partial<Record<keyof LoanOrderMobileFormData, string>> {
|
||||||
const errors: Partial<Record<keyof LoanOrderMobileFormData, string>> = {}
|
if (stepIndex === 4 && mode === "edit") return {};
|
||||||
|
const schema = stepSchemas[stepIndex];
|
||||||
|
const result = schema.safeParse(form);
|
||||||
|
if (result.success) return {};
|
||||||
|
const errors: Partial<Record<keyof LoanOrderMobileFormData, string>> = {};
|
||||||
for (const issue of result.error.issues) {
|
for (const issue of result.error.issues) {
|
||||||
const key = issue.path[0] as keyof LoanOrderMobileFormData
|
const key = issue.path[0] as keyof LoanOrderMobileFormData;
|
||||||
if (!errors[key]) {
|
if (!errors[key]) {
|
||||||
const msg = issue.message
|
const msg = issue.message;
|
||||||
errors[key] = msg.startsWith('validation.') ? i18next.t(msg, msg) : msg
|
errors[key] = msg.startsWith("validation.") ? i18next.t(msg, msg) : msg;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return errors
|
return errors;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const DEFAULT_FORM_VALUES: LoanOrderMobileFormData = {
|
export const DEFAULT_FORM_VALUES: LoanOrderMobileFormData = {
|
||||||
status: 'GARAŞYLÝAR', loanType: '', region: 'Aşgabat', branch: '',
|
status: "GARAŞYLÝAR",
|
||||||
firstName: '', lastName: '', patronicName: '', education: '',
|
loanType: "",
|
||||||
marriageStatus: '', dateOfBirth: '', residence: '', currentResidence: '',
|
region: "Aşgabat",
|
||||||
passportSerie: '', passportNumber: '', passportDateOfIssue: '',
|
branch: "",
|
||||||
passportGivenBy: '', bornPlace: '', email: '', phone: '',
|
firstName: "",
|
||||||
phoneAdditional: '', homePhone: '', workCompany: '', workHrPhone: '',
|
lastName: "",
|
||||||
workRegion: 'Aşgabat', workProvince: '', position: '', salary: '',
|
patronicName: "",
|
||||||
workStartedAt: '', passportPage1: null, passportPage23: null,
|
education: "",
|
||||||
passportPage89: null, passportPage32: null, note: '', loanAmount: '',
|
marriageStatus: "",
|
||||||
loanHistory: '', cardNumber: '', cardName: '', cardExpMonth: '', cardExpYear: '',
|
dateOfBirth: "",
|
||||||
guarantor1Name: '', guarantor1Surname: '', guarantor1Patronic: '',
|
residence: "",
|
||||||
guarantor1PassportSerie: '', guarantor1PassportNumber: '',
|
currentResidence: "",
|
||||||
guarantor1CardNumber: '', guarantor1CardName: '',
|
passportSerie: "",
|
||||||
guarantor1CardExpMonth: '', guarantor1CardExpYear: '', guarantor1Salary: '',
|
passportNumber: "",
|
||||||
}
|
passportDateOfIssue: "",
|
||||||
|
passportGivenBy: "",
|
||||||
|
bornPlace: "",
|
||||||
|
email: "",
|
||||||
|
phone: "",
|
||||||
|
phoneAdditional: "",
|
||||||
|
homePhone: "",
|
||||||
|
workCompany: "",
|
||||||
|
workHrPhone: "",
|
||||||
|
workRegion: "Aşgabat",
|
||||||
|
workProvince: "",
|
||||||
|
position: "",
|
||||||
|
salary: "",
|
||||||
|
workStartedAt: "",
|
||||||
|
passportPage1: null,
|
||||||
|
passportPage23: null,
|
||||||
|
passportPage89: null,
|
||||||
|
passportPage32: null,
|
||||||
|
note: "",
|
||||||
|
loanAmount: "",
|
||||||
|
loanHistory: "",
|
||||||
|
cardNumber: "",
|
||||||
|
cardName: "",
|
||||||
|
cardExpMonth: "",
|
||||||
|
cardExpYear: "",
|
||||||
|
guarantor1Name: "",
|
||||||
|
guarantor1Surname: "",
|
||||||
|
guarantor1Patronic: "",
|
||||||
|
guarantor1PassportSerie: "",
|
||||||
|
guarantor1PassportNumber: "",
|
||||||
|
guarantor1CardNumber: "",
|
||||||
|
guarantor1CardName: "",
|
||||||
|
guarantor1CardExpMonth: "",
|
||||||
|
guarantor1CardExpYear: "",
|
||||||
|
guarantor1Salary: "",
|
||||||
|
};
|
||||||
|
|
||||||
export function buildPayload(data: LoanOrderMobileFormData) {
|
export function buildPayload(data: LoanOrderMobileFormData) {
|
||||||
return {
|
return {
|
||||||
status: data.status,
|
status: data.status,
|
||||||
loanType: data.loanType,
|
loanType: data.loanType,
|
||||||
region: data.region,
|
region: data.region,
|
||||||
branch: data.branch,
|
branch: data.branch,
|
||||||
firstName: data.firstName,
|
firstName: data.firstName,
|
||||||
lastName: data.lastName,
|
lastName: data.lastName,
|
||||||
patronicName: data.patronicName || undefined,
|
patronicName: data.patronicName || undefined,
|
||||||
education: data.education,
|
education: data.education,
|
||||||
marriageStatus: data.marriageStatus,
|
marriageStatus: data.marriageStatus,
|
||||||
dateOfBirth: data.dateOfBirth,
|
dateOfBirth: data.dateOfBirth,
|
||||||
residence: data.residence,
|
residence: data.residence,
|
||||||
currentResidence: data.currentResidence || undefined,
|
currentResidence: data.currentResidence || undefined,
|
||||||
passportSerie: data.passportSerie,
|
passportSerie: data.passportSerie,
|
||||||
passportNumber: data.passportNumber,
|
passportNumber: data.passportNumber,
|
||||||
passportDateOfIssue: data.passportDateOfIssue,
|
passportDateOfIssue: data.passportDateOfIssue,
|
||||||
passportGivenBy: data.passportGivenBy,
|
passportGivenBy: data.passportGivenBy,
|
||||||
bornPlace: data.bornPlace || undefined,
|
bornPlace: data.bornPlace || undefined,
|
||||||
email: data.email || undefined,
|
email: data.email || undefined,
|
||||||
phone: data.phone,
|
phone: data.phone,
|
||||||
phoneAdditional: data.phoneAdditional || undefined,
|
phoneAdditional: data.phoneAdditional || undefined,
|
||||||
homePhone: data.homePhone || undefined,
|
homePhone: data.homePhone || undefined,
|
||||||
workCompany: data.workCompany,
|
workCompany: data.workCompany,
|
||||||
workHrPhone: data.workHrPhone || undefined,
|
workHrPhone: data.workHrPhone || undefined,
|
||||||
workRegion: data.workRegion || undefined,
|
workRegion: data.workRegion || undefined,
|
||||||
workProvince: data.workProvince || undefined,
|
workProvince: data.workProvince || undefined,
|
||||||
position: data.position,
|
position: data.position,
|
||||||
salary: Number(data.salary),
|
salary: Number(data.salary),
|
||||||
workStartedAt: data.workStartedAt,
|
workStartedAt: data.workStartedAt,
|
||||||
note: data.note || undefined,
|
note: data.note || undefined,
|
||||||
loanAmount: Number(data.loanAmount) || undefined,
|
loanAmount: Number(data.loanAmount) || undefined,
|
||||||
loanHistory: data.loanHistory || undefined,
|
loanHistory: data.loanHistory || undefined,
|
||||||
cardNumber: data.cardNumber || undefined,
|
cardNumber: data.cardNumber || undefined,
|
||||||
cardName: data.cardName || undefined,
|
cardName: data.cardName || undefined,
|
||||||
cardExpMonth: data.cardExpMonth || undefined,
|
cardExpMonth: data.cardExpMonth || undefined,
|
||||||
cardExpYear: data.cardExpYear || undefined,
|
cardExpYear: data.cardExpYear || undefined,
|
||||||
guarantor1Name: data.guarantor1Name || undefined,
|
guarantor1Name: data.guarantor1Name || undefined,
|
||||||
guarantor1Surname: data.guarantor1Surname || undefined,
|
guarantor1Surname: data.guarantor1Surname || undefined,
|
||||||
guarantor1Patronic: data.guarantor1Patronic || undefined,
|
guarantor1Patronic: data.guarantor1Patronic || undefined,
|
||||||
guarantor1PassportSerie: data.guarantor1PassportSerie || undefined,
|
guarantor1PassportSerie: data.guarantor1PassportSerie || undefined,
|
||||||
guarantor1PassportNumber: data.guarantor1PassportNumber || undefined,
|
guarantor1PassportNumber: data.guarantor1PassportNumber || undefined,
|
||||||
guarantor1CardNumber: data.guarantor1CardNumber || undefined,
|
guarantor1CardNumber: data.guarantor1CardNumber || undefined,
|
||||||
guarantor1CardName: data.guarantor1CardName || undefined,
|
guarantor1CardName: data.guarantor1CardName || undefined,
|
||||||
guarantor1CardExpMonth: data.guarantor1CardExpMonth || undefined,
|
guarantor1CardExpMonth: data.guarantor1CardExpMonth || undefined,
|
||||||
guarantor1CardExpYear: data.guarantor1CardExpYear || undefined,
|
guarantor1CardExpYear: data.guarantor1CardExpYear || undefined,
|
||||||
guarantor1Salary: Number(data.guarantor1Salary) || undefined,
|
guarantor1Salary: Number(data.guarantor1Salary) || undefined,
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
File diff suppressed because it is too large.
Load diff
@@ -1,175 +1,297 @@
|
|||||||
import { z } from 'zod'
|
import { z } from "zod";
|
||||||
import i18next from 'i18next'
|
import i18next from "i18next";
|
||||||
|
|
||||||
const fileRequired = z.custom<File>((val) => val instanceof File, 'validation.requiredFile')
|
|
||||||
|
|
||||||
|
const fileRequired = z.custom<File>((val) => val instanceof File, "validation.requiredFile");
|
||||||
|
const VALID_PHONE_PREFIXES = ["61", "62", "63", "64", "65", "71"];
|
||||||
export const loanOrderFormSchema = z.object({
|
export const loanOrderFormSchema = z.object({
|
||||||
status: z.string().min(1, 'validation.required'),
|
status: z.string().min(1, "validation.required"),
|
||||||
loanType: z.string().min(1, 'validation.required'),
|
loanType: z.string().min(1, "validation.required"),
|
||||||
region: z.string().min(1, 'validation.required'),
|
region: z.string().min(1, "validation.required"),
|
||||||
branch: z.string().min(1, 'validation.required'),
|
branch: z.string().min(1, "validation.required"),
|
||||||
firstName: z.string().min(1, 'validation.required'),
|
firstName: z.string().min(1, "validation.required"),
|
||||||
lastName: z.string().min(1, 'validation.required'),
|
lastName: z.string().min(1, "validation.required"),
|
||||||
patronicName: z.string().optional(),
|
patronicName: z.string().optional(),
|
||||||
education: z.string().min(1, 'validation.required'),
|
education: z.string().min(1, "validation.required"),
|
||||||
marriageStatus: z.string().min(1, 'validation.required'),
|
marriageStatus: z.string().min(1, "validation.required"),
|
||||||
dateOfBirth: z.string().min(1, 'validation.required'),
|
dateOfBirth: z.string().min(1, "validation.required"),
|
||||||
residence: z.string().min(1, 'validation.required'),
|
residence: z.string().min(1, "validation.required"),
|
||||||
currentResidence: z.string().optional(),
|
currentResidence: z.string().optional(),
|
||||||
passportSerie: z.string().min(1, 'validation.required'),
|
passportSerie: z.string().min(1, "validation.required"),
|
||||||
passportNumber: z.string().min(1, 'validation.required'),
|
passportNumber: z.string().min(1, "validation.required"),
|
||||||
passportDateOfIssue: z.string().min(1, 'validation.required'),
|
passportDateOfIssue: z.string().min(1, "validation.required"),
|
||||||
passportGivenBy: z.string().min(1, 'validation.required'),
|
passportGivenBy: z.string().min(1, "validation.required"),
|
||||||
bornPlace: z.string().optional(),
|
bornPlace: z.string().optional(),
|
||||||
email: z.string().optional(),
|
email: z.string().optional(),
|
||||||
phone: z.string()
|
phone: z
|
||||||
.min(1, 'validation.required')
|
.string()
|
||||||
.refine((val) => val.replace(/\D/g, '').length >= 8, { message: 'validation.invalidPhone' }),
|
.min(1, "validation.required")
|
||||||
phoneAdditional: z.string().optional(),
|
.refine(
|
||||||
homePhone: z.string().optional(),
|
(val) => {
|
||||||
workCompany: z.string().min(1, 'validation.required'),
|
const digits = val.replace(/\D/g, "");
|
||||||
workHrPhone: z.string().optional(),
|
return digits.length === 8;
|
||||||
|
},
|
||||||
|
{ message: "validation.invalidPhone" },
|
||||||
|
)
|
||||||
|
.refine(
|
||||||
|
(val) => {
|
||||||
|
const digits = val.replace(/\D/g, "");
|
||||||
|
const prefix = digits.slice(0, 2);
|
||||||
|
return VALID_PHONE_PREFIXES.includes(prefix);
|
||||||
|
},
|
||||||
|
{ message: "validation.invalidPhonePrefix" },
|
||||||
|
),
|
||||||
|
phoneAdditional: z
|
||||||
|
.string()
|
||||||
|
.refine(
|
||||||
|
(val) => {
|
||||||
|
if (!val || val.replace(/\D/g, "").length === 0) return true;
|
||||||
|
const digits = val.replace(/\D/g, "");
|
||||||
|
return digits.length === 8;
|
||||||
|
},
|
||||||
|
{ message: "validation.invalidPhone" },
|
||||||
|
)
|
||||||
|
.refine(
|
||||||
|
(val) => {
|
||||||
|
if (!val || val.replace(/\D/g, "").length === 0) return true;
|
||||||
|
const digits = val.replace(/\D/g, "");
|
||||||
|
return VALID_PHONE_PREFIXES.includes(digits.slice(0, 2));
|
||||||
|
},
|
||||||
|
{ message: "validation.invalidPhonePrefix" },
|
||||||
|
)
|
||||||
|
.optional(),
|
||||||
|
|
||||||
|
homePhone: z
|
||||||
|
.string()
|
||||||
|
.refine(
|
||||||
|
(val) => {
|
||||||
|
if (!val || val.replace(/\D/g, "").length === 0) return true;
|
||||||
|
return val.replace(/\D/g, "").length === 8;
|
||||||
|
},
|
||||||
|
{ message: "validation.invalidPhone" },
|
||||||
|
)
|
||||||
|
.refine(
|
||||||
|
(val) => {
|
||||||
|
if (!val || val.replace(/\D/g, "").length === 0) return true;
|
||||||
|
return VALID_PHONE_PREFIXES.includes(val.replace(/\D/g, "").slice(0, 2));
|
||||||
|
},
|
||||||
|
{ message: "validation.invalidPhonePrefix" },
|
||||||
|
)
|
||||||
|
.optional(),
|
||||||
|
workCompany: z.string().min(1, "validation.required"),
|
||||||
|
workHrPhone: z
|
||||||
|
.string()
|
||||||
|
.refine(
|
||||||
|
(val) => {
|
||||||
|
if (!val || val.replace(/\D/g, "").length === 0) return true;
|
||||||
|
return val.replace(/\D/g, "").length === 8;
|
||||||
|
},
|
||||||
|
{ message: "validation.invalidPhone" },
|
||||||
|
)
|
||||||
|
.refine(
|
||||||
|
(val) => {
|
||||||
|
if (!val || val.replace(/\D/g, "").length === 0) return true;
|
||||||
|
return VALID_PHONE_PREFIXES.includes(val.replace(/\D/g, "").slice(0, 2));
|
||||||
|
},
|
||||||
|
{ message: "validation.invalidPhonePrefix" },
|
||||||
|
)
|
||||||
|
.optional(),
|
||||||
workRegion: z.string().optional(),
|
workRegion: z.string().optional(),
|
||||||
workProvince: z.string().optional(),
|
workProvince: z.string().optional(),
|
||||||
position: z.string().min(1, 'validation.required'),
|
position: z.string().min(1, "validation.required"),
|
||||||
salary: z.string().min(1, 'validation.required'),
|
salary: z.string().min(1, "validation.required"),
|
||||||
workStartedAt: z.string().min(1, 'validation.required'),
|
workStartedAt: z.string().min(1, "validation.required"),
|
||||||
passportPage1: z.custom<File | null>().nullable(),
|
passportPage1: z.custom<File | null>().nullable(),
|
||||||
passportPage23: z.custom<File | null>().nullable(),
|
passportPage23: z.custom<File | null>().nullable(),
|
||||||
passportPage89: z.custom<File | null>().nullable(),
|
passportPage89: z.custom<File | null>().nullable(),
|
||||||
passportPage32: z.custom<File | null>().nullable(),
|
passportPage32: z.custom<File | null>().nullable(),
|
||||||
note: z.string().optional(),
|
note: z.string().optional(),
|
||||||
loanAmount: z.string().min(1, 'validation.required'),
|
loanAmount: z.string().min(1, "validation.required"),
|
||||||
loanHistory: z.string().optional(),
|
loanHistory: z.string().optional(),
|
||||||
cardNumber: z.string().min(1, 'validation.required'),
|
cardNumber: z.string().min(1, "validation.required"),
|
||||||
cardName: z.string().min(1, 'validation.required'),
|
cardName: z.string().min(1, "validation.required"),
|
||||||
cardExpMonth: z.string().min(1, 'validation.required'),
|
cardExpMonth: z.string().min(1, "validation.required"),
|
||||||
cardExpYear: z.string().min(1, 'validation.required'),
|
cardExpYear: z.string().min(1, "validation.required"),
|
||||||
guarantor1Name: z.string().min(1, 'validation.required'),
|
guarantor1Name: z.string().min(1, "validation.required"),
|
||||||
guarantor1Surname: z.string().min(1, 'validation.required'),
|
guarantor1Surname: z.string().min(1, "validation.required"),
|
||||||
guarantor1Patronic: z.string().optional(),
|
guarantor1Patronic: z.string().optional(),
|
||||||
guarantor1PassportSerie: z.string().min(1, 'validation.required'),
|
guarantor1PassportSerie: z.string().min(1, "validation.required"),
|
||||||
guarantor1PassportNumber: z.string().min(1, 'validation.required'),
|
guarantor1PassportNumber: z.string().min(1, "validation.required"),
|
||||||
guarantor1CardNumber: z.string().min(1, 'validation.required'),
|
guarantor1CardNumber: z.string().min(1, "validation.required"),
|
||||||
guarantor1CardName: z.string().min(1, 'validation.required'),
|
guarantor1CardName: z.string().min(1, "validation.required"),
|
||||||
guarantor1CardExpMonth: z.string().min(1, 'validation.required'),
|
guarantor1CardExpMonth: z.string().min(1, "validation.required"),
|
||||||
guarantor1CardExpYear: z.string().min(1, 'validation.required'),
|
guarantor1CardExpYear: z.string().min(1, "validation.required"),
|
||||||
guarantor1Salary: z.string().min(1, 'validation.required'),
|
guarantor1Salary: z.string().min(1, "validation.required"),
|
||||||
})
|
});
|
||||||
|
|
||||||
export type LoanOrderFormData = z.infer<typeof loanOrderFormSchema>
|
export type LoanOrderFormData = z.infer<typeof loanOrderFormSchema>;
|
||||||
|
|
||||||
export const stepSchemas: Record<number, z.ZodType<Partial<LoanOrderFormData>>> = {
|
export const stepSchemas: Record<number, z.ZodType<Partial<LoanOrderFormData>>> = {
|
||||||
0: loanOrderFormSchema.pick({ status: true }),
|
0: loanOrderFormSchema.pick({ status: true }),
|
||||||
1: loanOrderFormSchema.pick({ loanType: true, loanAmount: true }),
|
1: loanOrderFormSchema.pick({ loanType: true, loanAmount: true }),
|
||||||
2: loanOrderFormSchema.pick({ region: true, branch: true }),
|
2: loanOrderFormSchema.pick({ region: true, branch: true }),
|
||||||
3: loanOrderFormSchema.pick({
|
3: loanOrderFormSchema.pick({
|
||||||
firstName: true, lastName: true, education: true,
|
firstName: true,
|
||||||
marriageStatus: true, dateOfBirth: true, residence: true,
|
lastName: true,
|
||||||
|
education: true,
|
||||||
|
marriageStatus: true,
|
||||||
|
dateOfBirth: true,
|
||||||
|
residence: true,
|
||||||
}),
|
}),
|
||||||
4: loanOrderFormSchema.pick({
|
4: loanOrderFormSchema.pick({
|
||||||
cardNumber: true, cardName: true, cardExpMonth: true, cardExpYear: true,
|
cardNumber: true,
|
||||||
|
cardName: true,
|
||||||
|
cardExpMonth: true,
|
||||||
|
cardExpYear: true,
|
||||||
}),
|
}),
|
||||||
5: loanOrderFormSchema.pick({
|
5: loanOrderFormSchema.pick({
|
||||||
passportSerie: true, passportNumber: true,
|
passportSerie: true,
|
||||||
passportDateOfIssue: true, passportGivenBy: true,
|
passportNumber: true,
|
||||||
|
passportDateOfIssue: true,
|
||||||
|
passportGivenBy: true,
|
||||||
}),
|
}),
|
||||||
6: loanOrderFormSchema.pick({ phone: true }),
|
6: loanOrderFormSchema.pick({ phone: true, phoneAdditional: true, homePhone: true }),
|
||||||
7: loanOrderFormSchema.pick({
|
7: loanOrderFormSchema.pick({
|
||||||
workCompany: true, position: true, salary: true, workStartedAt: true,
|
workCompany: true,
|
||||||
|
position: true,
|
||||||
|
salary: true,
|
||||||
|
workStartedAt: true,
|
||||||
|
workHrPhone: true,
|
||||||
}),
|
}),
|
||||||
8: z.object({
|
8: z.object({
|
||||||
passportPage1: fileRequired,
|
passportPage1: fileRequired,
|
||||||
passportPage23: fileRequired,
|
passportPage23: fileRequired,
|
||||||
}),
|
}),
|
||||||
9: loanOrderFormSchema.pick({
|
9: loanOrderFormSchema.pick({
|
||||||
guarantor1Name: true, guarantor1Surname: true,
|
guarantor1Name: true,
|
||||||
guarantor1PassportSerie: true, guarantor1PassportNumber: true,
|
guarantor1Surname: true,
|
||||||
guarantor1CardNumber: true, guarantor1CardName: true,
|
guarantor1PassportSerie: true,
|
||||||
guarantor1CardExpMonth: true, guarantor1CardExpYear: true,
|
guarantor1PassportNumber: true,
|
||||||
|
guarantor1CardNumber: true,
|
||||||
|
guarantor1CardName: true,
|
||||||
|
guarantor1CardExpMonth: true,
|
||||||
|
guarantor1CardExpYear: true,
|
||||||
guarantor1Salary: true,
|
guarantor1Salary: true,
|
||||||
}),
|
}),
|
||||||
}
|
};
|
||||||
|
|
||||||
export function validateStep(stepIndex: number, form: LoanOrderFormData, mode: 'create' | 'edit'): Partial<Record<keyof LoanOrderFormData, string>> {
|
export function validateStep(
|
||||||
if (stepIndex === 8 && mode === 'edit') return {}
|
stepIndex: number,
|
||||||
const schema = stepSchemas[stepIndex]
|
form: LoanOrderFormData,
|
||||||
const result = schema.safeParse(form)
|
mode: "create" | "edit",
|
||||||
if (result.success) return {}
|
): Partial<Record<keyof LoanOrderFormData, string>> {
|
||||||
const errors: Partial<Record<keyof LoanOrderFormData, string>> = {}
|
if (stepIndex === 8 && mode === "edit") return {};
|
||||||
|
const schema = stepSchemas[stepIndex];
|
||||||
|
const result = schema.safeParse(form);
|
||||||
|
if (result.success) return {};
|
||||||
|
const errors: Partial<Record<keyof LoanOrderFormData, string>> = {};
|
||||||
for (const issue of result.error.issues) {
|
for (const issue of result.error.issues) {
|
||||||
const key = issue.path[0] as keyof LoanOrderFormData
|
const key = issue.path[0] as keyof LoanOrderFormData;
|
||||||
if (!errors[key]) {
|
if (!errors[key]) {
|
||||||
const msg = issue.message
|
const msg = issue.message;
|
||||||
errors[key] = msg.startsWith('validation.') ? i18next.t(msg, msg) : msg
|
errors[key] = msg.startsWith("validation.") ? i18next.t(msg, msg) : msg;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return errors
|
return errors;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const DEFAULT_FORM_VALUES: LoanOrderFormData = {
|
export const DEFAULT_FORM_VALUES: LoanOrderFormData = {
|
||||||
status: 'GARAŞYLÝAR', loanType: '', region: 'Aşgabat', branch: '',
|
status: "GARAŞYLÝAR",
|
||||||
firstName: '', lastName: '', patronicName: '', education: '',
|
loanType: "",
|
||||||
marriageStatus: '', dateOfBirth: '', residence: '', currentResidence: '',
|
region: "Aşgabat",
|
||||||
passportSerie: '', passportNumber: '', passportDateOfIssue: '',
|
branch: "",
|
||||||
passportGivenBy: '', bornPlace: '', email: '', phone: '',
|
firstName: "",
|
||||||
phoneAdditional: '', homePhone: '', workCompany: '', workHrPhone: '',
|
lastName: "",
|
||||||
workRegion: 'Aşgabat', workProvince: '', position: '', salary: '',
|
patronicName: "",
|
||||||
workStartedAt: '', passportPage1: null, passportPage23: null,
|
education: "",
|
||||||
passportPage89: null, passportPage32: null, note: '', loanAmount: '',
|
marriageStatus: "",
|
||||||
loanHistory: '', cardNumber: '', cardName: '', cardExpMonth: '', cardExpYear: '',
|
dateOfBirth: "",
|
||||||
guarantor1Name: '', guarantor1Surname: '', guarantor1Patronic: '',
|
residence: "",
|
||||||
guarantor1PassportSerie: '', guarantor1PassportNumber: '',
|
currentResidence: "",
|
||||||
guarantor1CardNumber: '', guarantor1CardName: '',
|
passportSerie: "",
|
||||||
guarantor1CardExpMonth: '', guarantor1CardExpYear: '', guarantor1Salary: '',
|
passportNumber: "",
|
||||||
}
|
passportDateOfIssue: "",
|
||||||
|
passportGivenBy: "",
|
||||||
|
bornPlace: "",
|
||||||
|
email: "",
|
||||||
|
phone: "",
|
||||||
|
phoneAdditional: "",
|
||||||
|
homePhone: "",
|
||||||
|
workCompany: "",
|
||||||
|
workHrPhone: "",
|
||||||
|
workRegion: "Aşgabat",
|
||||||
|
workProvince: "",
|
||||||
|
position: "",
|
||||||
|
salary: "",
|
||||||
|
workStartedAt: "",
|
||||||
|
passportPage1: null,
|
||||||
|
passportPage23: null,
|
||||||
|
passportPage89: null,
|
||||||
|
passportPage32: null,
|
||||||
|
note: "",
|
||||||
|
loanAmount: "",
|
||||||
|
loanHistory: "",
|
||||||
|
cardNumber: "",
|
||||||
|
cardName: "",
|
||||||
|
cardExpMonth: "",
|
||||||
|
cardExpYear: "",
|
||||||
|
guarantor1Name: "",
|
||||||
|
guarantor1Surname: "",
|
||||||
|
guarantor1Patronic: "",
|
||||||
|
guarantor1PassportSerie: "",
|
||||||
|
guarantor1PassportNumber: "",
|
||||||
|
guarantor1CardNumber: "",
|
||||||
|
guarantor1CardName: "",
|
||||||
|
guarantor1CardExpMonth: "",
|
||||||
|
guarantor1CardExpYear: "",
|
||||||
|
guarantor1Salary: "",
|
||||||
|
};
|
||||||
|
|
||||||
export function buildPayload(data: LoanOrderFormData) {
|
export function buildPayload(data: LoanOrderFormData) {
|
||||||
return {
|
return {
|
||||||
status: data.status,
|
status: data.status,
|
||||||
loanType: data.loanType,
|
loanType: data.loanType,
|
||||||
region: data.region,
|
region: data.region,
|
||||||
branch: data.branch,
|
branch: data.branch,
|
||||||
firstName: data.firstName,
|
firstName: data.firstName,
|
||||||
lastName: data.lastName,
|
lastName: data.lastName,
|
||||||
patronicName: data.patronicName || undefined,
|
patronicName: data.patronicName || undefined,
|
||||||
education: data.education,
|
education: data.education,
|
||||||
marriageStatus: data.marriageStatus,
|
marriageStatus: data.marriageStatus,
|
||||||
dateOfBirth: data.dateOfBirth,
|
dateOfBirth: data.dateOfBirth,
|
||||||
residence: data.residence,
|
residence: data.residence,
|
||||||
currentResidence: data.currentResidence || undefined,
|
currentResidence: data.currentResidence || undefined,
|
||||||
passportSerie: data.passportSerie,
|
passportSerie: data.passportSerie,
|
||||||
passportNumber: data.passportNumber,
|
passportNumber: data.passportNumber,
|
||||||
passportDateOfIssue: data.passportDateOfIssue,
|
passportDateOfIssue: data.passportDateOfIssue,
|
||||||
passportGivenBy: data.passportGivenBy,
|
passportGivenBy: data.passportGivenBy,
|
||||||
bornPlace: data.bornPlace || undefined,
|
bornPlace: data.bornPlace || undefined,
|
||||||
email: data.email || undefined,
|
email: data.email || undefined,
|
||||||
phone: data.phone,
|
phone: data.phone,
|
||||||
phoneAdditional: data.phoneAdditional || undefined,
|
phoneAdditional: data.phoneAdditional || undefined,
|
||||||
homePhone: data.homePhone || undefined,
|
homePhone: data.homePhone || undefined,
|
||||||
workCompany: data.workCompany,
|
workCompany: data.workCompany,
|
||||||
workHrPhone: data.workHrPhone || undefined,
|
workHrPhone: data.workHrPhone || undefined,
|
||||||
workRegion: data.workRegion || undefined,
|
workRegion: data.workRegion || undefined,
|
||||||
workProvince: data.workProvince || undefined,
|
workProvince: data.workProvince || undefined,
|
||||||
position: data.position,
|
position: data.position,
|
||||||
salary: Number(data.salary),
|
salary: Number(data.salary),
|
||||||
workStartedAt: data.workStartedAt,
|
workStartedAt: data.workStartedAt,
|
||||||
note: data.note || undefined,
|
note: data.note || undefined,
|
||||||
loanAmount: Number(data.loanAmount) || undefined,
|
loanAmount: Number(data.loanAmount) || undefined,
|
||||||
loanHistory: data.loanHistory || undefined,
|
loanHistory: data.loanHistory || undefined,
|
||||||
cardNumber: data.cardNumber || undefined,
|
cardNumber: data.cardNumber || undefined,
|
||||||
cardName: data.cardName || undefined,
|
cardName: data.cardName || undefined,
|
||||||
cardExpMonth: data.cardExpMonth || undefined,
|
cardExpMonth: data.cardExpMonth || undefined,
|
||||||
cardExpYear: data.cardExpYear || undefined,
|
cardExpYear: data.cardExpYear || undefined,
|
||||||
guarantor1Name: data.guarantor1Name || undefined,
|
guarantor1Name: data.guarantor1Name || undefined,
|
||||||
guarantor1Surname: data.guarantor1Surname || undefined,
|
guarantor1Surname: data.guarantor1Surname || undefined,
|
||||||
guarantor1Patronic: data.guarantor1Patronic || undefined,
|
guarantor1Patronic: data.guarantor1Patronic || undefined,
|
||||||
guarantor1PassportSerie: data.guarantor1PassportSerie || undefined,
|
guarantor1PassportSerie: data.guarantor1PassportSerie || undefined,
|
||||||
guarantor1PassportNumber: data.guarantor1PassportNumber || undefined,
|
guarantor1PassportNumber: data.guarantor1PassportNumber || undefined,
|
||||||
guarantor1CardNumber: data.guarantor1CardNumber || undefined,
|
guarantor1CardNumber: data.guarantor1CardNumber || undefined,
|
||||||
guarantor1CardName: data.guarantor1CardName || undefined,
|
guarantor1CardName: data.guarantor1CardName || undefined,
|
||||||
guarantor1CardExpMonth: data.guarantor1CardExpMonth || undefined,
|
guarantor1CardExpMonth: data.guarantor1CardExpMonth || undefined,
|
||||||
guarantor1CardExpYear: data.guarantor1CardExpYear || undefined,
|
guarantor1CardExpYear: data.guarantor1CardExpYear || undefined,
|
||||||
guarantor1Salary: Number(data.guarantor1Salary) || undefined,
|
guarantor1Salary: Number(data.guarantor1Salary) || undefined,
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
@@ -1,238 +1,226 @@
|
|||||||
import { useMemo, useEffect, useCallback } from 'react'
|
import { useMemo, useEffect, useCallback } from "react";
|
||||||
import { useNavigate } from 'react-router-dom'
|
import { useNavigate } from "react-router-dom";
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from "react-i18next";
|
||||||
import { useForm } from 'react-hook-form'
|
import { useForm } from "react-hook-form";
|
||||||
import { zodResolver } from '@hookform/resolvers/zod'
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
import { Checkbox } from '@/components/ui/checkbox'
|
import { Checkbox } from "@/components/ui/checkbox";
|
||||||
import { FormActions } from '@/components/formActions'
|
import { FormActions } from "@/components/formActions";
|
||||||
import { FormInput } from '@/components/formInput'
|
import { FormInput } from "@/components/formInput";
|
||||||
import { useCreateOperator, useUpdateOperator } from '../hooks/useOperators'
|
import { useCreateOperator, useUpdateOperator } from "../hooks/useOperators";
|
||||||
import { operatorFormSchema, DEFAULT_FORM_VALUES, buildPayload } from '../schemas/operator.schema'
|
import { operatorFormSchema, DEFAULT_FORM_VALUES, buildPayload } from "../schemas/operator.schema";
|
||||||
import type { OperatorFormData } from '../schemas/operator.schema'
|
import type { OperatorFormData } from "../schemas/operator.schema";
|
||||||
import type { Operator } from '../api/operatorsApi'
|
import type { Operator } from "../api/operatorsApi";
|
||||||
|
|
||||||
// ─── Types ────────────────────────────────────────────────────────────────────
|
// ─── Types ────────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
interface OperatorFormProps {
|
interface OperatorFormProps {
|
||||||
mode: 'create' | 'edit'
|
mode: "create" | "edit";
|
||||||
initialData?: Operator
|
initialData?: Operator;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ─── Helpers ──────────────────────────────────────────────────────────────────
|
// ─── Helpers ──────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
type FlatErrors = Partial<Record<keyof OperatorFormData, string>>
|
type FlatErrors = Partial<Record<keyof OperatorFormData, string>>;
|
||||||
|
|
||||||
function flattenErrors(errors: Record<string, { message?: string } | undefined>): FlatErrors {
|
function flattenErrors(errors: Record<string, { message?: string } | undefined>): FlatErrors {
|
||||||
const result: FlatErrors = {}
|
const result: FlatErrors = {};
|
||||||
for (const key of Object.keys(errors)) {
|
for (const key of Object.keys(errors)) {
|
||||||
const msg = errors[key]?.message
|
const msg = errors[key]?.message;
|
||||||
if (msg) result[key as keyof OperatorFormData] = msg
|
if (msg) result[key as keyof OperatorFormData] = msg;
|
||||||
}
|
}
|
||||||
return result
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ─── OperatorForm ─────────────────────────────────────────────────────────────
|
// ─── OperatorForm ─────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
export function OperatorForm({ mode, initialData }: OperatorFormProps) {
|
export function OperatorForm({ mode, initialData }: OperatorFormProps) {
|
||||||
const { t: _t, i18n } = useTranslation()
|
const { t: _t, i18n } = useTranslation();
|
||||||
const t: (key: string, fallback?: string) => string = useCallback(
|
const t: (key: string, fallback?: string) => string = useCallback(
|
||||||
(key, fallback) => _t(key, fallback ?? key) as string,
|
(key, fallback) => _t(key, fallback ?? key) as string,
|
||||||
[_t, i18n.language],
|
[_t, i18n.language],
|
||||||
)
|
);
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate();
|
||||||
|
|
||||||
const createMutation = useCreateOperator()
|
const createMutation = useCreateOperator();
|
||||||
const updateMutation = useUpdateOperator(initialData?.id ?? 0)
|
const updateMutation = useUpdateOperator(initialData?.id ?? 0);
|
||||||
|
|
||||||
const isPending = createMutation.isPending || updateMutation.isPending
|
const isPending = createMutation.isPending || updateMutation.isPending;
|
||||||
|
|
||||||
const schema = useMemo(() => operatorFormSchema(mode, t), [mode, t, i18n.language])
|
const schema = useMemo(() => operatorFormSchema(mode, t), [mode, t, i18n.language]);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
watch, setValue, getValues, formState: { errors: rhfErrors }, clearErrors, trigger,
|
watch,
|
||||||
|
setValue,
|
||||||
|
getValues,
|
||||||
|
formState: { errors: rhfErrors },
|
||||||
|
clearErrors,
|
||||||
|
trigger,
|
||||||
} = useForm<OperatorFormData>({
|
} = useForm<OperatorFormData>({
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
resolver: zodResolver(schema as any),
|
resolver: zodResolver(schema as any),
|
||||||
defaultValues: initialData
|
defaultValues: initialData
|
||||||
? {
|
? {
|
||||||
...DEFAULT_FORM_VALUES,
|
...DEFAULT_FORM_VALUES,
|
||||||
username: initialData.username,
|
username: initialData.username,
|
||||||
name: initialData.name,
|
name: initialData.name,
|
||||||
phone: initialData.phone ?? '',
|
phone: initialData.phone ?? "",
|
||||||
email: initialData.email ?? '',
|
email: initialData.email ?? "",
|
||||||
password: '',
|
password: "",
|
||||||
isActive: initialData.isActive,
|
isActive: initialData.isActive,
|
||||||
}
|
}
|
||||||
: DEFAULT_FORM_VALUES,
|
: DEFAULT_FORM_VALUES,
|
||||||
})
|
});
|
||||||
|
|
||||||
const form = watch()
|
const form = watch();
|
||||||
const errors = useMemo(() => flattenErrors(rhfErrors as Record<string, { message?: string } | undefined>), [rhfErrors])
|
const errors = useMemo(() => flattenErrors(rhfErrors as Record<string, { message?: string } | undefined>), [rhfErrors]);
|
||||||
|
|
||||||
const setField = <K extends keyof OperatorFormData>(key: K, value: OperatorFormData[K]) => {
|
const setField = <K extends keyof OperatorFormData>(key: K, value: OperatorFormData[K]) => {
|
||||||
;(setValue as (name: K, val: OperatorFormData[K]) => void)(key, value)
|
(setValue as (name: K, val: OperatorFormData[K]) => void)(key, value);
|
||||||
clearErrors(key)
|
clearErrors(key);
|
||||||
}
|
};
|
||||||
|
|
||||||
// ── Re-validate on language change ──
|
// ── Re-validate on language change ──
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (Object.keys(rhfErrors).length > 0) {
|
if (Object.keys(rhfErrors).length > 0) {
|
||||||
trigger()
|
trigger();
|
||||||
}
|
}
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [i18n.language])
|
}, [i18n.language]);
|
||||||
|
|
||||||
// ── Submit ──────────────────────────────────────────────────────────────────
|
// ── Submit ──────────────────────────────────────────────────────────────────
|
||||||
const handleSubmit = async () => {
|
const handleSubmit = async () => {
|
||||||
const isValid = await trigger()
|
const isValid = await trigger();
|
||||||
if (!isValid) return
|
if (!isValid) return;
|
||||||
|
|
||||||
const data = getValues()
|
const data = getValues();
|
||||||
|
|
||||||
if (mode === 'create') {
|
if (mode === "create") {
|
||||||
const payload = buildPayload(data)
|
const payload = buildPayload(data);
|
||||||
createMutation.mutate(payload, {
|
createMutation.mutate(payload, {
|
||||||
onSuccess: () => navigate('/operators'),
|
onSuccess: () => navigate("/operators"),
|
||||||
})
|
});
|
||||||
} else {
|
} else {
|
||||||
updateMutation.mutate({
|
updateMutation.mutate(
|
||||||
username: data.username.trim(),
|
{
|
||||||
name: data.name.trim(),
|
username: data.username.trim(),
|
||||||
phone: data.phone.trim() || undefined,
|
name: data.name.trim(),
|
||||||
email: data.email.trim() || undefined,
|
phone: data.phone.trim() || undefined,
|
||||||
isActive: data.isActive,
|
email: data.email.trim() || undefined,
|
||||||
...(data.password.trim() ? { password: data.password } : {}),
|
isActive: data.isActive,
|
||||||
}, {
|
...(data.password.trim() ? { password: data.password } : {}),
|
||||||
onSuccess: () => navigate(`/operators/${initialData!.id}`),
|
},
|
||||||
})
|
{
|
||||||
|
onSuccess: () => navigate(`/operators/${initialData!.id}`),
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
// ── Render ──────────────────────────────────────────────────────────────────
|
// ── Render ──────────────────────────────────────────────────────────────────
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col gap-5">
|
<div className="flex flex-col gap-5">
|
||||||
<h1 className="text-xl font-semibold text-foreground">
|
<h1 className="text-xl font-semibold text-foreground">
|
||||||
{mode === 'create'
|
{mode === "create" ? t("operators.createTitle", "Operator dörediň") : t("operators.editTitle", "Operator üýtgetmek")}
|
||||||
? t('operators.createTitle', 'Operator dörediň')
|
|
||||||
: t('operators.editTitle', 'Operator üýtgetmek')}
|
|
||||||
</h1>
|
</h1>
|
||||||
<div className="bg-card border border-border rounded-xl overflow-hidden">
|
<div className="bg-card border border-border rounded-xl overflow-hidden">
|
||||||
{/* Username */}
|
{/* Username */}
|
||||||
<div className="grid grid-cols-[220px_1fr] items-start py-4 px-6 border-b border-border">
|
<div className="grid grid-cols-[220px_1fr] items-start py-4 px-6 border-b border-border">
|
||||||
<span className="text-sm text-muted-foreground pt-2">
|
<span className="text-xs font-bold text-muted-foreground pt-2">
|
||||||
{t('operators.fields.username', 'Ulanyjy ady')}
|
{t("operators.fields.username", "Ulanyjy ady")}
|
||||||
<span className="text-destructive ml-0.5">*</span>
|
<span className="text-destructive ml-0.5">*</span>
|
||||||
</span>
|
</span>
|
||||||
<FormInput
|
|
||||||
type="text"
|
|
||||||
value={form.username}
|
|
||||||
onChange={(v) => setField('username', v)}
|
|
||||||
placeholder={t('operators.fields.username', 'Ulanyjy ady')}
|
|
||||||
error={errors.username}
|
|
||||||
disabled={isPending}
|
|
||||||
className="max-w-lg"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Name */}
|
|
||||||
<div className="grid grid-cols-[220px_1fr] items-start py-4 px-6 border-b border-border">
|
|
||||||
<span className="text-sm text-muted-foreground pt-2">
|
|
||||||
{t('operators.fields.name', 'Ady')}
|
|
||||||
<span className="text-destructive ml-0.5">*</span>
|
|
||||||
</span>
|
|
||||||
<FormInput
|
|
||||||
type="text"
|
|
||||||
value={form.name}
|
|
||||||
onChange={(v) => setField('name', v)}
|
|
||||||
placeholder={t('operators.fields.name', 'Ady')}
|
|
||||||
error={errors.name}
|
|
||||||
disabled={isPending}
|
|
||||||
className="max-w-lg"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Phone */}
|
|
||||||
<div className="grid grid-cols-[220px_1fr] items-start py-4 px-6 border-b border-border">
|
|
||||||
<span className="text-sm text-muted-foreground pt-2">
|
|
||||||
{t('operators.fields.phone', 'Telefon')}
|
|
||||||
</span>
|
|
||||||
<FormInput
|
|
||||||
type="phone"
|
|
||||||
value={form.phone}
|
|
||||||
onChange={(v) => setField('phone', v)}
|
|
||||||
disabled={isPending}
|
|
||||||
className="max-w-lg"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Email */}
|
|
||||||
<div className="grid grid-cols-[220px_1fr] items-start py-4 px-6 border-b border-border">
|
|
||||||
<span className="text-sm text-muted-foreground pt-2">
|
|
||||||
{t('operators.fields.email', 'E-poçta')}
|
|
||||||
</span>
|
|
||||||
<FormInput
|
|
||||||
type="email"
|
|
||||||
value={form.email}
|
|
||||||
onChange={(v) => setField('email', v)}
|
|
||||||
placeholder={t('operators.fields.email', 'E-poçta')}
|
|
||||||
disabled={isPending}
|
|
||||||
className="max-w-lg"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Password */}
|
|
||||||
<div className="grid grid-cols-[220px_1fr] items-start py-4 px-6 border-b border-border">
|
|
||||||
<span className="text-sm text-muted-foreground pt-2">
|
|
||||||
{t('operators.fields.password', 'Açar sözi')}
|
|
||||||
{mode === 'create' && <span className="text-destructive ml-0.5">*</span>}
|
|
||||||
</span>
|
|
||||||
<div className="max-w-lg space-y-1">
|
|
||||||
<FormInput
|
<FormInput
|
||||||
type="password"
|
type="text"
|
||||||
value={form.password}
|
value={form.username}
|
||||||
onChange={(v) => setField('password', v)}
|
onChange={(v) => setField("username", v)}
|
||||||
placeholder={
|
placeholder={t("operators.fields.username", "Ulanyjy ady")}
|
||||||
mode === 'edit'
|
error={errors.username}
|
||||||
? t('operators.fields.passwordEditHint', 'Üýtgetmek üçin täze açar söz giriziň')
|
|
||||||
: t('operators.fields.password', 'Açar sözi')
|
|
||||||
}
|
|
||||||
error={errors.password}
|
|
||||||
disabled={isPending}
|
disabled={isPending}
|
||||||
|
className="max-w-lg"
|
||||||
/>
|
/>
|
||||||
{mode === 'edit' && (
|
|
||||||
<p className="text-xs text-muted-foreground">
|
|
||||||
{t(
|
|
||||||
'operators.fields.passwordEditNote',
|
|
||||||
'Boş goýsaňyz, açar sözi üýtgemez',
|
|
||||||
)}
|
|
||||||
</p>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* isActive */}
|
{/* Name */}
|
||||||
<div className="grid grid-cols-[220px_1fr] items-center py-4 px-6">
|
<div className="grid grid-cols-[220px_1fr] items-start py-4 px-6 border-b border-border">
|
||||||
<span className="text-sm text-muted-foreground">
|
<span className="text-sm text-muted-foreground pt-2">
|
||||||
{t('operators.fields.isActive', 'Işjeň')}
|
{t("operators.fields.name", "Ady")}
|
||||||
</span>
|
<span className="text-destructive ml-0.5">*</span>
|
||||||
<Checkbox
|
</span>
|
||||||
checked={form.isActive}
|
<FormInput
|
||||||
onCheckedChange={(v) => setField('isActive', !!v)}
|
type="text"
|
||||||
disabled={isPending}
|
value={form.name}
|
||||||
className="data-[state=checked]:bg-primary data-[state=checked]:border-primary"
|
onChange={(v) => setField("name", v)}
|
||||||
|
placeholder={t("operators.fields.name", "Ady")}
|
||||||
|
error={errors.name}
|
||||||
|
disabled={isPending}
|
||||||
|
className="max-w-lg"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Phone */}
|
||||||
|
<div className="grid grid-cols-[220px_1fr] items-start py-4 px-6 border-b border-border">
|
||||||
|
<span className="text-sm text-muted-foreground pt-2">{t("operators.fields.phone", "Telefon")}</span>
|
||||||
|
<FormInput type="phone" value={form.phone} onChange={(v) => setField("phone", v)} disabled={isPending} className="max-w-lg" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Email */}
|
||||||
|
<div className="grid grid-cols-[220px_1fr] items-start py-4 px-6 border-b border-border">
|
||||||
|
<span className="text-sm text-muted-foreground pt-2">{t("operators.fields.email", "E-poçta")}</span>
|
||||||
|
<FormInput
|
||||||
|
type="email"
|
||||||
|
value={form.email}
|
||||||
|
onChange={(v) => setField("email", v)}
|
||||||
|
placeholder={t("operators.fields.email", "E-poçta")}
|
||||||
|
disabled={isPending}
|
||||||
|
className="max-w-lg"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Password */}
|
||||||
|
<div className="grid grid-cols-[220px_1fr] items-start py-4 px-6 border-b border-border">
|
||||||
|
<span className="text-sm text-muted-foreground pt-2">
|
||||||
|
{t("operators.fields.password", "Açar sözi")}
|
||||||
|
{mode === "create" && <span className="text-destructive ml-0.5">*</span>}
|
||||||
|
</span>
|
||||||
|
<div className="max-w-lg space-y-1">
|
||||||
|
<FormInput
|
||||||
|
type="password"
|
||||||
|
value={form.password}
|
||||||
|
onChange={(v) => setField("password", v)}
|
||||||
|
placeholder={
|
||||||
|
mode === "edit"
|
||||||
|
? t("operators.fields.passwordEditHint", "Üýtgetmek üçin täze açar söz giriziň")
|
||||||
|
: t("operators.fields.password", "Açar sözi")
|
||||||
|
}
|
||||||
|
error={errors.password}
|
||||||
|
disabled={isPending}
|
||||||
|
/>
|
||||||
|
{mode === "edit" && (
|
||||||
|
<p className="text-xs text-muted-foreground">{t("operators.fields.passwordEditNote", "Boş goýsaňyz, açar sözi üýtgemez")}</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* isActive */}
|
||||||
|
<div className="grid grid-cols-[220px_1fr] items-center py-4 px-6">
|
||||||
|
<span className="text-sm text-muted-foreground">{t("operators.fields.isActive", "Işjeň")}</span>
|
||||||
|
<Checkbox
|
||||||
|
checked={form.isActive}
|
||||||
|
onCheckedChange={(v) => setField("isActive", !!v)}
|
||||||
|
disabled={isPending}
|
||||||
|
className="data-[state=checked]:bg-primary data-[state=checked]:border-primary"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<FormActions
|
||||||
|
isPending={isPending}
|
||||||
|
onSubmit={handleSubmit}
|
||||||
|
onCancel={() => navigate(-1)}
|
||||||
|
cancelVariant="ghost"
|
||||||
|
submitLabel={mode === "create" ? t("operators.createBtn", "Operator döredin") : t("operators.updateBtn", "Üýtgetmeleri sakla")}
|
||||||
|
className="px-6 py-4 border-t border-border bg-muted/20"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<FormActions
|
|
||||||
isPending={isPending}
|
|
||||||
onSubmit={handleSubmit}
|
|
||||||
onCancel={() => navigate(-1)}
|
|
||||||
cancelVariant="ghost"
|
|
||||||
submitLabel={mode === 'create'
|
|
||||||
? t('operators.createBtn', 'Operator döredin')
|
|
||||||
: t('operators.updateBtn', 'Üýtgetmeleri sakla')}
|
|
||||||
className="px-6 py-4 border-t border-border bg-muted/20"
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
);
|
||||||
)
|
|
||||||
}
|
}
|
||||||
@@ -1,36 +1,53 @@
|
|||||||
import { z } from 'zod'
|
import { z } from "zod";
|
||||||
import type { CreateOperatorPayload } from '../api/operatorsApi'
|
import type { CreateOperatorPayload } from "../api/operatorsApi";
|
||||||
|
|
||||||
export function operatorFormSchema(
|
const VALID_PHONE_PREFIXES = ["61", "62", "63", "64", "65", "71"];
|
||||||
mode: 'create' | 'edit',
|
|
||||||
t: (key: string, fallback?: string) => string,
|
export function operatorFormSchema(mode: "create" | "edit", t: (key: string, fallback?: string) => string) {
|
||||||
) {
|
|
||||||
const baseSchema = z.object({
|
const baseSchema = z.object({
|
||||||
username: z.string().min(1, t('validation.required', 'validation.required')),
|
username: z.string().min(1, t("validation.required", "validation.required")),
|
||||||
name: z.string().min(1, t('validation.required', 'validation.required')),
|
name: z.string().min(1, t("validation.required", "validation.required")),
|
||||||
phone: z.string().default(''),
|
phone: z
|
||||||
email: z.string().default(''),
|
.string()
|
||||||
|
.refine(
|
||||||
|
(val) => {
|
||||||
|
if (!val) return true;
|
||||||
|
const digits = val.replace(/\D/g, "");
|
||||||
|
return digits.length === 8;
|
||||||
|
},
|
||||||
|
{ message: "validation.invalidPhone" },
|
||||||
|
)
|
||||||
|
.refine(
|
||||||
|
(val) => {
|
||||||
|
if (!val) return true;
|
||||||
|
const digits = val.replace(/\D/g, "");
|
||||||
|
return VALID_PHONE_PREFIXES.includes(digits.slice(0, 2));
|
||||||
|
},
|
||||||
|
{ message: "validation.invalidPhonePrefix" },
|
||||||
|
)
|
||||||
|
.default(""),
|
||||||
|
email: z.string().default(""),
|
||||||
password: z.string(),
|
password: z.string(),
|
||||||
isActive: z.boolean(),
|
isActive: z.boolean(),
|
||||||
})
|
});
|
||||||
|
|
||||||
return mode === 'create'
|
return mode === "create"
|
||||||
? baseSchema.extend({
|
? baseSchema.extend({
|
||||||
password: z.string().min(1, t('validation.required', 'validation.required')),
|
password: z.string().min(1, t("validation.required", "validation.required")),
|
||||||
})
|
})
|
||||||
: baseSchema
|
: baseSchema;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type OperatorFormData = z.infer<ReturnType<typeof operatorFormSchema>>
|
export type OperatorFormData = z.infer<ReturnType<typeof operatorFormSchema>>;
|
||||||
|
|
||||||
export const DEFAULT_FORM_VALUES: OperatorFormData = {
|
export const DEFAULT_FORM_VALUES: OperatorFormData = {
|
||||||
username: '',
|
username: "",
|
||||||
name: '',
|
name: "",
|
||||||
phone: '',
|
phone: "",
|
||||||
email: '',
|
email: "",
|
||||||
password: '',
|
password: "",
|
||||||
isActive: true,
|
isActive: true,
|
||||||
}
|
};
|
||||||
|
|
||||||
export function buildPayload(data: OperatorFormData): CreateOperatorPayload {
|
export function buildPayload(data: OperatorFormData): CreateOperatorPayload {
|
||||||
return {
|
return {
|
||||||
@@ -40,5 +57,5 @@ export function buildPayload(data: OperatorFormData): CreateOperatorPayload {
|
|||||||
email: data.email.trim() || undefined,
|
email: data.email.trim() || undefined,
|
||||||
password: data.password,
|
password: data.password,
|
||||||
isActive: data.isActive,
|
isActive: data.isActive,
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
@@ -311,6 +311,7 @@ function StepPersonal({
|
|||||||
label={t("Phone Additional") || "Telefon goşmaça"}
|
label={t("Phone Additional") || "Telefon goşmaça"}
|
||||||
value={form.phoneExtra}
|
value={form.phoneExtra}
|
||||||
onChange={(v) => set("phoneExtra", v)}
|
onChange={(v) => set("phoneExtra", v)}
|
||||||
|
error={errors.phoneExtra}
|
||||||
/>
|
/>
|
||||||
</BentoCard>
|
</BentoCard>
|
||||||
<BentoCard>
|
<BentoCard>
|
||||||
|
|||||||
@@ -1,113 +1,163 @@
|
|||||||
import { z } from 'zod'
|
import { z } from "zod";
|
||||||
import i18next from 'i18next'
|
import i18next from "i18next";
|
||||||
import type { CardOrderStatus } from '../api/orderNewCardApi'
|
import type { CardOrderStatus } from "../api/orderNewCardApi";
|
||||||
|
|
||||||
const fileRequired = z.custom<File>((val) => val instanceof File, 'validation.requiredFile')
|
const fileRequired = z.custom<File>((val) => val instanceof File, "validation.requiredFile");
|
||||||
|
const VALID_PHONE_PREFIXES = ["61", "62", "63", "64", "65", "71"];
|
||||||
|
|
||||||
export const orderNewCardFormSchema = z.object({
|
export const orderNewCardFormSchema = z.object({
|
||||||
isPaid: z.boolean(),
|
isPaid: z.boolean(),
|
||||||
status: z.string().min(1, 'validation.required'),
|
status: z.string().min(1, "validation.required"),
|
||||||
note: z.string().optional(),
|
note: z.string().optional(),
|
||||||
issuanceReasonId: z.string().min(1, 'validation.required'),
|
issuanceReasonId: z.string().min(1, "validation.required"),
|
||||||
cardTypeId: z.string().min(1, 'validation.required'),
|
cardTypeId: z.string().min(1, "validation.required"),
|
||||||
provinceId: z.string().min(1, 'validation.required'),
|
provinceId: z.string().min(1, "validation.required"),
|
||||||
branchId: z.string().min(1, 'validation.required'),
|
branchId: z.string().min(1, "validation.required"),
|
||||||
firstName: z.string().min(1, 'validation.required'),
|
firstName: z.string().min(1, "validation.required"),
|
||||||
lastName: z.string().min(1, 'validation.required'),
|
lastName: z.string().min(1, "validation.required"),
|
||||||
middleName: z.string().optional(),
|
middleName: z.string().optional(),
|
||||||
formerLastName: z.string().optional(),
|
formerLastName: z.string().optional(),
|
||||||
birthDate: z.string().min(1, 'validation.required'),
|
birthDate: z.string().min(1, "validation.required"),
|
||||||
phone: z.string().min(1, 'validation.required'),
|
phone: z
|
||||||
phoneExtra: z.string().optional(),
|
.string()
|
||||||
citizenship: z.string().min(1, 'validation.required'),
|
.min(1, "validation.required")
|
||||||
registeredAddress: z.string().min(1, 'validation.required'),
|
.refine(
|
||||||
currentAddress: z.string().min(1, 'validation.required'),
|
(val) => {
|
||||||
workplace: z.string().min(1, 'validation.required'),
|
const digits = val.replace(/\D/g, "");
|
||||||
passportSeriesId: z.string().min(1, 'validation.required'),
|
return digits.length === 8;
|
||||||
passportNumber: z.string().min(1, 'validation.required'),
|
},
|
||||||
passportIssueDate: z.string().min(1, 'validation.required'),
|
{ message: "validation.invalidPhone" },
|
||||||
passportIssuedBy: z.string().min(1, 'validation.required'),
|
)
|
||||||
passportBirthPlace: z.string().min(1, 'validation.required'),
|
.refine(
|
||||||
|
(val) => {
|
||||||
|
const digits = val.replace(/\D/g, "");
|
||||||
|
const prefix = digits.slice(0, 2);
|
||||||
|
return VALID_PHONE_PREFIXES.includes(prefix);
|
||||||
|
},
|
||||||
|
{ message: "validation.invalidPhonePrefix" },
|
||||||
|
),
|
||||||
|
phoneExtra: z
|
||||||
|
.string()
|
||||||
|
.refine(
|
||||||
|
(val) => {
|
||||||
|
if (!val || val.replace(/\D/g, "").length === 0) return true;
|
||||||
|
const digits = val.replace(/\D/g, "");
|
||||||
|
return digits.length === 8;
|
||||||
|
},
|
||||||
|
{ message: "validation.invalidPhone" },
|
||||||
|
)
|
||||||
|
.refine(
|
||||||
|
(val) => {
|
||||||
|
if (!val || val.replace(/\D/g, "").length === 0) return true;
|
||||||
|
const digits = val.replace(/\D/g, "");
|
||||||
|
return VALID_PHONE_PREFIXES.includes(digits.slice(0, 2));
|
||||||
|
},
|
||||||
|
{ message: "validation.invalidPhonePrefix" },
|
||||||
|
)
|
||||||
|
.optional(),
|
||||||
|
citizenship: z.string().min(1, "validation.required"),
|
||||||
|
registeredAddress: z.string().min(1, "validation.required"),
|
||||||
|
currentAddress: z.string().min(1, "validation.required"),
|
||||||
|
workplace: z.string().min(1, "validation.required"),
|
||||||
|
passportSeriesId: z.string().min(1, "validation.required"),
|
||||||
|
passportNumber: z.string().min(1, "validation.required"),
|
||||||
|
passportIssueDate: z.string().min(1, "validation.required"),
|
||||||
|
passportIssuedBy: z.string().min(1, "validation.required"),
|
||||||
|
passportBirthPlace: z.string().min(1, "validation.required"),
|
||||||
passportPage1: z.custom<File | null>().nullable(),
|
passportPage1: z.custom<File | null>().nullable(),
|
||||||
passportPage23: z.custom<File | null>().nullable(),
|
passportPage23: z.custom<File | null>().nullable(),
|
||||||
passportPage89: z.custom<File | null>().nullable(),
|
passportPage89: z.custom<File | null>().nullable(),
|
||||||
passportPage32: z.custom<File | null>().nullable(),
|
passportPage32: z.custom<File | null>().nullable(),
|
||||||
termsAccepted: z.boolean(),
|
termsAccepted: z.boolean(),
|
||||||
})
|
});
|
||||||
|
|
||||||
export type OrderNewCardFormData = z.infer<typeof orderNewCardFormSchema>
|
export type OrderNewCardFormData = z.infer<typeof orderNewCardFormSchema>;
|
||||||
|
|
||||||
export const stepSchemas: Record<number, z.ZodType<Partial<OrderNewCardFormData>>> = {
|
export const stepSchemas: Record<number, z.ZodType<Partial<OrderNewCardFormData>>> = {
|
||||||
0: orderNewCardFormSchema.pick({
|
0: orderNewCardFormSchema.pick({
|
||||||
status: true, issuanceReasonId: true, cardTypeId: true, provinceId: true, branchId: true,
|
status: true,
|
||||||
|
issuanceReasonId: true,
|
||||||
|
cardTypeId: true,
|
||||||
|
provinceId: true,
|
||||||
|
branchId: true,
|
||||||
}),
|
}),
|
||||||
1: orderNewCardFormSchema.pick({
|
1: orderNewCardFormSchema.pick({
|
||||||
firstName: true, lastName: true, birthDate: true, phone: true, citizenship: true,
|
firstName: true,
|
||||||
registeredAddress: true, currentAddress: true, workplace: true,
|
lastName: true,
|
||||||
|
birthDate: true,
|
||||||
|
phone: true,
|
||||||
|
phoneExtra: true,
|
||||||
|
citizenship: true,
|
||||||
|
registeredAddress: true,
|
||||||
|
currentAddress: true,
|
||||||
|
workplace: true,
|
||||||
}),
|
}),
|
||||||
2: orderNewCardFormSchema.pick({
|
2: orderNewCardFormSchema.pick({
|
||||||
passportSeriesId: true, passportNumber: true, passportIssueDate: true,
|
passportSeriesId: true,
|
||||||
passportIssuedBy: true, passportBirthPlace: true,
|
passportNumber: true,
|
||||||
|
passportIssueDate: true,
|
||||||
|
passportIssuedBy: true,
|
||||||
|
passportBirthPlace: true,
|
||||||
}),
|
}),
|
||||||
3: z.object({
|
3: z.object({
|
||||||
passportPage1: fileRequired,
|
passportPage1: fileRequired,
|
||||||
passportPage23: fileRequired,
|
passportPage23: fileRequired,
|
||||||
passportPage89: fileRequired,
|
passportPage89: fileRequired,
|
||||||
passportPage32: fileRequired,
|
passportPage32: fileRequired,
|
||||||
termsAccepted: z.literal(true, { message: 'validation.requiredTerms' }),
|
termsAccepted: z.literal(true, { message: "validation.requiredTerms" }),
|
||||||
}),
|
}),
|
||||||
}
|
};
|
||||||
|
|
||||||
export function validateStep(
|
export function validateStep(
|
||||||
stepIndex: number,
|
stepIndex: number,
|
||||||
form: OrderNewCardFormData,
|
form: OrderNewCardFormData,
|
||||||
mode: 'create' | 'edit',
|
mode: "create" | "edit",
|
||||||
): Partial<Record<keyof OrderNewCardFormData, string>> {
|
): Partial<Record<keyof OrderNewCardFormData, string>> {
|
||||||
if (stepIndex === 3 && mode === 'edit') return {}
|
if (stepIndex === 3 && mode === "edit") return {};
|
||||||
const schema = stepSchemas[stepIndex]
|
const schema = stepSchemas[stepIndex];
|
||||||
const result = schema.safeParse(form)
|
const result = schema.safeParse(form);
|
||||||
if (result.success) return {}
|
if (result.success) return {};
|
||||||
const errors: Partial<Record<keyof OrderNewCardFormData, string>> = {}
|
const errors: Partial<Record<keyof OrderNewCardFormData, string>> = {};
|
||||||
for (const issue of result.error.issues) {
|
for (const issue of result.error.issues) {
|
||||||
const key = issue.path[0] as keyof OrderNewCardFormData
|
const key = issue.path[0] as keyof OrderNewCardFormData;
|
||||||
if (!errors[key]) {
|
if (!errors[key]) {
|
||||||
const msg = issue.message
|
const msg = issue.message;
|
||||||
errors[key] = msg.startsWith('validation.') ? i18next.t(msg, msg) : msg
|
errors[key] = msg.startsWith("validation.") ? i18next.t(msg, msg) : msg;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return errors
|
return errors;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const DEFAULT_FORM_VALUES: OrderNewCardFormData = {
|
export const DEFAULT_FORM_VALUES: OrderNewCardFormData = {
|
||||||
isPaid: false,
|
isPaid: false,
|
||||||
status: '',
|
status: "",
|
||||||
note: '',
|
note: "",
|
||||||
issuanceReasonId: '',
|
issuanceReasonId: "",
|
||||||
cardTypeId: '',
|
cardTypeId: "",
|
||||||
provinceId: '',
|
provinceId: "",
|
||||||
branchId: '',
|
branchId: "",
|
||||||
firstName: '',
|
firstName: "",
|
||||||
lastName: '',
|
lastName: "",
|
||||||
middleName: '',
|
middleName: "",
|
||||||
formerLastName: '',
|
formerLastName: "",
|
||||||
birthDate: '',
|
birthDate: "",
|
||||||
phone: '',
|
phone: "",
|
||||||
phoneExtra: '',
|
phoneExtra: "",
|
||||||
citizenship: 'Turkmenistan',
|
citizenship: "Turkmenistan",
|
||||||
registeredAddress: '',
|
registeredAddress: "",
|
||||||
currentAddress: '',
|
currentAddress: "",
|
||||||
workplace: '',
|
workplace: "",
|
||||||
passportSeriesId: '',
|
passportSeriesId: "",
|
||||||
passportNumber: '',
|
passportNumber: "",
|
||||||
passportIssueDate: '',
|
passportIssueDate: "",
|
||||||
passportIssuedBy: '',
|
passportIssuedBy: "",
|
||||||
passportBirthPlace: '',
|
passportBirthPlace: "",
|
||||||
passportPage1: null,
|
passportPage1: null,
|
||||||
passportPage23: null,
|
passportPage23: null,
|
||||||
passportPage89: null,
|
passportPage89: null,
|
||||||
passportPage32: null,
|
passportPage32: null,
|
||||||
termsAccepted: false,
|
termsAccepted: false,
|
||||||
}
|
};
|
||||||
|
|
||||||
export function buildPayload(data: OrderNewCardFormData) {
|
export function buildPayload(data: OrderNewCardFormData) {
|
||||||
return {
|
return {
|
||||||
@@ -134,9 +184,9 @@ export function buildPayload(data: OrderNewCardFormData) {
|
|||||||
passportIssueDate: data.passportIssueDate,
|
passportIssueDate: data.passportIssueDate,
|
||||||
passportIssuedBy: data.passportIssuedBy,
|
passportIssuedBy: data.passportIssuedBy,
|
||||||
passportBirthPlace: data.passportBirthPlace,
|
passportBirthPlace: data.passportBirthPlace,
|
||||||
...(data.passportPage1 && { passportPage1: data.passportPage1 }),
|
...(data.passportPage1 && { passportPage1: data.passportPage1 }),
|
||||||
...(data.passportPage23 && { passportPage23: data.passportPage23 }),
|
...(data.passportPage23 && { passportPage23: data.passportPage23 }),
|
||||||
...(data.passportPage89 && { passportPage89: data.passportPage89 }),
|
...(data.passportPage89 && { passportPage89: data.passportPage89 }),
|
||||||
...(data.passportPage32 && { passportPage32: data.passportPage32 }),
|
...(data.passportPage32 && { passportPage32: data.passportPage32 }),
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
@@ -1,22 +1,40 @@
|
|||||||
import { z } from 'zod'
|
import { z } from "zod";
|
||||||
import type { CreateSberPaymentPayload, PaymentStatus } from '@/features/sberPayments/api/sberPaymentsApi'
|
import type { CreateSberPaymentPayload, PaymentStatus } from "@/features/sberPayments/api/sberPaymentsApi";
|
||||||
|
|
||||||
const fileField = z.custom<File | null>((val) => val === null || val instanceof File).nullable()
|
const fileField = z.custom<File | null>((val) => val === null || val instanceof File).nullable();
|
||||||
|
const VALID_PHONE_PREFIXES = ["61", "62", "63", "64", "65", "71"];
|
||||||
|
|
||||||
export const sberPaymentFormSchema = z.object({
|
export const sberPaymentFormSchema = z.object({
|
||||||
welayat: z.string().min(1, 'validation.required'),
|
welayat: z.string().min(1, "validation.required"),
|
||||||
sahamca: z.string().min(1, 'validation.required'),
|
sahamca: z.string().min(1, "validation.required"),
|
||||||
firstName: z.string().min(1, 'validation.required'),
|
firstName: z.string().min(1, "validation.required"),
|
||||||
lastName: z.string().min(1, 'validation.required'),
|
lastName: z.string().min(1, "validation.required"),
|
||||||
phone: z.string().min(1, 'validation.required'),
|
phone: z
|
||||||
|
.string()
|
||||||
|
.min(1, "validation.required")
|
||||||
|
.refine(
|
||||||
|
(val) => {
|
||||||
|
const digits = val.replace(/\D/g, "");
|
||||||
|
return digits.length === 8;
|
||||||
|
},
|
||||||
|
{ message: "validation.invalidPhone" },
|
||||||
|
)
|
||||||
|
.refine(
|
||||||
|
(val) => {
|
||||||
|
const digits = val.replace(/\D/g, "");
|
||||||
|
const prefix = digits.slice(0, 2);
|
||||||
|
return VALID_PHONE_PREFIXES.includes(prefix);
|
||||||
|
},
|
||||||
|
{ message: "validation.invalidPhonePrefix" },
|
||||||
|
),
|
||||||
email: z.string(),
|
email: z.string(),
|
||||||
address: z.string().min(1, 'validation.required'),
|
address: z.string().min(1, "validation.required"),
|
||||||
status: z.string().min(1, 'validation.required'),
|
status: z.string().min(1, "validation.required"),
|
||||||
bellik: z.string(),
|
bellik: z.string(),
|
||||||
accountNumber: z.string().min(1, 'validation.required'),
|
accountNumber: z.string().min(1, "validation.required"),
|
||||||
passportSeries: z.string().min(1, 'validation.required'),
|
passportSeries: z.string().min(1, "validation.required"),
|
||||||
passportNumber: z.string().min(1, 'validation.required'),
|
passportNumber: z.string().min(1, "validation.required"),
|
||||||
fullName: z.string().min(1, 'validation.required'),
|
fullName: z.string().min(1, "validation.required"),
|
||||||
client_id: z.string().optional(),
|
client_id: z.string().optional(),
|
||||||
acc_sberbank_card: fileField,
|
acc_sberbank_card: fileField,
|
||||||
acc_enrollment: fileField,
|
acc_enrollment: fileField,
|
||||||
@@ -32,54 +50,54 @@ export const sberPaymentFormSchema = z.object({
|
|||||||
snt_relation_doc: fileField,
|
snt_relation_doc: fileField,
|
||||||
snt_new_passport_series: fileField,
|
snt_new_passport_series: fileField,
|
||||||
snt_old_passport_series: fileField,
|
snt_old_passport_series: fileField,
|
||||||
})
|
});
|
||||||
|
|
||||||
export type SberPaymentFormData = z.infer<typeof sberPaymentFormSchema>
|
export type SberPaymentFormData = z.infer<typeof sberPaymentFormSchema>;
|
||||||
|
|
||||||
export const stepSchemas: Record<number, z.ZodType<Partial<SberPaymentFormData>>> = {
|
export const stepSchemas: Record<number, z.ZodType<Partial<SberPaymentFormData>>> = {
|
||||||
0: sberPaymentFormSchema.pick({ status: true }),
|
0: sberPaymentFormSchema.pick({ status: true }),
|
||||||
1: sberPaymentFormSchema.pick({ welayat: true, sahamca: true }),
|
1: sberPaymentFormSchema.pick({ welayat: true, sahamca: true }),
|
||||||
2: sberPaymentFormSchema.pick({ firstName: true, lastName: true, phone: true, address: true }),
|
2: sberPaymentFormSchema.pick({ firstName: true, lastName: true, phone: true, address: true }),
|
||||||
3: sberPaymentFormSchema.pick({ passportSeries: true, passportNumber: true, fullName: true, accountNumber: true }),
|
3: sberPaymentFormSchema.pick({ passportSeries: true, passportNumber: true, fullName: true, accountNumber: true }),
|
||||||
}
|
};
|
||||||
|
|
||||||
export function validateStep(
|
export function validateStep(
|
||||||
stepIndex: number,
|
stepIndex: number,
|
||||||
form: SberPaymentFormData,
|
form: SberPaymentFormData,
|
||||||
mode: 'create' | 'edit',
|
mode: "create" | "edit",
|
||||||
t?: (key: string, fallback?: string) => string,
|
t?: (key: string, fallback?: string) => string,
|
||||||
): Partial<Record<keyof SberPaymentFormData, string>> {
|
): Partial<Record<keyof SberPaymentFormData, string>> {
|
||||||
void mode
|
void mode;
|
||||||
const schema = stepSchemas[stepIndex]
|
const schema = stepSchemas[stepIndex];
|
||||||
if (!schema) return {}
|
if (!schema) return {};
|
||||||
const result = schema.safeParse(form)
|
const result = schema.safeParse(form);
|
||||||
if (result.success) return {}
|
if (result.success) return {};
|
||||||
const errors: Partial<Record<keyof SberPaymentFormData, string>> = {}
|
const errors: Partial<Record<keyof SberPaymentFormData, string>> = {};
|
||||||
for (const issue of result.error.issues) {
|
for (const issue of result.error.issues) {
|
||||||
const key = issue.path[0] as keyof SberPaymentFormData
|
const key = issue.path[0] as keyof SberPaymentFormData;
|
||||||
if (!errors[key]) {
|
if (!errors[key]) {
|
||||||
const msg = issue.message
|
const msg = issue.message;
|
||||||
errors[key] = t && msg.startsWith('validation.') ? t(msg, msg) : msg
|
errors[key] = t && msg.startsWith("validation.") ? t(msg, msg) : msg;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return errors
|
return errors;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const DEFAULT_FORM_VALUES: SberPaymentFormData = {
|
export const DEFAULT_FORM_VALUES: SberPaymentFormData = {
|
||||||
client_id: '',
|
client_id: "",
|
||||||
welayat: '',
|
welayat: "",
|
||||||
sahamca: '',
|
sahamca: "",
|
||||||
firstName: '',
|
firstName: "",
|
||||||
lastName: '',
|
lastName: "",
|
||||||
phone: '',
|
phone: "",
|
||||||
email: '',
|
email: "",
|
||||||
address: '',
|
address: "",
|
||||||
status: 'GARASYLYYAR',
|
status: "GARASYLYYAR",
|
||||||
bellik: '',
|
bellik: "",
|
||||||
accountNumber: '',
|
accountNumber: "",
|
||||||
passportSeries: '',
|
passportSeries: "",
|
||||||
passportNumber: '',
|
passportNumber: "",
|
||||||
fullName: '',
|
fullName: "",
|
||||||
acc_sberbank_card: null,
|
acc_sberbank_card: null,
|
||||||
acc_enrollment: null,
|
acc_enrollment: null,
|
||||||
acc_summons: null,
|
acc_summons: null,
|
||||||
@@ -94,7 +112,7 @@ export const DEFAULT_FORM_VALUES: SberPaymentFormData = {
|
|||||||
snt_relation_doc: null,
|
snt_relation_doc: null,
|
||||||
snt_new_passport_series: null,
|
snt_new_passport_series: null,
|
||||||
snt_old_passport_series: null,
|
snt_old_passport_series: null,
|
||||||
}
|
};
|
||||||
|
|
||||||
export function buildPayload(data: SberPaymentFormData): CreateSberPaymentPayload {
|
export function buildPayload(data: SberPaymentFormData): CreateSberPaymentPayload {
|
||||||
return {
|
return {
|
||||||
@@ -111,5 +129,5 @@ export function buildPayload(data: SberPaymentFormData): CreateSberPaymentPayloa
|
|||||||
passportSeries: data.passportSeries,
|
passportSeries: data.passportSeries,
|
||||||
passportNumber: data.passportNumber,
|
passportNumber: data.passportNumber,
|
||||||
fullName: data.fullName,
|
fullName: data.fullName,
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
@@ -1,26 +1,44 @@
|
|||||||
import { z } from 'zod'
|
import { z } from "zod";
|
||||||
import i18next from 'i18next'
|
import i18next from "i18next";
|
||||||
import type { IntlPaymentCreatePayload, IntlPaymentStatus, CurrencyType } from '../api/visaMasterPaymentsApi'
|
import type { IntlPaymentCreatePayload, IntlPaymentStatus, CurrencyType } from "../api/visaMasterPaymentsApi";
|
||||||
|
|
||||||
const fileField = z.custom<File | null>().nullable()
|
const fileField = z.custom<File | null>().nullable();
|
||||||
|
const VALID_PHONE_PREFIXES = ["61", "62", "63", "64", "65", "71"];
|
||||||
|
|
||||||
export const visaMasterPaymentFormSchema = z.object({
|
export const visaMasterPaymentFormSchema = z.object({
|
||||||
client_id: z.string().min(1, 'validation.required'),
|
client_id: z.string().min(1, "validation.required"),
|
||||||
status: z.string().min(1, 'validation.required'),
|
status: z.string().min(1, "validation.required"),
|
||||||
note: z.string().optional().default(''),
|
note: z.string().optional().default(""),
|
||||||
currency_type: z.string().min(1, 'validation.required'),
|
currency_type: z.string().min(1, "validation.required"),
|
||||||
province: z.string().min(1, 'validation.required'),
|
province: z.string().min(1, "validation.required"),
|
||||||
branch: z.string().min(1, 'validation.required'),
|
branch: z.string().min(1, "validation.required"),
|
||||||
passport_first_name: z.string().min(1, 'validation.required'),
|
passport_first_name: z.string().min(1, "validation.required"),
|
||||||
passport_last_name: z.string().min(1, 'validation.required'),
|
passport_last_name: z.string().min(1, "validation.required"),
|
||||||
phone: z.string().min(1, 'validation.required'),
|
phone: z
|
||||||
email: z.string().optional().default(''),
|
.string()
|
||||||
home_address: z.string().optional().default(''),
|
.min(1, "validation.required")
|
||||||
passport_series: z.string().min(1, 'validation.required'),
|
.refine(
|
||||||
passport_number: z.string().min(1, 'validation.required'),
|
(val) => {
|
||||||
payer_full_name: z.string().min(1, 'validation.required'),
|
const digits = val.replace(/\D/g, "");
|
||||||
payer_account_number: z.string().min(1, 'validation.required'),
|
return digits.length === 8;
|
||||||
receiver_info: z.string().min(1, 'validation.required'),
|
},
|
||||||
|
{ message: "validation.invalidPhone" },
|
||||||
|
)
|
||||||
|
.refine(
|
||||||
|
(val) => {
|
||||||
|
const digits = val.replace(/\D/g, "");
|
||||||
|
const prefix = digits.slice(0, 2);
|
||||||
|
return VALID_PHONE_PREFIXES.includes(prefix);
|
||||||
|
},
|
||||||
|
{ message: "validation.invalidPhonePrefix" },
|
||||||
|
),
|
||||||
|
email: z.string().optional().default(""),
|
||||||
|
home_address: z.string().optional().default(""),
|
||||||
|
passport_series: z.string().min(1, "validation.required"),
|
||||||
|
passport_number: z.string().min(1, "validation.required"),
|
||||||
|
payer_full_name: z.string().min(1, "validation.required"),
|
||||||
|
payer_account_number: z.string().min(1, "validation.required"),
|
||||||
|
receiver_info: z.string().min(1, "validation.required"),
|
||||||
doc_sberbank_account: fileField,
|
doc_sberbank_account: fileField,
|
||||||
doc_school_enrollment: fileField,
|
doc_school_enrollment: fileField,
|
||||||
doc_summons: fileField,
|
doc_summons: fileField,
|
||||||
@@ -36,62 +54,82 @@ export const visaMasterPaymentFormSchema = z.object({
|
|||||||
upd_doc_acceptance_letter: fileField,
|
upd_doc_acceptance_letter: fileField,
|
||||||
upd_doc_passport_biometric: fileField,
|
upd_doc_passport_biometric: fileField,
|
||||||
upd_doc_passport_old: fileField,
|
upd_doc_passport_old: fileField,
|
||||||
})
|
});
|
||||||
|
|
||||||
export type IntlPaymentFormData = z.infer<typeof visaMasterPaymentFormSchema>
|
export type IntlPaymentFormData = z.infer<typeof visaMasterPaymentFormSchema>;
|
||||||
|
|
||||||
export const stepSchemas: Record<number, z.ZodType<Partial<IntlPaymentFormData>>> = {
|
export const stepSchemas: Record<number, z.ZodType<Partial<IntlPaymentFormData>>> = {
|
||||||
0: visaMasterPaymentFormSchema.pick({ client_id: true, status: true, currency_type: true }),
|
0: visaMasterPaymentFormSchema.pick({ client_id: true, status: true, currency_type: true }),
|
||||||
1: visaMasterPaymentFormSchema.pick({ province: true, branch: true }),
|
1: visaMasterPaymentFormSchema.pick({ province: true, branch: true }),
|
||||||
2: visaMasterPaymentFormSchema.pick({ passport_first_name: true, passport_last_name: true, phone: true }),
|
2: visaMasterPaymentFormSchema.pick({ passport_first_name: true, passport_last_name: true, phone: true }),
|
||||||
3: visaMasterPaymentFormSchema.pick({
|
3: visaMasterPaymentFormSchema.pick({
|
||||||
passport_series: true, passport_number: true,
|
passport_series: true,
|
||||||
payer_full_name: true, payer_account_number: true, receiver_info: true,
|
passport_number: true,
|
||||||
|
payer_full_name: true,
|
||||||
|
payer_account_number: true,
|
||||||
|
receiver_info: true,
|
||||||
}),
|
}),
|
||||||
4: z.object({}),
|
4: z.object({}),
|
||||||
}
|
};
|
||||||
|
|
||||||
export function validateStep(
|
export function validateStep(
|
||||||
stepIndex: number,
|
stepIndex: number,
|
||||||
form: IntlPaymentFormData,
|
form: IntlPaymentFormData,
|
||||||
mode: 'create' | 'edit',
|
mode: "create" | "edit",
|
||||||
): Partial<Record<keyof IntlPaymentFormData, string>> {
|
): Partial<Record<keyof IntlPaymentFormData, string>> {
|
||||||
void mode
|
void mode;
|
||||||
const schema = stepSchemas[stepIndex]
|
const schema = stepSchemas[stepIndex];
|
||||||
const result = schema.safeParse(form)
|
const result = schema.safeParse(form);
|
||||||
if (result.success) return {}
|
if (result.success) return {};
|
||||||
const errors: Partial<Record<keyof IntlPaymentFormData, string>> = {}
|
const errors: Partial<Record<keyof IntlPaymentFormData, string>> = {};
|
||||||
for (const issue of result.error.issues) {
|
for (const issue of result.error.issues) {
|
||||||
const key = issue.path[0] as keyof IntlPaymentFormData
|
const key = issue.path[0] as keyof IntlPaymentFormData;
|
||||||
if (!errors[key]) {
|
if (!errors[key]) {
|
||||||
const msg = issue.message
|
const msg = issue.message;
|
||||||
errors[key] = msg.startsWith('validation.') ? i18next.t(msg, msg) : msg
|
errors[key] = msg.startsWith("validation.") ? i18next.t(msg, msg) : msg;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return errors
|
return errors;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const DEFAULT_FORM_VALUES: IntlPaymentFormData = {
|
export const DEFAULT_FORM_VALUES: IntlPaymentFormData = {
|
||||||
client_id: '', status: 'pending', note: '', currency_type: '',
|
client_id: "",
|
||||||
province: '', branch: '',
|
status: "pending",
|
||||||
passport_first_name: '', passport_last_name: '', phone: '',
|
note: "",
|
||||||
email: '', home_address: '',
|
currency_type: "",
|
||||||
passport_series: '', passport_number: '',
|
province: "",
|
||||||
payer_full_name: '', payer_account_number: '', receiver_info: '',
|
branch: "",
|
||||||
doc_sberbank_account: null, doc_school_enrollment: null,
|
passport_first_name: "",
|
||||||
doc_summons: null, doc_passport_tm: null,
|
passport_last_name: "",
|
||||||
doc_foreign_passport: null, doc_foreign_passport_copy: null,
|
phone: "",
|
||||||
doc_exit_permission: null, doc_school_foreign_info: null,
|
email: "",
|
||||||
|
home_address: "",
|
||||||
|
passport_series: "",
|
||||||
|
passport_number: "",
|
||||||
|
payer_full_name: "",
|
||||||
|
payer_account_number: "",
|
||||||
|
receiver_info: "",
|
||||||
|
doc_sberbank_account: null,
|
||||||
|
doc_school_enrollment: null,
|
||||||
|
doc_summons: null,
|
||||||
|
doc_passport_tm: null,
|
||||||
|
doc_foreign_passport: null,
|
||||||
|
doc_foreign_passport_copy: null,
|
||||||
|
doc_exit_permission: null,
|
||||||
|
doc_school_foreign_info: null,
|
||||||
doc_school_departure_info: null,
|
doc_school_departure_info: null,
|
||||||
upd_doc_passport_tm: null, upd_doc_foreign_passport: null,
|
upd_doc_passport_tm: null,
|
||||||
upd_doc_visa: null, upd_doc_acceptance_letter: null,
|
upd_doc_foreign_passport: null,
|
||||||
upd_doc_passport_biometric: null, upd_doc_passport_old: null,
|
upd_doc_visa: null,
|
||||||
}
|
upd_doc_acceptance_letter: null,
|
||||||
|
upd_doc_passport_biometric: null,
|
||||||
|
upd_doc_passport_old: null,
|
||||||
|
};
|
||||||
|
|
||||||
export function buildPayload(data: IntlPaymentFormData): IntlPaymentCreatePayload {
|
export function buildPayload(data: IntlPaymentFormData): IntlPaymentCreatePayload {
|
||||||
return {
|
return {
|
||||||
...data,
|
...data,
|
||||||
status: data.status as IntlPaymentStatus,
|
status: data.status as IntlPaymentStatus,
|
||||||
currency_type: data.currency_type as CurrencyType,
|
currency_type: data.currency_type as CurrencyType,
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
+1218
-1217
File diff suppressed because it is too large.
Load diff
+1219
-1218
File diff suppressed because it is too large.
Load diff
+1219
-1218
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user