Compare commits
236 Commits
release/mo
...
dev
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3c25ba30d0 | ||
|
|
ba36eb502b | ||
|
|
2c9a2bd30c | ||
|
|
f35acee64b | ||
|
|
a4c02a747f | ||
|
|
66b1e2cdcb | ||
|
|
81eca1c6e0 | ||
|
|
89f2b3b68c | ||
|
|
549bd901da | ||
|
|
6aad2d3aa2 | ||
|
|
09959e3ac3 | ||
|
|
7014462d42 | ||
|
|
62417b88ba | ||
|
|
bf0b5c9907 | ||
|
|
5347c3ef6c | ||
|
|
194292c083 | ||
|
|
7d023dba1e | ||
|
|
9c63cadf29 | ||
|
|
88b7501b4d | ||
|
|
8f53187a3c | ||
|
|
ef8059b3b1 | ||
|
|
8627233a17 | ||
|
|
2ece25dcb6 | ||
|
|
0eccd799c7 | ||
|
|
2e8c333374 | ||
|
|
671b25a087 | ||
|
|
4a314326fb | ||
|
|
d0270a3c9e | ||
|
|
71fc44e7a6 | ||
|
|
d6f5c73b9d | ||
|
|
d7908bb5da | ||
|
|
ed5391076c | ||
|
|
4a190e962a | ||
|
|
4644dbb404 | ||
|
|
5c6b419452 | ||
|
|
048d132da2 | ||
|
|
dd154a3004 | ||
|
|
8dbcf4bb7f | ||
|
|
c0f825a587 | ||
|
|
2b3dd5e7b9 | ||
|
|
5d1aa99d75 | ||
|
|
4be47fced5 | ||
|
|
66fc8ee70e | ||
|
|
09fc6956d8 | ||
|
|
501ed13f8a | ||
|
|
61132928b5 | ||
|
|
21b009c833 | ||
|
|
c616b981f1 | ||
|
|
93d16cf35c | ||
|
|
bd7cf3284b | ||
|
|
a0e6c4ff2f | ||
|
|
88fbb616b5 | ||
|
|
7efea2acc9 | ||
|
|
907f288815 | ||
|
|
2fea400060 | ||
|
|
f695835c61 | ||
|
|
47d47a0bfd | ||
|
|
540d5642a1 | ||
|
|
2ec2a14706 | ||
|
|
f7110497d3 | ||
|
|
c9326697f6 | ||
|
|
c2982cf31b | ||
|
|
8c69b3b9c4 | ||
|
|
24987be78e | ||
|
|
defc625324 | ||
|
|
eee91d5f2d | ||
|
|
a65202c653 | ||
|
|
ffaad142e8 | ||
|
|
9e40e5141c | ||
|
|
79e707a232 | ||
|
|
d374208097 | ||
|
|
557053caa6 | ||
|
|
e258873976 | ||
|
|
59e45ddc63 | ||
|
|
eaf95c6007 | ||
|
|
f3518244ab | ||
|
|
c5683f7edd | ||
|
|
acdacbf18e | ||
|
|
ef88c12e74 | ||
|
|
ab0d455afb | ||
|
|
e0d2836f4a | ||
|
|
4bc5234d09 | ||
|
|
6041082fec | ||
|
|
f426ca7f23 | ||
|
|
5115551b0e | ||
|
|
5ce9484e43 | ||
|
|
8a117e250c | ||
|
|
8089f62c31 | ||
|
|
bd775babf9 | ||
|
|
e222a3093a | ||
|
|
53debf2cff | ||
|
|
c092b8f47c | ||
|
|
6b7c679a0d | ||
|
|
7a00478727 | ||
|
|
677ab1d75b | ||
|
|
126302a10a | ||
|
|
35ce71c149 | ||
|
|
47b57c0c73 | ||
|
|
46c0b305b6 | ||
|
|
eb6f0ef949 | ||
|
|
7ca4e41980 | ||
|
|
662b04be0f | ||
|
|
e2d37712ad | ||
|
|
4c3d305e7f | ||
|
|
1aaa84e31d | ||
|
|
5a290d5be9 | ||
|
|
ac14a86c33 | ||
|
|
175cb63515 | ||
|
|
803b4a1cfb | ||
|
|
709eda1b50 | ||
|
|
bdc6d032aa | ||
|
|
3462395818 | ||
|
|
9308417c4d | ||
|
|
d0f11cbc63 | ||
|
|
eb1eb44769 | ||
|
|
6c300c8688 | ||
|
|
3898fc1bdf | ||
|
|
0c0dc7de53 | ||
|
|
703cee467c | ||
|
|
c154568bb4 | ||
|
|
8dd9627849 | ||
|
|
07c87d583f | ||
|
|
0ff6ba3f74 | ||
|
|
ae0b72aebd | ||
|
|
10f3760c63 | ||
|
|
db29a77d37 | ||
|
|
0936d1cdd7 | ||
|
|
5c039597b3 | ||
|
|
17a9810878 | ||
|
|
438242ac31 | ||
|
|
78064edf81 | ||
|
|
565cabb9bd | ||
|
|
903b32084a | ||
|
|
0f61d4a399 | ||
|
|
7df69f92e8 | ||
|
|
58d7a05591 | ||
|
|
802885e726 | ||
|
|
caeb304d15 | ||
|
|
d4c70101f2 | ||
|
|
6fd64a62bf | ||
|
|
11820a7b5d | ||
|
|
f9eda3c6b0 | ||
|
|
c77f60fdc3 | ||
|
|
84de7a84e8 | ||
|
|
498fa217fe | ||
|
|
0f32abc6b2 | ||
|
|
7ce8104b87 | ||
|
|
0952ce12ee | ||
|
|
b90bfc74d9 | ||
|
|
d06b6e20d5 | ||
|
|
654865e845 | ||
|
|
4fd5c3602e | ||
|
|
4a65a39ba3 | ||
|
|
e9edf189e7 | ||
|
|
e6289b7174 | ||
|
|
aaa8cadc02 | ||
|
|
554a702e6c | ||
|
|
8e65d864ef | ||
|
|
2090056b81 | ||
|
|
159fb85e63 | ||
|
|
56b6510933 | ||
|
|
6a828ce82b | ||
|
|
074de953c9 | ||
|
|
fe614b2529 | ||
|
|
b7ae72d4c0 | ||
|
|
805dc4dba3 | ||
|
|
290526b933 | ||
|
|
fd972aadad | ||
|
|
78c2446945 | ||
|
|
9a7e074863 | ||
|
|
9ea4eeb6ce | ||
|
|
cadfec5fc2 | ||
|
|
5c8560e266 | ||
|
|
2d0117bc4c | ||
|
|
05ed1b6aef | ||
|
|
4f509aefdf | ||
|
|
befa92fbce | ||
|
|
f4acf8c316 | ||
|
|
c9523328da | ||
|
|
0ed21711db | ||
|
|
c98167e609 | ||
|
|
feb72a3021 | ||
|
|
8e3fb86169 | ||
|
|
6a95fbb3f2 | ||
|
|
ab5700dd92 | ||
|
|
383b70434f | ||
|
|
f8adc2e8c7 | ||
|
|
0246916fca | ||
|
|
4383bc54b3 | ||
|
|
2800184cfe | ||
|
|
616313eb20 | ||
|
|
96e792b91d | ||
|
|
1d5328db73 | ||
|
|
45494483a0 | ||
|
|
7fb706cdaf | ||
|
|
d620cf0c92 | ||
|
|
5940f4c048 | ||
|
|
bb6a3986b1 | ||
|
|
2bea56fa87 | ||
|
|
d195530b15 | ||
|
|
04b7def049 | ||
|
|
a2471a0ca8 | ||
|
|
c9a9f3a66d | ||
|
|
910c5627d2 | ||
|
|
860ecb9384 | ||
|
|
87e4783dd5 | ||
|
|
0d35042e41 | ||
|
|
95040c5a10 | ||
|
|
06e7687fc1 | ||
|
|
79179c10f3 | ||
|
|
5e2fd20520 | ||
|
|
3e7d350248 | ||
|
|
618d8cca58 | ||
|
|
90c0ef481b | ||
|
|
1ea11f8eff | ||
|
|
e8d1057c69 | ||
|
|
5442905966 | ||
|
|
9d45a7bff0 | ||
|
|
29460f4509 | ||
|
|
44ccd85e86 | ||
|
|
57c28c741e | ||
|
|
d01047752f | ||
|
|
d1df501f86 | ||
|
|
b786f49aa1 | ||
|
|
4f972a4cfe | ||
|
|
b15de1ffe2 | ||
|
|
96c4a095b1 | ||
|
|
d6db50a582 | ||
|
|
fa3b6a2390 | ||
|
|
24e4d8cd7d | ||
|
|
259a63f787 | ||
|
|
e77a8e03d4 | ||
|
|
e2bbbaaeab | ||
|
|
ff6d7f57a2 | ||
|
|
3dbef34d33 | ||
|
|
156c6c51b5 |
@ -5,5 +5,8 @@ yarn.lock
|
||||
package-lock.json
|
||||
**/*.test.js
|
||||
coverage
|
||||
mocks
|
||||
graphql
|
||||
.eslintrc.js
|
||||
**/*.config.js
|
||||
**/scripts
|
||||
**/package.json
|
||||
turbo.json
|
||||
11
.eslintrc.js
Normal file
11
.eslintrc.js
Normal file
@ -0,0 +1,11 @@
|
||||
module.exports = {
|
||||
root: true,
|
||||
settings: {
|
||||
next: {
|
||||
rootDir: ['apps/*/'],
|
||||
},
|
||||
react: {
|
||||
version: 'detect',
|
||||
},
|
||||
},
|
||||
};
|
||||
@ -1,89 +0,0 @@
|
||||
{
|
||||
"root": true,
|
||||
"env": {
|
||||
"browser": true,
|
||||
"es2021": true,
|
||||
"node": true
|
||||
},
|
||||
"extends": [
|
||||
"next",
|
||||
"prettier",
|
||||
"airbnb",
|
||||
"airbnb-typescript",
|
||||
"plugin:@typescript-eslint/recommended",
|
||||
"plugin:unicorn/recommended"
|
||||
],
|
||||
"parserOptions": {
|
||||
"project": "./tsconfig.json"
|
||||
},
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"plugins": ["react", "prettier", "@typescript-eslint", "unicorn", "testing-library"],
|
||||
"rules": {
|
||||
"linebreak-style": ["error", "windows"],
|
||||
"comma-dangle": "off",
|
||||
"@typescript-eslint/comma-dangle": ["off"],
|
||||
"react/react-in-jsx-scope": "off",
|
||||
"react/jsx-props-no-spreading": "off",
|
||||
"react/jsx-filename-extension": [2, { "extensions": [".js", ".jsx", ".ts", ".tsx"] }],
|
||||
"react/forbid-prop-types": "off",
|
||||
"react/require-default-props": [
|
||||
"error",
|
||||
{
|
||||
"ignoreFunctionalComponents": true
|
||||
}
|
||||
],
|
||||
"import/extensions": "off",
|
||||
"object-curly-newline": [
|
||||
"warn",
|
||||
{
|
||||
"ObjectExpression": "always",
|
||||
"ObjectPattern": { "multiline": true },
|
||||
"ImportDeclaration": "never",
|
||||
"ExportDeclaration": { "multiline": true, "minProperties": 3 }
|
||||
}
|
||||
],
|
||||
"lines-between-class-members": "off",
|
||||
"@typescript-eslint/lines-between-class-members": ["off"],
|
||||
"indent": "off",
|
||||
"@typescript-eslint/indent": ["off"],
|
||||
"react/jsx-no-bind": [
|
||||
"error",
|
||||
{
|
||||
"ignoreDOMComponents": false,
|
||||
"ignoreRefs": false,
|
||||
"allowArrowFunctions": false,
|
||||
"allowFunctions": true,
|
||||
"allowBind": false
|
||||
}
|
||||
],
|
||||
"newline-before-return": "warn",
|
||||
"@typescript-eslint/consistent-type-imports": "error",
|
||||
"react/prop-types": "off",
|
||||
// Airbnb prefers forEach
|
||||
"unicorn/no-array-for-each": "off",
|
||||
"unicorn/prevent-abbreviations": "off",
|
||||
"unicorn/no-null": "off",
|
||||
"unicorn/prefer-node-protocol": "off",
|
||||
"unicorn/no-array-reduce": "off",
|
||||
"unicorn/prefer-module": "off",
|
||||
"unicorn/text-encoding-identifier-case": "off",
|
||||
"unicorn/filename-case": [
|
||||
"error",
|
||||
{
|
||||
"case": "kebabCase",
|
||||
"ignore": ["^.*.(jsx|tsx)$"]
|
||||
}
|
||||
],
|
||||
"import/no-unresolved": "warn",
|
||||
"implicit-arrow-linebreak": "warn",
|
||||
"operator-linebreak": "warn",
|
||||
"function-paren-newline": "warn"
|
||||
},
|
||||
"overrides": [
|
||||
// Only uses Testing Library lint rules in test files
|
||||
{
|
||||
"files": ["**/__tests__/**/*.[jt]s?(x)", "**/?(*.)+(spec|test).[jt]s?(x)"],
|
||||
"extends": ["plugin:testing-library/react"]
|
||||
}
|
||||
]
|
||||
}
|
||||
47
.gitignore
vendored
47
.gitignore
vendored
@ -1,12 +1,37 @@
|
||||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||
# Created by https://www.toptal.com/developers/gitignore/api/visualstudiocode
|
||||
# Edit at https://www.toptal.com/developers/gitignore?templates=visualstudiocode
|
||||
|
||||
### VisualStudioCode ###
|
||||
.vscode/*
|
||||
!.vscode/settings.json
|
||||
!.vscode/tasks.json
|
||||
!.vscode/launch.json
|
||||
!.vscode/extensions.json
|
||||
!.vscode/*.code-snippets
|
||||
|
||||
# Local History for Visual Studio Code
|
||||
.history/
|
||||
|
||||
# Built Visual Studio Code Extensions
|
||||
*.vsix
|
||||
|
||||
### VisualStudioCode Patch ###
|
||||
# Ignore all local history of files
|
||||
.history
|
||||
.ionide
|
||||
|
||||
# End of https://www.toptal.com/developers/gitignore/api/visualstudiocode
|
||||
# Created by https://www.toptal.com/developers/gitignore/api/nextjs
|
||||
# Edit at https://www.toptal.com/developers/gitignore?templates=nextjs
|
||||
|
||||
### NextJS ###
|
||||
# dependencies
|
||||
node_modules
|
||||
.pnp
|
||||
.pnp.js
|
||||
|
||||
# testing
|
||||
/coverage
|
||||
coverage
|
||||
|
||||
# next.js
|
||||
.next/
|
||||
@ -34,14 +59,14 @@ yarn-error.log*
|
||||
# typescript
|
||||
*.tsbuildinfo
|
||||
|
||||
# Yarn
|
||||
.pnp.*
|
||||
.yarn/*
|
||||
!.yarn/patches
|
||||
!.yarn/plugins
|
||||
!.yarn/releases
|
||||
!.yarn/sdks
|
||||
!.yarn/versions
|
||||
# End of https://www.toptal.com/developers/gitignore/api/nextjs
|
||||
# Created by https://www.toptal.com/developers/gitignore/api/turbo
|
||||
# Edit at https://www.toptal.com/developers/gitignore?templates=turbo
|
||||
|
||||
# turbo
|
||||
### Turbo ###
|
||||
# Turborepo task cache
|
||||
.turbo
|
||||
|
||||
# End of https://www.toptal.com/developers/gitignore/api/turbo
|
||||
|
||||
.pnpm
|
||||
@ -1,4 +1,4 @@
|
||||
#!/bin/sh
|
||||
. "$(dirname "$0")/_/husky.sh"
|
||||
#!/usr/bin/env sh
|
||||
. "$(dirname -- "$0")/_/husky.sh"
|
||||
|
||||
yarn precommit
|
||||
npx lint-staged --concurrent false
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
.next
|
||||
public
|
||||
graphql
|
||||
**/graphql/*.types.ts
|
||||
**/graphql/*.schema.graphql
|
||||
node_modules
|
||||
@ -4,7 +4,7 @@
|
||||
"bracketSpacing": true,
|
||||
"htmlWhitespaceSensitivity": "ignore",
|
||||
"insertPragma": false,
|
||||
"jsxBracketSameLine": false,
|
||||
"bracketSameLine": false,
|
||||
"jsxSingleQuote": false,
|
||||
"printWidth": 100,
|
||||
"proseWrap": "preserve",
|
||||
|
||||
10
.vscode/launch.json
vendored
10
.vscode/launch.json
vendored
@ -9,9 +9,15 @@
|
||||
},
|
||||
{
|
||||
"name": "Next.js: debug client-side",
|
||||
"type": "pwa-chrome",
|
||||
"type": "chrome",
|
||||
"request": "launch",
|
||||
"url": "http://localhost:3000"
|
||||
"url": "http://localhost:3000",
|
||||
"webRoot": "${workspaceFolder}/apps/web",
|
||||
"sourceMaps": true,
|
||||
"sourceMapPathOverrides": {
|
||||
"webpack://_N_E/*": "${webRoot}/*"
|
||||
},
|
||||
"skipFiles": ["**/<node_internals>/**", "**/node_modules/**"]
|
||||
},
|
||||
{
|
||||
"name": "Next.js: debug full stack",
|
||||
|
||||
18
.vscode/settings.json
vendored
18
.vscode/settings.json
vendored
@ -13,9 +13,19 @@
|
||||
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
||||
"editor.formatOnSave": true,
|
||||
"editor.codeActionsOnSave": {
|
||||
"source.organizeImports": true,
|
||||
"source.fixAll.eslint": true,
|
||||
"source.fixAll.format": true
|
||||
"source.fixAll": "explicit",
|
||||
"source.fixAll.eslint": "explicit",
|
||||
"source.removeUnusedImports": "explicit"
|
||||
},
|
||||
"workbench.editor.labelFormat": "short"
|
||||
"workbench.editor.labelFormat": "short",
|
||||
"eslint.workingDirectories": [{ "directory": "apps/web", "changeProcessCWD": true }],
|
||||
"eslint.validate": [
|
||||
"javascript",
|
||||
"javascriptreact",
|
||||
"json",
|
||||
"typescript",
|
||||
"typescriptreact",
|
||||
"yaml"
|
||||
],
|
||||
"eslint.lintTask.enable": true
|
||||
}
|
||||
|
||||
35
.yarn/plugins/@yarnpkg/plugin-outdated.cjs
vendored
35
.yarn/plugins/@yarnpkg/plugin-outdated.cjs
vendored
File diff suppressed because one or more lines are too long
9
.yarn/plugins/@yarnpkg/plugin-typescript.cjs
vendored
9
.yarn/plugins/@yarnpkg/plugin-typescript.cjs
vendored
File diff suppressed because one or more lines are too long
807
.yarn/releases/yarn-3.3.0.cjs
vendored
807
.yarn/releases/yarn-3.3.0.cjs
vendored
File diff suppressed because one or more lines are too long
@ -1,9 +0,0 @@
|
||||
nodeLinker: node-modules
|
||||
|
||||
plugins:
|
||||
- path: .yarn/plugins/@yarnpkg/plugin-typescript.cjs
|
||||
spec: '@yarnpkg/plugin-typescript'
|
||||
- path: .yarn/plugins/@yarnpkg/plugin-outdated.cjs
|
||||
spec: 'https://mskelton.dev/yarn-outdated/v3'
|
||||
|
||||
yarnPath: .yarn/releases/yarn-3.3.0.cjs
|
||||
@ -1,7 +0,0 @@
|
||||
/* eslint-disable import/prefer-default-export */
|
||||
import { isEmpty } from 'radash';
|
||||
import type { BaseOption } from 'ui/elements/types';
|
||||
|
||||
export function normalizeOptions(options: any[] | null | undefined) {
|
||||
return (isEmpty(options) ? [] : options) as BaseOption[];
|
||||
}
|
||||
@ -1,23 +0,0 @@
|
||||
/* eslint-disable import/prefer-default-export */
|
||||
import type { IReactionDisposer } from 'mobx';
|
||||
import { autorun } from 'mobx';
|
||||
|
||||
export function makeDisposable(
|
||||
createReaction: () => IReactionDisposer,
|
||||
mustBeDisposed: () => boolean
|
||||
) {
|
||||
let disposer: IReactionDisposer | undefined;
|
||||
|
||||
function cleanDisposer() {
|
||||
disposer = undefined;
|
||||
}
|
||||
|
||||
autorun(() => {
|
||||
if (mustBeDisposed()) {
|
||||
if (disposer !== undefined) disposer();
|
||||
cleanDisposer();
|
||||
} else {
|
||||
disposer = createReaction();
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -1,18 +0,0 @@
|
||||
/* eslint-disable implicit-arrow-linebreak */
|
||||
export function parser(value?: string) {
|
||||
if (!value) return 0;
|
||||
|
||||
const normalized = value.replace(/\s/g, '').replaceAll(',', '.');
|
||||
|
||||
return Number.parseFloat(normalized);
|
||||
}
|
||||
export const formatter = (value?: number) =>
|
||||
Intl.NumberFormat('ru', {
|
||||
minimumFractionDigits: 2,
|
||||
}).format(value || 0);
|
||||
|
||||
export const formatterExtra = (value?: number) =>
|
||||
Intl.NumberFormat('ru', {
|
||||
minimumFractionDigits: 2,
|
||||
maximumFractionDigits: 6,
|
||||
}).format(value || 0);
|
||||
@ -1,12 +0,0 @@
|
||||
{
|
||||
"name": "tools",
|
||||
"version": "0.0.0",
|
||||
"main": "./index.tsx",
|
||||
"types": "./index.tsx",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"mobx": "^6.7.0",
|
||||
"radash": "^10.3.0",
|
||||
"ui": "*"
|
||||
}
|
||||
}
|
||||
@ -1,11 +0,0 @@
|
||||
/* eslint-disable import/prefer-default-export */
|
||||
import { createGlobalStyle } from 'styled-components';
|
||||
|
||||
export const GlobalStyle = createGlobalStyle`
|
||||
:root {
|
||||
--color-background: rgb(240, 240, 240);
|
||||
--color-primary: ${process.env.NEXT_PUBLIC_COLOR_PRIMARY};
|
||||
--color-secondary: ${process.env.NEXT_PUBLIC_COLOR_SECONDARY};
|
||||
--color-tertiarty: ${process.env.NEXT_PUBLIC_COLOR_TERTIARTY};
|
||||
}
|
||||
`;
|
||||
@ -1,3 +0,0 @@
|
||||
/* eslint-disable unicorn/filename-case */
|
||||
/* eslint-disable no-restricted-exports */
|
||||
export { Alert as default } from 'antd';
|
||||
@ -1,34 +0,0 @@
|
||||
import { Button as AntButton } from 'antd';
|
||||
import type { BaseButtonProps } from 'antd/lib/button/button';
|
||||
import type { FC } from 'react';
|
||||
import { useThrottledCallback } from 'use-debounce';
|
||||
import type { BaseElementProps } from './types';
|
||||
|
||||
type ElementProps = {
|
||||
action: () => void;
|
||||
text: string;
|
||||
};
|
||||
|
||||
type ButtonProps = BaseButtonProps & Pick<ElementProps, 'text'>;
|
||||
|
||||
export default (function Button({
|
||||
status,
|
||||
action,
|
||||
text,
|
||||
...props
|
||||
}: BaseElementProps<never> & ElementProps) {
|
||||
const throttledAction = useThrottledCallback(action, 1200, {
|
||||
trailing: false,
|
||||
});
|
||||
|
||||
return (
|
||||
<AntButton
|
||||
disabled={status === 'Disabled'}
|
||||
loading={status === 'Loading'}
|
||||
onClick={throttledAction}
|
||||
{...props}
|
||||
>
|
||||
{text}
|
||||
</AntButton>
|
||||
);
|
||||
} as FC<ButtonProps>);
|
||||
@ -1,40 +0,0 @@
|
||||
import type { CheckboxProps as AntCheckboxProps } from 'antd';
|
||||
import { Checkbox as AntCheckbox, Form } from 'antd';
|
||||
import type { CheckboxChangeEvent } from 'antd/lib/checkbox';
|
||||
import type { FC } from 'react';
|
||||
import type { BaseElementProps } from './types';
|
||||
|
||||
const { Item: FormItem } = Form;
|
||||
|
||||
type ElementProps = {
|
||||
text: string;
|
||||
};
|
||||
|
||||
type CheckboxProps = AntCheckboxProps & ElementProps;
|
||||
|
||||
export default (function Checkbox({
|
||||
value,
|
||||
setValue,
|
||||
status,
|
||||
isValid,
|
||||
help,
|
||||
text,
|
||||
...props
|
||||
}: BaseElementProps<boolean> & ElementProps) {
|
||||
function handleChange(e: CheckboxChangeEvent) {
|
||||
setValue(e.target.checked);
|
||||
}
|
||||
|
||||
return (
|
||||
<FormItem hasFeedback validateStatus={isValid === false ? 'error' : ''} help={help}>
|
||||
<AntCheckbox
|
||||
checked={value}
|
||||
onChange={handleChange}
|
||||
disabled={status === 'Disabled'}
|
||||
{...props}
|
||||
>
|
||||
{text}
|
||||
</AntCheckbox>
|
||||
</FormItem>
|
||||
);
|
||||
} as FC<CheckboxProps>);
|
||||
@ -1,25 +0,0 @@
|
||||
import type { InputProps } from 'antd';
|
||||
import { Form, Input as AntInput } from 'antd';
|
||||
import type { ChangeEvent, FC } from 'react';
|
||||
import type { BaseElementProps } from './types';
|
||||
|
||||
const { Item: FormItem } = Form;
|
||||
|
||||
export default (function Input({
|
||||
value,
|
||||
setValue,
|
||||
status,
|
||||
isValid,
|
||||
help,
|
||||
...props
|
||||
}: BaseElementProps<string>) {
|
||||
function handleChange(e: ChangeEvent<HTMLInputElement>) {
|
||||
setValue(e.target.value);
|
||||
}
|
||||
|
||||
return (
|
||||
<FormItem hasFeedback validateStatus={isValid === false ? 'error' : ''} help={help}>
|
||||
<AntInput value={value} onChange={handleChange} disabled={status === 'Disabled'} {...props} />
|
||||
</FormItem>
|
||||
);
|
||||
} as FC<InputProps>);
|
||||
@ -1,29 +0,0 @@
|
||||
import type { InputNumberProps as AntInputNumberProps } from 'antd';
|
||||
import { Form, InputNumber as AntInputNumber } from 'antd';
|
||||
import type { FC } from 'react';
|
||||
import type { BaseElementProps } from './types';
|
||||
|
||||
const { Item: FormItem } = Form;
|
||||
|
||||
type InputNumberProps = AntInputNumberProps<number>;
|
||||
|
||||
export default (function InputNumber({
|
||||
setValue,
|
||||
status,
|
||||
isValid,
|
||||
help,
|
||||
...props
|
||||
}: BaseElementProps<number>) {
|
||||
return (
|
||||
<FormItem hasFeedback validateStatus={isValid === false ? 'error' : ''} help={help}>
|
||||
<AntInputNumber
|
||||
onChange={setValue}
|
||||
disabled={status === 'Disabled'}
|
||||
style={{
|
||||
width: '100%',
|
||||
}}
|
||||
{...props}
|
||||
/>
|
||||
</FormItem>
|
||||
);
|
||||
} as FC<InputNumberProps>);
|
||||
@ -1,30 +0,0 @@
|
||||
import { Button as AntButton } from 'antd';
|
||||
import type { BaseButtonProps } from 'antd/lib/button/button';
|
||||
import type { FC } from 'react';
|
||||
import type { BaseElementProps } from './types';
|
||||
|
||||
type ElementProps = {
|
||||
text: string;
|
||||
};
|
||||
|
||||
type LinkProps = BaseButtonProps & ElementProps;
|
||||
|
||||
export default (function Link({
|
||||
value,
|
||||
status,
|
||||
text,
|
||||
...props
|
||||
}: BaseElementProps<string> & ElementProps) {
|
||||
return (
|
||||
<AntButton
|
||||
rel="noopener"
|
||||
target="_blank"
|
||||
href={value}
|
||||
disabled={status === 'Disabled' || !value}
|
||||
loading={status === 'Loading'}
|
||||
{...props}
|
||||
>
|
||||
{text}
|
||||
</AntButton>
|
||||
);
|
||||
} as FC<LinkProps>);
|
||||
@ -1,49 +0,0 @@
|
||||
import type { RadioChangeEvent, RadioGroupProps, SpaceProps } from 'antd';
|
||||
import { Form, Radio as AntRadio, Space } from 'antd';
|
||||
import type { FC } from 'react';
|
||||
import type { BaseElementProps, BaseOption } from './types';
|
||||
|
||||
const { Item: FormItem } = Form;
|
||||
|
||||
type ElementProps = BaseElementProps<string | null> & {
|
||||
options: BaseOption[];
|
||||
spaceProps?: SpaceProps;
|
||||
};
|
||||
|
||||
type RadioProps = RadioGroupProps & {
|
||||
spaceProps?: SpaceProps;
|
||||
};
|
||||
|
||||
export default (function Radio({
|
||||
value = null,
|
||||
setValue,
|
||||
options,
|
||||
status,
|
||||
isValid,
|
||||
help,
|
||||
spaceProps,
|
||||
...props
|
||||
}: ElementProps) {
|
||||
function handleChange(e: RadioChangeEvent) {
|
||||
setValue(e.target.value);
|
||||
}
|
||||
|
||||
return (
|
||||
<FormItem hasFeedback validateStatus={isValid === false ? 'error' : ''} help={help}>
|
||||
<AntRadio.Group
|
||||
value={value}
|
||||
onChange={handleChange}
|
||||
disabled={status === 'Disabled'}
|
||||
{...props}
|
||||
>
|
||||
<Space {...spaceProps}>
|
||||
{options.map((option) => (
|
||||
<AntRadio key={option.value} value={option.value}>
|
||||
{option.label}
|
||||
</AntRadio>
|
||||
))}
|
||||
</Space>
|
||||
</AntRadio.Group>
|
||||
</FormItem>
|
||||
);
|
||||
} as FC<RadioProps>);
|
||||
@ -1,3 +0,0 @@
|
||||
/* eslint-disable unicorn/filename-case */
|
||||
/* eslint-disable no-restricted-exports */
|
||||
export { Result as default } from 'antd';
|
||||
@ -1,32 +0,0 @@
|
||||
import type { SegmentedProps } from 'antd';
|
||||
import { Form, Segmented as AntSegmented } from 'antd';
|
||||
import type { FC } from 'react';
|
||||
import type { BaseElementProps, BaseOption } from './types';
|
||||
|
||||
const { Item: FormItem } = Form;
|
||||
|
||||
type ElementProps = BaseElementProps<string | number> & {
|
||||
options: BaseOption[];
|
||||
};
|
||||
|
||||
export default (function Segmented({
|
||||
value,
|
||||
setValue,
|
||||
options,
|
||||
status,
|
||||
isValid,
|
||||
help,
|
||||
...props
|
||||
}: ElementProps) {
|
||||
return (
|
||||
<FormItem hasFeedback validateStatus={isValid === false ? 'error' : ''} help={help}>
|
||||
<AntSegmented
|
||||
value={value}
|
||||
onChange={setValue}
|
||||
disabled={status === 'Disabled'}
|
||||
options={options}
|
||||
{...props}
|
||||
/>
|
||||
</FormItem>
|
||||
);
|
||||
} as FC<Partial<SegmentedProps>>);
|
||||
@ -1,46 +0,0 @@
|
||||
import type { SelectProps } from 'antd';
|
||||
import { Form, Select as AntSelect } from 'antd';
|
||||
import type { FC } from 'react';
|
||||
import { useMemo } from 'react';
|
||||
import type { BaseElementProps, BaseOption } from './types';
|
||||
|
||||
const { Item: FormItem } = Form;
|
||||
|
||||
type ElementProps = {
|
||||
options: BaseOption[];
|
||||
};
|
||||
|
||||
export default (function Select({
|
||||
value = null,
|
||||
setValue,
|
||||
options = [],
|
||||
status,
|
||||
isValid,
|
||||
help,
|
||||
...props
|
||||
}: BaseElementProps<string | null> & ElementProps) {
|
||||
const optionsWithNull = useMemo(
|
||||
() => [
|
||||
{
|
||||
label: 'Не выбрано',
|
||||
value: null,
|
||||
},
|
||||
...options,
|
||||
],
|
||||
[options]
|
||||
);
|
||||
|
||||
return (
|
||||
<FormItem hasFeedback validateStatus={isValid === false ? 'error' : ''} help={help}>
|
||||
<AntSelect
|
||||
value={value}
|
||||
onChange={setValue}
|
||||
disabled={status === 'Disabled'}
|
||||
loading={status === 'Loading'}
|
||||
optionFilterProp="children"
|
||||
options={optionsWithNull}
|
||||
{...props}
|
||||
/>
|
||||
</FormItem>
|
||||
);
|
||||
} as FC<SelectProps>);
|
||||
@ -1,21 +0,0 @@
|
||||
import type { SwitchProps } from 'antd';
|
||||
import { Form, Switch as AntSwitch } from 'antd';
|
||||
import type { FC } from 'react';
|
||||
import type { BaseElementProps } from './types';
|
||||
|
||||
const { Item: FormItem } = Form;
|
||||
|
||||
export default (function Switch({
|
||||
value,
|
||||
setValue,
|
||||
status,
|
||||
isValid,
|
||||
help,
|
||||
...props
|
||||
}: BaseElementProps<boolean>) {
|
||||
return (
|
||||
<FormItem hasFeedback validateStatus={isValid === false ? 'error' : ''} help={help}>
|
||||
<AntSwitch checked={value} onChange={setValue} disabled={status === 'Disabled'} {...props} />
|
||||
</FormItem>
|
||||
);
|
||||
} as FC<SwitchProps>);
|
||||
@ -1,4 +0,0 @@
|
||||
/* eslint-disable unicorn/filename-case */
|
||||
/* eslint-disable no-restricted-exports */
|
||||
|
||||
export { Table as default } from 'antd';
|
||||
@ -1,16 +0,0 @@
|
||||
import type { FC, ReactNode } from 'react';
|
||||
import styled from 'styled-components';
|
||||
|
||||
const Span = styled.span`
|
||||
margin-bottom: 18px;
|
||||
font-size: 0.85rem;
|
||||
`;
|
||||
|
||||
type TextProps = {
|
||||
value: any;
|
||||
children: ReactNode;
|
||||
};
|
||||
|
||||
export default (function Text({ value, ...props }: TextProps) {
|
||||
return <Span {...props}>{value || props.children}</Span>;
|
||||
} as FC<TextProps>);
|
||||
@ -1,3 +0,0 @@
|
||||
/* eslint-disable unicorn/filename-case */
|
||||
/* eslint-disable no-restricted-exports */
|
||||
export { Tooltip as default } from 'antd';
|
||||
@ -1,4 +0,0 @@
|
||||
/* eslint-disable unicorn/filename-case */
|
||||
|
||||
export { ConfigProvider } from 'antd';
|
||||
export { default as ru_RU } from 'antd/lib/locale/ru_RU';
|
||||
@ -1,3 +0,0 @@
|
||||
import DownloadOutlined from '@ant-design/icons/lib/icons/DownloadOutlined';
|
||||
|
||||
export default <DownloadOutlined />;
|
||||
@ -1,15 +0,0 @@
|
||||
export { default as Button } from './Button';
|
||||
export { default as Checkbox } from './Checkbox';
|
||||
export { default as Input } from './Input';
|
||||
export { default as InputNumber } from './InputNumber';
|
||||
export { default as Link } from './Link';
|
||||
export { default as message } from './message';
|
||||
export { default as notification } from './notification';
|
||||
export { default as Radio } from './Radio';
|
||||
export { default as Result } from './Result';
|
||||
export { default as Segmented } from './Segmented';
|
||||
export { default as Select } from './Select';
|
||||
export { default as Switch } from './Switch';
|
||||
export { default as Table } from './Table';
|
||||
export { default as Text } from './Text';
|
||||
export { default as Tooltip } from './Tooltip';
|
||||
@ -1,4 +0,0 @@
|
||||
/* eslint-disable unicorn/filename-case */
|
||||
/* eslint-disable no-restricted-exports */
|
||||
|
||||
export { Divider as default } from 'antd';
|
||||
@ -1,4 +0,0 @@
|
||||
/* eslint-disable unicorn/filename-case */
|
||||
/* eslint-disable no-restricted-exports */
|
||||
|
||||
export { Tabs as default } from 'antd';
|
||||
@ -1,9 +0,0 @@
|
||||
/* eslint-disable unicorn/prefer-export-from */
|
||||
import { message } from 'antd';
|
||||
|
||||
message.config({
|
||||
top: 70,
|
||||
maxCount: 3,
|
||||
});
|
||||
|
||||
export default message;
|
||||
@ -1,8 +0,0 @@
|
||||
/* eslint-disable unicorn/prefer-export-from */
|
||||
import { notification } from 'antd';
|
||||
|
||||
notification.config({
|
||||
placement: 'bottomRight',
|
||||
});
|
||||
|
||||
export default notification;
|
||||
@ -1 +0,0 @@
|
||||
@import 'antd/dist/antd.less';
|
||||
@ -1,14 +0,0 @@
|
||||
export type Status = 'Default' | 'Disabled' | 'Loading' | 'Hidden';
|
||||
|
||||
export type BaseElementProps<Value> = {
|
||||
value: Value;
|
||||
setValue: (value: Value) => void;
|
||||
status?: Status;
|
||||
isValid?: boolean;
|
||||
help?: string;
|
||||
};
|
||||
|
||||
export type BaseOption<Value = any> = {
|
||||
label: string;
|
||||
value: Value;
|
||||
};
|
||||
@ -1,18 +0,0 @@
|
||||
const screens = {
|
||||
tablet: 768,
|
||||
laptop: 1024,
|
||||
'laptop-hd': 1280,
|
||||
desktop: 1680,
|
||||
'desktop-xl': 1921,
|
||||
};
|
||||
|
||||
const threshold = 0;
|
||||
|
||||
export function min(breakpoint: keyof typeof screens) {
|
||||
return `@media (min-width: calc(${screens[breakpoint]}px + ${threshold}px))`;
|
||||
}
|
||||
export function max(breakpoint: keyof typeof screens) {
|
||||
return `@media (max-width: calc(${screens[breakpoint]}px))`;
|
||||
}
|
||||
|
||||
export const breakpoints = Object.values(screens).map((value) => `${value + threshold}px`);
|
||||
@ -1,20 +0,0 @@
|
||||
{
|
||||
"name": "ui",
|
||||
"version": "0.0.0",
|
||||
"main": "./index.tsx",
|
||||
"types": "./index.tsx",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@types/react": "18.0.20",
|
||||
"@types/rebass": "^4.0.10",
|
||||
"@types/styled-components": "^5"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ant-design/icons": "^4.8.0",
|
||||
"antd": "4.24.5",
|
||||
"react": "^18.2.0",
|
||||
"rebass": "^4.0.7",
|
||||
"styled-components": "^5.3.6",
|
||||
"use-debounce": "^9.0.2"
|
||||
}
|
||||
}
|
||||
@ -1,7 +0,0 @@
|
||||
import { breakpoints } from './mq';
|
||||
|
||||
const theme = {
|
||||
breakpoints,
|
||||
};
|
||||
|
||||
export default theme;
|
||||
@ -1,13 +0,0 @@
|
||||
/* eslint-disable object-curly-newline */
|
||||
import type { FormTabRows } from '../../lib/render-rows';
|
||||
|
||||
export const id = 'create-kp';
|
||||
export const title = 'Создание КП';
|
||||
|
||||
export const rows: FormTabRows = [
|
||||
[['cbxPriceWithDiscount', 'cbxFullPriceWithDiscount', 'cbxCostIncrease']],
|
||||
[['cbxInsurance', 'cbxRegistrationQuote', 'cbxTechnicalCardQuote']],
|
||||
[['cbxNSIB', 'cbxQuoteRedemptionGraph', 'cbxShowFinGAP']],
|
||||
[['tbxQuoteName', 'radioQuoteContactGender'], { gridTemplateColumns: '1fr 1fr' }],
|
||||
[['btnCreateKP', 'linkDownloadKp'], { gridTemplateColumns: '1fr 1fr' }],
|
||||
];
|
||||
@ -1,67 +0,0 @@
|
||||
/* eslint-disable import/prefer-default-export */
|
||||
import type { ColumnsType } from 'antd/lib/table';
|
||||
import { MAX_INSURANCE } from 'constants/values';
|
||||
import { formatter, parser } from 'tools/number';
|
||||
import InputNumber from 'ui/elements/InputNumber';
|
||||
import Select from 'ui/elements/Select';
|
||||
import { buildOptionComponent, buildValueComponent } from './builders';
|
||||
import type * as Insurance from './types';
|
||||
|
||||
export const columns: ColumnsType<Insurance.RowValues> = [
|
||||
{
|
||||
key: 'policyType',
|
||||
dataIndex: 'policyType',
|
||||
title: 'Тип полиса',
|
||||
},
|
||||
{
|
||||
key: 'insuranceCompany',
|
||||
dataIndex: 'insuranceCompany',
|
||||
title: 'Страховая компания',
|
||||
width: 300,
|
||||
render: (_, record) => {
|
||||
const Component = buildOptionComponent(record.key, Select, 'insuranceCompany');
|
||||
|
||||
return <Component showSearch optionFilterProp="label" />;
|
||||
},
|
||||
},
|
||||
{
|
||||
key: 'insured',
|
||||
dataIndex: 'insured',
|
||||
title: 'Плательщик',
|
||||
render: (_, record) => {
|
||||
const Component = buildOptionComponent(record.key, Select, 'insured');
|
||||
|
||||
return <Component />;
|
||||
},
|
||||
},
|
||||
{
|
||||
key: 'insCost',
|
||||
dataIndex: 'insCost',
|
||||
title: 'Стоимость за 1-й период',
|
||||
render: (_, record) => {
|
||||
const Component = buildValueComponent(record.key, InputNumber, 'insCost');
|
||||
|
||||
return (
|
||||
<Component
|
||||
min={0}
|
||||
max={MAX_INSURANCE}
|
||||
step={1000}
|
||||
precision={2}
|
||||
parser={parser}
|
||||
formatter={formatter}
|
||||
addonAfter="₽"
|
||||
/>
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
key: 'insTerm',
|
||||
dataIndex: 'insTerm',
|
||||
title: 'Срок страхования',
|
||||
render: (_, record) => {
|
||||
const Component = buildOptionComponent(record.key, Select, 'insTerm');
|
||||
|
||||
return <Component />;
|
||||
},
|
||||
},
|
||||
];
|
||||
@ -1,12 +0,0 @@
|
||||
import type { FormTabRows } from '../../lib/render-rows';
|
||||
|
||||
export const id = 'insurance';
|
||||
export const title = 'Страхование';
|
||||
|
||||
export const rows: FormTabRows = [
|
||||
[['tbxLeaseObjectYear', 'selectLeaseObjectUseFor', 'selectLegalClientRegion']],
|
||||
[['selectEngineType', 'tbxInsFranchise', 'selectLegalClientTown']],
|
||||
[['selectLeaseObjectCategory', 'tbxMileage', 'tbxINNForCalc']],
|
||||
[['tbxLeaseObjectMotorPower', 'cbxWithTrailer', 'selectGPSBrand']],
|
||||
[['tbxEngineVolume', 'cbxInsDecentral', 'selectGPSModel']],
|
||||
];
|
||||
@ -1,12 +0,0 @@
|
||||
import renderFormRows from '../../lib/render-rows';
|
||||
import { id, rows, title } from './config';
|
||||
|
||||
function LeasingObject() {
|
||||
return renderFormRows(rows);
|
||||
}
|
||||
|
||||
export default {
|
||||
id,
|
||||
title,
|
||||
Component: LeasingObject,
|
||||
};
|
||||
@ -1,14 +0,0 @@
|
||||
/* eslint-disable import/prefer-default-export */
|
||||
import { observer } from 'mobx-react-lite';
|
||||
import type { ComponentType } from 'react';
|
||||
import { useRowStatus } from 'stores/tables/payments/hooks';
|
||||
import { usePaymentValue } from './hooks';
|
||||
|
||||
export function buildValueComponent<T>(index: number, Component: ComponentType<T>) {
|
||||
return observer((props: T) => {
|
||||
const [value, setValue] = usePaymentValue(index);
|
||||
const status = useRowStatus(index);
|
||||
|
||||
return <Component value={value} setValue={setValue} status={status} {...props} />;
|
||||
});
|
||||
}
|
||||
@ -1,38 +0,0 @@
|
||||
/* eslint-disable import/prefer-default-export */
|
||||
import type { ColumnsType } from 'antd/lib/table';
|
||||
import InputNumber from 'ui/elements/InputNumber';
|
||||
|
||||
import { buildValueComponent } from './builders';
|
||||
|
||||
type Payment = {
|
||||
key: number;
|
||||
num: number;
|
||||
paymentRelation: number;
|
||||
};
|
||||
|
||||
export const columns: ColumnsType<Payment> = [
|
||||
{
|
||||
key: 'num',
|
||||
dataIndex: 'num',
|
||||
title: '#',
|
||||
width: '7%',
|
||||
render: (_value, payment) => payment.num + 1,
|
||||
},
|
||||
{
|
||||
key: 'paymentRelation',
|
||||
dataIndex: 'paymentRelation',
|
||||
title: '% платежа',
|
||||
render: (_value, payment) => {
|
||||
const Component = buildValueComponent(payment.num, InputNumber);
|
||||
|
||||
return (
|
||||
<Component
|
||||
min={payment.num === 0 ? 0 : 0.01}
|
||||
max={100}
|
||||
step={1}
|
||||
precision={payment.num === 0 ? 4 : 2}
|
||||
/>
|
||||
);
|
||||
},
|
||||
},
|
||||
];
|
||||
@ -1,28 +0,0 @@
|
||||
/* eslint-disable import/prefer-default-export */
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useRowValue } from 'stores/tables/payments/hooks';
|
||||
import { useDebouncedCallback } from 'use-debounce';
|
||||
|
||||
export function usePaymentValue(index) {
|
||||
const [storeValue, setStoreValue] = useRowValue(index);
|
||||
const [value, setValue] = useState(storeValue);
|
||||
|
||||
// eslint-disable-next-line object-curly-newline
|
||||
const debouncedSetStoreValue = useDebouncedCallback(setStoreValue, 350, { maxWait: 1000 });
|
||||
|
||||
useEffect(
|
||||
() => {
|
||||
if (storeValue !== value) {
|
||||
debouncedSetStoreValue(value);
|
||||
}
|
||||
},
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
[value]
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
setValue(storeValue);
|
||||
}, [storeValue]);
|
||||
|
||||
return [value, setValue];
|
||||
}
|
||||
@ -1,89 +0,0 @@
|
||||
import { computed } from 'mobx';
|
||||
import { observer } from 'mobx-react-lite';
|
||||
import { useStore } from 'stores/hooks';
|
||||
import styled from 'styled-components';
|
||||
import Alert from 'ui/elements/Alert';
|
||||
import Table from 'ui/elements/Table';
|
||||
import { Box, Flex } from 'ui/grid';
|
||||
import { min } from 'ui/mq';
|
||||
import { columns } from './config';
|
||||
|
||||
const Grid = styled(Flex)`
|
||||
flex-direction: column;
|
||||
`;
|
||||
|
||||
const TableWrapper = styled.div`
|
||||
td > * {
|
||||
margin: 0;
|
||||
}
|
||||
`;
|
||||
|
||||
const TablesGroupGrid = styled(Box)`
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
|
||||
${min('tablet')} {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(5, 1fr);
|
||||
}
|
||||
`;
|
||||
|
||||
const Validation = observer(() => {
|
||||
const store = useStore();
|
||||
const { payments } = store.$tables;
|
||||
|
||||
const messages = payments.validation.getMessages();
|
||||
|
||||
if (messages?.length) {
|
||||
return <Alert type="error" banner message={messages[0]} />;
|
||||
}
|
||||
|
||||
return null;
|
||||
});
|
||||
|
||||
const SPLIT_NUMBER = 12;
|
||||
|
||||
function TablePart({ num }) {
|
||||
const store = useStore();
|
||||
const { payments } = store.$tables;
|
||||
|
||||
const values = payments.values.slice(num * SPLIT_NUMBER, num * SPLIT_NUMBER + SPLIT_NUMBER);
|
||||
|
||||
const dataSource = values.map((value, index) => ({
|
||||
key: index + num * SPLIT_NUMBER,
|
||||
num: index + num * SPLIT_NUMBER,
|
||||
paymentRelation: value,
|
||||
}));
|
||||
|
||||
return (
|
||||
<TableWrapper>
|
||||
<Table size="small" columns={columns} dataSource={dataSource} pagination={false} />
|
||||
</TableWrapper>
|
||||
);
|
||||
}
|
||||
|
||||
const TablesGroup = observer(() => {
|
||||
const store = useStore();
|
||||
const { payments } = store.$tables;
|
||||
|
||||
const valuesLength = computed(() => payments.values.length).get();
|
||||
|
||||
const tablesNumber = Math.ceil(valuesLength / SPLIT_NUMBER);
|
||||
|
||||
const tables = [];
|
||||
for (let i = 0; i < tablesNumber; i += 1) {
|
||||
tables.push(<TablePart key={i} num={i} />);
|
||||
}
|
||||
|
||||
return <TablesGroupGrid>{tables}</TablesGroupGrid>;
|
||||
});
|
||||
|
||||
export default function TablePayments() {
|
||||
return (
|
||||
<Grid>
|
||||
<Validation />
|
||||
<TablesGroup />
|
||||
</Grid>
|
||||
);
|
||||
}
|
||||
@ -1,20 +0,0 @@
|
||||
/* eslint-disable import/prefer-default-export */
|
||||
/* eslint-disable object-curly-newline */
|
||||
import type { FormTabRows } from '../lib/render-rows';
|
||||
|
||||
const defaultRowStyle = { gridTemplateColumns: '1fr' };
|
||||
|
||||
export const rows: FormTabRows = [
|
||||
{ title: 'Выбор Интереса/ЛС' },
|
||||
[['selectLead'], defaultRowStyle],
|
||||
[['selectOpportunity'], defaultRowStyle],
|
||||
[['cbxRecalcWithRevision'], defaultRowStyle],
|
||||
[['selectQuote'], defaultRowStyle],
|
||||
[['btnCalculate'], defaultRowStyle],
|
||||
|
||||
{ title: 'Параметры расчета' },
|
||||
[['labelIrrInfo'], defaultRowStyle],
|
||||
[['radioCalcType'], defaultRowStyle],
|
||||
[['tbxIRR_Perc'], defaultRowStyle],
|
||||
[['tbxTotalPayments'], defaultRowStyle],
|
||||
];
|
||||
@ -1,21 +0,0 @@
|
||||
import styled from 'styled-components';
|
||||
import Background from 'ui/elements/layout/Background';
|
||||
import { min } from 'ui/mq';
|
||||
import renderFormRows from '../lib/render-rows';
|
||||
import { rows } from './config';
|
||||
|
||||
const Wrapper = styled(Background)`
|
||||
padding: 4px 10px;
|
||||
|
||||
${min('tablet')} {
|
||||
min-height: 790px;
|
||||
}
|
||||
|
||||
${min('laptop')} {
|
||||
padding: 4px 18px 10px;
|
||||
}
|
||||
`;
|
||||
|
||||
export default function Settings() {
|
||||
return <Wrapper>{renderFormRows(rows)}</Wrapper>;
|
||||
}
|
||||
@ -1,32 +0,0 @@
|
||||
import { gql, useQuery } from '@apollo/client';
|
||||
import type * as CRMTypes from 'graphql/crm.types';
|
||||
import { observer } from 'mobx-react-lite';
|
||||
import { useStore } from 'stores/hooks';
|
||||
|
||||
const QUERY_GET_CURRENCY_SYMBOL = gql`
|
||||
query GetCurrencySymbol($currencyid: Uuid!) {
|
||||
transactioncurrency(transactioncurrencyid: $currencyid) {
|
||||
currencysymbol
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
const CurrencyAddon = observer(() => {
|
||||
const { $calculation } = useStore();
|
||||
|
||||
const currencyid = $calculation.element('selectSupplierCurrency').getValue();
|
||||
|
||||
const { data } = useQuery<
|
||||
CRMTypes.GetCurrencySymbolQuery,
|
||||
CRMTypes.GetCurrencySymbolQueryVariables
|
||||
>(QUERY_GET_CURRENCY_SYMBOL, {
|
||||
variables: {
|
||||
currencyid: currencyid!,
|
||||
},
|
||||
skip: !currencyid,
|
||||
});
|
||||
|
||||
return <span>{data?.transactioncurrency?.currencysymbol}</span>;
|
||||
});
|
||||
|
||||
export default <CurrencyAddon />;
|
||||
@ -1,27 +0,0 @@
|
||||
/* eslint-disable react/jsx-no-bind */
|
||||
import { observer } from 'mobx-react-lite';
|
||||
import type { ComponentType } from 'react';
|
||||
import { useStatus } from 'stores/calculation/statuses/hooks';
|
||||
import type { Elements } from '../config/map/actions';
|
||||
|
||||
type BuilderProps = {
|
||||
elementName: Elements;
|
||||
valueName: string;
|
||||
};
|
||||
|
||||
export default function buildAction<T>(
|
||||
Component: ComponentType<T>,
|
||||
{ elementName, valueName: actionName }: BuilderProps
|
||||
) {
|
||||
return observer((props: T) => {
|
||||
const status = useStatus(elementName);
|
||||
|
||||
return (
|
||||
<Component
|
||||
status={status}
|
||||
action={() => import(`process/${actionName}`).then((m) => m.default())}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
});
|
||||
}
|
||||
@ -1,37 +0,0 @@
|
||||
import { observer } from 'mobx-react-lite';
|
||||
import type { ComponentType } from 'react';
|
||||
import { useOptions } from 'stores/calculation/options/hooks';
|
||||
import { useStatus } from 'stores/calculation/statuses/hooks';
|
||||
import { useValidation } from 'stores/calculation/validation/hooks';
|
||||
import type { Values } from 'stores/calculation/values/types';
|
||||
import type { Elements } from '../config/map/values';
|
||||
import { useStoreValue } from './hooks';
|
||||
|
||||
type BuilderProps = {
|
||||
elementName: Elements;
|
||||
valueName: Values;
|
||||
};
|
||||
|
||||
export default function buildOptions<T>(
|
||||
Component: ComponentType<T>,
|
||||
{ elementName, valueName }: BuilderProps
|
||||
) {
|
||||
return observer((props: T) => {
|
||||
const [value, setValue] = useStoreValue(valueName);
|
||||
const status = useStatus(elementName);
|
||||
const { isValid, help } = useValidation(elementName);
|
||||
const options = useOptions(elementName);
|
||||
|
||||
return (
|
||||
<Component
|
||||
value={value}
|
||||
setValue={setValue}
|
||||
options={options}
|
||||
status={status}
|
||||
isValid={isValid}
|
||||
help={help}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
});
|
||||
}
|
||||
@ -1,23 +0,0 @@
|
||||
import { observer } from 'mobx-react-lite';
|
||||
import type { ComponentType } from 'react';
|
||||
import { useStatus } from 'stores/calculation/statuses/hooks';
|
||||
import { useValue } from 'stores/calculation/values/hooks';
|
||||
import type { Values } from 'stores/calculation/values/types';
|
||||
import type { Elements } from '../config/map/values';
|
||||
|
||||
type BuilderProps = {
|
||||
elementName: Elements;
|
||||
valueName: Values;
|
||||
};
|
||||
|
||||
export default function buildReadonly<T>(
|
||||
Component: ComponentType<T>,
|
||||
{ elementName, valueName }: BuilderProps
|
||||
) {
|
||||
return observer((props: T) => {
|
||||
const [value] = useValue(valueName);
|
||||
const status = useStatus(elementName);
|
||||
|
||||
return <Component value={value} status={status} readOnly {...props} />;
|
||||
});
|
||||
}
|
||||
@ -1,153 +0,0 @@
|
||||
import buildAction from '../builders/build-action';
|
||||
import buildOptions from '../builders/build-options';
|
||||
import buildReadonly from '../builders/build-readonly';
|
||||
import buildValue from '../builders/build-value';
|
||||
import type { Elements as ActionElements } from './map/actions';
|
||||
import type { Elements as ValuesElements } from './map/values';
|
||||
|
||||
function wrapElementsBuilders<C, T extends Record<ValuesElements | ActionElements, C>>(arg: T) {
|
||||
return arg;
|
||||
}
|
||||
|
||||
const builders = wrapElementsBuilders({
|
||||
cbxRecalcWithRevision: buildValue,
|
||||
tbxLeaseObjectPrice: buildValue,
|
||||
tbxLeaseObjectPriceWthtVAT: buildValue,
|
||||
tbxVATInLeaseObjectPrice: buildValue,
|
||||
tbxEngineHours: buildValue,
|
||||
tbxSupplierDiscountRub: buildValue,
|
||||
tbxSupplierDiscountPerc: buildValue,
|
||||
tbxLeasingPeriod: buildValue,
|
||||
tbxFirstPaymentPerc: buildValue,
|
||||
tbxFirstPaymentRub: buildValue,
|
||||
tbxLastPaymentPerc: buildValue,
|
||||
tbxLastPaymentRub: buildValue,
|
||||
selectImportProgram: buildOptions,
|
||||
tbxImportProgramSum: buildReadonly,
|
||||
tbxAddEquipmentPrice: buildValue,
|
||||
tbxRedemptionPaymentSum: buildValue,
|
||||
tbxParmentsDecreasePercent: buildValue,
|
||||
tbxComissionPerc: buildValue,
|
||||
tbxComissionRub: buildValue,
|
||||
tbxSaleBonus: buildValue,
|
||||
tbxIRR_Perc: buildValue,
|
||||
tbxLeaseObjectCount: buildValue,
|
||||
cbxWithTrailer: buildValue,
|
||||
cbxLeaseObjectUsed: buildValue,
|
||||
tbxMaxMass: buildValue,
|
||||
tbxCountSeats: buildValue,
|
||||
tbxMaxSpeed: buildValue,
|
||||
tbxLeaseObjectYear: buildValue,
|
||||
tbxLeaseObjectMotorPower: buildValue,
|
||||
tbxEngineVolume: buildValue,
|
||||
tbxDealerRewardSumm: buildValue,
|
||||
tbxDealerBrokerRewardSumm: buildValue,
|
||||
tbxIndAgentRewardSumm: buildValue,
|
||||
tbxCalcDoubleAgentRewardSumm: buildValue,
|
||||
tbxCalcBrokerRewardSum: buildValue,
|
||||
tbxFinDepartmentRewardSumm: buildValue,
|
||||
cbxInsDecentral: buildValue,
|
||||
tbxInsFranchise: buildValue,
|
||||
cbxInsUnlimitDrivers: buildValue,
|
||||
tbxInsAgeDrivers: buildValue,
|
||||
tbxInsExpDrivers: buildValue,
|
||||
tbxINNForCalc: buildValue,
|
||||
cbxLastPaymentRedemption: buildValue,
|
||||
cbxPriceWithDiscount: buildValue,
|
||||
cbxFullPriceWithDiscount: buildValue,
|
||||
cbxCostIncrease: buildValue,
|
||||
cbxInsurance: buildValue,
|
||||
cbxRegistrationQuote: buildValue,
|
||||
cbxTechnicalCardQuote: buildValue,
|
||||
cbxNSIB: buildValue,
|
||||
tbxQuoteName: buildValue,
|
||||
cbxQuoteRedemptionGraph: buildValue,
|
||||
cbxShowFinGAP: buildValue,
|
||||
tbxCreditRate: buildValue,
|
||||
tbxMaxPriceChange: buildValue,
|
||||
tbxImporterRewardPerc: buildValue,
|
||||
tbxImporterRewardRub: buildValue,
|
||||
cbxDisableChecks: buildValue,
|
||||
tbxMileage: buildValue,
|
||||
tbxTotalPayments: buildValue,
|
||||
tbxVehicleTaxInYear: buildValue,
|
||||
tbxVehicleTaxInLeasingPeriod: buildValue,
|
||||
tbxMinPriceChange: buildValue,
|
||||
|
||||
selectProduct: buildOptions,
|
||||
selectClientRisk: buildOptions,
|
||||
selectClientType: buildOptions,
|
||||
selectSupplierCurrency: buildOptions,
|
||||
selectSeasonType: buildOptions,
|
||||
selectHighSeasonStart: buildOptions,
|
||||
selectLeaseObjectType: buildOptions,
|
||||
selectBrand: buildOptions,
|
||||
selectModel: buildOptions,
|
||||
selectConfiguration: buildOptions,
|
||||
selectLeaseObjectUseFor: buildOptions,
|
||||
selectLeaseObjectCategory: buildOptions,
|
||||
selectEngineType: buildOptions,
|
||||
selectDealer: buildOptions,
|
||||
selectDealerPerson: buildOptions,
|
||||
selectDealerRewardCondition: buildOptions,
|
||||
selectDealerBroker: buildOptions,
|
||||
selectDealerBrokerRewardCondition: buildOptions,
|
||||
selectIndAgent: buildOptions,
|
||||
selectIndAgentRewardCondition: buildOptions,
|
||||
selectCalcDoubleAgent: buildOptions,
|
||||
selectCalcDoubleAgentRewardCondition: buildOptions,
|
||||
selectCalcBroker: buildOptions,
|
||||
selectCalcBrokerRewardCondition: buildOptions,
|
||||
selectCalcFinDepartment: buildOptions,
|
||||
selectFinDepartmentRewardCondtion: buildOptions,
|
||||
selectGPSBrand: buildOptions,
|
||||
selectGPSModel: buildOptions,
|
||||
selectRegionRegistration: buildOptions,
|
||||
selectTownRegistration: buildOptions,
|
||||
selectRegistration: buildOptions,
|
||||
selectInsNSIB: buildOptions,
|
||||
selectTracker: buildOptions,
|
||||
selectTelematic: buildOptions,
|
||||
selectTechnicalCard: buildOptions,
|
||||
selectTarif: buildOptions,
|
||||
selectRate: buildOptions,
|
||||
selectLead: buildOptions,
|
||||
selectOpportunity: buildOptions,
|
||||
selectQuote: buildOptions,
|
||||
selectObjectRegionRegistration: buildOptions,
|
||||
selectObjectCategoryTax: buildOptions,
|
||||
selectObjectTypeTax: buildOptions,
|
||||
selectLegalClientRegion: buildOptions,
|
||||
selectLegalClientTown: buildOptions,
|
||||
selectSubsidy: buildOptions,
|
||||
selectFuelCard: buildOptions,
|
||||
radioBalanceHolder: buildOptions,
|
||||
radioLastPaymentRule: buildOptions,
|
||||
radioGraphType: buildOptions,
|
||||
radioDeliveryTime: buildOptions,
|
||||
radioInsKaskoType: buildOptions,
|
||||
radioInfuranceOPF: buildOptions,
|
||||
selectRequirementTelematic: buildOptions,
|
||||
radioQuoteContactGender: buildOptions,
|
||||
radioCalcType: buildOptions,
|
||||
radioObjectRegistration: buildOptions,
|
||||
radioTypePTS: buildOptions,
|
||||
tbxBonusCoefficient: buildValue,
|
||||
|
||||
labelLeaseObjectRisk: buildReadonly,
|
||||
tbxInsKaskoPriceLeasePeriod: buildReadonly,
|
||||
labelIrrInfo: buildReadonly,
|
||||
labelRegistrationDescription: buildReadonly,
|
||||
labelDepreciationGroup: buildReadonly,
|
||||
tbxSubsidySum: buildReadonly,
|
||||
|
||||
btnCreateKP: buildAction,
|
||||
btnCalculate: buildAction,
|
||||
|
||||
linkDownloadKp: buildReadonly,
|
||||
linkLeadUrl: buildReadonly,
|
||||
linkOpportunityUrl: buildReadonly,
|
||||
linkQuoteUrl: buildReadonly,
|
||||
});
|
||||
|
||||
export default builders;
|
||||
@ -1,159 +0,0 @@
|
||||
import type { ComponentProps } from 'react';
|
||||
import * as elements from 'ui/elements';
|
||||
import type { Elements as ActionElements } from './map/actions';
|
||||
import type { Elements as ValuesElements } from './map/values';
|
||||
|
||||
function wrapComponentsMap<C, T extends Record<ValuesElements | ActionElements, C>>(arg: T) {
|
||||
return arg;
|
||||
}
|
||||
|
||||
const components = wrapComponentsMap({
|
||||
selectProduct: elements.Select,
|
||||
selectClientRisk: elements.Select,
|
||||
selectClientType: elements.Select,
|
||||
selectSupplierCurrency: elements.Select,
|
||||
tbxLeaseObjectPrice: elements.InputNumber,
|
||||
tbxLeaseObjectPriceWthtVAT: elements.InputNumber,
|
||||
tbxVATInLeaseObjectPrice: elements.InputNumber,
|
||||
tbxSupplierDiscountRub: elements.InputNumber,
|
||||
tbxSupplierDiscountPerc: elements.InputNumber,
|
||||
radioBalanceHolder: elements.Radio,
|
||||
tbxSaleBonus: elements.InputNumber,
|
||||
tbxFirstPaymentPerc: elements.InputNumber,
|
||||
tbxFirstPaymentRub: elements.InputNumber,
|
||||
radioLastPaymentRule: elements.Segmented,
|
||||
tbxLastPaymentPerc: elements.InputNumber,
|
||||
tbxLastPaymentRub: elements.InputNumber,
|
||||
selectImportProgram: elements.Select,
|
||||
tbxImportProgramSum: elements.InputNumber,
|
||||
tbxAddEquipmentPrice: elements.InputNumber,
|
||||
tbxRedemptionPaymentSum: elements.InputNumber,
|
||||
tbxLeasingPeriod: elements.InputNumber,
|
||||
radioGraphType: elements.Radio,
|
||||
tbxParmentsDecreasePercent: elements.InputNumber,
|
||||
selectSeasonType: elements.Select,
|
||||
selectHighSeasonStart: elements.Select,
|
||||
tbxComissionPerc: elements.InputNumber,
|
||||
tbxComissionRub: elements.InputNumber,
|
||||
selectLeaseObjectType: elements.Select,
|
||||
selectBrand: elements.Select,
|
||||
selectModel: elements.Select,
|
||||
selectConfiguration: elements.Select,
|
||||
cbxLeaseObjectUsed: elements.Checkbox,
|
||||
radioDeliveryTime: elements.Segmented,
|
||||
tbxLeaseObjectCount: elements.InputNumber,
|
||||
selectLeaseObjectUseFor: elements.Select,
|
||||
tbxLeaseObjectYear: elements.InputNumber,
|
||||
selectLeaseObjectCategory: elements.Select,
|
||||
selectEngineType: elements.Select,
|
||||
tbxLeaseObjectMotorPower: elements.InputNumber,
|
||||
tbxEngineVolume: elements.InputNumber,
|
||||
tbxMaxMass: elements.InputNumber,
|
||||
tbxCountSeats: elements.InputNumber,
|
||||
tbxMaxSpeed: elements.InputNumber,
|
||||
cbxWithTrailer: elements.Checkbox,
|
||||
selectDealer: elements.Select,
|
||||
selectDealerPerson: elements.Select,
|
||||
selectDealerRewardCondition: elements.Select,
|
||||
tbxDealerRewardSumm: elements.InputNumber,
|
||||
selectDealerBroker: elements.Select,
|
||||
selectDealerBrokerRewardCondition: elements.Select,
|
||||
tbxDealerBrokerRewardSumm: elements.InputNumber,
|
||||
selectIndAgent: elements.Select,
|
||||
selectIndAgentRewardCondition: elements.Select,
|
||||
tbxIndAgentRewardSumm: elements.InputNumber,
|
||||
selectCalcDoubleAgent: elements.Select,
|
||||
selectCalcDoubleAgentRewardCondition: elements.Select,
|
||||
tbxCalcDoubleAgentRewardSumm: elements.InputNumber,
|
||||
selectCalcBroker: elements.Select,
|
||||
selectCalcBrokerRewardCondition: elements.Select,
|
||||
tbxCalcBrokerRewardSum: elements.InputNumber,
|
||||
selectCalcFinDepartment: elements.Select,
|
||||
selectFinDepartmentRewardCondtion: elements.Select,
|
||||
tbxFinDepartmentRewardSumm: elements.InputNumber,
|
||||
cbxInsDecentral: elements.Switch,
|
||||
radioInsKaskoType: elements.Radio,
|
||||
tbxInsFranchise: elements.InputNumber,
|
||||
cbxInsUnlimitDrivers: elements.Switch,
|
||||
tbxInsAgeDrivers: elements.InputNumber,
|
||||
tbxInsExpDrivers: elements.InputNumber,
|
||||
tbxINNForCalc: elements.InputNumber,
|
||||
selectGPSBrand: elements.Select,
|
||||
selectGPSModel: elements.Select,
|
||||
selectRegionRegistration: elements.Select,
|
||||
selectTownRegistration: elements.Select,
|
||||
radioInfuranceOPF: elements.Radio,
|
||||
selectRegistration: elements.Select,
|
||||
selectInsNSIB: elements.Select,
|
||||
selectRequirementTelematic: elements.Select,
|
||||
selectTracker: elements.Select,
|
||||
selectTelematic: elements.Select,
|
||||
selectTechnicalCard: elements.Select,
|
||||
cbxLastPaymentRedemption: elements.Switch,
|
||||
cbxPriceWithDiscount: elements.Switch,
|
||||
cbxFullPriceWithDiscount: elements.Switch,
|
||||
cbxCostIncrease: elements.Switch,
|
||||
cbxInsurance: elements.Switch,
|
||||
cbxRegistrationQuote: elements.Switch,
|
||||
cbxTechnicalCardQuote: elements.Switch,
|
||||
cbxNSIB: elements.Switch,
|
||||
cbxQuoteRedemptionGraph: elements.Switch,
|
||||
cbxShowFinGAP: elements.Switch,
|
||||
tbxQuoteName: elements.Input,
|
||||
radioQuoteContactGender: elements.Radio,
|
||||
cbxDisableChecks: elements.Switch,
|
||||
selectTarif: elements.Select,
|
||||
tbxCreditRate: elements.InputNumber,
|
||||
selectRate: elements.Select,
|
||||
tbxMaxPriceChange: elements.InputNumber,
|
||||
tbxImporterRewardPerc: elements.InputNumber,
|
||||
tbxImporterRewardRub: elements.InputNumber,
|
||||
selectLead: elements.Select,
|
||||
selectOpportunity: elements.Select,
|
||||
selectQuote: elements.Select,
|
||||
cbxRecalcWithRevision: elements.Checkbox,
|
||||
tbxIRR_Perc: elements.InputNumber,
|
||||
tbxMileage: elements.InputNumber,
|
||||
tbxEngineHours: elements.InputNumber,
|
||||
radioCalcType: elements.Segmented,
|
||||
tbxTotalPayments: elements.InputNumber,
|
||||
radioObjectRegistration: elements.Radio,
|
||||
selectObjectRegionRegistration: elements.Select,
|
||||
tbxVehicleTaxInYear: elements.InputNumber,
|
||||
tbxVehicleTaxInLeasingPeriod: elements.InputNumber,
|
||||
selectObjectCategoryTax: elements.Select,
|
||||
selectObjectTypeTax: elements.Select,
|
||||
radioTypePTS: elements.Radio,
|
||||
selectLegalClientRegion: elements.Select,
|
||||
selectLegalClientTown: elements.Select,
|
||||
selectSubsidy: elements.Select,
|
||||
selectFuelCard: elements.Select,
|
||||
tbxMinPriceChange: elements.InputNumber,
|
||||
tbxBonusCoefficient: elements.InputNumber,
|
||||
|
||||
/** Readonly Elements */
|
||||
labelLeaseObjectRisk: elements.Text,
|
||||
tbxInsKaskoPriceLeasePeriod: elements.InputNumber,
|
||||
labelIrrInfo: elements.Text,
|
||||
labelRegistrationDescription: elements.Text,
|
||||
labelDepreciationGroup: elements.Text,
|
||||
tbxSubsidySum: elements.InputNumber,
|
||||
|
||||
/** Button Elements */
|
||||
btnCreateKP: elements.Button,
|
||||
btnCalculate: elements.Button,
|
||||
|
||||
/** Link Elements */
|
||||
linkDownloadKp: elements.Link,
|
||||
linkLeadUrl: elements.Link,
|
||||
linkOpportunityUrl: elements.Link,
|
||||
linkQuoteUrl: elements.Link,
|
||||
});
|
||||
|
||||
export default components;
|
||||
|
||||
type ComponentsTypes = typeof components;
|
||||
|
||||
export type ElementsProps = {
|
||||
[Component in keyof ComponentsTypes]: ComponentProps<ComponentsTypes[Component]>;
|
||||
};
|
||||
@ -1,205 +0,0 @@
|
||||
/* eslint-disable object-curly-newline */
|
||||
import { Container, Head } from 'Components/Layout/Element';
|
||||
import { observer } from 'mobx-react-lite';
|
||||
import type { ComponentProps } from 'react';
|
||||
import { useStore } from 'stores/hooks';
|
||||
import Link from 'ui/elements/Link';
|
||||
import Tooltip from 'ui/elements/Tooltip';
|
||||
import buildReadonly from '../../builders/build-readonly';
|
||||
import builders from '../elements-builders';
|
||||
import components from '../elements-components';
|
||||
import elementsProps from '../elements-props';
|
||||
import titles from '../elements-titles';
|
||||
import map from '../map';
|
||||
import type { RenderProps } from './types';
|
||||
|
||||
const defaultLinkProps: ComponentProps<typeof Link> = {
|
||||
text: 'Открыть в CRM',
|
||||
type: 'link',
|
||||
};
|
||||
|
||||
const overrideRender: Partial<Record<keyof typeof map, RenderProps>> = {
|
||||
selectLead: {
|
||||
render: () => {
|
||||
const elementName = 'selectLead';
|
||||
const title = titles.selectLead;
|
||||
const valueName = map.selectLead;
|
||||
const Component = components.selectLead;
|
||||
const props = elementsProps.selectLead;
|
||||
const builder = builders.selectLead;
|
||||
|
||||
const Element = builder(Component, {
|
||||
elementName,
|
||||
valueName,
|
||||
});
|
||||
|
||||
const LinkComponent = buildReadonly(Link, {
|
||||
elementName: 'linkLeadUrl',
|
||||
valueName: 'leadUrl',
|
||||
});
|
||||
|
||||
return (
|
||||
<Container key={elementName}>
|
||||
<Head
|
||||
htmlFor={elementName}
|
||||
title={title}
|
||||
addon={<LinkComponent {...defaultLinkProps} />}
|
||||
/>
|
||||
<Element {...props} id={elementName} />
|
||||
</Container>
|
||||
);
|
||||
},
|
||||
},
|
||||
|
||||
selectOpportunity: {
|
||||
render: () => {
|
||||
const elementName = 'selectOpportunity';
|
||||
const title = titles.selectOpportunity;
|
||||
const valueName = map.selectOpportunity;
|
||||
const Component = components.selectOpportunity;
|
||||
const props = elementsProps.selectOpportunity;
|
||||
const builder = builders.selectOpportunity;
|
||||
|
||||
const Element = builder(Component, {
|
||||
elementName,
|
||||
valueName,
|
||||
});
|
||||
|
||||
const LinkComponent = buildReadonly(Link, {
|
||||
elementName: 'linkOpportunityUrl',
|
||||
valueName: 'opportunityUrl',
|
||||
});
|
||||
|
||||
return (
|
||||
<Container key={elementName}>
|
||||
<Head
|
||||
htmlFor={elementName}
|
||||
title={title}
|
||||
addon={<LinkComponent {...defaultLinkProps} />}
|
||||
/>
|
||||
<Element {...props} id={elementName} />
|
||||
</Container>
|
||||
);
|
||||
},
|
||||
},
|
||||
|
||||
selectQuote: {
|
||||
render: () => {
|
||||
const elementName = 'selectQuote';
|
||||
const title = titles.selectQuote;
|
||||
const valueName = map.selectQuote;
|
||||
const Component = components.selectQuote;
|
||||
const props = elementsProps.selectQuote;
|
||||
const builder = builders.selectQuote;
|
||||
|
||||
const Element = builder(Component, {
|
||||
elementName,
|
||||
valueName,
|
||||
});
|
||||
|
||||
const LinkComponent = buildReadonly(Link, {
|
||||
elementName: 'linkQuoteUrl',
|
||||
valueName: 'quoteUrl',
|
||||
});
|
||||
|
||||
return (
|
||||
<Container key={elementName}>
|
||||
<Head
|
||||
htmlFor={elementName}
|
||||
title={title}
|
||||
addon={<LinkComponent {...defaultLinkProps} />}
|
||||
/>
|
||||
<Element {...props} id={elementName} />
|
||||
</Container>
|
||||
);
|
||||
},
|
||||
},
|
||||
|
||||
tbxVehicleTaxInYear: {
|
||||
render: () => {
|
||||
const elementName = 'tbxVehicleTaxInYear';
|
||||
const title = titles.tbxVehicleTaxInYear;
|
||||
const valueName = map.tbxVehicleTaxInYear;
|
||||
const Component = components.tbxVehicleTaxInYear;
|
||||
const props = elementsProps.tbxVehicleTaxInYear;
|
||||
const builder = builders.tbxVehicleTaxInYear;
|
||||
|
||||
const Element = builder(Component, {
|
||||
elementName,
|
||||
valueName,
|
||||
});
|
||||
|
||||
return (
|
||||
<Tooltip title="Без учета налога на роскошь" placement="topLeft">
|
||||
<Container>
|
||||
<Head htmlFor={elementName} title={title} />
|
||||
<Element {...props} id={elementName} />
|
||||
</Container>
|
||||
</Tooltip>
|
||||
);
|
||||
},
|
||||
},
|
||||
|
||||
selectHighSeasonStart: {
|
||||
render: () => {
|
||||
const elementName = 'selectHighSeasonStart';
|
||||
const title = titles.selectHighSeasonStart;
|
||||
const valueName = map.selectHighSeasonStart;
|
||||
const Component = components.selectHighSeasonStart;
|
||||
const props = elementsProps.selectHighSeasonStart;
|
||||
const builder = builders.selectHighSeasonStart;
|
||||
|
||||
const Element = builder(Component, {
|
||||
elementName,
|
||||
valueName,
|
||||
});
|
||||
|
||||
return (
|
||||
<Tooltip title="С какого платежа начинается полный высокий сезон" placement="topLeft">
|
||||
<Container>
|
||||
<Head htmlFor={elementName} title={title} />
|
||||
<Element {...props} id={elementName} />
|
||||
</Container>
|
||||
</Tooltip>
|
||||
);
|
||||
},
|
||||
},
|
||||
|
||||
selectSeasonType: {
|
||||
render: () => {
|
||||
const elementName = 'selectSeasonType';
|
||||
const valueName = map.selectSeasonType;
|
||||
const Component = components.selectSeasonType;
|
||||
const props = elementsProps.selectSeasonType;
|
||||
const builder = builders.selectSeasonType;
|
||||
|
||||
const Element = builder(Component, {
|
||||
elementName,
|
||||
valueName,
|
||||
});
|
||||
|
||||
const Title = observer(() => {
|
||||
const { $calculation } = useStore();
|
||||
const graphType = $calculation.element('radioGraphType').getValue();
|
||||
|
||||
switch (graphType) {
|
||||
case 100_000_001:
|
||||
return <span>Тип дегрессии</span>;
|
||||
case 100_000_003:
|
||||
return <span>Тип сезонности</span>;
|
||||
default:
|
||||
return <span>{titles.selectSeasonType}</span>;
|
||||
}
|
||||
});
|
||||
|
||||
return (
|
||||
<Container>
|
||||
<Head htmlFor={elementName} title={<Title />} />
|
||||
<Element {...props} id={elementName} />
|
||||
</Container>
|
||||
);
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export default overrideRender;
|
||||
@ -1,2 +0,0 @@
|
||||
export { default as Form } from './Form';
|
||||
export { default as Settings } from './Settings';
|
||||
@ -1,13 +0,0 @@
|
||||
/* eslint-disable import/prefer-default-export */
|
||||
import Button from 'ui/elements/Button';
|
||||
import Result from 'ui/elements/Result';
|
||||
|
||||
function handleRetry() {
|
||||
window.location.reload();
|
||||
}
|
||||
|
||||
const RetryButton = <Button action={handleRetry} text="Попробовать еще раз" />;
|
||||
|
||||
export function CRMError() {
|
||||
return <Result status="500" title="500" subTitle="Ошибка соединения с CRM" extra={RetryButton} />;
|
||||
}
|
||||
@ -1,41 +0,0 @@
|
||||
import Image from 'next/image';
|
||||
import logo from 'public/assets/images/logo-primary.svg';
|
||||
import styled from 'styled-components';
|
||||
import { Flex } from 'ui/grid';
|
||||
import { min } from 'ui/mq';
|
||||
|
||||
const ImageWrapper = styled.div`
|
||||
width: 100px;
|
||||
${min('laptop')} {
|
||||
width: 135px;
|
||||
}
|
||||
|
||||
img {
|
||||
filter: brightness(0) invert(1);
|
||||
}
|
||||
`;
|
||||
|
||||
const LogoText = styled.h3`
|
||||
margin: 0;
|
||||
text-transform: uppercase;
|
||||
color: #fff;
|
||||
font-size: 0.85rem;
|
||||
font-family: 'Montserrat';
|
||||
font-weight: 500;
|
||||
${min('laptop')} {
|
||||
font-size: 1.2rem;
|
||||
}
|
||||
`;
|
||||
|
||||
function Logo() {
|
||||
return (
|
||||
<Flex flexDirection="column" alignItems="flex-start" justifyContent="space-between">
|
||||
<ImageWrapper>
|
||||
<Image alt="logo" src={logo} layout="responsive" objectFit="contain" />
|
||||
</ImageWrapper>
|
||||
<LogoText>Лизинговый Калькулятор</LogoText>
|
||||
</Flex>
|
||||
);
|
||||
}
|
||||
|
||||
export default Logo;
|
||||
@ -1,13 +0,0 @@
|
||||
/* eslint-disable react/prop-types */
|
||||
/* eslint-disable import/no-unresolved */
|
||||
import { Flex } from 'ui/grid';
|
||||
import Header from './Header';
|
||||
|
||||
export default function Layout({ children }) {
|
||||
return (
|
||||
<Flex flexDirection="column">
|
||||
<Header />
|
||||
<main>{children}</main>
|
||||
</Flex>
|
||||
);
|
||||
}
|
||||
@ -1,40 +0,0 @@
|
||||
/* eslint-disable import/prefer-default-export */
|
||||
|
||||
import type { ColumnsType } from 'antd/lib/table';
|
||||
import type { Payment } from './types';
|
||||
|
||||
export const columns: ColumnsType<Payment> = [
|
||||
{
|
||||
key: 'num',
|
||||
dataIndex: 'num',
|
||||
title: '#',
|
||||
width: '10%',
|
||||
},
|
||||
{
|
||||
key: 'paymentSum',
|
||||
dataIndex: 'paymentSum',
|
||||
title: 'Сумма платежа',
|
||||
render: Intl.NumberFormat('ru', {
|
||||
style: 'currency',
|
||||
currency: 'RUB',
|
||||
}).format,
|
||||
},
|
||||
{
|
||||
key: 'ndsCompensation',
|
||||
dataIndex: 'ndsCompensation',
|
||||
title: 'НДС к возмещению',
|
||||
render: Intl.NumberFormat('ru', {
|
||||
style: 'currency',
|
||||
currency: 'RUB',
|
||||
}).format,
|
||||
},
|
||||
{
|
||||
key: 'redemptionAmount',
|
||||
dataIndex: 'redemptionAmount',
|
||||
title: 'Сумма досрочного выкупа',
|
||||
render: Intl.NumberFormat('ru', {
|
||||
style: 'currency',
|
||||
currency: 'RUB',
|
||||
}).format,
|
||||
},
|
||||
];
|
||||
@ -1,32 +0,0 @@
|
||||
import { MAX_LEASING_PERIOD } from 'constants/values';
|
||||
import { toJS } from 'mobx';
|
||||
import { observer } from 'mobx-react-lite';
|
||||
import { useStore } from 'stores/hooks';
|
||||
import Table from 'ui/elements/Table';
|
||||
import { columns } from './config';
|
||||
|
||||
const PaymentsTable = observer(() => {
|
||||
const { $results } = useStore();
|
||||
|
||||
return (
|
||||
<Table
|
||||
columns={columns}
|
||||
dataSource={toJS($results.payments)}
|
||||
size="small"
|
||||
pagination={{
|
||||
defaultPageSize: 12,
|
||||
pageSizeOptions: [12, MAX_LEASING_PERIOD],
|
||||
responsive: true,
|
||||
}}
|
||||
scroll={{
|
||||
x: true,
|
||||
}}
|
||||
/>
|
||||
);
|
||||
});
|
||||
|
||||
export default {
|
||||
id: 'payments-table',
|
||||
title: 'Таблица платежей',
|
||||
Component: PaymentsTable,
|
||||
};
|
||||
@ -1,7 +0,0 @@
|
||||
export type Payment = {
|
||||
key: string;
|
||||
num: number;
|
||||
paymentSum: string;
|
||||
ndsCompensation: string;
|
||||
redemptionAmount: string;
|
||||
};
|
||||
@ -1,76 +0,0 @@
|
||||
/* eslint-disable object-curly-newline */
|
||||
|
||||
import type { Values } from 'stores/results/types';
|
||||
|
||||
export const id = 'output';
|
||||
export const title = 'Результаты';
|
||||
|
||||
export const titles: Record<Values, string> = {
|
||||
resultTotalGraphwithNDS: 'Итого по графику, с НДС',
|
||||
resultPlPrice: 'Стоимость ПЛ с НДС',
|
||||
resultPriceUpPr: 'Удорожание, год',
|
||||
resultIRRGraphPerc: 'IRR по графику клиента, %',
|
||||
resultIRRNominalPerc: 'IRR (номинал), %',
|
||||
resultInsKasko: 'КАСКО, НС, ДГО в графике',
|
||||
resultInsOsago: 'ОСАГО в графике',
|
||||
resultDopProdSum: 'Общая сумма доп.продуктов',
|
||||
resultFirstPayment: 'Первый платеж',
|
||||
resultLastPayment: 'Последний платеж',
|
||||
resultTerm: 'Срок, мес.',
|
||||
resultAB_FL: 'АВ ФЛ, без НДФЛ.',
|
||||
resultAB_UL: 'АВ ЮЛ, с НДС.',
|
||||
resultBonusMPL: 'Бонус МПЛ за лизинг, без НДФЛ',
|
||||
resultDopMPLLeasing: 'Доп.бонус МПЛ за лизинг, без НДФЛ',
|
||||
resultBonusDopProd: 'Бонус МПЛ за доп.продукты, без НДФЛ',
|
||||
resultBonusSafeFinance: 'Бонус за Safe Finance без НДФЛ',
|
||||
resultFirstPaymentRiskPolicy: 'Первый платеж по риск политике, %',
|
||||
};
|
||||
|
||||
const moneyFormatters = Object.fromEntries(
|
||||
(
|
||||
[
|
||||
'resultTotalGraphwithNDS',
|
||||
'resultPlPrice',
|
||||
'resultInsKasko',
|
||||
'resultInsOsago',
|
||||
'resultDopProdSum',
|
||||
'resultFirstPayment',
|
||||
'resultLastPayment',
|
||||
'resultAB_FL',
|
||||
'resultAB_UL',
|
||||
'resultBonusMPL',
|
||||
'resultDopMPLLeasing',
|
||||
'resultBonusDopProd',
|
||||
'tbxSubsidySum',
|
||||
'resultBonusSafeFinance',
|
||||
'resultPriceUpPr',
|
||||
] as Values[]
|
||||
).map((a) => [
|
||||
a,
|
||||
// prettier-ignore
|
||||
Intl.NumberFormat('ru', {
|
||||
style: 'currency',
|
||||
currency: 'RUB',
|
||||
}).format,
|
||||
])
|
||||
);
|
||||
|
||||
const percentFormatters = Object.fromEntries(
|
||||
(['resultIRRGraphPerc', 'resultIRRNominalPerc', 'resultFirstPaymentRiskPolicy'] as Values[]).map(
|
||||
(a) => [
|
||||
a,
|
||||
// prettier-ignore
|
||||
Intl.NumberFormat('ru', {
|
||||
style: 'percent',
|
||||
minimumFractionDigits: 2,
|
||||
maximumFractionDigits: 2,
|
||||
}).format,
|
||||
]
|
||||
)
|
||||
);
|
||||
|
||||
const defaultFormatters = {
|
||||
resultTerm: Intl.NumberFormat('ru').format,
|
||||
};
|
||||
|
||||
export const formatters = Object.assign(moneyFormatters, percentFormatters, defaultFormatters);
|
||||
@ -1,46 +0,0 @@
|
||||
import { Container, Head } from 'Components/Layout/Element';
|
||||
import { toJS } from 'mobx';
|
||||
import { observer } from 'mobx-react-lite';
|
||||
import { useStore } from 'stores/hooks';
|
||||
import styled from 'styled-components';
|
||||
import Text from 'ui/elements/Text';
|
||||
import { Box } from 'ui/grid';
|
||||
import { min } from 'ui/mq';
|
||||
import { formatters, id, title, titles } from './config';
|
||||
|
||||
const Grid = styled(Box)`
|
||||
display: grid;
|
||||
grid-template-columns: 1fr;
|
||||
|
||||
${min('tablet')} {
|
||||
grid-template-columns: 1fr 1fr;
|
||||
}
|
||||
`;
|
||||
|
||||
const Results = observer(() => {
|
||||
const { $results } = useStore();
|
||||
const values = toJS($results.values);
|
||||
|
||||
return (
|
||||
<Grid>
|
||||
{Object.keys(values).map((valueName) => {
|
||||
const formatter = formatters[valueName];
|
||||
const storeValue = values[valueName];
|
||||
const value = formatter(storeValue);
|
||||
|
||||
return (
|
||||
<Container key={valueName}>
|
||||
<Head title={titles[valueName]} />
|
||||
<Text>{value}</Text>
|
||||
</Container>
|
||||
);
|
||||
})}
|
||||
</Grid>
|
||||
);
|
||||
});
|
||||
|
||||
export default {
|
||||
id,
|
||||
title,
|
||||
Component: Results,
|
||||
};
|
||||
@ -1,89 +0,0 @@
|
||||
import { observer } from 'mobx-react-lite';
|
||||
import { useStore } from 'stores/hooks';
|
||||
import styled from 'styled-components';
|
||||
import Alert from 'ui/elements/Alert';
|
||||
import { Box, Flex } from 'ui/grid';
|
||||
|
||||
const Bold = styled.span`
|
||||
font-weight: bold;
|
||||
`;
|
||||
|
||||
function Message(title, text) {
|
||||
return (
|
||||
<>
|
||||
<Bold>{title}</Bold>
|
||||
{': '}
|
||||
{text}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
const AlertWrapper = styled(Box)`
|
||||
margin: 0 0 5px 0;
|
||||
`;
|
||||
|
||||
function getElementsErrors($calculation) {
|
||||
const errors = Object.values($calculation.$validation).map((validation) => {
|
||||
const elementErrors = validation.getMessages();
|
||||
const elementTitle = validation.params.err_title;
|
||||
|
||||
return elementErrors.map((error) => (
|
||||
<AlertWrapper>
|
||||
<Alert key={error.name} type="error" showIcon message={Message(elementTitle, error)} />
|
||||
</AlertWrapper>
|
||||
));
|
||||
});
|
||||
|
||||
return errors;
|
||||
}
|
||||
|
||||
function getPaymentsTableErrors($tables) {
|
||||
const { payments } = $tables;
|
||||
const messages = payments.validation.getMessages();
|
||||
const title = payments.validation.params.err_title;
|
||||
|
||||
return messages.map((text) => <Alert type="error" showIcon message={Message(title, text)} />);
|
||||
}
|
||||
|
||||
function getInsuranceTableErrors($tables) {
|
||||
const { insurance } = $tables;
|
||||
const messages = insurance.validation.getMessages();
|
||||
|
||||
return messages.map((message) => <Alert type="error" showIcon message={message} />);
|
||||
}
|
||||
|
||||
const Errors = observer(() => {
|
||||
const { $calculation, $tables } = useStore();
|
||||
|
||||
const hasElementsErrors = Object.values($calculation.$validation).some(
|
||||
(validation) => validation.hasErrors
|
||||
);
|
||||
const hasPaymentsErrors = $tables.payments.validation.hasErrors;
|
||||
const hasInsuranceErrors = $tables.insurance.validation.hasErrors;
|
||||
|
||||
if (!hasElementsErrors && !hasPaymentsErrors && !hasInsuranceErrors) {
|
||||
return <Alert type="success" showIcon message="Ошибок нет 🙂" />;
|
||||
}
|
||||
|
||||
const elementsErrors = getElementsErrors($calculation);
|
||||
const paymentsErrors = getPaymentsTableErrors($tables);
|
||||
const insuranceErrors = getInsuranceTableErrors($tables);
|
||||
|
||||
const errors = [...elementsErrors, ...paymentsErrors, ...insuranceErrors];
|
||||
|
||||
return <Flex flexDirection="column">{errors}</Flex>;
|
||||
});
|
||||
|
||||
function Validation() {
|
||||
return (
|
||||
<Box>
|
||||
<Errors />
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
export default {
|
||||
id: 'validation',
|
||||
title: 'Ошибки',
|
||||
Component: Validation,
|
||||
};
|
||||
@ -1,35 +0,0 @@
|
||||
import styled from 'styled-components';
|
||||
import Background from 'ui/elements/layout/Background';
|
||||
import Tabs from 'ui/elements/layout/Tabs';
|
||||
import { min } from 'ui/mq';
|
||||
import PaymentsTable from './PaymentsTable';
|
||||
import Results from './Results';
|
||||
import Validation from './Validation';
|
||||
|
||||
const outputTabs = [PaymentsTable, Results, Validation];
|
||||
|
||||
const Wrapper = styled(Background)`
|
||||
padding: 4px 10px;
|
||||
min-height: 200px;
|
||||
|
||||
${min('laptop')} {
|
||||
padding: 4px 18px;
|
||||
min-height: 641px;
|
||||
}
|
||||
`;
|
||||
|
||||
function Output() {
|
||||
return (
|
||||
<Wrapper>
|
||||
<Tabs>
|
||||
{outputTabs.map(({ id, title, Component }) => (
|
||||
<Tabs.TabPane tab={title} key={id}>
|
||||
<Component />
|
||||
</Tabs.TabPane>
|
||||
))}
|
||||
</Tabs>
|
||||
</Wrapper>
|
||||
);
|
||||
}
|
||||
|
||||
export default Output;
|
||||
69
Dockerfile
69
Dockerfile
@ -1,69 +0,0 @@
|
||||
# Install dependencies only when needed
|
||||
FROM node:16-alpine AS deps
|
||||
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
|
||||
RUN apk add --no-cache libc6-compat
|
||||
WORKDIR /app
|
||||
COPY package.json yarn.lock ./
|
||||
RUN yarn install --frozen-lockfile
|
||||
|
||||
# If using npm with a `package-lock.json` comment out above and use below instead
|
||||
# COPY package.json package-lock.json ./
|
||||
# RUN npm ci
|
||||
|
||||
# Rebuild the source code only when needed
|
||||
FROM node:16-alpine AS builder
|
||||
WORKDIR /app
|
||||
COPY --from=deps /app/node_modules ./node_modules
|
||||
COPY . .
|
||||
|
||||
ARG NEXT_PUBLIC_BASE_PATH
|
||||
ARG NEXT_PUBLIC_COLOR_PRIMARY
|
||||
ARG NEXT_PUBLIC_COLOR_SECONDARY
|
||||
ARG NEXT_PUBLIC_COLOR_TERTIARTY
|
||||
ARG NEXT_PUBLIC_FAVICON
|
||||
ARG NEXT_TELEMETRY_DISABLED
|
||||
ARG NEXT_PUBLIC_URL_CRM_GRAPHQL_PROXY
|
||||
ARG NEXT_PUBLIC_URL_CRM_GRAPHQL_DIRECT
|
||||
ARG NEXT_PUBLIC_URL_GET_USER_PROXY
|
||||
ARG NEXT_PUBLIC_URL_GET_USER_DIRECT
|
||||
ARG NEXT_PUBLIC_URL_CORE_FINGAP_PROXY
|
||||
ARG NEXT_PUBLIC_URL_CORE_FINGAP_DIRECT
|
||||
|
||||
# Next.js collects completely anonymous telemetry data about general usage.
|
||||
# Learn more here: https://nextjs.org/telemetry
|
||||
# Uncomment the following line in case you want to disable telemetry during the build.
|
||||
# ENV NEXT_TELEMETRY_DISABLED 1
|
||||
|
||||
RUN yarn build
|
||||
|
||||
# If using npm comment out above and use below instead
|
||||
# RUN npm run build
|
||||
|
||||
# Production image, copy all the files and run next
|
||||
FROM node:16-alpine AS runner
|
||||
WORKDIR /app
|
||||
|
||||
ENV NODE_ENV production
|
||||
# Uncomment the following line in case you want to disable telemetry during runtime.
|
||||
# ENV NEXT_TELEMETRY_DISABLED 1
|
||||
|
||||
RUN addgroup --system --gid 1001 nodejs
|
||||
RUN adduser --system --uid 1001 nextjs
|
||||
|
||||
# You only need to copy next.config.js if you are NOT using the default configuration
|
||||
COPY --from=builder /app/next.config.js ./
|
||||
COPY --from=builder /app/public ./public
|
||||
COPY --from=builder /app/package.json ./package.json
|
||||
|
||||
# Automatically leverage output traces to reduce image size
|
||||
# https://nextjs.org/docs/advanced-features/output-file-tracing
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
||||
|
||||
USER nextjs
|
||||
|
||||
EXPOSE 3000
|
||||
|
||||
ENV PORT 3000
|
||||
|
||||
CMD ["node", "server.js"]
|
||||
85
README.md
85
README.md
@ -1,34 +1,81 @@
|
||||
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).
|
||||
# Turborepo starter
|
||||
|
||||
## Getting Started
|
||||
This is an official starter Turborepo.
|
||||
|
||||
First, run the development server:
|
||||
## Using this example
|
||||
|
||||
```bash
|
||||
npm run dev
|
||||
# or
|
||||
yarn dev
|
||||
Run the following command:
|
||||
|
||||
```sh
|
||||
npx create-turbo@latest
|
||||
```
|
||||
|
||||
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
|
||||
## What's inside?
|
||||
|
||||
You can start editing the page by modifying `pages/index.tsx`. The page auto-updates as you edit the file.
|
||||
This Turborepo includes the following packages/apps:
|
||||
|
||||
[API routes](https://nextjs.org/docs/api-routes/introduction) can be accessed on [http://localhost:3000/api/hello](http://localhost:3000/api/hello). This endpoint can be edited in `pages/api/hello.ts`.
|
||||
### Apps and Packages
|
||||
|
||||
The `pages/api` directory is mapped to `/api/*`. Files in this directory are treated as [API routes](https://nextjs.org/docs/api-routes/introduction) instead of React pages.
|
||||
- `docs`: a [Next.js](https://nextjs.org/) app
|
||||
- `web`: another [Next.js](https://nextjs.org/) app
|
||||
- `@repo/ui`: a stub React component library shared by both `web` and `docs` applications
|
||||
- `@repo/eslint-config`: `eslint` configurations (includes `eslint-config-next` and `eslint-config-prettier`)
|
||||
- `@repo/tsconfig`: `tsconfig.json`s used throughout the monorepo
|
||||
|
||||
## Learn More
|
||||
Each package/app is 100% [TypeScript](https://www.typescriptlang.org/).
|
||||
|
||||
To learn more about Next.js, take a look at the following resources:
|
||||
### Utilities
|
||||
|
||||
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
|
||||
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
|
||||
This Turborepo has some additional tools already setup for you:
|
||||
|
||||
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!
|
||||
- [TypeScript](https://www.typescriptlang.org/) for static type checking
|
||||
- [ESLint](https://eslint.org/) for code linting
|
||||
- [Prettier](https://prettier.io) for code formatting
|
||||
|
||||
## Deploy on Vercel
|
||||
### Build
|
||||
|
||||
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
|
||||
To build all apps and packages, run the following command:
|
||||
|
||||
Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
|
||||
```
|
||||
cd my-turborepo
|
||||
pnpm build
|
||||
```
|
||||
|
||||
### Develop
|
||||
|
||||
To develop all apps and packages, run the following command:
|
||||
|
||||
```
|
||||
cd my-turborepo
|
||||
pnpm dev
|
||||
```
|
||||
|
||||
### Remote Caching
|
||||
|
||||
Turborepo can use a technique known as [Remote Caching](https://turbo.build/repo/docs/core-concepts/remote-caching) to share cache artifacts across machines, enabling you to share build caches with your team and CI/CD pipelines.
|
||||
|
||||
By default, Turborepo will cache locally. To enable Remote Caching you will need an account with Vercel. If you don't have an account you can [create one](https://vercel.com/signup), then enter the following commands:
|
||||
|
||||
```
|
||||
cd my-turborepo
|
||||
npx turbo login
|
||||
```
|
||||
|
||||
This will authenticate the Turborepo CLI with your [Vercel account](https://vercel.com/docs/concepts/personal-accounts/overview).
|
||||
|
||||
Next, you can link your Turborepo to your Remote Cache by running the following command from the root of your Turborepo:
|
||||
|
||||
```
|
||||
npx turbo link
|
||||
```
|
||||
|
||||
## Useful Links
|
||||
|
||||
Learn more about the power of Turborepo:
|
||||
|
||||
- [Tasks](https://turbo.build/repo/docs/core-concepts/monorepos/running-tasks)
|
||||
- [Caching](https://turbo.build/repo/docs/core-concepts/caching)
|
||||
- [Remote Caching](https://turbo.build/repo/docs/core-concepts/remote-caching)
|
||||
- [Filtering](https://turbo.build/repo/docs/core-concepts/monorepos/filtering)
|
||||
- [Configuration Options](https://turbo.build/repo/docs/reference/configuration)
|
||||
- [CLI Usage](https://turbo.build/repo/docs/reference/command-line-reference)
|
||||
|
||||
@ -1,16 +0,0 @@
|
||||
/* eslint-disable import/prefer-default-export */
|
||||
import type { QueryFunctionContext } from '@tanstack/react-query';
|
||||
import axios from 'axios';
|
||||
import type { RequestFinGAP, ResponseFinGAP } from './types';
|
||||
|
||||
export async function calculateFinGAP(payload: RequestFinGAP, { signal }: QueryFunctionContext) {
|
||||
const { data } = await axios.post<ResponseFinGAP>(
|
||||
process.env.NEXT_PUBLIC_URL_CORE_FINGAP_PROXY!,
|
||||
payload,
|
||||
{
|
||||
signal,
|
||||
}
|
||||
);
|
||||
|
||||
return data;
|
||||
}
|
||||
@ -1,16 +0,0 @@
|
||||
/* eslint-disable import/prefer-default-export */
|
||||
import type { AxiosRequestConfig } from 'axios';
|
||||
import axios from 'axios';
|
||||
import { love } from './tools';
|
||||
import type { User } from './types';
|
||||
|
||||
// prettier-ignore
|
||||
const uri = typeof window === 'undefined'
|
||||
? process.env.NEXT_PUBLIC_URL_GET_USER_DIRECT
|
||||
: process.env.NEXT_PUBLIC_URL_GET_USER_PROXY;
|
||||
|
||||
export async function getUser(config: AxiosRequestConfig) {
|
||||
const user = await axios.get<User>(uri!, config).then((res) => love(res.data));
|
||||
|
||||
return user;
|
||||
}
|
||||
@ -1,10 +0,0 @@
|
||||
/* eslint-disable import/prefer-default-export */
|
||||
import type { User } from './types';
|
||||
|
||||
export function love(user: User) {
|
||||
const superUsers: string[] = JSON.parse(process.env.USERS_SUPER || '');
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
if (superUsers?.includes(user.username)) user.displayName += '🧡';
|
||||
|
||||
return user;
|
||||
}
|
||||
@ -1,12 +0,0 @@
|
||||
/** @type {import('apollo').ApolloConfig} */
|
||||
module.exports = {
|
||||
client: {
|
||||
service: {
|
||||
name: 'crmgraphql',
|
||||
url: process.env.NEXT_PUBLIC_URL_CRM_GRAPHQL_DIRECT,
|
||||
localSchemaFile: './graphql/crm.schema.graphql',
|
||||
},
|
||||
excludes: ['graphql/**/*'],
|
||||
includes: ['pages/**/*', 'process/**/*', 'Components/**/*'],
|
||||
},
|
||||
};
|
||||
@ -1,35 +0,0 @@
|
||||
/* eslint-disable no-underscore-dangle */
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
import { ApolloClient, InMemoryCache } from '@apollo/client';
|
||||
|
||||
/** @type {import('@apollo/client').ApolloClient<NormalizedCacheObject>} */
|
||||
let apolloClient;
|
||||
|
||||
// prettier-ignore
|
||||
const uri = typeof window === 'undefined'
|
||||
? process.env.NEXT_PUBLIC_URL_CRM_GRAPHQL_DIRECT
|
||||
: process.env.NEXT_PUBLIC_URL_CRM_GRAPHQL_PROXY;
|
||||
|
||||
function createApolloClient() {
|
||||
return new ApolloClient({
|
||||
ssrMode: typeof window === 'undefined',
|
||||
uri,
|
||||
cache: new InMemoryCache(),
|
||||
});
|
||||
}
|
||||
|
||||
export default function initializeApollo(initialState = null) {
|
||||
const _apolloClient = apolloClient ?? createApolloClient();
|
||||
|
||||
// If your page has Next.js data fetching methods that use Apollo Client, the initial state
|
||||
// gets hydrated here
|
||||
if (initialState) {
|
||||
_apolloClient.cache.restore(initialState);
|
||||
}
|
||||
// For SSG and SSR always create a new Apollo Client
|
||||
if (typeof window === 'undefined') return _apolloClient;
|
||||
// Create the Apollo Client once in the client
|
||||
if (!apolloClient) apolloClient = _apolloClient;
|
||||
|
||||
return _apolloClient;
|
||||
}
|
||||
7
apps/api/.dockerignore
Normal file
7
apps/api/.dockerignore
Normal file
@ -0,0 +1,7 @@
|
||||
.git
|
||||
Dockerfile
|
||||
.dockerignore
|
||||
node_modules
|
||||
*.log
|
||||
dist
|
||||
README.md
|
||||
13
apps/api/.eslintrc.js
Normal file
13
apps/api/.eslintrc.js
Normal file
@ -0,0 +1,13 @@
|
||||
const { createConfig } = require('@vchikalkin/eslint-config-awesome');
|
||||
|
||||
module.exports = createConfig('typescript', {
|
||||
parserOptions: {
|
||||
project: './tsconfig.json',
|
||||
tsconfigRootDir: __dirname,
|
||||
},
|
||||
ignorePatterns: ['*.config.js', '.eslintrc.js'],
|
||||
rules: {
|
||||
'import/no-duplicates': 'off',
|
||||
'import/consistent-type-specifier-style': 'off',
|
||||
},
|
||||
});
|
||||
56
apps/api/.gitignore
vendored
Normal file
56
apps/api/.gitignore
vendored
Normal file
@ -0,0 +1,56 @@
|
||||
# compiled output
|
||||
/dist
|
||||
/node_modules
|
||||
/build
|
||||
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
pnpm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
lerna-debug.log*
|
||||
|
||||
# OS
|
||||
.DS_Store
|
||||
|
||||
# Tests
|
||||
/coverage
|
||||
/.nyc_output
|
||||
|
||||
# IDEs and editors
|
||||
/.idea
|
||||
.project
|
||||
.classpath
|
||||
.c9/
|
||||
*.launch
|
||||
.settings/
|
||||
*.sublime-workspace
|
||||
|
||||
# IDE - VSCode
|
||||
.vscode/*
|
||||
!.vscode/settings.json
|
||||
!.vscode/tasks.json
|
||||
!.vscode/launch.json
|
||||
!.vscode/extensions.json
|
||||
|
||||
# dotenv environment variable files
|
||||
.env
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
.env.local
|
||||
|
||||
# temp directory
|
||||
.temp
|
||||
.tmp
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
*.pid.lock
|
||||
|
||||
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
||||
4
apps/api/.prettierrc
Normal file
4
apps/api/.prettierrc
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"singleQuote": true,
|
||||
"trailingComma": "all"
|
||||
}
|
||||
45
apps/api/Dockerfile
Normal file
45
apps/api/Dockerfile
Normal file
@ -0,0 +1,45 @@
|
||||
# This Dockerfile is copy-pasted into our main docs at /docs/handbook/deploying-with-docker.
|
||||
# Make sure you update both files!
|
||||
|
||||
FROM node:alpine AS builder
|
||||
RUN corepack enable && corepack prepare pnpm@8.9.0 --activate
|
||||
ENV PNPM_HOME=/usr/local/bin
|
||||
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
|
||||
RUN apk add --no-cache libc6-compat
|
||||
RUN apk update
|
||||
# Set working directory
|
||||
WORKDIR /app
|
||||
RUN pnpm add -g turbo@1.12.4 dotenv-cli
|
||||
COPY . .
|
||||
RUN turbo prune --scope=api --docker
|
||||
|
||||
# Add lockfile and package.json's of isolated subworkspace
|
||||
FROM node:alpine AS installer
|
||||
RUN corepack enable && corepack prepare pnpm@latest --activate
|
||||
ENV PNPM_HOME=/usr/local/bin
|
||||
RUN apk add --no-cache libc6-compat
|
||||
RUN apk update
|
||||
WORKDIR /app
|
||||
|
||||
# First install dependencies (as they change less often)
|
||||
COPY .gitignore .gitignore
|
||||
COPY --from=builder /app/out/json/ .
|
||||
COPY --from=builder /app/out/pnpm-lock.yaml ./pnpm-lock.yaml
|
||||
COPY --from=builder /app/out/pnpm-workspace.yaml ./pnpm-workspace.yaml
|
||||
RUN pnpm install
|
||||
|
||||
# Build the project and its dependencies
|
||||
COPY --from=builder /app/out/full/ .
|
||||
COPY turbo.json turbo.json
|
||||
RUN pnpm dotenv -e .env turbo run build --filter=api...
|
||||
|
||||
FROM node:alpine AS runner
|
||||
WORKDIR /app
|
||||
|
||||
# Don't run production as root
|
||||
RUN addgroup --system --gid 1001 nestjs
|
||||
RUN adduser --system --uid 1001 nestjs
|
||||
USER nestjs
|
||||
COPY --from=installer /app .
|
||||
|
||||
CMD node apps/api/dist/main.js
|
||||
73
apps/api/README.md
Normal file
73
apps/api/README.md
Normal file
@ -0,0 +1,73 @@
|
||||
<p align="center">
|
||||
<a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo-small.svg" width="200" alt="Nest Logo" /></a>
|
||||
</p>
|
||||
|
||||
[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456
|
||||
[circleci-url]: https://circleci.com/gh/nestjs/nest
|
||||
|
||||
<p align="center">A progressive <a href="http://nodejs.org" target="_blank">Node.js</a> framework for building efficient and scalable server-side applications.</p>
|
||||
<p align="center">
|
||||
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/v/@nestjs/core.svg" alt="NPM Version" /></a>
|
||||
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/l/@nestjs/core.svg" alt="Package License" /></a>
|
||||
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/dm/@nestjs/common.svg" alt="NPM Downloads" /></a>
|
||||
<a href="https://circleci.com/gh/nestjs/nest" target="_blank"><img src="https://img.shields.io/circleci/build/github/nestjs/nest/master" alt="CircleCI" /></a>
|
||||
<a href="https://coveralls.io/github/nestjs/nest?branch=master" target="_blank"><img src="https://coveralls.io/repos/github/nestjs/nest/badge.svg?branch=master#9" alt="Coverage" /></a>
|
||||
<a href="https://discord.gg/G7Qnnhy" target="_blank"><img src="https://img.shields.io/badge/discord-online-brightgreen.svg" alt="Discord"/></a>
|
||||
<a href="https://opencollective.com/nest#backer" target="_blank"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a>
|
||||
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://opencollective.com/nest/sponsors/badge.svg" alt="Sponsors on Open Collective" /></a>
|
||||
<a href="https://paypal.me/kamilmysliwiec" target="_blank"><img src="https://img.shields.io/badge/Donate-PayPal-ff3f59.svg"/></a>
|
||||
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://img.shields.io/badge/Support%20us-Open%20Collective-41B883.svg" alt="Support us"></a>
|
||||
<a href="https://twitter.com/nestframework" target="_blank"><img src="https://img.shields.io/twitter/follow/nestframework.svg?style=social&label=Follow"></a>
|
||||
</p>
|
||||
<!--[](https://opencollective.com/nest#backer)
|
||||
[](https://opencollective.com/nest#sponsor)-->
|
||||
|
||||
## Description
|
||||
|
||||
[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository.
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
$ pnpm install
|
||||
```
|
||||
|
||||
## Running the app
|
||||
|
||||
```bash
|
||||
# development
|
||||
$ pnpm run start
|
||||
|
||||
# watch mode
|
||||
$ pnpm run start:dev
|
||||
|
||||
# production mode
|
||||
$ pnpm run start:prod
|
||||
```
|
||||
|
||||
## Test
|
||||
|
||||
```bash
|
||||
# unit tests
|
||||
$ pnpm run test
|
||||
|
||||
# e2e tests
|
||||
$ pnpm run test:e2e
|
||||
|
||||
# test coverage
|
||||
$ pnpm run test:cov
|
||||
```
|
||||
|
||||
## Support
|
||||
|
||||
Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support).
|
||||
|
||||
## Stay in touch
|
||||
|
||||
- Author - [Kamil Myśliwiec](https://kamilmysliwiec.com)
|
||||
- Website - [https://nestjs.com](https://nestjs.com/)
|
||||
- Twitter - [@nestframework](https://twitter.com/nestframework)
|
||||
|
||||
## License
|
||||
|
||||
Nest is [MIT licensed](LICENSE).
|
||||
8
apps/api/nest-cli.json
Normal file
8
apps/api/nest-cli.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/nest-cli",
|
||||
"collection": "@nestjs/schematics",
|
||||
"sourceRoot": "src",
|
||||
"compilerOptions": {
|
||||
"deleteOutDir": true
|
||||
}
|
||||
}
|
||||
74
apps/api/package.json
Normal file
74
apps/api/package.json
Normal file
@ -0,0 +1,74 @@
|
||||
{
|
||||
"name": "api",
|
||||
"version": "0.0.1",
|
||||
"description": "",
|
||||
"author": "",
|
||||
"private": true,
|
||||
"license": "UNLICENSED",
|
||||
"scripts": {
|
||||
"build": "nest build",
|
||||
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
|
||||
"start": "nest start",
|
||||
"dev": "nest start --watch",
|
||||
"start:debug": "nest start --debug --watch",
|
||||
"start:prod": "node dist/main",
|
||||
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
|
||||
"test": "jest",
|
||||
"test:watch": "jest --watch",
|
||||
"test:cov": "jest --coverage",
|
||||
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
|
||||
"test:e2e": "jest --config ./test/jest-e2e.json"
|
||||
},
|
||||
"dependencies": {
|
||||
"@nestjs/cache-manager": "^2.2.1",
|
||||
"@nestjs/common": "^10.0.0",
|
||||
"@nestjs/config": "^3.2.0",
|
||||
"@nestjs/core": "^10.0.0",
|
||||
"@nestjs/platform-express": "^10.0.0",
|
||||
"@nestjs/platform-fastify": "^10.3.3",
|
||||
"cache-manager": "^5.4.0",
|
||||
"cache-manager-ioredis": "^2.1.0",
|
||||
"ioredis": "^5.3.2",
|
||||
"reflect-metadata": "^0.2.0",
|
||||
"rxjs": "^7.8.1",
|
||||
"zod": "^3.22.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@nestjs/cli": "^10.0.0",
|
||||
"@nestjs/schematics": "^10.0.0",
|
||||
"@nestjs/testing": "^10.0.0",
|
||||
"@types/jest": "^29.5.2",
|
||||
"@types/node": "^20.3.1",
|
||||
"@types/supertest": "^6.0.0",
|
||||
"@vchikalkin/eslint-config-awesome": "^1.1.6",
|
||||
"eslint": "^8.52.0",
|
||||
"fastify": "^4.26.1",
|
||||
"jest": "^29.5.0",
|
||||
"prettier": "^3.0.0",
|
||||
"shared": "workspace:*",
|
||||
"source-map-support": "^0.5.21",
|
||||
"supertest": "^6.3.3",
|
||||
"ts-jest": "29.1.1",
|
||||
"ts-loader": "^9.4.3",
|
||||
"ts-node": "^10.9.1",
|
||||
"tsconfig-paths": "^4.2.0",
|
||||
"typescript": "^5.3.3"
|
||||
},
|
||||
"jest": {
|
||||
"moduleFileExtensions": [
|
||||
"js",
|
||||
"json",
|
||||
"ts"
|
||||
],
|
||||
"rootDir": "src",
|
||||
"testRegex": ".*\\.spec\\.ts$",
|
||||
"transform": {
|
||||
"^.+\\.(t|j)s$": "ts-jest"
|
||||
},
|
||||
"collectCoverageFrom": [
|
||||
"**/*.(t|j)s"
|
||||
],
|
||||
"coverageDirectory": "../coverage",
|
||||
"testEnvironment": "node"
|
||||
}
|
||||
}
|
||||
16
apps/api/src/app.module.ts
Normal file
16
apps/api/src/app.module.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import { ProxyModule } from './proxy/proxy.module';
|
||||
import { Global, Module } from '@nestjs/common';
|
||||
import { ConfigModule } from '@nestjs/config';
|
||||
|
||||
@Global()
|
||||
@Module({
|
||||
imports: [
|
||||
ConfigModule.forRoot({
|
||||
isGlobal: true,
|
||||
}),
|
||||
ProxyModule,
|
||||
],
|
||||
providers: [],
|
||||
})
|
||||
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
|
||||
export class AppModule {}
|
||||
3
apps/api/src/config/constants.ts
Normal file
3
apps/api/src/config/constants.ts
Normal file
@ -0,0 +1,3 @@
|
||||
import { seconds } from 'src/utils/time';
|
||||
|
||||
export const DEFAULT_CACHE_TTL = seconds().fromMinutes(15);
|
||||
3
apps/api/src/config/env.ts
Normal file
3
apps/api/src/config/env.ts
Normal file
@ -0,0 +1,3 @@
|
||||
import envSchema from './schema/env';
|
||||
|
||||
export const env = envSchema.parse(process.env);
|
||||
21
apps/api/src/config/schema/env.ts
Normal file
21
apps/api/src/config/schema/env.ts
Normal file
@ -0,0 +1,21 @@
|
||||
import { DEFAULT_CACHE_TTL } from '../constants';
|
||||
import { z } from 'zod';
|
||||
|
||||
const envSchema = z.object({
|
||||
CACHE_TTL: z
|
||||
.string()
|
||||
.transform((val) => Number.parseInt(val, 10))
|
||||
.default(DEFAULT_CACHE_TTL.toString()),
|
||||
PORT: z
|
||||
.string()
|
||||
.transform((val) => Number.parseInt(val, 10))
|
||||
.default('3001'),
|
||||
REDIS_HOST: z.string(),
|
||||
REDIS_PORT: z
|
||||
.string()
|
||||
.transform((val) => Number.parseInt(val, 10))
|
||||
.default('6379'),
|
||||
URL_CRM_GRAPHQL_DIRECT: z.string(),
|
||||
});
|
||||
|
||||
export default envSchema;
|
||||
15
apps/api/src/main.ts
Normal file
15
apps/api/src/main.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import { AppModule } from './app.module';
|
||||
import { env } from './config/env';
|
||||
import { NestFactory } from '@nestjs/core';
|
||||
import type { NestFastifyApplication } from '@nestjs/platform-fastify';
|
||||
import { FastifyAdapter } from '@nestjs/platform-fastify';
|
||||
|
||||
async function bootstrap() {
|
||||
const app = await NestFactory.create<NestFastifyApplication>(
|
||||
AppModule,
|
||||
new FastifyAdapter(),
|
||||
);
|
||||
|
||||
await app.listen(env.PORT, '0.0.0.0');
|
||||
}
|
||||
bootstrap();
|
||||
64
apps/api/src/proxy/lib/config.ts
Normal file
64
apps/api/src/proxy/lib/config.ts
Normal file
@ -0,0 +1,64 @@
|
||||
import { seconds } from 'src/utils/time';
|
||||
|
||||
export const queryTTL: Record<string, number | false> = {
|
||||
GetAddProductType: seconds().fromHours(12),
|
||||
GetAddproductTypes: seconds().fromHours(12),
|
||||
GetAgent: seconds().fromHours(12),
|
||||
GetBrand: seconds().fromHours(3),
|
||||
GetBrands: seconds().fromHours(3),
|
||||
GetCoefficients: seconds().fromHours(12),
|
||||
GetConfiguration: seconds().fromHours(3),
|
||||
GetConfigurations: seconds().fromMinutes(15),
|
||||
GetCurrencyChanges: seconds().fromHours(1),
|
||||
GetDealer: seconds().fromHours(1),
|
||||
GetDealerPerson: seconds().fromHours(1),
|
||||
GetDealerPersons: seconds().fromHours(1),
|
||||
GetDealers: seconds().fromMinutes(15),
|
||||
GetEltInsuranceRules: seconds().fromHours(12),
|
||||
GetFuelCards: seconds().fromHours(12),
|
||||
GetGPSBrands: seconds().fromHours(24),
|
||||
GetGPSModels: seconds().fromHours(24),
|
||||
GetImportProgram: seconds().fromHours(12),
|
||||
GetInsNSIBTypes: seconds().fromHours(12),
|
||||
GetInsuranceCompanies: seconds().fromHours(12),
|
||||
GetInsuranceCompany: seconds().fromHours(12),
|
||||
GetLead: false,
|
||||
GetLeadUrl: seconds().fromHours(12),
|
||||
GetLeads: false,
|
||||
GetLeaseObjectType: seconds().fromHours(24),
|
||||
GetLeaseObjectTypes: seconds().fromHours(24),
|
||||
GetLeasingWithoutKaskoTypes: seconds().fromHours(12),
|
||||
GetModel: seconds().fromHours(3),
|
||||
GetModels: seconds().fromMinutes(15),
|
||||
GetOpportunities: false,
|
||||
GetOpportunity: false,
|
||||
GetOpportunityUrl: seconds().fromHours(12),
|
||||
GetOsagoAddproductTypes: seconds().fromHours(12),
|
||||
GetProduct: seconds().fromHours(12),
|
||||
GetProducts: seconds().fromHours(12),
|
||||
GetQuote: false,
|
||||
GetQuoteData: false,
|
||||
GetQuoteUrl: seconds().fromHours(12),
|
||||
GetQuotes: false,
|
||||
GetRate: seconds().fromHours(12),
|
||||
GetRates: seconds().fromHours(12),
|
||||
GetRegion: seconds().fromHours(24),
|
||||
GetRegions: seconds().fromHours(24),
|
||||
GetRegistrationTypes: seconds().fromHours(12),
|
||||
GetRewardCondition: seconds().fromHours(1),
|
||||
GetRewardConditions: seconds().fromHours(1),
|
||||
GetRoles: seconds().fromHours(12),
|
||||
GetSotCoefficientType: seconds().fromHours(12),
|
||||
GetSubsidies: seconds().fromHours(12),
|
||||
GetSubsidy: seconds().fromHours(12),
|
||||
GetSystemUser: seconds().fromHours(12),
|
||||
GetTarif: seconds().fromHours(12),
|
||||
GetTarifs: seconds().fromHours(12),
|
||||
GetTechnicalCards: seconds().fromHours(12),
|
||||
GetTelematicTypes: seconds().fromHours(12),
|
||||
GetTown: seconds().fromHours(24),
|
||||
GetTowns: seconds().fromHours(24),
|
||||
GetTrackerTypes: seconds().fromHours(12),
|
||||
GetTransactionCurrencies: seconds().fromHours(12),
|
||||
GetTransactionCurrency: seconds().fromHours(12),
|
||||
};
|
||||
127
apps/api/src/proxy/proxy.controller.ts
Normal file
127
apps/api/src/proxy/proxy.controller.ts
Normal file
@ -0,0 +1,127 @@
|
||||
import { queryTTL } from './lib/config';
|
||||
import type { GQLRequest, GQLResponse } from './types';
|
||||
import { CACHE_MANAGER } from '@nestjs/cache-manager';
|
||||
import {
|
||||
All,
|
||||
Controller,
|
||||
Delete,
|
||||
Get,
|
||||
HttpException,
|
||||
HttpStatus,
|
||||
Inject,
|
||||
Query,
|
||||
Req,
|
||||
Res,
|
||||
} from '@nestjs/common';
|
||||
import type { Cache } from 'cache-manager';
|
||||
import { FastifyReply, FastifyRequest } from 'fastify';
|
||||
import type { QueryItem } from 'shared/types/cache';
|
||||
import { env } from 'src/config/env';
|
||||
|
||||
type RedisStore = Omit<Cache, 'set'> & {
|
||||
set: (key: string, value: unknown, { ttl }: { ttl: number }) => Promise<void>;
|
||||
};
|
||||
|
||||
@Controller('proxy')
|
||||
export class ProxyController {
|
||||
constructor(
|
||||
@Inject(CACHE_MANAGER) private readonly cacheManager: RedisStore,
|
||||
) {}
|
||||
|
||||
@All('/graphql')
|
||||
public async graphql(@Req() req: FastifyRequest, @Res() reply: FastifyReply) {
|
||||
const { operationName, query, variables } = req.body as GQLRequest;
|
||||
|
||||
const key = `${operationName} ${JSON.stringify(variables)}`;
|
||||
const cached = await this.cacheManager.get(key);
|
||||
|
||||
if (cached) return reply.send(cached);
|
||||
|
||||
const response = await fetch(env.URL_CRM_GRAPHQL_DIRECT, {
|
||||
body: JSON.stringify({ operationName, query, variables }),
|
||||
headers: {
|
||||
Authorization: req.headers.authorization,
|
||||
'Content-Type': 'application/json',
|
||||
Cookie: req.headers.cookie,
|
||||
},
|
||||
method: req.method,
|
||||
});
|
||||
|
||||
const data = (await response.json()) as GQLResponse;
|
||||
|
||||
if (!response.ok || data?.error || data?.errors?.length)
|
||||
throw new HttpException(
|
||||
response.statusText,
|
||||
response.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
|
||||
const ttl = queryTTL[operationName];
|
||||
if (data && ttl !== false)
|
||||
await this.cacheManager.set(key, data, { ttl: ttl || env.CACHE_TTL });
|
||||
|
||||
return reply.send(data);
|
||||
}
|
||||
|
||||
@Get('/get-queries')
|
||||
public async getQueriesList(@Res() reply: FastifyReply) {
|
||||
const res = await this.getAllQueries();
|
||||
|
||||
return reply.send(res);
|
||||
}
|
||||
|
||||
private async getAllQueries() {
|
||||
const list = await this.cacheManager.store.keys('*');
|
||||
|
||||
return (Object.keys(queryTTL) as Array<keyof typeof queryTTL>).reduce(
|
||||
(acc, queryName) => {
|
||||
const queries = list.filter((x) => x.split(' ').at(0) === queryName);
|
||||
if (queries.length) {
|
||||
const ttl = queryTTL[queryName];
|
||||
acc[queryName] = { queries, ttl };
|
||||
}
|
||||
|
||||
return acc;
|
||||
},
|
||||
{} as Record<string, QueryItem>,
|
||||
);
|
||||
}
|
||||
|
||||
@Delete('/delete-query')
|
||||
public async deleteQuery(
|
||||
@Query('queryKey') queryKey: string,
|
||||
@Res() reply: FastifyReply,
|
||||
) {
|
||||
try {
|
||||
await this.cacheManager.del(queryKey);
|
||||
|
||||
return reply.send('ok');
|
||||
} catch (error) {
|
||||
throw new HttpException(error, HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@Delete('/reset')
|
||||
public async reset(@Res() reply: FastifyReply) {
|
||||
try {
|
||||
await this.cacheManager.reset();
|
||||
|
||||
return reply.send('ok');
|
||||
} catch (error) {
|
||||
throw new HttpException(error, HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@Get('/get-query')
|
||||
public async getQueryValue(
|
||||
@Query('queryKey') queryKey: string,
|
||||
@Res() reply: FastifyReply,
|
||||
) {
|
||||
try {
|
||||
const value = await this.cacheManager.get(queryKey);
|
||||
|
||||
return reply.send(value);
|
||||
} catch (error) {
|
||||
throw new HttpException(error, HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
20
apps/api/src/proxy/proxy.module.ts
Normal file
20
apps/api/src/proxy/proxy.module.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import { ProxyController } from './proxy.controller';
|
||||
import { CacheModule } from '@nestjs/cache-manager';
|
||||
import { Module } from '@nestjs/common';
|
||||
import * as redisStore from 'cache-manager-ioredis';
|
||||
import type { RedisOptions } from 'ioredis';
|
||||
import { env } from 'src/config/env';
|
||||
|
||||
@Module({
|
||||
controllers: [ProxyController],
|
||||
imports: [
|
||||
CacheModule.register<RedisOptions>({
|
||||
host: env.REDIS_HOST,
|
||||
port: env.REDIS_PORT,
|
||||
store: redisStore,
|
||||
ttl: env.CACHE_TTL,
|
||||
}),
|
||||
],
|
||||
})
|
||||
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
|
||||
export class ProxyModule {}
|
||||
11
apps/api/src/proxy/types.ts
Normal file
11
apps/api/src/proxy/types.ts
Normal file
@ -0,0 +1,11 @@
|
||||
export type GQLRequest = {
|
||||
operationName: string;
|
||||
query: string;
|
||||
variables: string;
|
||||
};
|
||||
|
||||
export type GQLResponse = {
|
||||
data: unknown;
|
||||
error?: unknown;
|
||||
errors?: unknown[];
|
||||
};
|
||||
13
apps/api/src/utils/time.ts
Normal file
13
apps/api/src/utils/time.ts
Normal file
@ -0,0 +1,13 @@
|
||||
export function seconds() {
|
||||
return {
|
||||
fromDays(days: number) {
|
||||
return days * 24 * 60 * 60;
|
||||
},
|
||||
fromHours(hours: number) {
|
||||
return hours * 60 * 60;
|
||||
},
|
||||
fromMinutes(minutes: number) {
|
||||
return minutes * 60;
|
||||
},
|
||||
};
|
||||
}
|
||||
4
apps/api/tsconfig.build.json
Normal file
4
apps/api/tsconfig.build.json
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"exclude": ["node_modules", "test", "dist", "**/*spec.ts"]
|
||||
}
|
||||
22
apps/api/tsconfig.json
Normal file
22
apps/api/tsconfig.json
Normal file
@ -0,0 +1,22 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"declaration": true,
|
||||
"removeComments": true,
|
||||
"emitDecoratorMetadata": true,
|
||||
"experimentalDecorators": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"target": "ES2021",
|
||||
"sourceMap": true,
|
||||
"outDir": "./dist",
|
||||
"baseUrl": "./",
|
||||
"incremental": true,
|
||||
"skipLibCheck": true,
|
||||
"strictNullChecks": false,
|
||||
"noImplicitAny": false,
|
||||
"strictBindCallApply": false,
|
||||
"forceConsistentCasingInFileNames": false,
|
||||
"noFallthroughCasesInSwitch": false
|
||||
},
|
||||
"exclude": ["node_modules"]
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user