improves steppbar, and phone validation, added formatter
This commit is contained in:
1
.husky/pre-commit
Normal file
1
.husky/pre-commit
Normal file
@@ -0,0 +1 @@
|
||||
npx lint-staged
|
||||
9
.lintstagedrc
Normal file
9
.lintstagedrc
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"*.{js,jsx,ts,tsx}": [
|
||||
"eslint --fix",
|
||||
"prettier --write"
|
||||
],
|
||||
"*.{css,scss,md,json,html}": [
|
||||
"prettier --write"
|
||||
]
|
||||
}
|
||||
15
.prettierignore
Normal file
15
.prettierignore
Normal file
@@ -0,0 +1,15 @@
|
||||
node_modules/
|
||||
dist/
|
||||
build/
|
||||
.env
|
||||
.env.*
|
||||
public/
|
||||
*.png
|
||||
*.jpg
|
||||
*.jpeg
|
||||
*.svg
|
||||
*.gif
|
||||
*.woff
|
||||
*.woff2
|
||||
*.ttf
|
||||
*.eot
|
||||
11
.prettierrc
Normal file
11
.prettierrc
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"printWidth": 140,
|
||||
"tabWidth": 2,
|
||||
"useTabs": false,
|
||||
"semi": true,
|
||||
"singleQuote": false,
|
||||
"trailingComma": "all",
|
||||
"bracketSpacing": true,
|
||||
"arrowParens": "always",
|
||||
"endOfLine": "auto"
|
||||
}
|
||||
@@ -1,22 +1,19 @@
|
||||
import js from '@eslint/js'
|
||||
import globals from 'globals'
|
||||
import reactHooks from 'eslint-plugin-react-hooks'
|
||||
import reactRefresh from 'eslint-plugin-react-refresh'
|
||||
import tseslint from 'typescript-eslint'
|
||||
import { defineConfig, globalIgnores } from 'eslint/config'
|
||||
import js from "@eslint/js";
|
||||
import globals from "globals";
|
||||
import reactHooks from "eslint-plugin-react-hooks";
|
||||
import reactRefresh from "eslint-plugin-react-refresh";
|
||||
import tseslint from "typescript-eslint";
|
||||
import { defineConfig, globalIgnores } from "eslint/config";
|
||||
import eslintConfigPrettier from "eslint-config-prettier";
|
||||
|
||||
export default defineConfig([
|
||||
globalIgnores(['dist']),
|
||||
globalIgnores(["dist"]),
|
||||
{
|
||||
files: ['**/*.{ts,tsx}'],
|
||||
extends: [
|
||||
js.configs.recommended,
|
||||
tseslint.configs.recommended,
|
||||
reactHooks.configs.flat.recommended,
|
||||
reactRefresh.configs.vite,
|
||||
],
|
||||
files: ["**/*.{ts,tsx}"],
|
||||
extends: [js.configs.recommended, tseslint.configs.recommended, reactHooks.configs.flat.recommended, reactRefresh.configs.vite],
|
||||
languageOptions: {
|
||||
globals: globals.browser,
|
||||
},
|
||||
},
|
||||
])
|
||||
eslintConfigPrettier,
|
||||
]);
|
||||
|
||||
368
package-lock.json
generated
368
package-lock.json
generated
@@ -50,10 +50,14 @@
|
||||
"@vitejs/plugin-react": "^6.0.1",
|
||||
"autoprefixer": "^10.5.0",
|
||||
"eslint": "^10.2.1",
|
||||
"eslint-config-prettier": "^10.1.8",
|
||||
"eslint-plugin-react-hooks": "^7.1.1",
|
||||
"eslint-plugin-react-refresh": "^0.5.2",
|
||||
"globals": "^17.5.0",
|
||||
"husky": "^9.1.7",
|
||||
"lint-staged": "^16.4.0",
|
||||
"postcss": "^8.5.13",
|
||||
"prettier": "^3.8.3",
|
||||
"tailwindcss": "^4.2.4",
|
||||
"typescript": "~6.0.2",
|
||||
"typescript-eslint": "^8.58.2",
|
||||
@@ -4459,6 +4463,22 @@
|
||||
"integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==",
|
||||
"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": {
|
||||
"version": "6.2.2",
|
||||
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.2.2.tgz",
|
||||
@@ -4805,6 +4825,40 @@
|
||||
"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": {
|
||||
"version": "4.1.0",
|
||||
"resolved": "https://registry.npmjs.org/cli-width/-/cli-width-4.1.0.tgz",
|
||||
@@ -4902,6 +4956,13 @@
|
||||
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
|
||||
"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": {
|
||||
"version": "1.0.8",
|
||||
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
|
||||
@@ -5419,6 +5480,19 @@
|
||||
"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": {
|
||||
"version": "1.3.4",
|
||||
"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": {
|
||||
"version": "7.1.1",
|
||||
"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_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": {
|
||||
"version": "26.0.8",
|
||||
"resolved": "https://registry.npmjs.org/i18next/-/i18next-26.0.8.tgz",
|
||||
@@ -7231,6 +7337,79 @@
|
||||
"integrity": "sha512-NT1CJtq3hHIreOianA8aSXn6Cw0JzYOuDQbOrSPe7gqFnCpKP++MQe3ODgO3oh2GJFORkAAdqredOa60z63GbA==",
|
||||
"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": {
|
||||
"version": "6.0.0",
|
||||
"resolved": "https://registry.npmjs.org/locate-path/-/locate-path-6.0.0.tgz",
|
||||
@@ -7275,6 +7454,90 @@
|
||||
"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": {
|
||||
"version": "5.1.1",
|
||||
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-5.1.1.tgz",
|
||||
@@ -7981,6 +8244,22 @@
|
||||
"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": {
|
||||
"version": "9.3.0",
|
||||
"resolved": "https://registry.npmjs.org/pretty-ms/-/pretty-ms-9.3.0.tgz",
|
||||
@@ -8683,6 +8962,13 @@
|
||||
"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": {
|
||||
"version": "1.0.0-rc.17",
|
||||
"resolved": "https://registry.npmjs.org/rolldown/-/rolldown-1.0.0-rc.17.tgz",
|
||||
@@ -9037,6 +9323,52 @@
|
||||
"integrity": "sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg==",
|
||||
"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": {
|
||||
"version": "2.0.7",
|
||||
"resolved": "https://registry.npmjs.org/sonner/-/sonner-2.0.7.tgz",
|
||||
@@ -9092,6 +9424,16 @@
|
||||
"integrity": "sha512-vMgjE/GGEPEFnhFub6pa4FmJBRBVOLpIII2hvCZ8Kzb7K0hlHo7mQv6xYrBvCL2LtAIBwFUK8wvuJgTVSQ5MFQ==",
|
||||
"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": {
|
||||
"version": "7.2.0",
|
||||
"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==",
|
||||
"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": {
|
||||
"version": "0.2.16",
|
||||
"resolved": "https://registry.npmjs.org/tinyglobby/-/tinyglobby-0.2.16.tgz",
|
||||
@@ -9829,6 +10181,22 @@
|
||||
"integrity": "sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g==",
|
||||
"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": {
|
||||
"version": "17.7.2",
|
||||
"resolved": "https://registry.npmjs.org/yargs/-/yargs-17.7.2.tgz",
|
||||
|
||||
@@ -7,7 +7,9 @@
|
||||
"dev": "vite",
|
||||
"build": "tsc -b && vite build",
|
||||
"lint": "eslint .",
|
||||
"preview": "vite preview"
|
||||
"format": "prettier --write .",
|
||||
"preview": "vite preview",
|
||||
"prepare": "husky"
|
||||
},
|
||||
"dependencies": {
|
||||
"@fontsource-variable/geist": "^5.2.8",
|
||||
@@ -52,10 +54,14 @@
|
||||
"@vitejs/plugin-react": "^6.0.1",
|
||||
"autoprefixer": "^10.5.0",
|
||||
"eslint": "^10.2.1",
|
||||
"eslint-config-prettier": "^10.1.8",
|
||||
"eslint-plugin-react-hooks": "^7.1.1",
|
||||
"eslint-plugin-react-refresh": "^0.5.2",
|
||||
"globals": "^17.5.0",
|
||||
"husky": "^9.1.7",
|
||||
"lint-staged": "^16.4.0",
|
||||
"postcss": "^8.5.13",
|
||||
"prettier": "^3.8.3",
|
||||
"tailwindcss": "^4.2.4",
|
||||
"typescript": "~6.0.2",
|
||||
"typescript-eslint": "^8.58.2",
|
||||
|
||||
@@ -1,95 +1,94 @@
|
||||
import { useState, useRef, useEffect } from 'react'
|
||||
import * as CollapsiblePrimitive from '@radix-ui/react-collapsible'
|
||||
import { Check, ChevronsUpDown, Search, X, Eye, EyeOff, Upload, Hash } from 'lucide-react'
|
||||
import { useState, useRef, useEffect } from "react";
|
||||
import * as CollapsiblePrimitive from "@radix-ui/react-collapsible";
|
||||
import { Check, ChevronsUpDown, Search, X, Eye, EyeOff, Upload, Hash } from "lucide-react";
|
||||
|
||||
import { cn } from '@/lib/utils'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { Textarea } from '@/components/ui/textarea'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover'
|
||||
import { Calendar } from '@/components/ui/calendar'
|
||||
import { format, parse, isValid } from 'date-fns'
|
||||
import { CalendarIcon } from 'lucide-react'
|
||||
import { cn } from "@/lib/utils";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
|
||||
import { Calendar } from "@/components/ui/calendar";
|
||||
import { format, parse, isValid } from "date-fns";
|
||||
import { CalendarIcon } from "lucide-react";
|
||||
|
||||
// ─── Collapsible aliases ──────────────────────────────────────────────────────
|
||||
|
||||
const Collapsible = CollapsiblePrimitive.Root
|
||||
const CollapsibleTrigger = CollapsiblePrimitive.Trigger
|
||||
const CollapsibleContent = CollapsiblePrimitive.Content
|
||||
const Collapsible = CollapsiblePrimitive.Root;
|
||||
const CollapsibleTrigger = CollapsiblePrimitive.Trigger;
|
||||
const CollapsibleContent = CollapsiblePrimitive.Content;
|
||||
|
||||
// ─── Types ────────────────────────────────────────────────────────────────────
|
||||
|
||||
export type FormInputType =
|
||||
| 'text'
|
||||
| 'number'
|
||||
| 'phone'
|
||||
| 'email'
|
||||
| 'password'
|
||||
| 'date'
|
||||
| 'select'
|
||||
| 'searchable-select'
|
||||
| 'file'
|
||||
| 'textarea'
|
||||
| "text"
|
||||
| "number"
|
||||
| "phone"
|
||||
| "email"
|
||||
| "password"
|
||||
| "date"
|
||||
| "select"
|
||||
| "searchable-select"
|
||||
| "file"
|
||||
| "textarea";
|
||||
|
||||
export interface SelectOption {
|
||||
value: string
|
||||
label: string
|
||||
value: string;
|
||||
label: string;
|
||||
}
|
||||
|
||||
export interface FormInputProps {
|
||||
type?: FormInputType
|
||||
label?: string
|
||||
value?: string
|
||||
onChange?: (value: string) => void
|
||||
placeholder?: string
|
||||
error?: string
|
||||
required?: boolean
|
||||
disabled?: boolean
|
||||
options?: SelectOption[]
|
||||
accept?: string
|
||||
onFileChange?: (file: File | null) => void
|
||||
fileValue?: File | null
|
||||
className?: string
|
||||
phonePrefix?: string
|
||||
rows?: number
|
||||
name?: string
|
||||
readOnly?: boolean
|
||||
type?: FormInputType;
|
||||
label?: string;
|
||||
value?: string;
|
||||
onChange?: (value: string) => void;
|
||||
placeholder?: string;
|
||||
error?: string;
|
||||
required?: boolean;
|
||||
disabled?: boolean;
|
||||
options?: SelectOption[];
|
||||
accept?: string;
|
||||
onFileChange?: (file: File | null) => void;
|
||||
fileValue?: File | null;
|
||||
className?: string;
|
||||
phonePrefix?: string;
|
||||
rows?: number;
|
||||
name?: string;
|
||||
readOnly?: boolean;
|
||||
}
|
||||
|
||||
// ─── FieldLabel ───────────────────────────────────────────────────────────────
|
||||
|
||||
function FieldLabel({ label, required }: { label?: string; required?: boolean }) {
|
||||
if (!label) return null
|
||||
if (!label) return null;
|
||||
return (
|
||||
<label className="block text-xs font-semibold text-muted-foreground uppercase tracking-wider mb-1.5 select-none">
|
||||
{label}
|
||||
{required && <span className="text-destructive ml-0.5">*</span>}
|
||||
</label>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// ─── ErrorMsg ─────────────────────────────────────────────────────────────────
|
||||
|
||||
function ErrorMsg({ error }: { error?: string }) {
|
||||
if (!error) return null
|
||||
if (!error) return null;
|
||||
return (
|
||||
<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" />
|
||||
{error}
|
||||
</p>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// ─── error border helper ──────────────────────────────────────────────────────
|
||||
|
||||
const withError = (error?: string) =>
|
||||
error ? 'border-destructive focus-visible:ring-destructive/30' : ''
|
||||
const withError = (error?: string) => (error ? "border-destructive focus-visible:ring-destructive/30" : "");
|
||||
|
||||
// ─── TextInput ────────────────────────────────────────────────────────────────
|
||||
|
||||
function TextInput({
|
||||
type = 'text',
|
||||
value = '',
|
||||
type = "text",
|
||||
value = "",
|
||||
onChange,
|
||||
placeholder,
|
||||
error,
|
||||
@@ -101,11 +100,11 @@ function TextInput({
|
||||
readOnly,
|
||||
rows = 3,
|
||||
}: FormInputProps) {
|
||||
const [showPass, setShowPass] = useState(false)
|
||||
const [showPass, setShowPass] = useState(false);
|
||||
|
||||
const isPassword = type === 'password'
|
||||
const isTextarea = type === 'textarea'
|
||||
const isNumber = type === 'number'
|
||||
const isPassword = type === "password";
|
||||
const isTextarea = type === "textarea";
|
||||
const isNumber = type === "number";
|
||||
|
||||
return (
|
||||
<div className={className}>
|
||||
@@ -121,35 +120,26 @@ function TextInput({
|
||||
disabled={disabled}
|
||||
readOnly={readOnly}
|
||||
rows={rows}
|
||||
className={cn('resize-none', withError(error))}
|
||||
className={cn("resize-none", withError(error))}
|
||||
/>
|
||||
) : (
|
||||
<Input
|
||||
name={name}
|
||||
type={
|
||||
isPassword ? (showPass ? 'text' : 'password')
|
||||
: isNumber ? 'number'
|
||||
: type === 'email' ? 'email'
|
||||
: 'text'
|
||||
}
|
||||
type={isPassword ? (showPass ? "text" : "password") : isNumber ? "number" : type === "email" ? "email" : "text"}
|
||||
min={isNumber ? 0 : undefined}
|
||||
value={value}
|
||||
onChange={(e) => {
|
||||
if (isNumber) {
|
||||
const num = e.target.value
|
||||
if (num === '' || Number(num) >= 0) onChange?.(num)
|
||||
const num = e.target.value;
|
||||
if (num === "" || Number(num) >= 0) onChange?.(num);
|
||||
} else {
|
||||
onChange?.(e.target.value)
|
||||
onChange?.(e.target.value);
|
||||
}
|
||||
}}
|
||||
placeholder={placeholder}
|
||||
disabled={disabled}
|
||||
readOnly={readOnly}
|
||||
className={cn(
|
||||
isPassword && 'pr-10',
|
||||
isNumber && 'pr-10',
|
||||
withError(error),
|
||||
)}
|
||||
className={cn(isPassword && "pr-10", isNumber && "pr-10", withError(error))}
|
||||
/>
|
||||
)}
|
||||
|
||||
@@ -164,43 +154,48 @@ function TextInput({
|
||||
</button>
|
||||
)}
|
||||
|
||||
{isNumber && (
|
||||
<Hash
|
||||
size={14}
|
||||
className="absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground pointer-events-none"
|
||||
/>
|
||||
)}
|
||||
{isNumber && <Hash size={14} className="absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground pointer-events-none" />}
|
||||
</div>
|
||||
|
||||
<ErrorMsg error={error} />
|
||||
</div>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// ─── PhoneInput ───────────────────────────────────────────────────────────────
|
||||
|
||||
function PhoneInput({
|
||||
value = '',
|
||||
value = "",
|
||||
onChange,
|
||||
placeholder = '61 111213',
|
||||
placeholder = "61 097651",
|
||||
error,
|
||||
disabled,
|
||||
required,
|
||||
label,
|
||||
className,
|
||||
phonePrefix = '+993',
|
||||
phonePrefix = "+993",
|
||||
}: 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 (
|
||||
<div className={className}>
|
||||
<FieldLabel label={label} required={required} />
|
||||
|
||||
<div
|
||||
className={cn(
|
||||
'flex h-8 w-full rounded-md border bg-background overflow-hidden',
|
||||
'ring-offset-background transition-colors duration-150',
|
||||
'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',
|
||||
disabled && 'opacity-50 cursor-not-allowed',
|
||||
"flex h-8 w-full rounded-md border bg-background overflow-hidden",
|
||||
"ring-offset-background transition-colors duration-150",
|
||||
"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",
|
||||
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">
|
||||
@@ -209,7 +204,7 @@ function PhoneInput({
|
||||
<input
|
||||
type="tel"
|
||||
value={value}
|
||||
onChange={(e) => onChange?.(e.target.value.replace(/[^\d\s-]/g, ''))}
|
||||
onChange={handleChange}
|
||||
placeholder={placeholder}
|
||||
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"
|
||||
@@ -218,31 +213,22 @@ function PhoneInput({
|
||||
|
||||
<ErrorMsg error={error} />
|
||||
</div>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// ─── DateInput (shadcn Popover + Calendar) ───────────────────────────────────
|
||||
|
||||
function DateInput({
|
||||
value = '',
|
||||
onChange,
|
||||
error,
|
||||
disabled,
|
||||
required,
|
||||
label,
|
||||
className,
|
||||
placeholder = 'Sene saýlaň',
|
||||
}: FormInputProps) {
|
||||
const [open, setOpen] = useState(false)
|
||||
function DateInput({ value = "", onChange, error, disabled, required, label, className, placeholder = "Sene saýlaň" }: FormInputProps) {
|
||||
const [open, setOpen] = useState(false);
|
||||
|
||||
// value is stored as 'yyyy-MM-dd' string
|
||||
const parsed = value ? parse(value, 'yyyy-MM-dd', new Date()) : undefined
|
||||
const selected = parsed && isValid(parsed) ? parsed : undefined
|
||||
const parsed = value ? parse(value, "yyyy-MM-dd", new Date()) : undefined;
|
||||
const selected = parsed && isValid(parsed) ? parsed : undefined;
|
||||
|
||||
const handleSelect = (day: Date | undefined) => {
|
||||
onChange?.(day ? format(day, 'yyyy-MM-dd') : '')
|
||||
setOpen(false)
|
||||
}
|
||||
onChange?.(day ? format(day, "yyyy-MM-dd") : "");
|
||||
setOpen(false);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={className}>
|
||||
@@ -254,15 +240,15 @@ function DateInput({
|
||||
type="button"
|
||||
disabled={disabled}
|
||||
className={cn(
|
||||
'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',
|
||||
'focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-0',
|
||||
'disabled:cursor-not-allowed disabled:opacity-50',
|
||||
error ? 'border-destructive' : 'border-input',
|
||||
!selected && 'text-muted-foreground/60',
|
||||
"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",
|
||||
"focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-0",
|
||||
"disabled:cursor-not-allowed disabled:opacity-50",
|
||||
error ? "border-destructive" : "border-input",
|
||||
!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" />
|
||||
</button>
|
||||
</PopoverTrigger>
|
||||
@@ -282,42 +268,39 @@ function DateInput({
|
||||
|
||||
<ErrorMsg error={error} />
|
||||
</div>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// ─── SelectInput ──────────────────────────────────────────────────────────────
|
||||
|
||||
// ─── SelectInput ──────────────────────────────────────────────────────────────
|
||||
// Artık Collapsible tabanlı — SearchableSelect ile aynı mekanizma
|
||||
|
||||
function SelectInput({
|
||||
value = '',
|
||||
value = "",
|
||||
onChange,
|
||||
options = [],
|
||||
placeholder = '—',
|
||||
placeholder = "—",
|
||||
error,
|
||||
disabled,
|
||||
required,
|
||||
label,
|
||||
className,
|
||||
}: 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) => {
|
||||
onChange?.(val)
|
||||
setOpen(false)
|
||||
}
|
||||
onChange?.(val);
|
||||
setOpen(false);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={cn('relative', className)}>
|
||||
<div className={cn("relative", className)}>
|
||||
<FieldLabel label={label} required={required} />
|
||||
|
||||
<Collapsible
|
||||
open={open}
|
||||
onOpenChange={(next) => {
|
||||
if (!disabled) setOpen(next)
|
||||
if (!disabled) setOpen(next);
|
||||
}}
|
||||
>
|
||||
<CollapsibleTrigger asChild>
|
||||
@@ -325,23 +308,20 @@ function SelectInput({
|
||||
type="button"
|
||||
disabled={disabled}
|
||||
className={cn(
|
||||
'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',
|
||||
'focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-0',
|
||||
'disabled:cursor-not-allowed disabled:opacity-50',
|
||||
error ? 'border-destructive' : 'border-input',
|
||||
open && !error && 'ring-2 ring-ring ring-offset-0 border-transparent',
|
||||
"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",
|
||||
"focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-0",
|
||||
"disabled:cursor-not-allowed disabled:opacity-50",
|
||||
error ? "border-destructive" : "border-input",
|
||||
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}
|
||||
</span>
|
||||
<ChevronsUpDown
|
||||
size={14}
|
||||
className={cn(
|
||||
'text-muted-foreground transition-transform duration-200 shrink-0',
|
||||
open && 'text-foreground',
|
||||
)}
|
||||
className={cn("text-muted-foreground transition-transform duration-200 shrink-0", open && "text-foreground")}
|
||||
/>
|
||||
</button>
|
||||
</CollapsibleTrigger>
|
||||
@@ -349,22 +329,25 @@ function SelectInput({
|
||||
<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">
|
||||
{options.map((opt) => {
|
||||
const isSelected = opt.value === value
|
||||
const isSelected = opt.value === value;
|
||||
return (
|
||||
<button
|
||||
key={opt.value}
|
||||
type="button"
|
||||
onMouseDown={(e) => { e.preventDefault(); handleSelect(opt.value) }}
|
||||
onMouseDown={(e) => {
|
||||
e.preventDefault();
|
||||
handleSelect(opt.value);
|
||||
}}
|
||||
className={cn(
|
||||
'flex items-center justify-between w-full text-left px-3 py-2 text-sm transition-colors',
|
||||
'hover:bg-accent hover:text-accent-foreground',
|
||||
isSelected && 'text-primary font-medium bg-primary/10',
|
||||
"flex items-center justify-between w-full text-left px-3 py-2 text-sm transition-colors",
|
||||
"hover:bg-accent hover:text-accent-foreground",
|
||||
isSelected && "text-primary font-medium bg-primary/10",
|
||||
)}
|
||||
>
|
||||
<span>{opt.label}</span>
|
||||
{isSelected && <Check size={13} className="text-primary shrink-0" />}
|
||||
</button>
|
||||
)
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</CollapsibleContent>
|
||||
@@ -372,7 +355,7 @@ function SelectInput({
|
||||
|
||||
<ErrorMsg error={error} />
|
||||
</div>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// ─── SearchableSelect ─────────────────────────────────────────────────────────
|
||||
@@ -381,67 +364,76 @@ function SelectInput({
|
||||
// firing before the selection is registered.
|
||||
|
||||
function SearchableSelect({
|
||||
value = '',
|
||||
value = "",
|
||||
onChange,
|
||||
options = [],
|
||||
placeholder = 'Saýlamak üçin basyň',
|
||||
placeholder = "Saýlamak üçin basyň",
|
||||
error,
|
||||
disabled,
|
||||
required,
|
||||
label,
|
||||
className,
|
||||
}: FormInputProps) {
|
||||
const [open, setOpen] = useState(false)
|
||||
const [query, setQuery] = useState('')
|
||||
const searchRef = useRef<HTMLInputElement>(null)
|
||||
const [open, setOpen] = useState(false);
|
||||
const [query, setQuery] = useState("");
|
||||
const searchRef = useRef<HTMLInputElement>(null);
|
||||
|
||||
const selected = options.find((o) => o.value === value)
|
||||
const filtered = query.trim()
|
||||
? options.filter((o) => o.label.toLowerCase().includes(query.toLowerCase()))
|
||||
: options
|
||||
const selected = options.find((o) => o.value === value);
|
||||
const filtered = query.trim() ? options.filter((o) => o.label.toLowerCase().includes(query.toLowerCase())) : options;
|
||||
|
||||
const openDropdown = () => {
|
||||
setOpen(true)
|
||||
setOpen(true);
|
||||
// Focus search after Collapsible animation frame
|
||||
requestAnimationFrame(() => searchRef.current?.focus())
|
||||
}
|
||||
requestAnimationFrame(() => searchRef.current?.focus());
|
||||
};
|
||||
|
||||
const closeDropdown = () => {
|
||||
setOpen(false)
|
||||
setQuery('')
|
||||
}
|
||||
setOpen(false);
|
||||
setQuery("");
|
||||
};
|
||||
|
||||
const handleSelect = (val: string) => {
|
||||
onChange?.(val)
|
||||
closeDropdown()
|
||||
}
|
||||
onChange?.(val);
|
||||
closeDropdown();
|
||||
};
|
||||
|
||||
const handleClear = (e: React.MouseEvent) => {
|
||||
e.preventDefault()
|
||||
e.stopPropagation()
|
||||
onChange?.('')
|
||||
}
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
onChange?.("");
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={cn('relative', className)}>
|
||||
<div className={cn("relative", className)}>
|
||||
<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 */}
|
||||
<CollapsibleTrigger asChild>
|
||||
<button
|
||||
type="button"
|
||||
disabled={disabled}
|
||||
className={cn(
|
||||
'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',
|
||||
'focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-0',
|
||||
'disabled:cursor-not-allowed disabled:opacity-50',
|
||||
error ? 'border-destructive' : 'border-input',
|
||||
open && !error && 'ring-2 ring-ring ring-offset-0 border-transparent',
|
||||
"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",
|
||||
"focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-0",
|
||||
"disabled:cursor-not-allowed disabled:opacity-50",
|
||||
error ? "border-destructive" : "border-input",
|
||||
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}
|
||||
</span>
|
||||
|
||||
@@ -458,10 +450,7 @@ function SearchableSelect({
|
||||
)}
|
||||
<ChevronsUpDown
|
||||
size={14}
|
||||
className={cn(
|
||||
'text-muted-foreground transition-transform duration-200 shrink-0',
|
||||
open && 'text-foreground',
|
||||
)}
|
||||
className={cn("text-muted-foreground transition-transform duration-200 shrink-0", open && "text-foreground")}
|
||||
/>
|
||||
</div>
|
||||
</button>
|
||||
@@ -484,7 +473,7 @@ function SearchableSelect({
|
||||
<button
|
||||
type="button"
|
||||
tabIndex={-1}
|
||||
onMouseDown={() => setQuery('')}
|
||||
onMouseDown={() => setQuery("")}
|
||||
className="text-muted-foreground hover:text-foreground transition-colors"
|
||||
>
|
||||
<X size={12} />
|
||||
@@ -495,27 +484,28 @@ function SearchableSelect({
|
||||
{/* Options */}
|
||||
<div className="max-h-52 overflow-y-auto py-1">
|
||||
{filtered.length === 0 ? (
|
||||
<p className="px-3 py-4 text-sm text-muted-foreground text-center">
|
||||
Netije tapylmady
|
||||
</p>
|
||||
<p className="px-3 py-4 text-sm text-muted-foreground text-center">Netije tapylmady</p>
|
||||
) : (
|
||||
filtered.map((opt) => {
|
||||
const isSelected = opt.value === value
|
||||
const isSelected = opt.value === value;
|
||||
return (
|
||||
<button
|
||||
key={opt.value}
|
||||
type="button"
|
||||
onMouseDown={(e) => { e.preventDefault(); handleSelect(opt.value) }}
|
||||
onMouseDown={(e) => {
|
||||
e.preventDefault();
|
||||
handleSelect(opt.value);
|
||||
}}
|
||||
className={cn(
|
||||
'flex items-center justify-between w-full text-left px-3 py-2 text-sm transition-colors',
|
||||
'hover:bg-accent hover:text-accent-foreground',
|
||||
isSelected && 'text-primary font-medium bg-primary/10',
|
||||
"flex items-center justify-between w-full text-left px-3 py-2 text-sm transition-colors",
|
||||
"hover:bg-accent hover:text-accent-foreground",
|
||||
isSelected && "text-primary font-medium bg-primary/10",
|
||||
)}
|
||||
>
|
||||
<span>{opt.label}</span>
|
||||
{isSelected && <Check size={13} className="text-primary shrink-0" />}
|
||||
</button>
|
||||
)
|
||||
);
|
||||
})
|
||||
)}
|
||||
</div>
|
||||
@@ -524,50 +514,56 @@ function SearchableSelect({
|
||||
|
||||
<ErrorMsg error={error} />
|
||||
</div>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// ─── FileInput ────────────────────────────────────────────────────────────────
|
||||
|
||||
// ─── FileInput ────────────────────────────────────────────────────────────────
|
||||
|
||||
function FileInput({
|
||||
label,
|
||||
required,
|
||||
error,
|
||||
disabled,
|
||||
accept = 'image/*',
|
||||
accept = "image/*",
|
||||
onFileChange,
|
||||
fileValue,
|
||||
className,
|
||||
placeholder = 'Faýl saýlaň ýa-da salmak üçin basyň',
|
||||
placeholder = "Faýl saýlaň ýa-da salmak üçin basyň",
|
||||
}: FormInputProps) {
|
||||
const inputRef = useRef<HTMLInputElement>(null)
|
||||
const [dragOver, setDragOver] = useState(false)
|
||||
const [preview, setPreview] = useState<string | null>(null)
|
||||
const inputRef = useRef<HTMLInputElement>(null);
|
||||
const [dragOver, setDragOver] = useState(false);
|
||||
const [preview, setPreview] = useState<string | null>(null);
|
||||
|
||||
// fileValue prop'u değişince preview'i güncelle + memory leak önle
|
||||
useEffect(() => {
|
||||
if (fileValue?.type.startsWith('image/')) {
|
||||
const url = URL.createObjectURL(fileValue)
|
||||
setPreview(url)
|
||||
return () => URL.revokeObjectURL(url)
|
||||
let url: string | null = null;
|
||||
let timer: ReturnType<typeof setTimeout>;
|
||||
|
||||
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
|
||||
const handleFile = (file: File | null) => {
|
||||
onFileChange?.(file)
|
||||
}
|
||||
onFileChange?.(file);
|
||||
};
|
||||
|
||||
const handleDrop = (e: React.DragEvent) => {
|
||||
e.preventDefault()
|
||||
setDragOver(false)
|
||||
handleFile(e.dataTransfer.files[0] ?? null)
|
||||
}
|
||||
e.preventDefault();
|
||||
setDragOver(false);
|
||||
handleFile(e.dataTransfer.files[0] ?? null);
|
||||
};
|
||||
|
||||
const isImage = fileValue?.type.startsWith('image/')
|
||||
const isImage = fileValue?.type.startsWith("image/");
|
||||
|
||||
return (
|
||||
<div className={className}>
|
||||
@@ -577,38 +573,38 @@ function FileInput({
|
||||
role="button"
|
||||
tabIndex={disabled ? -1 : 0}
|
||||
onClick={() => !disabled && inputRef.current?.click()}
|
||||
onKeyDown={(e) => e.key === 'Enter' && !disabled && inputRef.current?.click()}
|
||||
onDragOver={(e) => { e.preventDefault(); setDragOver(true) }}
|
||||
onKeyDown={(e) => e.key === "Enter" && !disabled && inputRef.current?.click()}
|
||||
onDragOver={(e) => {
|
||||
e.preventDefault();
|
||||
setDragOver(true);
|
||||
}}
|
||||
onDragLeave={() => setDragOver(false)}
|
||||
onDrop={handleDrop}
|
||||
className={cn(
|
||||
'relative flex flex-col items-center justify-center',
|
||||
'min-h-[88px] rounded-md border-2 border-dashed cursor-pointer select-none',
|
||||
'transition-all duration-200',
|
||||
'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]',
|
||||
error ? 'border-destructive/60' : 'border-border',
|
||||
!dragOver && !error && 'hover:border-primary/50 hover:bg-muted/20',
|
||||
disabled && 'opacity-50 cursor-not-allowed pointer-events-none',
|
||||
fileValue && isImage && '!border-solid !border-border overflow-hidden',
|
||||
"relative flex flex-col items-center justify-center",
|
||||
"min-h-[88px] rounded-md border-2 border-dashed cursor-pointer select-none",
|
||||
"transition-all duration-200",
|
||||
"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]",
|
||||
error ? "border-destructive/60" : "border-border",
|
||||
!dragOver && !error && "hover:border-primary/50 hover:bg-muted/20",
|
||||
disabled && "opacity-50 cursor-not-allowed pointer-events-none",
|
||||
fileValue && isImage && "!border-solid !border-border overflow-hidden",
|
||||
)}
|
||||
>
|
||||
{fileValue && isImage && preview ? (
|
||||
<>
|
||||
<img
|
||||
src={preview}
|
||||
alt="preview"
|
||||
className="w-full max-h-56 object-contain bg-muted/30 p-2"
|
||||
/>
|
||||
<img 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">
|
||||
<span className="text-xs text-muted-foreground truncate max-w-[200px]">
|
||||
{fileValue.name}
|
||||
</span>
|
||||
<span className="text-xs text-muted-foreground truncate max-w-[200px]">{fileValue.name}</span>
|
||||
<Button
|
||||
type="button"
|
||||
size="icon"
|
||||
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"
|
||||
>
|
||||
<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">
|
||||
<Upload size={14} className="text-primary" />
|
||||
</div>
|
||||
<p className="text-xs font-medium text-foreground text-center truncate max-w-[180px]">
|
||||
{fileValue.name}
|
||||
</p>
|
||||
<p className="text-xs font-medium text-foreground text-center truncate max-w-[180px]">{fileValue.name}</p>
|
||||
<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"
|
||||
>
|
||||
Aýyr
|
||||
@@ -636,9 +633,7 @@ function FileInput({
|
||||
<div className="w-8 h-8 rounded-md bg-muted flex items-center justify-center">
|
||||
<Upload size={14} className="text-muted-foreground" />
|
||||
</div>
|
||||
<p className="text-xs text-muted-foreground text-center leading-relaxed">
|
||||
{placeholder}
|
||||
</p>
|
||||
<p className="text-xs text-muted-foreground text-center leading-relaxed">{placeholder}</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
@@ -654,20 +649,19 @@ function FileInput({
|
||||
|
||||
<ErrorMsg error={error} />
|
||||
</div>
|
||||
)
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
// ─── FormInput (router) ───────────────────────────────────────────────────────
|
||||
|
||||
export function FormInput(props: FormInputProps) {
|
||||
const { type = 'text' } = props
|
||||
const { type = "text" } = props;
|
||||
|
||||
if (type === 'phone') return <PhoneInput {...props} />
|
||||
if (type === 'date') return <DateInput {...props} />
|
||||
if (type === 'select') return <SelectInput {...props} />
|
||||
if (type === 'searchable-select') return <SearchableSelect {...props} />
|
||||
if (type === 'file') return <FileInput {...props} />
|
||||
if (type === 'textarea') return <TextInput {...props} type="textarea" />
|
||||
return <TextInput {...props} />
|
||||
}
|
||||
if (type === "phone") return <PhoneInput {...props} />;
|
||||
if (type === "date") return <DateInput {...props} />;
|
||||
if (type === "select") return <SelectInput {...props} />;
|
||||
if (type === "searchable-select") return <SearchableSelect {...props} />;
|
||||
if (type === "file") return <FileInput {...props} />;
|
||||
if (type === "textarea") return <TextInput {...props} type="textarea" />;
|
||||
return <TextInput {...props} />;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
import {
|
||||
type LucideIcon,
|
||||
ChevronRight,
|
||||
Check,
|
||||
AlertTriangle,
|
||||
} from "lucide-react";
|
||||
import { useRef, useEffect } from "react";
|
||||
import { type LucideIcon, ChevronRight, Check, AlertTriangle } from "lucide-react";
|
||||
import { cn } from "@/lib/utils";
|
||||
import type { StepStatus } from "./stepBar";
|
||||
|
||||
@@ -21,95 +17,151 @@ interface StepBarCardsProps {
|
||||
}
|
||||
|
||||
export function StepBarCards({ steps, onGoTo }: StepBarCardsProps) {
|
||||
return (
|
||||
<nav
|
||||
role="tablist"
|
||||
aria-label="Form adımları"
|
||||
className={cn(
|
||||
"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");
|
||||
const wrapRef = useRef<HTMLDivElement>(null);
|
||||
const isDragging = useRef(false);
|
||||
const startX = useRef(0);
|
||||
const scrollX = useRef(0);
|
||||
const moved = useRef(false);
|
||||
|
||||
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(
|
||||
"group flex items-center gap-3 rounded-lg px-3 py-2.5 transition-all duration-200",
|
||||
"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",
|
||||
reachable && !isActive && "hover:bg-muted/40 cursor-pointer",
|
||||
isActive && "bg-muted/60",
|
||||
)}
|
||||
>
|
||||
{/* Icon disc */}
|
||||
<span
|
||||
// Auto-scroll active step to center
|
||||
useEffect(() => {
|
||||
const wrap = wrapRef.current;
|
||||
if (!wrap) return;
|
||||
const active = wrap.querySelector<HTMLElement>('[aria-current="step"]');
|
||||
if (!active) return;
|
||||
const wrapRect = wrap.getBoundingClientRect();
|
||||
const btnRect = active.getBoundingClientRect();
|
||||
wrap.scrollTo({
|
||||
left: wrap.scrollLeft + (btnRect.left - wrapRect.left) - wrapRect.width / 2 + btnRect.width / 2,
|
||||
behavior: "smooth",
|
||||
});
|
||||
}, [steps]);
|
||||
|
||||
// Mouse drag-to-scroll
|
||||
useEffect(() => {
|
||||
const wrap = wrapRef.current;
|
||||
if (!wrap) return;
|
||||
|
||||
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(
|
||||
"relative flex items-center justify-center rounded-full w-11 h-11 shrink-0 transition-all duration-300",
|
||||
isActive &&
|
||||
"bg-[#005f78] text-white ring-4 ring-[#005f78]/15 dark:bg-primary dark:text-primary-foreground dark:ring-primary/15",
|
||||
isDone &&
|
||||
"bg-[#005f78]/10 text-[#005f78] dark:bg-muted dark:text-foreground",
|
||||
isError &&
|
||||
"bg-destructive/10 text-destructive ring-2 ring-destructive/30",
|
||||
isIdle && "bg-muted text-muted-foreground",
|
||||
reachable && !isActive && "group-hover:scale-105",
|
||||
"group flex items-center gap-3 rounded-lg px-3 py-2.5 transition-all duration-200",
|
||||
"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",
|
||||
reachable && !isActive && "hover:bg-muted/40 cursor-pointer",
|
||||
isActive && "bg-muted/60",
|
||||
)}
|
||||
>
|
||||
{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>
|
||||
|
||||
{/* Texts */}
|
||||
<span className="flex flex-col items-start text-left leading-tight">
|
||||
{/* Icon disc */}
|
||||
<span
|
||||
className={cn(
|
||||
"text-sm font-semibold tracking-tight",
|
||||
isActive && "text-[#005f78] dark:text-foreground",
|
||||
isDone && "text-[#005f78] dark:text-foreground",
|
||||
!isActive && !isDone && !isError && "text-foreground/90",
|
||||
isError && "text-destructive",
|
||||
"relative flex items-center justify-center rounded-full w-11 h-11 shrink-0 transition-all duration-300",
|
||||
isActive &&
|
||||
"bg-[#005f78] text-white ring-4 ring-[#005f78]/15 dark:bg-primary dark:text-primary-foreground dark:ring-primary/15",
|
||||
isDone && "bg-[#005f78]/10 text-[#005f78] dark:bg-muted dark:text-foreground",
|
||||
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 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>
|
||||
{/* Texts */}
|
||||
<span className="flex flex-col items-start text-left leading-tight">
|
||||
<span
|
||||
className={cn(
|
||||
"text-sm font-semibold tracking-tight",
|
||||
isActive && "text-[#005f78] dark:text-foreground",
|
||||
isDone && "text-[#005f78] dark:text-foreground",
|
||||
!isActive && !isDone && !isError && "text-foreground/90",
|
||||
isError && "text-destructive",
|
||||
)}
|
||||
>
|
||||
{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 type { CreateUserPayload } from '../api/allUsersApi'
|
||||
import { z } from "zod";
|
||||
import type { CreateUserPayload } from "../api/allUsersApi";
|
||||
|
||||
export function allUserFormSchema(
|
||||
mode: 'create' | 'edit',
|
||||
t: (key: string, fallback?: string) => string,
|
||||
) {
|
||||
const VALID_PHONE_PREFIXES = ["61", "62", "63", "64", "65", "71"];
|
||||
|
||||
export function allUserFormSchema(mode: "create" | "edit", t: (key: string, fallback?: string) => string) {
|
||||
const baseSchema = z.object({
|
||||
username: z.string()
|
||||
.min(1, t('validation.required', 'validation.required'))
|
||||
.min(3, t('validation.minLength', 'validation.minLength')),
|
||||
name: z.string().min(1, t('validation.required', 'validation.required')),
|
||||
phone: z.string()
|
||||
.min(1, t('validation.required', 'validation.required'))
|
||||
.regex(/^\d[\d\s-]{6,}$/, t('validation.invalidPhone', 'validation.invalidPhone')),
|
||||
email: z.string()
|
||||
username: z.string().min(1, t("validation.required", "validation.required")).min(3, t("validation.minLength", "validation.minLength")),
|
||||
name: z.string().min(1, t("validation.required", "validation.required")),
|
||||
phone: z
|
||||
.string()
|
||||
.min(1, t("validation.required", "validation.required"))
|
||||
.refine(
|
||||
(v) => !v || /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(v),
|
||||
t('validation.invalidEmail', 'validation.invalidEmail'),
|
||||
(val) => {
|
||||
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(),
|
||||
phoneVerified: z.boolean(),
|
||||
isActive: z.boolean(),
|
||||
})
|
||||
});
|
||||
|
||||
return mode === 'create'
|
||||
return mode === "create"
|
||||
? baseSchema.extend({
|
||||
password: z.string()
|
||||
.min(1, t('validation.required', 'validation.required'))
|
||||
.min(6, t('validation.minLength', 'validation.minLength')),
|
||||
password: z
|
||||
.string()
|
||||
.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 = {
|
||||
username: '',
|
||||
name: '',
|
||||
phone: '',
|
||||
email: '',
|
||||
password: '',
|
||||
username: "",
|
||||
name: "",
|
||||
phone: "",
|
||||
email: "",
|
||||
password: "",
|
||||
phoneVerified: false,
|
||||
isActive: true,
|
||||
}
|
||||
};
|
||||
|
||||
export function buildPayload(data: AllUserFormData): CreateUserPayload {
|
||||
return {
|
||||
@@ -54,5 +65,5 @@ export function buildPayload(data: AllUserFormData): CreateUserPayload {
|
||||
password: data.password,
|
||||
phoneVerified: data.phoneVerified,
|
||||
isActive: data.isActive,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,67 +1,91 @@
|
||||
import { z } from 'zod'
|
||||
import type { CreateBranchPayload } from '@/features/branches/api/branchesApi'
|
||||
import { z } from "zod";
|
||||
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) {
|
||||
return z.object({
|
||||
nameTk: 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')),
|
||||
code: 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')),
|
||||
addressRu: 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')),
|
||||
email: z.string().min(1, t('validation.required', 'validation.required')),
|
||||
workingHours: 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")),
|
||||
nameEn: 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")),
|
||||
addressTk: 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")),
|
||||
phone: z
|
||||
.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().min(1, t("validation.required", "validation.required")),
|
||||
workingHours: z.string().min(1, t("validation.required", "validation.required")),
|
||||
description: z.string().optional(),
|
||||
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 {
|
||||
const schema = createBranchFormSchema(t)
|
||||
const schema = createBranchFormSchema(t);
|
||||
return {
|
||||
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 }),
|
||||
2: schema.pick({ workingHours: true }),
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export function validateStep(
|
||||
stepIndex: number,
|
||||
form: BranchFormData,
|
||||
mode: 'create' | 'edit',
|
||||
mode: "create" | "edit",
|
||||
t: (key: string, fallback?: string) => string,
|
||||
): Partial<Record<keyof BranchFormData, string>> {
|
||||
void mode
|
||||
const stepSchemas = createStepSchemas(t)
|
||||
const schema = stepSchemas[stepIndex]
|
||||
if (!schema) return {}
|
||||
const result = schema.safeParse(form)
|
||||
if (result.success) return {}
|
||||
const errors: Partial<Record<keyof BranchFormData, string>> = {}
|
||||
void mode;
|
||||
const stepSchemas = createStepSchemas(t);
|
||||
const schema = stepSchemas[stepIndex];
|
||||
if (!schema) return {};
|
||||
const result = schema.safeParse(form);
|
||||
if (result.success) return {};
|
||||
const errors: Partial<Record<keyof BranchFormData, string>> = {};
|
||||
for (const issue of result.error.issues) {
|
||||
const key = issue.path[0] as keyof BranchFormData
|
||||
if (!errors[key]) errors[key] = issue.message
|
||||
const key = issue.path[0] as keyof BranchFormData;
|
||||
if (!errors[key]) errors[key] = issue.message;
|
||||
}
|
||||
return errors
|
||||
return errors;
|
||||
}
|
||||
|
||||
export const DEFAULT_FORM_VALUES: BranchFormData = {
|
||||
nameTk: '', nameRu: '', nameEn: '',
|
||||
code: '',
|
||||
districtId: '',
|
||||
addressTk: '', addressRu: '', addressEn: '',
|
||||
phone: '', email: '',
|
||||
workingHours: '',
|
||||
description: '',
|
||||
nameTk: "",
|
||||
nameRu: "",
|
||||
nameEn: "",
|
||||
code: "",
|
||||
districtId: "",
|
||||
addressTk: "",
|
||||
addressRu: "",
|
||||
addressEn: "",
|
||||
phone: "",
|
||||
email: "",
|
||||
workingHours: "",
|
||||
description: "",
|
||||
isActive: true,
|
||||
}
|
||||
};
|
||||
|
||||
export function buildPayload(data: BranchFormData): CreateBranchPayload {
|
||||
return {
|
||||
@@ -72,7 +96,7 @@ export function buildPayload(data: BranchFormData): CreateBranchPayload {
|
||||
phone: data.phone,
|
||||
email: data.email,
|
||||
workingHours: data.workingHours,
|
||||
description: (data.description ?? '').trim() || null,
|
||||
description: (data.description ?? "").trim() || null,
|
||||
isActive: data.isActive,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,96 +1,121 @@
|
||||
import { z } from 'zod'
|
||||
import i18next from 'i18next'
|
||||
import { z } from "zod";
|
||||
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({
|
||||
status: z.string().min(1, 'validation.required'),
|
||||
status: z.string().min(1, "validation.required"),
|
||||
note: z.string().optional(),
|
||||
card_type: z.string().min(1, 'validation.required'),
|
||||
card_number: z.string().min(1, 'validation.required'),
|
||||
province: z.string().min(1, 'validation.required'),
|
||||
branch: z.string().min(1, 'validation.required'),
|
||||
first_name: z.string().min(1, 'validation.required'),
|
||||
last_name: z.string().min(1, 'validation.required'),
|
||||
card_type: z.string().min(1, "validation.required"),
|
||||
card_number: z.string().min(1, "validation.required"),
|
||||
province: z.string().min(1, "validation.required"),
|
||||
branch: z.string().min(1, "validation.required"),
|
||||
first_name: z.string().min(1, "validation.required"),
|
||||
last_name: z.string().min(1, "validation.required"),
|
||||
father_name: z.string().optional(),
|
||||
birth_date: z.string().min(1, 'validation.required'),
|
||||
phone: z.string().min(1, 'validation.required'),
|
||||
passport_series: z.string().min(1, 'validation.required'),
|
||||
passport_number: z.string().min(1, 'validation.required'),
|
||||
birth_date: 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" },
|
||||
),
|
||||
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_2: z.custom<File | null>().nullable(),
|
||||
passport_file_3: 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 = {
|
||||
status: 'pending',
|
||||
note: '',
|
||||
card_type: '',
|
||||
card_number: '',
|
||||
province: '',
|
||||
branch: '',
|
||||
first_name: '',
|
||||
last_name: '',
|
||||
father_name: '',
|
||||
birth_date: '',
|
||||
phone: '',
|
||||
passport_series: '',
|
||||
passport_number: '',
|
||||
status: "pending",
|
||||
note: "",
|
||||
card_type: "",
|
||||
card_number: "",
|
||||
province: "",
|
||||
branch: "",
|
||||
first_name: "",
|
||||
last_name: "",
|
||||
father_name: "",
|
||||
birth_date: "",
|
||||
phone: "",
|
||||
passport_series: "",
|
||||
passport_number: "",
|
||||
passport_file_1: null,
|
||||
passport_file_2: null,
|
||||
passport_file_3: null,
|
||||
passport_file_4: null,
|
||||
}
|
||||
};
|
||||
|
||||
export const stepSchemas: Record<number, z.ZodType<Partial<CardPinFormData>>> = {
|
||||
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({
|
||||
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({
|
||||
passport_series: z.string().min(1, 'validation.required'),
|
||||
passport_number: z.string().min(1, 'validation.required'),
|
||||
passport_series: z.string().min(1, "validation.required"),
|
||||
passport_number: z.string().min(1, "validation.required"),
|
||||
passport_file_1: fileRequired,
|
||||
passport_file_2: fileRequired,
|
||||
passport_file_3: fileRequired,
|
||||
passport_file_4: fileRequired,
|
||||
}),
|
||||
}
|
||||
};
|
||||
|
||||
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(
|
||||
stepIndex: number,
|
||||
form: CardPinFormData,
|
||||
mode: 'create' | 'edit',
|
||||
mode: "create" | "edit",
|
||||
): Partial<Record<keyof CardPinFormData, string>> {
|
||||
if (stepIndex === 2 && mode === 'edit') {
|
||||
const schema = cardPinFormSchema.pick({ passport_series: true, passport_number: true })
|
||||
const result = schema.safeParse(form)
|
||||
if (result.success) return {}
|
||||
const errors: Partial<Record<keyof CardPinFormData, string>> = {}
|
||||
if (stepIndex === 2 && mode === "edit") {
|
||||
const schema = cardPinFormSchema.pick({ passport_series: true, passport_number: true });
|
||||
const result = schema.safeParse(form);
|
||||
if (result.success) return {};
|
||||
const errors: Partial<Record<keyof CardPinFormData, string>> = {};
|
||||
for (const issue of result.error.issues) {
|
||||
const key = issue.path[0] as keyof CardPinFormData
|
||||
if (!errors[key]) errors[key] = translateMsg(issue.message)
|
||||
const key = issue.path[0] as keyof CardPinFormData;
|
||||
if (!errors[key]) errors[key] = translateMsg(issue.message);
|
||||
}
|
||||
return errors
|
||||
return errors;
|
||||
}
|
||||
|
||||
const schema = stepSchemas[stepIndex]
|
||||
const result = schema.safeParse(form)
|
||||
if (result.success) return {}
|
||||
const schema = stepSchemas[stepIndex];
|
||||
const result = schema.safeParse(form);
|
||||
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) {
|
||||
const key = issue.path[0] as keyof CardPinFormData
|
||||
if (!errors[key]) errors[key] = translateMsg(issue.message)
|
||||
const key = issue.path[0] as keyof CardPinFormData;
|
||||
if (!errors[key]) errors[key] = translateMsg(issue.message);
|
||||
}
|
||||
return errors
|
||||
return errors;
|
||||
}
|
||||
|
||||
@@ -1,96 +1,134 @@
|
||||
import { z } from 'zod'
|
||||
import i18next from 'i18next'
|
||||
import type { CardRequisiteStatus, CreateCardRequisitePayload } from '../api/cardRequisitesApi'
|
||||
import { z } from "zod";
|
||||
import i18next from "i18next";
|
||||
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({
|
||||
status: z.string().min(1, 'validation.required'),
|
||||
status: z.string().min(1, "validation.required"),
|
||||
note: z.string().optional(),
|
||||
card_type: 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_year: z.string().min(1, 'validation.required'),
|
||||
province_id: z.string().min(1, 'validation.required'),
|
||||
branch_id: z.string().min(1, 'validation.required'),
|
||||
first_name: z.string().min(1, 'validation.required'),
|
||||
last_name: z.string().min(1, 'validation.required'),
|
||||
card_type: 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_year: z.string().min(1, "validation.required"),
|
||||
province_id: z.string().min(1, "validation.required"),
|
||||
branch_id: z.string().min(1, "validation.required"),
|
||||
first_name: z.string().min(1, "validation.required"),
|
||||
last_name: z.string().min(1, "validation.required"),
|
||||
middle_name: z.string().optional(),
|
||||
birth_date: z.string().min(1, 'validation.required'),
|
||||
phone: z.string().min(1, 'validation.required'),
|
||||
passport_series: z.string().min(1, 'validation.required'),
|
||||
passport_number: z.string().min(1, 'validation.required'),
|
||||
birth_date: 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" },
|
||||
),
|
||||
passport_series: z.string().min(1, "validation.required"),
|
||||
passport_number: z.string().min(1, "validation.required"),
|
||||
passport_page1: z.custom<File | null>().nullable(),
|
||||
passport_page2_3: z.custom<File | null>().nullable(),
|
||||
passport_page8_9: 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>>> = {
|
||||
0: cardRequisiteFormSchema.pick({
|
||||
status: true, card_type: true, card_number: true,
|
||||
card_expiry_month: true, card_expiry_year: true,
|
||||
province_id: true, branch_id: true,
|
||||
status: true,
|
||||
card_type: true,
|
||||
card_number: true,
|
||||
card_expiry_month: true,
|
||||
card_expiry_year: true,
|
||||
province_id: true,
|
||||
branch_id: true,
|
||||
}),
|
||||
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({
|
||||
passport_series: z.string().min(1, 'validation.required'),
|
||||
passport_number: z.string().min(1, 'validation.required'),
|
||||
passport_series: z.string().min(1, "validation.required"),
|
||||
passport_number: z.string().min(1, "validation.required"),
|
||||
passport_page1: fileRequired,
|
||||
passport_page2_3: fileRequired,
|
||||
passport_page8_9: fileRequired,
|
||||
passport_page32: fileRequired,
|
||||
}),
|
||||
}
|
||||
};
|
||||
|
||||
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(
|
||||
stepIndex: number,
|
||||
form: CardRequisiteFormData,
|
||||
mode: 'create' | 'edit',
|
||||
mode: "create" | "edit",
|
||||
): Partial<Record<keyof CardRequisiteFormData, string>> {
|
||||
if (stepIndex === 2 && mode === 'edit') {
|
||||
if (stepIndex === 2 && mode === "edit") {
|
||||
const schema = z.object({
|
||||
passport_series: z.string().min(1, 'validation.required'),
|
||||
passport_number: z.string().min(1, 'validation.required'),
|
||||
})
|
||||
const result = schema.safeParse(form)
|
||||
if (result.success) return {}
|
||||
const errors: Partial<Record<keyof CardRequisiteFormData, string>> = {}
|
||||
passport_series: z.string().min(1, "validation.required"),
|
||||
passport_number: z.string().min(1, "validation.required"),
|
||||
});
|
||||
const result = schema.safeParse(form);
|
||||
if (result.success) return {};
|
||||
const errors: Partial<Record<keyof CardRequisiteFormData, string>> = {};
|
||||
for (const issue of result.error.issues) {
|
||||
const key = issue.path[0] as keyof CardRequisiteFormData
|
||||
if (!errors[key]) errors[key] = translateMsg(issue.message)
|
||||
const key = issue.path[0] as keyof CardRequisiteFormData;
|
||||
if (!errors[key]) errors[key] = translateMsg(issue.message);
|
||||
}
|
||||
return errors
|
||||
return errors;
|
||||
}
|
||||
|
||||
const schema = stepSchemas[stepIndex]
|
||||
if (!schema) return {}
|
||||
const result = schema.safeParse(form)
|
||||
if (result.success) return {}
|
||||
const errors: Partial<Record<keyof CardRequisiteFormData, string>> = {}
|
||||
const schema = stepSchemas[stepIndex];
|
||||
if (!schema) return {};
|
||||
const result = schema.safeParse(form);
|
||||
if (result.success) return {};
|
||||
const errors: Partial<Record<keyof CardRequisiteFormData, string>> = {};
|
||||
for (const issue of result.error.issues) {
|
||||
const key = issue.path[0] as keyof CardRequisiteFormData
|
||||
if (!errors[key]) errors[key] = translateMsg(issue.message)
|
||||
const key = issue.path[0] as keyof CardRequisiteFormData;
|
||||
if (!errors[key]) errors[key] = translateMsg(issue.message);
|
||||
}
|
||||
return errors
|
||||
return errors;
|
||||
}
|
||||
|
||||
export const DEFAULT_FORM_VALUES: CardRequisiteFormData = {
|
||||
status: 'pending', note: '', card_type: '', card_number: '',
|
||||
card_expiry_month: '', 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,
|
||||
}
|
||||
status: "pending",
|
||||
note: "",
|
||||
card_type: "",
|
||||
card_number: "",
|
||||
card_expiry_month: "",
|
||||
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 {
|
||||
return {
|
||||
@@ -113,5 +151,5 @@ export function buildPayload(data: CardRequisiteFormData): CreateCardRequisitePa
|
||||
...(data.passport_page2_3 && { passport_page2_3: data.passport_page2_3 }),
|
||||
...(data.passport_page8_9 && { passport_page8_9: data.passport_page8_9 }),
|
||||
...(data.passport_page32 && { passport_page32: data.passport_page32 }),
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,36 +1,52 @@
|
||||
import { z } from 'zod'
|
||||
import type { CreateClientPayload } from '../api/clientsApi'
|
||||
import { z } from "zod";
|
||||
import type { CreateClientPayload } from "../api/clientsApi";
|
||||
|
||||
export function clientFormSchema(
|
||||
mode: 'create' | 'edit',
|
||||
t: (key: string, fallback?: string) => string,
|
||||
) {
|
||||
const VALID_PHONE_PREFIXES = ["61", "62", "63", "64", "65", "71"];
|
||||
|
||||
export function clientFormSchema(mode: "create" | "edit", t: (key: string, fallback?: string) => string) {
|
||||
const baseSchema = z.object({
|
||||
username: 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')),
|
||||
email: z.string().default(''),
|
||||
username: 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"))
|
||||
.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(),
|
||||
isActive: z.boolean(),
|
||||
})
|
||||
});
|
||||
|
||||
return mode === 'create'
|
||||
return mode === "create"
|
||||
? 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 = {
|
||||
username: '',
|
||||
name: '',
|
||||
phone: '',
|
||||
email: '',
|
||||
password: '',
|
||||
username: "",
|
||||
name: "",
|
||||
phone: "",
|
||||
email: "",
|
||||
password: "",
|
||||
isActive: true,
|
||||
}
|
||||
};
|
||||
|
||||
export function buildPayload(data: ClientFormData): CreateClientPayload {
|
||||
return {
|
||||
@@ -40,5 +56,5 @@ export function buildPayload(data: ClientFormData): CreateClientPayload {
|
||||
email: data.email.trim() || undefined,
|
||||
password: data.password,
|
||||
isActive: data.isActive,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,168 +1,293 @@
|
||||
import { z } from 'zod'
|
||||
import i18next from 'i18next'
|
||||
import { z } from "zod";
|
||||
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({
|
||||
status: z.string().min(1, 'validation.required'),
|
||||
loanType: z.string().min(1, 'validation.required'),
|
||||
region: z.string().min(1, 'validation.required'),
|
||||
branch: z.string().min(1, 'validation.required'),
|
||||
firstName: z.string().min(1, 'validation.required'),
|
||||
lastName: z.string().min(1, 'validation.required'),
|
||||
status: z.string().min(1, "validation.required"),
|
||||
loanType: z.string().min(1, "validation.required"),
|
||||
region: z.string().min(1, "validation.required"),
|
||||
branch: z.string().min(1, "validation.required"),
|
||||
firstName: z.string().min(1, "validation.required"),
|
||||
lastName: z.string().min(1, "validation.required"),
|
||||
patronicName: z.string().optional(),
|
||||
education: z.string().min(1, 'validation.required'),
|
||||
marriageStatus: z.string().min(1, 'validation.required'),
|
||||
dateOfBirth: z.string().min(1, 'validation.required'),
|
||||
residence: z.string().min(1, 'validation.required'),
|
||||
education: z.string().min(1, "validation.required"),
|
||||
marriageStatus: z.string().min(1, "validation.required"),
|
||||
dateOfBirth: z.string().min(1, "validation.required"),
|
||||
residence: z.string().min(1, "validation.required"),
|
||||
currentResidence: z.string().optional(),
|
||||
passportSerie: z.string().min(1, 'validation.required'),
|
||||
passportNumber: z.string().min(1, 'validation.required'),
|
||||
passportDateOfIssue: z.string().min(1, 'validation.required'),
|
||||
passportGivenBy: z.string().min(1, 'validation.required'),
|
||||
passportSerie: z.string().min(1, "validation.required"),
|
||||
passportNumber: z.string().min(1, "validation.required"),
|
||||
passportDateOfIssue: z.string().min(1, "validation.required"),
|
||||
passportGivenBy: z.string().min(1, "validation.required"),
|
||||
bornPlace: z.string().optional(),
|
||||
email: z.string().optional(),
|
||||
phone: z.string()
|
||||
.min(1, 'validation.required')
|
||||
.refine((val) => val.replace(/\D/g, '').length >= 8, { message: 'validation.invalidPhone' }),
|
||||
phoneAdditional: z.string().optional(),
|
||||
homePhone: z.string().optional(),
|
||||
workCompany: z.string().min(1, 'validation.required'),
|
||||
workHrPhone: z.string().optional(),
|
||||
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" },
|
||||
),
|
||||
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(),
|
||||
workProvince: z.string().optional(),
|
||||
position: z.string().min(1, 'validation.required'),
|
||||
salary: z.string().min(1, 'validation.required'),
|
||||
workStartedAt: z.string().min(1, 'validation.required'),
|
||||
position: z.string().min(1, "validation.required"),
|
||||
salary: z.string().min(1, "validation.required"),
|
||||
workStartedAt: z.string().min(1, "validation.required"),
|
||||
passportPage1: z.custom<File | null>().nullable(),
|
||||
passportPage23: z.custom<File | null>().nullable(),
|
||||
passportPage89: z.custom<File | null>().nullable(),
|
||||
passportPage32: z.custom<File | null>().nullable(),
|
||||
note: z.string().optional(),
|
||||
loanAmount: z.string().min(1, 'validation.required'),
|
||||
loanAmount: z.string().min(1, "validation.required"),
|
||||
loanHistory: z.string().optional(),
|
||||
cardNumber: z.string().min(1, 'validation.required'),
|
||||
cardName: z.string().min(1, 'validation.required'),
|
||||
cardExpMonth: z.string().min(1, 'validation.required'),
|
||||
cardExpYear: z.string().min(1, 'validation.required'),
|
||||
guarantor1Name: z.string().min(1, 'validation.required'),
|
||||
guarantor1Surname: z.string().min(1, 'validation.required'),
|
||||
cardNumber: z.string().min(1, "validation.required"),
|
||||
cardName: z.string().min(1, "validation.required"),
|
||||
cardExpMonth: z.string().min(1, "validation.required"),
|
||||
cardExpYear: z.string().min(1, "validation.required"),
|
||||
guarantor1Name: z.string().min(1, "validation.required"),
|
||||
guarantor1Surname: z.string().min(1, "validation.required"),
|
||||
guarantor1Patronic: z.string().optional(),
|
||||
guarantor1PassportSerie: z.string().min(1, 'validation.required'),
|
||||
guarantor1PassportNumber: z.string().min(1, 'validation.required'),
|
||||
guarantor1CardNumber: z.string().min(1, 'validation.required'),
|
||||
guarantor1CardName: z.string().min(1, 'validation.required'),
|
||||
guarantor1CardExpMonth: z.string().min(1, 'validation.required'),
|
||||
guarantor1CardExpYear: z.string().min(1, 'validation.required'),
|
||||
guarantor1Salary: z.string().min(1, 'validation.required'),
|
||||
})
|
||||
guarantor1PassportSerie: z.string().min(1, "validation.required"),
|
||||
guarantor1PassportNumber: z.string().min(1, "validation.required"),
|
||||
guarantor1CardNumber: z.string().min(1, "validation.required"),
|
||||
guarantor1CardName: z.string().min(1, "validation.required"),
|
||||
guarantor1CardExpMonth: z.string().min(1, "validation.required"),
|
||||
guarantor1CardExpYear: 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>>> = {
|
||||
0: loanOrderMobileFormSchema.pick({ loanType: true, loanAmount: true, region: true, branch: true }),
|
||||
1: loanOrderMobileFormSchema.pick({
|
||||
firstName: true, lastName: true, education: true,
|
||||
marriageStatus: true, dateOfBirth: true, residence: true,
|
||||
passportSerie: true, passportNumber: true,
|
||||
passportDateOfIssue: true, passportGivenBy: true,
|
||||
firstName: true,
|
||||
lastName: true,
|
||||
education: true,
|
||||
marriageStatus: true,
|
||||
dateOfBirth: true,
|
||||
residence: true,
|
||||
passportSerie: true,
|
||||
passportNumber: true,
|
||||
passportDateOfIssue: true,
|
||||
passportGivenBy: true,
|
||||
}),
|
||||
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({
|
||||
cardNumber: true, cardName: true, cardExpMonth: true, cardExpYear: true,
|
||||
guarantor1Name: true, guarantor1Surname: true,
|
||||
guarantor1PassportSerie: true, guarantor1PassportNumber: true,
|
||||
guarantor1CardNumber: true, guarantor1CardName: true,
|
||||
guarantor1CardExpMonth: true, guarantor1CardExpYear: true,
|
||||
cardNumber: true,
|
||||
cardName: true,
|
||||
cardExpMonth: true,
|
||||
cardExpYear: true,
|
||||
guarantor1Name: true,
|
||||
guarantor1Surname: true,
|
||||
guarantor1PassportSerie: true,
|
||||
guarantor1PassportNumber: true,
|
||||
guarantor1CardNumber: true,
|
||||
guarantor1CardName: true,
|
||||
guarantor1CardExpMonth: true,
|
||||
guarantor1CardExpYear: true,
|
||||
guarantor1Salary: true,
|
||||
}),
|
||||
4: z.object({
|
||||
passportPage1: fileRequired,
|
||||
passportPage23: fileRequired,
|
||||
}),
|
||||
}
|
||||
};
|
||||
|
||||
export function validateStep(stepIndex: number, form: LoanOrderMobileFormData, mode: 'create' | 'edit'): 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>> = {}
|
||||
export function validateStep(
|
||||
stepIndex: number,
|
||||
form: LoanOrderMobileFormData,
|
||||
mode: "create" | "edit",
|
||||
): 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) {
|
||||
const key = issue.path[0] as keyof LoanOrderMobileFormData
|
||||
const key = issue.path[0] as keyof LoanOrderMobileFormData;
|
||||
if (!errors[key]) {
|
||||
const msg = issue.message
|
||||
errors[key] = msg.startsWith('validation.') ? i18next.t(msg, msg) : msg
|
||||
const msg = issue.message;
|
||||
errors[key] = msg.startsWith("validation.") ? i18next.t(msg, msg) : msg;
|
||||
}
|
||||
}
|
||||
return errors
|
||||
return errors;
|
||||
}
|
||||
|
||||
export const DEFAULT_FORM_VALUES: LoanOrderMobileFormData = {
|
||||
status: 'GARAŞYLÝAR', loanType: '', region: 'Aşgabat', branch: '',
|
||||
firstName: '', lastName: '', patronicName: '', education: '',
|
||||
marriageStatus: '', dateOfBirth: '', residence: '', currentResidence: '',
|
||||
passportSerie: '', 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: '',
|
||||
}
|
||||
status: "GARAŞYLÝAR",
|
||||
loanType: "",
|
||||
region: "Aşgabat",
|
||||
branch: "",
|
||||
firstName: "",
|
||||
lastName: "",
|
||||
patronicName: "",
|
||||
education: "",
|
||||
marriageStatus: "",
|
||||
dateOfBirth: "",
|
||||
residence: "",
|
||||
currentResidence: "",
|
||||
passportSerie: "",
|
||||
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) {
|
||||
return {
|
||||
status: data.status,
|
||||
loanType: data.loanType,
|
||||
region: data.region,
|
||||
branch: data.branch,
|
||||
firstName: data.firstName,
|
||||
lastName: data.lastName,
|
||||
patronicName: data.patronicName || undefined,
|
||||
education: data.education,
|
||||
marriageStatus: data.marriageStatus,
|
||||
dateOfBirth: data.dateOfBirth,
|
||||
residence: data.residence,
|
||||
currentResidence: data.currentResidence || undefined,
|
||||
passportSerie: data.passportSerie,
|
||||
passportNumber: data.passportNumber,
|
||||
status: data.status,
|
||||
loanType: data.loanType,
|
||||
region: data.region,
|
||||
branch: data.branch,
|
||||
firstName: data.firstName,
|
||||
lastName: data.lastName,
|
||||
patronicName: data.patronicName || undefined,
|
||||
education: data.education,
|
||||
marriageStatus: data.marriageStatus,
|
||||
dateOfBirth: data.dateOfBirth,
|
||||
residence: data.residence,
|
||||
currentResidence: data.currentResidence || undefined,
|
||||
passportSerie: data.passportSerie,
|
||||
passportNumber: data.passportNumber,
|
||||
passportDateOfIssue: data.passportDateOfIssue,
|
||||
passportGivenBy: data.passportGivenBy,
|
||||
bornPlace: data.bornPlace || undefined,
|
||||
email: data.email || undefined,
|
||||
phone: data.phone,
|
||||
phoneAdditional: data.phoneAdditional || undefined,
|
||||
homePhone: data.homePhone || undefined,
|
||||
workCompany: data.workCompany,
|
||||
workHrPhone: data.workHrPhone || undefined,
|
||||
workRegion: data.workRegion || undefined,
|
||||
workProvince: data.workProvince || undefined,
|
||||
position: data.position,
|
||||
salary: Number(data.salary),
|
||||
workStartedAt: data.workStartedAt,
|
||||
note: data.note || undefined,
|
||||
loanAmount: Number(data.loanAmount) || undefined,
|
||||
loanHistory: data.loanHistory || undefined,
|
||||
cardNumber: data.cardNumber || undefined,
|
||||
cardName: data.cardName || undefined,
|
||||
cardExpMonth: data.cardExpMonth || undefined,
|
||||
cardExpYear: data.cardExpYear || undefined,
|
||||
guarantor1Name: data.guarantor1Name || undefined,
|
||||
guarantor1Surname: data.guarantor1Surname || undefined,
|
||||
guarantor1Patronic: data.guarantor1Patronic || undefined,
|
||||
guarantor1PassportSerie: data.guarantor1PassportSerie || undefined,
|
||||
passportGivenBy: data.passportGivenBy,
|
||||
bornPlace: data.bornPlace || undefined,
|
||||
email: data.email || undefined,
|
||||
phone: data.phone,
|
||||
phoneAdditional: data.phoneAdditional || undefined,
|
||||
homePhone: data.homePhone || undefined,
|
||||
workCompany: data.workCompany,
|
||||
workHrPhone: data.workHrPhone || undefined,
|
||||
workRegion: data.workRegion || undefined,
|
||||
workProvince: data.workProvince || undefined,
|
||||
position: data.position,
|
||||
salary: Number(data.salary),
|
||||
workStartedAt: data.workStartedAt,
|
||||
note: data.note || undefined,
|
||||
loanAmount: Number(data.loanAmount) || undefined,
|
||||
loanHistory: data.loanHistory || undefined,
|
||||
cardNumber: data.cardNumber || undefined,
|
||||
cardName: data.cardName || undefined,
|
||||
cardExpMonth: data.cardExpMonth || undefined,
|
||||
cardExpYear: data.cardExpYear || undefined,
|
||||
guarantor1Name: data.guarantor1Name || undefined,
|
||||
guarantor1Surname: data.guarantor1Surname || undefined,
|
||||
guarantor1Patronic: data.guarantor1Patronic || undefined,
|
||||
guarantor1PassportSerie: data.guarantor1PassportSerie || undefined,
|
||||
guarantor1PassportNumber: data.guarantor1PassportNumber || undefined,
|
||||
guarantor1CardNumber: data.guarantor1CardNumber || undefined,
|
||||
guarantor1CardName: data.guarantor1CardName || undefined,
|
||||
guarantor1CardExpMonth: data.guarantor1CardExpMonth || undefined,
|
||||
guarantor1CardExpYear: data.guarantor1CardExpYear || undefined,
|
||||
guarantor1Salary: Number(data.guarantor1Salary) || undefined,
|
||||
}
|
||||
guarantor1CardNumber: data.guarantor1CardNumber || undefined,
|
||||
guarantor1CardName: data.guarantor1CardName || undefined,
|
||||
guarantor1CardExpMonth: data.guarantor1CardExpMonth || undefined,
|
||||
guarantor1CardExpYear: data.guarantor1CardExpYear || 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 i18next from 'i18next'
|
||||
|
||||
const fileRequired = z.custom<File>((val) => val instanceof File, 'validation.requiredFile')
|
||||
import { z } from "zod";
|
||||
import i18next from "i18next";
|
||||
|
||||
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({
|
||||
status: z.string().min(1, 'validation.required'),
|
||||
loanType: z.string().min(1, 'validation.required'),
|
||||
region: z.string().min(1, 'validation.required'),
|
||||
branch: z.string().min(1, 'validation.required'),
|
||||
firstName: z.string().min(1, 'validation.required'),
|
||||
lastName: z.string().min(1, 'validation.required'),
|
||||
status: z.string().min(1, "validation.required"),
|
||||
loanType: z.string().min(1, "validation.required"),
|
||||
region: z.string().min(1, "validation.required"),
|
||||
branch: z.string().min(1, "validation.required"),
|
||||
firstName: z.string().min(1, "validation.required"),
|
||||
lastName: z.string().min(1, "validation.required"),
|
||||
patronicName: z.string().optional(),
|
||||
education: z.string().min(1, 'validation.required'),
|
||||
marriageStatus: z.string().min(1, 'validation.required'),
|
||||
dateOfBirth: z.string().min(1, 'validation.required'),
|
||||
residence: z.string().min(1, 'validation.required'),
|
||||
education: z.string().min(1, "validation.required"),
|
||||
marriageStatus: z.string().min(1, "validation.required"),
|
||||
dateOfBirth: z.string().min(1, "validation.required"),
|
||||
residence: z.string().min(1, "validation.required"),
|
||||
currentResidence: z.string().optional(),
|
||||
passportSerie: z.string().min(1, 'validation.required'),
|
||||
passportNumber: z.string().min(1, 'validation.required'),
|
||||
passportDateOfIssue: z.string().min(1, 'validation.required'),
|
||||
passportGivenBy: z.string().min(1, 'validation.required'),
|
||||
passportSerie: z.string().min(1, "validation.required"),
|
||||
passportNumber: z.string().min(1, "validation.required"),
|
||||
passportDateOfIssue: z.string().min(1, "validation.required"),
|
||||
passportGivenBy: z.string().min(1, "validation.required"),
|
||||
bornPlace: z.string().optional(),
|
||||
email: z.string().optional(),
|
||||
phone: z.string()
|
||||
.min(1, 'validation.required')
|
||||
.refine((val) => val.replace(/\D/g, '').length >= 8, { message: 'validation.invalidPhone' }),
|
||||
phoneAdditional: z.string().optional(),
|
||||
homePhone: z.string().optional(),
|
||||
workCompany: z.string().min(1, 'validation.required'),
|
||||
workHrPhone: z.string().optional(),
|
||||
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" },
|
||||
),
|
||||
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(),
|
||||
workProvince: z.string().optional(),
|
||||
position: z.string().min(1, 'validation.required'),
|
||||
salary: z.string().min(1, 'validation.required'),
|
||||
workStartedAt: z.string().min(1, 'validation.required'),
|
||||
position: z.string().min(1, "validation.required"),
|
||||
salary: z.string().min(1, "validation.required"),
|
||||
workStartedAt: z.string().min(1, "validation.required"),
|
||||
passportPage1: z.custom<File | null>().nullable(),
|
||||
passportPage23: z.custom<File | null>().nullable(),
|
||||
passportPage89: z.custom<File | null>().nullable(),
|
||||
passportPage32: z.custom<File | null>().nullable(),
|
||||
note: z.string().optional(),
|
||||
loanAmount: z.string().min(1, 'validation.required'),
|
||||
loanAmount: z.string().min(1, "validation.required"),
|
||||
loanHistory: z.string().optional(),
|
||||
cardNumber: z.string().min(1, 'validation.required'),
|
||||
cardName: z.string().min(1, 'validation.required'),
|
||||
cardExpMonth: z.string().min(1, 'validation.required'),
|
||||
cardExpYear: z.string().min(1, 'validation.required'),
|
||||
guarantor1Name: z.string().min(1, 'validation.required'),
|
||||
guarantor1Surname: z.string().min(1, 'validation.required'),
|
||||
cardNumber: z.string().min(1, "validation.required"),
|
||||
cardName: z.string().min(1, "validation.required"),
|
||||
cardExpMonth: z.string().min(1, "validation.required"),
|
||||
cardExpYear: z.string().min(1, "validation.required"),
|
||||
guarantor1Name: z.string().min(1, "validation.required"),
|
||||
guarantor1Surname: z.string().min(1, "validation.required"),
|
||||
guarantor1Patronic: z.string().optional(),
|
||||
guarantor1PassportSerie: z.string().min(1, 'validation.required'),
|
||||
guarantor1PassportNumber: z.string().min(1, 'validation.required'),
|
||||
guarantor1CardNumber: z.string().min(1, 'validation.required'),
|
||||
guarantor1CardName: z.string().min(1, 'validation.required'),
|
||||
guarantor1CardExpMonth: z.string().min(1, 'validation.required'),
|
||||
guarantor1CardExpYear: z.string().min(1, 'validation.required'),
|
||||
guarantor1Salary: z.string().min(1, 'validation.required'),
|
||||
})
|
||||
guarantor1PassportSerie: z.string().min(1, "validation.required"),
|
||||
guarantor1PassportNumber: z.string().min(1, "validation.required"),
|
||||
guarantor1CardNumber: z.string().min(1, "validation.required"),
|
||||
guarantor1CardName: z.string().min(1, "validation.required"),
|
||||
guarantor1CardExpMonth: z.string().min(1, "validation.required"),
|
||||
guarantor1CardExpYear: 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>>> = {
|
||||
0: loanOrderFormSchema.pick({ status: true }),
|
||||
1: loanOrderFormSchema.pick({ loanType: true, loanAmount: true }),
|
||||
2: loanOrderFormSchema.pick({ region: true, branch: true }),
|
||||
3: loanOrderFormSchema.pick({
|
||||
firstName: true, lastName: true, education: true,
|
||||
marriageStatus: true, dateOfBirth: true, residence: true,
|
||||
firstName: true,
|
||||
lastName: true,
|
||||
education: true,
|
||||
marriageStatus: true,
|
||||
dateOfBirth: true,
|
||||
residence: true,
|
||||
}),
|
||||
4: loanOrderFormSchema.pick({
|
||||
cardNumber: true, cardName: true, cardExpMonth: true, cardExpYear: true,
|
||||
cardNumber: true,
|
||||
cardName: true,
|
||||
cardExpMonth: true,
|
||||
cardExpYear: true,
|
||||
}),
|
||||
5: loanOrderFormSchema.pick({
|
||||
passportSerie: true, passportNumber: true,
|
||||
passportDateOfIssue: true, passportGivenBy: true,
|
||||
passportSerie: true,
|
||||
passportNumber: true,
|
||||
passportDateOfIssue: true,
|
||||
passportGivenBy: true,
|
||||
}),
|
||||
6: loanOrderFormSchema.pick({ phone: true }),
|
||||
6: loanOrderFormSchema.pick({ phone: true, phoneAdditional: true, homePhone: true }),
|
||||
7: loanOrderFormSchema.pick({
|
||||
workCompany: true, position: true, salary: true, workStartedAt: true,
|
||||
workCompany: true,
|
||||
position: true,
|
||||
salary: true,
|
||||
workStartedAt: true,
|
||||
workHrPhone: true,
|
||||
}),
|
||||
8: z.object({
|
||||
passportPage1: fileRequired,
|
||||
passportPage23: fileRequired,
|
||||
}),
|
||||
9: loanOrderFormSchema.pick({
|
||||
guarantor1Name: true, guarantor1Surname: true,
|
||||
guarantor1PassportSerie: true, guarantor1PassportNumber: true,
|
||||
guarantor1CardNumber: true, guarantor1CardName: true,
|
||||
guarantor1CardExpMonth: true, guarantor1CardExpYear: true,
|
||||
guarantor1Name: true,
|
||||
guarantor1Surname: true,
|
||||
guarantor1PassportSerie: true,
|
||||
guarantor1PassportNumber: true,
|
||||
guarantor1CardNumber: true,
|
||||
guarantor1CardName: true,
|
||||
guarantor1CardExpMonth: true,
|
||||
guarantor1CardExpYear: true,
|
||||
guarantor1Salary: true,
|
||||
}),
|
||||
}
|
||||
};
|
||||
|
||||
export function validateStep(stepIndex: number, form: LoanOrderFormData, mode: 'create' | 'edit'): 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>> = {}
|
||||
export function validateStep(
|
||||
stepIndex: number,
|
||||
form: LoanOrderFormData,
|
||||
mode: "create" | "edit",
|
||||
): 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) {
|
||||
const key = issue.path[0] as keyof LoanOrderFormData
|
||||
const key = issue.path[0] as keyof LoanOrderFormData;
|
||||
if (!errors[key]) {
|
||||
const msg = issue.message
|
||||
errors[key] = msg.startsWith('validation.') ? i18next.t(msg, msg) : msg
|
||||
const msg = issue.message;
|
||||
errors[key] = msg.startsWith("validation.") ? i18next.t(msg, msg) : msg;
|
||||
}
|
||||
}
|
||||
return errors
|
||||
return errors;
|
||||
}
|
||||
|
||||
export const DEFAULT_FORM_VALUES: LoanOrderFormData = {
|
||||
status: 'GARAŞYLÝAR', loanType: '', region: 'Aşgabat', branch: '',
|
||||
firstName: '', lastName: '', patronicName: '', education: '',
|
||||
marriageStatus: '', dateOfBirth: '', residence: '', currentResidence: '',
|
||||
passportSerie: '', 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: '',
|
||||
}
|
||||
status: "GARAŞYLÝAR",
|
||||
loanType: "",
|
||||
region: "Aşgabat",
|
||||
branch: "",
|
||||
firstName: "",
|
||||
lastName: "",
|
||||
patronicName: "",
|
||||
education: "",
|
||||
marriageStatus: "",
|
||||
dateOfBirth: "",
|
||||
residence: "",
|
||||
currentResidence: "",
|
||||
passportSerie: "",
|
||||
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) {
|
||||
return {
|
||||
status: data.status,
|
||||
loanType: data.loanType,
|
||||
region: data.region,
|
||||
branch: data.branch,
|
||||
firstName: data.firstName,
|
||||
lastName: data.lastName,
|
||||
patronicName: data.patronicName || undefined,
|
||||
education: data.education,
|
||||
marriageStatus: data.marriageStatus,
|
||||
dateOfBirth: data.dateOfBirth,
|
||||
residence: data.residence,
|
||||
currentResidence: data.currentResidence || undefined,
|
||||
passportSerie: data.passportSerie,
|
||||
passportNumber: data.passportNumber,
|
||||
status: data.status,
|
||||
loanType: data.loanType,
|
||||
region: data.region,
|
||||
branch: data.branch,
|
||||
firstName: data.firstName,
|
||||
lastName: data.lastName,
|
||||
patronicName: data.patronicName || undefined,
|
||||
education: data.education,
|
||||
marriageStatus: data.marriageStatus,
|
||||
dateOfBirth: data.dateOfBirth,
|
||||
residence: data.residence,
|
||||
currentResidence: data.currentResidence || undefined,
|
||||
passportSerie: data.passportSerie,
|
||||
passportNumber: data.passportNumber,
|
||||
passportDateOfIssue: data.passportDateOfIssue,
|
||||
passportGivenBy: data.passportGivenBy,
|
||||
bornPlace: data.bornPlace || undefined,
|
||||
email: data.email || undefined,
|
||||
phone: data.phone,
|
||||
phoneAdditional: data.phoneAdditional || undefined,
|
||||
homePhone: data.homePhone || undefined,
|
||||
workCompany: data.workCompany,
|
||||
workHrPhone: data.workHrPhone || undefined,
|
||||
workRegion: data.workRegion || undefined,
|
||||
workProvince: data.workProvince || undefined,
|
||||
position: data.position,
|
||||
salary: Number(data.salary),
|
||||
workStartedAt: data.workStartedAt,
|
||||
note: data.note || undefined,
|
||||
loanAmount: Number(data.loanAmount) || undefined,
|
||||
loanHistory: data.loanHistory || undefined,
|
||||
cardNumber: data.cardNumber || undefined,
|
||||
cardName: data.cardName || undefined,
|
||||
cardExpMonth: data.cardExpMonth || undefined,
|
||||
cardExpYear: data.cardExpYear || undefined,
|
||||
guarantor1Name: data.guarantor1Name || undefined,
|
||||
guarantor1Surname: data.guarantor1Surname || undefined,
|
||||
guarantor1Patronic: data.guarantor1Patronic || undefined,
|
||||
guarantor1PassportSerie: data.guarantor1PassportSerie || undefined,
|
||||
passportGivenBy: data.passportGivenBy,
|
||||
bornPlace: data.bornPlace || undefined,
|
||||
email: data.email || undefined,
|
||||
phone: data.phone,
|
||||
phoneAdditional: data.phoneAdditional || undefined,
|
||||
homePhone: data.homePhone || undefined,
|
||||
workCompany: data.workCompany,
|
||||
workHrPhone: data.workHrPhone || undefined,
|
||||
workRegion: data.workRegion || undefined,
|
||||
workProvince: data.workProvince || undefined,
|
||||
position: data.position,
|
||||
salary: Number(data.salary),
|
||||
workStartedAt: data.workStartedAt,
|
||||
note: data.note || undefined,
|
||||
loanAmount: Number(data.loanAmount) || undefined,
|
||||
loanHistory: data.loanHistory || undefined,
|
||||
cardNumber: data.cardNumber || undefined,
|
||||
cardName: data.cardName || undefined,
|
||||
cardExpMonth: data.cardExpMonth || undefined,
|
||||
cardExpYear: data.cardExpYear || undefined,
|
||||
guarantor1Name: data.guarantor1Name || undefined,
|
||||
guarantor1Surname: data.guarantor1Surname || undefined,
|
||||
guarantor1Patronic: data.guarantor1Patronic || undefined,
|
||||
guarantor1PassportSerie: data.guarantor1PassportSerie || undefined,
|
||||
guarantor1PassportNumber: data.guarantor1PassportNumber || undefined,
|
||||
guarantor1CardNumber: data.guarantor1CardNumber || undefined,
|
||||
guarantor1CardName: data.guarantor1CardName || undefined,
|
||||
guarantor1CardExpMonth: data.guarantor1CardExpMonth || undefined,
|
||||
guarantor1CardExpYear: data.guarantor1CardExpYear || undefined,
|
||||
guarantor1Salary: Number(data.guarantor1Salary) || undefined,
|
||||
}
|
||||
guarantor1CardNumber: data.guarantor1CardNumber || undefined,
|
||||
guarantor1CardName: data.guarantor1CardName || undefined,
|
||||
guarantor1CardExpMonth: data.guarantor1CardExpMonth || undefined,
|
||||
guarantor1CardExpYear: data.guarantor1CardExpYear || undefined,
|
||||
guarantor1Salary: Number(data.guarantor1Salary) || undefined,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,238 +1,226 @@
|
||||
import { useMemo, useEffect, useCallback } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { useForm } from 'react-hook-form'
|
||||
import { zodResolver } from '@hookform/resolvers/zod'
|
||||
import { Checkbox } from '@/components/ui/checkbox'
|
||||
import { FormActions } from '@/components/formActions'
|
||||
import { FormInput } from '@/components/formInput'
|
||||
import { useCreateOperator, useUpdateOperator } from '../hooks/useOperators'
|
||||
import { operatorFormSchema, DEFAULT_FORM_VALUES, buildPayload } from '../schemas/operator.schema'
|
||||
import type { OperatorFormData } from '../schemas/operator.schema'
|
||||
import type { Operator } from '../api/operatorsApi'
|
||||
import { useMemo, useEffect, useCallback } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useForm } from "react-hook-form";
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { Checkbox } from "@/components/ui/checkbox";
|
||||
import { FormActions } from "@/components/formActions";
|
||||
import { FormInput } from "@/components/formInput";
|
||||
import { useCreateOperator, useUpdateOperator } from "../hooks/useOperators";
|
||||
import { operatorFormSchema, DEFAULT_FORM_VALUES, buildPayload } from "../schemas/operator.schema";
|
||||
import type { OperatorFormData } from "../schemas/operator.schema";
|
||||
import type { Operator } from "../api/operatorsApi";
|
||||
|
||||
// ─── Types ────────────────────────────────────────────────────────────────────
|
||||
|
||||
interface OperatorFormProps {
|
||||
mode: 'create' | 'edit'
|
||||
initialData?: Operator
|
||||
mode: "create" | "edit";
|
||||
initialData?: Operator;
|
||||
}
|
||||
|
||||
// ─── Helpers ──────────────────────────────────────────────────────────────────
|
||||
|
||||
type FlatErrors = Partial<Record<keyof OperatorFormData, string>>
|
||||
type FlatErrors = Partial<Record<keyof OperatorFormData, string>>;
|
||||
|
||||
function flattenErrors(errors: Record<string, { message?: string } | undefined>): FlatErrors {
|
||||
const result: FlatErrors = {}
|
||||
const result: FlatErrors = {};
|
||||
for (const key of Object.keys(errors)) {
|
||||
const msg = errors[key]?.message
|
||||
if (msg) result[key as keyof OperatorFormData] = msg
|
||||
const msg = errors[key]?.message;
|
||||
if (msg) result[key as keyof OperatorFormData] = msg;
|
||||
}
|
||||
return result
|
||||
return result;
|
||||
}
|
||||
|
||||
// ─── OperatorForm ─────────────────────────────────────────────────────────────
|
||||
|
||||
export function OperatorForm({ mode, initialData }: OperatorFormProps) {
|
||||
const { t: _t, i18n } = useTranslation()
|
||||
const { t: _t, i18n } = useTranslation();
|
||||
const t: (key: string, fallback?: string) => string = useCallback(
|
||||
(key, fallback) => _t(key, fallback ?? key) as string,
|
||||
[_t, i18n.language],
|
||||
)
|
||||
const navigate = useNavigate()
|
||||
);
|
||||
const navigate = useNavigate();
|
||||
|
||||
const createMutation = useCreateOperator()
|
||||
const updateMutation = useUpdateOperator(initialData?.id ?? 0)
|
||||
const createMutation = useCreateOperator();
|
||||
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 {
|
||||
watch, setValue, getValues, formState: { errors: rhfErrors }, clearErrors, trigger,
|
||||
watch,
|
||||
setValue,
|
||||
getValues,
|
||||
formState: { errors: rhfErrors },
|
||||
clearErrors,
|
||||
trigger,
|
||||
} = useForm<OperatorFormData>({
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
resolver: zodResolver(schema as any),
|
||||
defaultValues: initialData
|
||||
? {
|
||||
...DEFAULT_FORM_VALUES,
|
||||
username: initialData.username,
|
||||
name: initialData.name,
|
||||
phone: initialData.phone ?? '',
|
||||
email: initialData.email ?? '',
|
||||
password: '',
|
||||
phone: initialData.phone ?? "",
|
||||
email: initialData.email ?? "",
|
||||
password: "",
|
||||
isActive: initialData.isActive,
|
||||
}
|
||||
: DEFAULT_FORM_VALUES,
|
||||
})
|
||||
});
|
||||
|
||||
const form = watch()
|
||||
const errors = useMemo(() => flattenErrors(rhfErrors as Record<string, { message?: string } | undefined>), [rhfErrors])
|
||||
const form = watch();
|
||||
const errors = useMemo(() => flattenErrors(rhfErrors as Record<string, { message?: string } | undefined>), [rhfErrors]);
|
||||
|
||||
const setField = <K extends keyof OperatorFormData>(key: K, value: OperatorFormData[K]) => {
|
||||
;(setValue as (name: K, val: OperatorFormData[K]) => void)(key, value)
|
||||
clearErrors(key)
|
||||
}
|
||||
(setValue as (name: K, val: OperatorFormData[K]) => void)(key, value);
|
||||
clearErrors(key);
|
||||
};
|
||||
|
||||
// ── Re-validate on language change ──
|
||||
useEffect(() => {
|
||||
if (Object.keys(rhfErrors).length > 0) {
|
||||
trigger()
|
||||
trigger();
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [i18n.language])
|
||||
}, [i18n.language]);
|
||||
|
||||
// ── Submit ──────────────────────────────────────────────────────────────────
|
||||
const handleSubmit = async () => {
|
||||
const isValid = await trigger()
|
||||
if (!isValid) return
|
||||
const isValid = await trigger();
|
||||
if (!isValid) return;
|
||||
|
||||
const data = getValues()
|
||||
const data = getValues();
|
||||
|
||||
if (mode === 'create') {
|
||||
const payload = buildPayload(data)
|
||||
if (mode === "create") {
|
||||
const payload = buildPayload(data);
|
||||
createMutation.mutate(payload, {
|
||||
onSuccess: () => navigate('/operators'),
|
||||
})
|
||||
onSuccess: () => navigate("/operators"),
|
||||
});
|
||||
} else {
|
||||
updateMutation.mutate({
|
||||
username: data.username.trim(),
|
||||
name: data.name.trim(),
|
||||
phone: data.phone.trim() || undefined,
|
||||
email: data.email.trim() || undefined,
|
||||
isActive: data.isActive,
|
||||
...(data.password.trim() ? { password: data.password } : {}),
|
||||
}, {
|
||||
onSuccess: () => navigate(`/operators/${initialData!.id}`),
|
||||
})
|
||||
updateMutation.mutate(
|
||||
{
|
||||
username: data.username.trim(),
|
||||
name: data.name.trim(),
|
||||
phone: data.phone.trim() || undefined,
|
||||
email: data.email.trim() || undefined,
|
||||
isActive: data.isActive,
|
||||
...(data.password.trim() ? { password: data.password } : {}),
|
||||
},
|
||||
{
|
||||
onSuccess: () => navigate(`/operators/${initialData!.id}`),
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// ── Render ──────────────────────────────────────────────────────────────────
|
||||
return (
|
||||
<div className="flex flex-col gap-5">
|
||||
<h1 className="text-xl font-semibold text-foreground">
|
||||
{mode === 'create'
|
||||
? t('operators.createTitle', 'Operator dörediň')
|
||||
: t('operators.editTitle', 'Operator üýtgetmek')}
|
||||
{mode === "create" ? t("operators.createTitle", "Operator dörediň") : t("operators.editTitle", "Operator üýtgetmek")}
|
||||
</h1>
|
||||
<div className="bg-card border border-border rounded-xl overflow-hidden">
|
||||
{/* Username */}
|
||||
<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.username', 'Ulanyjy ady')}
|
||||
<span className="text-destructive ml-0.5">*</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">
|
||||
{/* Username */}
|
||||
<div className="grid grid-cols-[220px_1fr] items-start py-4 px-6 border-b border-border">
|
||||
<span className="text-xs font-bold text-muted-foreground pt-2">
|
||||
{t("operators.fields.username", "Ulanyjy ady")}
|
||||
<span className="text-destructive ml-0.5">*</span>
|
||||
</span>
|
||||
<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}
|
||||
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"
|
||||
/>
|
||||
{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"
|
||||
{/* 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
|
||||
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>
|
||||
|
||||
<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>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,36 +1,53 @@
|
||||
import { z } from 'zod'
|
||||
import type { CreateOperatorPayload } from '../api/operatorsApi'
|
||||
import { z } from "zod";
|
||||
import type { CreateOperatorPayload } from "../api/operatorsApi";
|
||||
|
||||
export function operatorFormSchema(
|
||||
mode: 'create' | 'edit',
|
||||
t: (key: string, fallback?: string) => string,
|
||||
) {
|
||||
const VALID_PHONE_PREFIXES = ["61", "62", "63", "64", "65", "71"];
|
||||
|
||||
export function operatorFormSchema(mode: "create" | "edit", t: (key: string, fallback?: string) => string) {
|
||||
const baseSchema = z.object({
|
||||
username: z.string().min(1, t('validation.required', 'validation.required')),
|
||||
name: z.string().min(1, t('validation.required', 'validation.required')),
|
||||
phone: z.string().default(''),
|
||||
email: z.string().default(''),
|
||||
username: z.string().min(1, t("validation.required", "validation.required")),
|
||||
name: z.string().min(1, t("validation.required", "validation.required")),
|
||||
phone: z
|
||||
.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(),
|
||||
isActive: z.boolean(),
|
||||
})
|
||||
});
|
||||
|
||||
return mode === 'create'
|
||||
return mode === "create"
|
||||
? 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 = {
|
||||
username: '',
|
||||
name: '',
|
||||
phone: '',
|
||||
email: '',
|
||||
password: '',
|
||||
username: "",
|
||||
name: "",
|
||||
phone: "",
|
||||
email: "",
|
||||
password: "",
|
||||
isActive: true,
|
||||
}
|
||||
};
|
||||
|
||||
export function buildPayload(data: OperatorFormData): CreateOperatorPayload {
|
||||
return {
|
||||
@@ -40,5 +57,5 @@ export function buildPayload(data: OperatorFormData): CreateOperatorPayload {
|
||||
email: data.email.trim() || undefined,
|
||||
password: data.password,
|
||||
isActive: data.isActive,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -311,6 +311,7 @@ function StepPersonal({
|
||||
label={t("Phone Additional") || "Telefon goşmaça"}
|
||||
value={form.phoneExtra}
|
||||
onChange={(v) => set("phoneExtra", v)}
|
||||
error={errors.phoneExtra}
|
||||
/>
|
||||
</BentoCard>
|
||||
<BentoCard>
|
||||
|
||||
@@ -1,113 +1,163 @@
|
||||
import { z } from 'zod'
|
||||
import i18next from 'i18next'
|
||||
import type { CardOrderStatus } from '../api/orderNewCardApi'
|
||||
import { z } from "zod";
|
||||
import i18next from "i18next";
|
||||
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({
|
||||
isPaid: z.boolean(),
|
||||
status: z.string().min(1, 'validation.required'),
|
||||
status: z.string().min(1, "validation.required"),
|
||||
note: z.string().optional(),
|
||||
issuanceReasonId: z.string().min(1, 'validation.required'),
|
||||
cardTypeId: z.string().min(1, 'validation.required'),
|
||||
provinceId: z.string().min(1, 'validation.required'),
|
||||
branchId: z.string().min(1, 'validation.required'),
|
||||
firstName: z.string().min(1, 'validation.required'),
|
||||
lastName: z.string().min(1, 'validation.required'),
|
||||
issuanceReasonId: z.string().min(1, "validation.required"),
|
||||
cardTypeId: z.string().min(1, "validation.required"),
|
||||
provinceId: z.string().min(1, "validation.required"),
|
||||
branchId: z.string().min(1, "validation.required"),
|
||||
firstName: z.string().min(1, "validation.required"),
|
||||
lastName: z.string().min(1, "validation.required"),
|
||||
middleName: z.string().optional(),
|
||||
formerLastName: z.string().optional(),
|
||||
birthDate: z.string().min(1, 'validation.required'),
|
||||
phone: z.string().min(1, 'validation.required'),
|
||||
phoneExtra: z.string().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'),
|
||||
birthDate: 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" },
|
||||
),
|
||||
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(),
|
||||
passportPage23: z.custom<File | null>().nullable(),
|
||||
passportPage89: z.custom<File | null>().nullable(),
|
||||
passportPage32: z.custom<File | null>().nullable(),
|
||||
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>>> = {
|
||||
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({
|
||||
firstName: true, lastName: true, birthDate: true, phone: true, citizenship: true,
|
||||
registeredAddress: true, currentAddress: true, workplace: true,
|
||||
firstName: true,
|
||||
lastName: true,
|
||||
birthDate: true,
|
||||
phone: true,
|
||||
phoneExtra: true,
|
||||
citizenship: true,
|
||||
registeredAddress: true,
|
||||
currentAddress: true,
|
||||
workplace: true,
|
||||
}),
|
||||
2: orderNewCardFormSchema.pick({
|
||||
passportSeriesId: true, passportNumber: true, passportIssueDate: true,
|
||||
passportIssuedBy: true, passportBirthPlace: true,
|
||||
passportSeriesId: true,
|
||||
passportNumber: true,
|
||||
passportIssueDate: true,
|
||||
passportIssuedBy: true,
|
||||
passportBirthPlace: true,
|
||||
}),
|
||||
3: z.object({
|
||||
passportPage1: fileRequired,
|
||||
passportPage23: fileRequired,
|
||||
passportPage89: fileRequired,
|
||||
passportPage32: fileRequired,
|
||||
termsAccepted: z.literal(true, { message: 'validation.requiredTerms' }),
|
||||
termsAccepted: z.literal(true, { message: "validation.requiredTerms" }),
|
||||
}),
|
||||
}
|
||||
};
|
||||
|
||||
export function validateStep(
|
||||
stepIndex: number,
|
||||
form: OrderNewCardFormData,
|
||||
mode: 'create' | 'edit',
|
||||
mode: "create" | "edit",
|
||||
): Partial<Record<keyof OrderNewCardFormData, string>> {
|
||||
if (stepIndex === 3 && mode === 'edit') return {}
|
||||
const schema = stepSchemas[stepIndex]
|
||||
const result = schema.safeParse(form)
|
||||
if (result.success) return {}
|
||||
const errors: Partial<Record<keyof OrderNewCardFormData, string>> = {}
|
||||
if (stepIndex === 3 && mode === "edit") return {};
|
||||
const schema = stepSchemas[stepIndex];
|
||||
const result = schema.safeParse(form);
|
||||
if (result.success) return {};
|
||||
const errors: Partial<Record<keyof OrderNewCardFormData, string>> = {};
|
||||
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]) {
|
||||
const msg = issue.message
|
||||
errors[key] = msg.startsWith('validation.') ? i18next.t(msg, msg) : msg
|
||||
const msg = issue.message;
|
||||
errors[key] = msg.startsWith("validation.") ? i18next.t(msg, msg) : msg;
|
||||
}
|
||||
}
|
||||
return errors
|
||||
return errors;
|
||||
}
|
||||
|
||||
export const DEFAULT_FORM_VALUES: OrderNewCardFormData = {
|
||||
isPaid: false,
|
||||
status: '',
|
||||
note: '',
|
||||
issuanceReasonId: '',
|
||||
cardTypeId: '',
|
||||
provinceId: '',
|
||||
branchId: '',
|
||||
firstName: '',
|
||||
lastName: '',
|
||||
middleName: '',
|
||||
formerLastName: '',
|
||||
birthDate: '',
|
||||
phone: '',
|
||||
phoneExtra: '',
|
||||
citizenship: 'Turkmenistan',
|
||||
registeredAddress: '',
|
||||
currentAddress: '',
|
||||
workplace: '',
|
||||
passportSeriesId: '',
|
||||
passportNumber: '',
|
||||
passportIssueDate: '',
|
||||
passportIssuedBy: '',
|
||||
passportBirthPlace: '',
|
||||
status: "",
|
||||
note: "",
|
||||
issuanceReasonId: "",
|
||||
cardTypeId: "",
|
||||
provinceId: "",
|
||||
branchId: "",
|
||||
firstName: "",
|
||||
lastName: "",
|
||||
middleName: "",
|
||||
formerLastName: "",
|
||||
birthDate: "",
|
||||
phone: "",
|
||||
phoneExtra: "",
|
||||
citizenship: "Turkmenistan",
|
||||
registeredAddress: "",
|
||||
currentAddress: "",
|
||||
workplace: "",
|
||||
passportSeriesId: "",
|
||||
passportNumber: "",
|
||||
passportIssueDate: "",
|
||||
passportIssuedBy: "",
|
||||
passportBirthPlace: "",
|
||||
passportPage1: null,
|
||||
passportPage23: null,
|
||||
passportPage89: null,
|
||||
passportPage32: null,
|
||||
termsAccepted: false,
|
||||
}
|
||||
};
|
||||
|
||||
export function buildPayload(data: OrderNewCardFormData) {
|
||||
return {
|
||||
@@ -134,9 +184,9 @@ export function buildPayload(data: OrderNewCardFormData) {
|
||||
passportIssueDate: data.passportIssueDate,
|
||||
passportIssuedBy: data.passportIssuedBy,
|
||||
passportBirthPlace: data.passportBirthPlace,
|
||||
...(data.passportPage1 && { passportPage1: data.passportPage1 }),
|
||||
...(data.passportPage1 && { passportPage1: data.passportPage1 }),
|
||||
...(data.passportPage23 && { passportPage23: data.passportPage23 }),
|
||||
...(data.passportPage89 && { passportPage89: data.passportPage89 }),
|
||||
...(data.passportPage32 && { passportPage32: data.passportPage32 }),
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,22 +1,40 @@
|
||||
import { z } from 'zod'
|
||||
import type { CreateSberPaymentPayload, PaymentStatus } from '@/features/sberPayments/api/sberPaymentsApi'
|
||||
import { z } from "zod";
|
||||
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({
|
||||
welayat: z.string().min(1, 'validation.required'),
|
||||
sahamca: z.string().min(1, 'validation.required'),
|
||||
firstName: z.string().min(1, 'validation.required'),
|
||||
lastName: z.string().min(1, 'validation.required'),
|
||||
phone: z.string().min(1, 'validation.required'),
|
||||
welayat: z.string().min(1, "validation.required"),
|
||||
sahamca: z.string().min(1, "validation.required"),
|
||||
firstName: z.string().min(1, "validation.required"),
|
||||
lastName: 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(),
|
||||
address: z.string().min(1, 'validation.required'),
|
||||
status: z.string().min(1, 'validation.required'),
|
||||
address: z.string().min(1, "validation.required"),
|
||||
status: z.string().min(1, "validation.required"),
|
||||
bellik: z.string(),
|
||||
accountNumber: z.string().min(1, 'validation.required'),
|
||||
passportSeries: z.string().min(1, 'validation.required'),
|
||||
passportNumber: z.string().min(1, 'validation.required'),
|
||||
fullName: z.string().min(1, 'validation.required'),
|
||||
accountNumber: z.string().min(1, "validation.required"),
|
||||
passportSeries: z.string().min(1, "validation.required"),
|
||||
passportNumber: z.string().min(1, "validation.required"),
|
||||
fullName: z.string().min(1, "validation.required"),
|
||||
client_id: z.string().optional(),
|
||||
acc_sberbank_card: fileField,
|
||||
acc_enrollment: fileField,
|
||||
@@ -32,54 +50,54 @@ export const sberPaymentFormSchema = z.object({
|
||||
snt_relation_doc: fileField,
|
||||
snt_new_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>>> = {
|
||||
0: sberPaymentFormSchema.pick({ status: true }),
|
||||
1: sberPaymentFormSchema.pick({ welayat: true, sahamca: true }),
|
||||
2: sberPaymentFormSchema.pick({ firstName: true, lastName: true, phone: true, address: true }),
|
||||
3: sberPaymentFormSchema.pick({ passportSeries: true, passportNumber: true, fullName: true, accountNumber: true }),
|
||||
}
|
||||
};
|
||||
|
||||
export function validateStep(
|
||||
stepIndex: number,
|
||||
form: SberPaymentFormData,
|
||||
mode: 'create' | 'edit',
|
||||
mode: "create" | "edit",
|
||||
t?: (key: string, fallback?: string) => string,
|
||||
): Partial<Record<keyof SberPaymentFormData, string>> {
|
||||
void mode
|
||||
const schema = stepSchemas[stepIndex]
|
||||
if (!schema) return {}
|
||||
const result = schema.safeParse(form)
|
||||
if (result.success) return {}
|
||||
const errors: Partial<Record<keyof SberPaymentFormData, string>> = {}
|
||||
void mode;
|
||||
const schema = stepSchemas[stepIndex];
|
||||
if (!schema) return {};
|
||||
const result = schema.safeParse(form);
|
||||
if (result.success) return {};
|
||||
const errors: Partial<Record<keyof SberPaymentFormData, string>> = {};
|
||||
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]) {
|
||||
const msg = issue.message
|
||||
errors[key] = t && msg.startsWith('validation.') ? t(msg, msg) : msg
|
||||
const msg = issue.message;
|
||||
errors[key] = t && msg.startsWith("validation.") ? t(msg, msg) : msg;
|
||||
}
|
||||
}
|
||||
return errors
|
||||
return errors;
|
||||
}
|
||||
|
||||
export const DEFAULT_FORM_VALUES: SberPaymentFormData = {
|
||||
client_id: '',
|
||||
welayat: '',
|
||||
sahamca: '',
|
||||
firstName: '',
|
||||
lastName: '',
|
||||
phone: '',
|
||||
email: '',
|
||||
address: '',
|
||||
status: 'GARASYLYYAR',
|
||||
bellik: '',
|
||||
accountNumber: '',
|
||||
passportSeries: '',
|
||||
passportNumber: '',
|
||||
fullName: '',
|
||||
client_id: "",
|
||||
welayat: "",
|
||||
sahamca: "",
|
||||
firstName: "",
|
||||
lastName: "",
|
||||
phone: "",
|
||||
email: "",
|
||||
address: "",
|
||||
status: "GARASYLYYAR",
|
||||
bellik: "",
|
||||
accountNumber: "",
|
||||
passportSeries: "",
|
||||
passportNumber: "",
|
||||
fullName: "",
|
||||
acc_sberbank_card: null,
|
||||
acc_enrollment: null,
|
||||
acc_summons: null,
|
||||
@@ -94,7 +112,7 @@ export const DEFAULT_FORM_VALUES: SberPaymentFormData = {
|
||||
snt_relation_doc: null,
|
||||
snt_new_passport_series: null,
|
||||
snt_old_passport_series: null,
|
||||
}
|
||||
};
|
||||
|
||||
export function buildPayload(data: SberPaymentFormData): CreateSberPaymentPayload {
|
||||
return {
|
||||
@@ -111,5 +129,5 @@ export function buildPayload(data: SberPaymentFormData): CreateSberPaymentPayloa
|
||||
passportSeries: data.passportSeries,
|
||||
passportNumber: data.passportNumber,
|
||||
fullName: data.fullName,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,26 +1,44 @@
|
||||
import { z } from 'zod'
|
||||
import i18next from 'i18next'
|
||||
import type { IntlPaymentCreatePayload, IntlPaymentStatus, CurrencyType } from '../api/visaMasterPaymentsApi'
|
||||
import { z } from "zod";
|
||||
import i18next from "i18next";
|
||||
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({
|
||||
client_id: z.string().min(1, 'validation.required'),
|
||||
status: z.string().min(1, 'validation.required'),
|
||||
note: z.string().optional().default(''),
|
||||
currency_type: z.string().min(1, 'validation.required'),
|
||||
province: z.string().min(1, 'validation.required'),
|
||||
branch: z.string().min(1, 'validation.required'),
|
||||
passport_first_name: z.string().min(1, 'validation.required'),
|
||||
passport_last_name: z.string().min(1, 'validation.required'),
|
||||
phone: z.string().min(1, 'validation.required'),
|
||||
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'),
|
||||
client_id: z.string().min(1, "validation.required"),
|
||||
status: z.string().min(1, "validation.required"),
|
||||
note: z.string().optional().default(""),
|
||||
currency_type: z.string().min(1, "validation.required"),
|
||||
province: z.string().min(1, "validation.required"),
|
||||
branch: z.string().min(1, "validation.required"),
|
||||
passport_first_name: z.string().min(1, "validation.required"),
|
||||
passport_last_name: 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().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_school_enrollment: fileField,
|
||||
doc_summons: fileField,
|
||||
@@ -36,62 +54,82 @@ export const visaMasterPaymentFormSchema = z.object({
|
||||
upd_doc_acceptance_letter: fileField,
|
||||
upd_doc_passport_biometric: 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>>> = {
|
||||
0: visaMasterPaymentFormSchema.pick({ client_id: true, status: true, currency_type: true }),
|
||||
1: visaMasterPaymentFormSchema.pick({ province: true, branch: true }),
|
||||
2: visaMasterPaymentFormSchema.pick({ passport_first_name: true, passport_last_name: true, phone: true }),
|
||||
3: visaMasterPaymentFormSchema.pick({
|
||||
passport_series: true, passport_number: true,
|
||||
payer_full_name: true, payer_account_number: true, receiver_info: true,
|
||||
passport_series: true,
|
||||
passport_number: true,
|
||||
payer_full_name: true,
|
||||
payer_account_number: true,
|
||||
receiver_info: true,
|
||||
}),
|
||||
4: z.object({}),
|
||||
}
|
||||
};
|
||||
|
||||
export function validateStep(
|
||||
stepIndex: number,
|
||||
form: IntlPaymentFormData,
|
||||
mode: 'create' | 'edit',
|
||||
mode: "create" | "edit",
|
||||
): Partial<Record<keyof IntlPaymentFormData, string>> {
|
||||
void mode
|
||||
const schema = stepSchemas[stepIndex]
|
||||
const result = schema.safeParse(form)
|
||||
if (result.success) return {}
|
||||
const errors: Partial<Record<keyof IntlPaymentFormData, string>> = {}
|
||||
void mode;
|
||||
const schema = stepSchemas[stepIndex];
|
||||
const result = schema.safeParse(form);
|
||||
if (result.success) return {};
|
||||
const errors: Partial<Record<keyof IntlPaymentFormData, string>> = {};
|
||||
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]) {
|
||||
const msg = issue.message
|
||||
errors[key] = msg.startsWith('validation.') ? i18next.t(msg, msg) : msg
|
||||
const msg = issue.message;
|
||||
errors[key] = msg.startsWith("validation.") ? i18next.t(msg, msg) : msg;
|
||||
}
|
||||
}
|
||||
return errors
|
||||
return errors;
|
||||
}
|
||||
|
||||
export const DEFAULT_FORM_VALUES: IntlPaymentFormData = {
|
||||
client_id: '', status: 'pending', note: '', currency_type: '',
|
||||
province: '', branch: '',
|
||||
passport_first_name: '', passport_last_name: '', phone: '',
|
||||
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,
|
||||
client_id: "",
|
||||
status: "pending",
|
||||
note: "",
|
||||
currency_type: "",
|
||||
province: "",
|
||||
branch: "",
|
||||
passport_first_name: "",
|
||||
passport_last_name: "",
|
||||
phone: "",
|
||||
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,
|
||||
upd_doc_passport_tm: null, upd_doc_foreign_passport: null,
|
||||
upd_doc_visa: null, upd_doc_acceptance_letter: null,
|
||||
upd_doc_passport_biometric: null, upd_doc_passport_old: null,
|
||||
}
|
||||
upd_doc_passport_tm: null,
|
||||
upd_doc_foreign_passport: 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 {
|
||||
return {
|
||||
...data,
|
||||
status: data.status as IntlPaymentStatus,
|
||||
currency_type: data.currency_type as CurrencyType,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user