code-style: prettier files

This commit is contained in:
Chika 2022-05-08 20:55:05 +03:00
parent 840eea78fd
commit c476f42e45
24 changed files with 83 additions and 131 deletions

View File

@ -1,5 +1,4 @@
import { Values, ValuesTypes } from 'stores/calculation/values/types'; import { Values, ValuesTypes } from 'stores/calculation/values/types';
import { Elements } from '../types/elements';
function wrapElementsMap<T extends Record<string, Values>>(arg: T) { function wrapElementsMap<T extends Record<string, Values>>(arg: T) {
return arg; return arg;
@ -160,3 +159,5 @@ export type ElementsTypes = {
export function getValueName(elementName: Elements) { export function getValueName(elementName: Elements) {
return elementsToValues[elementName]; return elementsToValues[elementName];
} }
export type Elements = keyof ElementsValues;

View File

@ -1,3 +0,0 @@
import { ElementsValues } from '../config/map';
export type Elements = keyof ElementsValues;

View File

@ -25,11 +25,7 @@ const LogoText = styled.h3`
function Logo() { function Logo() {
return ( return (
<Flex <Flex flexDirection="column" alignItems="flex-start" justifyContent="space-between">
flexDirection="column"
alignItems="flex-start"
justifyContent="space-between"
>
<ImageWrapper> <ImageWrapper>
<Image alt="logo" src={logo} layout="responsive" objectFit="contain" /> <Image alt="logo" src={logo} layout="responsive" objectFit="contain" />
</ImageWrapper> </ImageWrapper>

View File

@ -6,7 +6,7 @@ export default Spin;
const loadingOutlined = ( const loadingOutlined = (
<LoadingOutlined <LoadingOutlined
style={{ style={{
fontSize: 24 fontSize: 24,
}} }}
spin spin
/> />

View File

@ -16,5 +16,5 @@ export function max(breakpoint: keyof typeof screens) {
} }
export const mediaQuery = { export const mediaQuery = {
breakpoints: Object.values(screens).map(value => value + threshold + 'px'), breakpoints: Object.values(screens).map((value) => `${value + threshold}px`),
}; };

View File

@ -1,5 +1,7 @@
import { mediaQuery } from './mq'; import { mediaQuery } from './mq';
const theme = { ...mediaQuery }; const theme = {
...mediaQuery,
};
export default theme; export default theme;

View File

@ -1,12 +1,5 @@
import { Result } from 'antd'; import { Result } from 'antd';
export default function NotFound(props) { export default function NotFound(props) {
return ( return <Result status="500" title="" subTitle="Ой! Что-то сломалось." {...props} />;
<Result
status="500"
title=""
subTitle="Ой! Что-то сломалось."
{...props}
/>
);
} }

View File

@ -5,7 +5,7 @@ import { useApollo } from 'apollo/hooks';
import Layout from 'Components/Layout'; import Layout from 'Components/Layout';
import type { AppProps } from 'next/app'; import type { AppProps } from 'next/app';
import Head from 'next/head'; import Head from 'next/head';
import { StoreProvider } from 'stores/Provider'; import StoreProvider from 'stores/Provider';
import { ThemeProvider } from 'styled-components'; import { ThemeProvider } from 'styled-components';
import { GlobalStyle } from 'UIKit/colors'; import { GlobalStyle } from 'UIKit/colors';
import theme from 'UIKit/theme'; import theme from 'UIKit/theme';

View File

@ -32,16 +32,8 @@ export default class MyDocument extends Document {
<Head> <Head>
<meta charSet="utf-8" /> <meta charSet="utf-8" />
<link rel="preconnect" href="https://fonts.googleapis.com" /> <link rel="preconnect" href="https://fonts.googleapis.com" />
<link <link rel="preconnect" href="https://fonts.gstatic.com" crossOrigin="true" />
rel="preconnect" <link rel="preconnect" href="https://cdnjs.cloudflare.com" crossOrigin="true" />
href="https://fonts.gstatic.com"
crossOrigin="true"
/>
<link
rel="preconnect"
href="https://cdnjs.cloudflare.com"
crossOrigin="true"
/>
<link <link
href="https://fonts.googleapis.com/css2?family=Montserrat:wght@300;400;500;600;700&display=swap" href="https://fonts.googleapis.com/css2?family=Montserrat:wght@300;400;500;600;700&display=swap"
rel="stylesheet" rel="stylesheet"
@ -54,21 +46,13 @@ export default class MyDocument extends Document {
<link <link
rel="icon" rel="icon"
href={ href={process.env.NODE_ENV === 'production' ? 'favicon.prod.ico' : 'favicon.ico'}
process.env.NODE_ENV === 'production'
? 'favicon.prod.ico'
: 'favicon.ico'
}
crossOrigin="use-credentials" crossOrigin="use-credentials"
/> />
<meta name="theme-color" content="#000000" /> <meta name="theme-color" content="#000000" />
<meta name="description" content="Лизинговый калькулятор Эволюция" /> <meta name="description" content="Лизинговый калькулятор Эволюция" />
<link <link rel="apple-touch-icon" href="logo-100.png" crossOrigin="use-credentials" />
rel="apple-touch-icon"
href="logo-100.png"
crossOrigin="use-credentials"
/>
</Head> </Head>
<body> <body>
<Main /> <Main />

View File

@ -9,9 +9,7 @@ function Home() {
return <div>Home</div>; return <div>Home</div>;
} }
export const getServerSideProps: GetServerSideProps<PageProps> = async ( export const getServerSideProps: GetServerSideProps<PageProps> = async (ctx) => {
ctx
) => {
const user = await fetchUser({ const user = await fetchUser({
headers: ctx?.req?.headers?.cookie headers: ctx?.req?.headers?.cookie
? { ? {

View File

@ -10,7 +10,7 @@ function love(user: User) {
export async function fetchUser(config: AxiosRequestConfig) { export async function fetchUser(config: AxiosRequestConfig) {
const user = await axios const user = await axios
.get<User>(process.env.URL_GET_USER || '', config) .get<User>(process.env.URL_GET_USER || '', config)
.then(res => love(res.data)); .then((res) => love(res.data));
return user; return user;
} }

View File

@ -1,8 +1,7 @@
/* eslint-disable react/prop-types */
import { initializeStore, StoreContext } from '.'; import { initializeStore, StoreContext } from '.';
export function StoreProvider({ children, ...initialData }) { export default function StoreProvider({ children, ...initialData }) {
const store = initializeStore(initialData); const store = initializeStore(initialData);
return ( return <StoreContext.Provider value={store}>{children}</StoreContext.Provider>;
<StoreContext.Provider value={store}>{children}</StoreContext.Provider>
);
} }

View File

@ -1,9 +1,10 @@
import { RootStore } from 'stores/root'; /* eslint-disable import/no-cycle */
import { OptionsStore } from './options'; import RootStore from 'stores/root';
import { StatusStore } from './statuses'; import OptionsStore from './options';
import { ValuesStore } from './values'; import StatusStore from './statuses';
import ValuesStore from './values';
export class CalculationStore { export default class CalculationStore {
$values: ValuesStore; $values: ValuesStore;
$status: StatusStore; $status: StatusStore;
$options: OptionsStore; $options: OptionsStore;

View File

@ -1,15 +1,17 @@
import type { Elements } from 'Components/Calculation/types/elements'; /* eslint-disable function-paren-newline */
/* eslint-disable implicit-arrow-linebreak */
/* eslint-disable no-confusing-arrow */
/* eslint-disable object-curly-newline */
/* eslint-disable import/no-cycle */
import type { Elements } from 'Components/Calculation/config/map';
import { mergeWith } from 'lodash'; import { mergeWith } from 'lodash';
import { makeAutoObservable } from 'mobx'; import { makeAutoObservable } from 'mobx';
import { RootStore } from 'stores/root'; import RootStore from 'stores/root';
import { CalculationOptions, Filter, Options, OptionsFilters } from './types'; import { CalculationOptions, Filter, Options, OptionsFilters } from './types';
const _EXCLUDE_RESET_ELEMENTS: Elements[] = [ const EXCLUDE_RESET_ELEMENTS: Elements[] = ['selectTechnicalCard', 'selectTownRegistration'];
'selectTechnicalCard',
'selectTownRegistration',
];
const _AUTO_SET_VALUE_ELEMENTS: Elements[] = [ const AUTO_SET_VALUE_ELEMENTS: Elements[] = [
'selectProduct', 'selectProduct',
'selectLeaseObjectType', 'selectLeaseObjectType',
'selectBrand', 'selectBrand',
@ -23,7 +25,7 @@ const _AUTO_SET_VALUE_ELEMENTS: Elements[] = [
'selectTownRegistration', 'selectTownRegistration',
]; ];
export class OptionsStore { export default class OptionsStore {
root: RootStore; root: RootStore;
#options: Partial<CalculationOptions> = {}; #options: Partial<CalculationOptions> = {};
#filters: Partial<OptionsFilters> = {}; #filters: Partial<OptionsFilters> = {};
@ -41,17 +43,21 @@ export class OptionsStore {
getOption(elementName: Elements) { getOption(elementName: Elements) {
const value = this.root.$calculation.$values.getValueByElement(elementName); const value = this.root.$calculation.$values.getValueByElement(elementName);
return this.#options[elementName]?.find(x => x.value === value); return this.#options[elementName]?.find((x) => x.value === value);
} }
getOptions(elementName: Elements, settings?: { filtered: true }) { getOptions(
elementName: Elements,
settings?: {
filtered: true;
}
) {
const options = this.#options[elementName]; const options = this.#options[elementName];
if (!options) return;
if (!settings?.filtered) return options; if (!settings?.filtered) return options;
const filter = this.#filters[elementName]; const filter = this.#filters[elementName];
return filter ? filter(options) : options; return filter ? options && filter(options) : options;
} }
setOptions(elementName: Elements, options: Options) { setOptions(elementName: Elements, options: Options) {
@ -59,9 +65,9 @@ export class OptionsStore {
} }
mergeOptions(options: Partial<CalculationOptions>) { mergeOptions(options: Partial<CalculationOptions>) {
mergeWith(this.#options, options, function (objValue, srcValue) { mergeWith(this.#options, options, (objValue, srcValue) =>
return objValue === undefined ? srcValue : objValue; objValue === undefined ? srcValue : objValue
}); );
} }
clearOptions(elementName: Elements) { clearOptions(elementName: Elements) {
@ -84,34 +90,25 @@ export class OptionsStore {
/** /**
* Проверяем, что значение есть в отфильтрованном списке, * Проверяем, что значение есть в отфильтрованном списке,
* иначе сбрасываем значение * иначе сбрасываем значение
* (кроме исключений {@link _EXCLUDE_RESET_ELEMENTS}) * (кроме исключений {@link EXCLUDE_RESET_ELEMENTS})
*/ */
const filteredOptons = this.getOptions(elementName); const filteredOptons = this.getOptions(elementName);
if (!_EXCLUDE_RESET_ELEMENTS.includes(elementName)) { if (!EXCLUDE_RESET_ELEMENTS.includes(elementName)) {
const elementValue = const elementValue = this.root.$calculation.$values.getValueByElement(elementName);
this.root.$calculation.$values.getValueByElement(elementName);
if ( if (!filteredOptons?.length || !filteredOptons.some((x) => x.value === elementValue)) {
!filteredOptons?.length ||
!filteredOptons.some(x => x.value === elementValue)
)
this.root.$calculation.$values.clearValueOfElement(elementName); this.root.$calculation.$values.clearValueOfElement(elementName);
}
return; return;
} }
/** /**
* Если после фильтрации остается одна запись, то указываем ее * Если после фильтрации остается одна запись, то указываем ее
* (для элементов из списка {@link _AUTO_SET_VALUE_ELEMENTS}) * (для элементов из списка {@link AUTO_SET_VALUE_ELEMENTS})
*/ */
if ( if (filteredOptons?.length === 1 && AUTO_SET_VALUE_ELEMENTS.includes(elementName)) {
filteredOptons?.length === 1 && this.root.$calculation.$values.setValueOfElement(elementName, filteredOptons[0].value);
_AUTO_SET_VALUE_ELEMENTS.includes(elementName)
) {
this.root.$calculation.$values.setValueOfElement(
elementName,
filteredOptons[0].value,
);
} }
} }

View File

@ -1,4 +1,4 @@
import type { Elements } from 'Components/Calculation/types/elements'; import type { Elements } from 'Components/Calculation/config/map';
export type BaseOption = { export type BaseOption = {
name: string; name: string;

View File

@ -1,9 +1,11 @@
/* eslint-disable object-curly-newline */
/* eslint-disable import/no-cycle */
import type { Elements } from 'Components/Calculation/types/elements'; import type { Elements } from 'Components/Calculation/types/elements';
import { makeAutoObservable } from 'mobx'; import { makeAutoObservable } from 'mobx';
import { RootStore } from 'stores/root'; import RootStore from 'stores/root';
import type { CalculationStatuses, Status } from './types'; import type { CalculationStatuses, Status } from './types';
export class StatusStore { export default class StatusStore {
root: RootStore; root: RootStore;
#statuses: CalculationStatuses = {}; #statuses: CalculationStatuses = {};

View File

@ -1,4 +1,4 @@
import type { Elements } from 'Components/Calculation/types/elements'; import type { Elements } from 'Components/Calculation/config/map';
export type Status = 'Default' | 'Disabled' | 'Loading' | 'Hidden'; export type Status = 'Default' | 'Disabled' | 'Loading' | 'Hidden';

View File

@ -1,11 +1,12 @@
import type { ElementsTypes } from 'Components/Calculation/config/map'; /* eslint-disable object-curly-newline */
/* eslint-disable import/no-cycle */
import type { Elements, ElementsTypes } from 'Components/Calculation/config/map';
import { getValueName } from 'Components/Calculation/config/map'; import { getValueName } from 'Components/Calculation/config/map';
import type { Elements } from 'Components/Calculation/types/elements';
import { makeAutoObservable } from 'mobx'; import { makeAutoObservable } from 'mobx';
import { RootStore } from '../../root'; import RootStore from '../../root';
import type { CalculationValues, Values, ValuesTypes } from './types'; import type { CalculationValues, Values, ValuesTypes } from './types';
export class ValuesStore { export default class ValuesStore {
root: RootStore; root: RootStore;
#values: CalculationValues = {}; #values: CalculationValues = {};
@ -29,6 +30,7 @@ export class ValuesStore {
getValues<V extends Values>(valuesNames: readonly V[]) { getValues<V extends Values>(valuesNames: readonly V[]) {
return valuesNames.reduce((values, valueName) => { return valuesNames.reduce((values, valueName) => {
// eslint-disable-next-line no-param-reassign
values[valueName] = this.getValue(valueName); values[valueName] = this.getValue(valueName);
return values; return values;
}, {} as Pick<CalculationValues, typeof valuesNames[number]>); }, {} as Pick<CalculationValues, typeof valuesNames[number]>);
@ -38,10 +40,7 @@ export class ValuesStore {
this.#values[valueName] = value; this.#values[valueName] = value;
} }
setValueOfElement<E extends Elements>( setValueOfElement<E extends Elements>(elementName: E, value: ElementsTypes[E]) {
elementName: E,
value: ElementsTypes[E],
) {
const valueName = getValueName(elementName); const valueName = getValueName(elementName);
this.setValue(valueName, value); this.setValue(valueName, value);
} }

View File

@ -18,12 +18,7 @@ interface Types {
lastPaymentRule: 100_000_000 | 100_000_001 | 100_000_002; lastPaymentRule: 100_000_000 | 100_000_001 | 100_000_002;
redemptionPaymentSum: number; redemptionPaymentSum: number;
balanceHolder: 100_000_000 | 100_000_001; balanceHolder: 100_000_000 | 100_000_001;
graphType: graphType: 100_000_000 | 100_000_001 | 100_000_002 | 100_000_003 | 100_000_004;
| 100_000_000
| 100_000_001
| 100_000_002
| 100_000_003
| 100_000_004;
parmentsDecreasePercent: number; parmentsDecreasePercent: number;
seasonType: seasonType:
@ -79,18 +74,8 @@ interface Types {
model: string; model: string;
configuration: string; configuration: string;
leaseObjectYear: number; leaseObjectYear: number;
engineType: engineType: 100_000_000 | 100_000_001 | 100_000_002 | 100_000_003 | 100_000_004;
| 100_000_000 leaseObjectCategory: 100_000_000 | 100_000_001 | 100_000_002 | 100_000_003 | 100_000_004;
| 100_000_001
| 100_000_002
| 100_000_003
| 100_000_004;
leaseObjectCategory:
| 100_000_000
| 100_000_001
| 100_000_002
| 100_000_003
| 100_000_004;
leaseObjectMotorPower: number; leaseObjectMotorPower: number;
engineVolume: number; engineVolume: number;
leaseObjectUseFor: leaseObjectUseFor:
@ -208,13 +193,7 @@ interface Types {
| 100_000_018 | 100_000_018
| 100_000_019 | 100_000_019
| 100_000_020; | 100_000_020;
objectTypeTax: objectTypeTax: 100_000_000 | 100_000_001 | 100_000_002 | 100_000_003 | 100_000_004 | 100_000_005;
| 100_000_000
| 100_000_001
| 100_000_002
| 100_000_003
| 100_000_004
| 100_000_005;
typePTS: 100_000_000 | 100_000_001; typePTS: 100_000_000 | 100_000_001;
legalClientRegion: string; legalClientRegion: string;
legalClientTown: string; legalClientTown: string;

View File

@ -1,3 +1,4 @@
/* eslint-disable import/prefer-default-export */
import { useContext } from 'react'; import { useContext } from 'react';
import { StoreContext } from '.'; import { StoreContext } from '.';

View File

@ -1,5 +1,5 @@
import { createContext } from 'react'; import { createContext } from 'react';
import { RootStore } from './root'; import RootStore from './root';
/** @type{RootStore} */ /** @type{RootStore} */
let store; let store;

View File

@ -1,10 +1,11 @@
/* eslint-disable import/no-cycle */
import { enableStaticRendering } from 'mobx-react-lite'; import { enableStaticRendering } from 'mobx-react-lite';
import { CalculationStore } from './calculation'; import CalculationStore from './calculation';
import { UserStore } from './user'; import UserStore from './user';
enableStaticRendering(typeof window === 'undefined'); enableStaticRendering(typeof window === 'undefined');
export class RootStore { export default class RootStore {
$user: UserStore; $user: UserStore;
$calculation: CalculationStore; $calculation: CalculationStore;

View File

@ -1,8 +1,9 @@
/* eslint-disable import/no-cycle */
import { makeAutoObservable } from 'mobx'; import { makeAutoObservable } from 'mobx';
import type { User } from 'services/user/types'; import type { User } from 'services/user/types';
import { RootStore } from './root'; import RootStore from './root';
export class UserStore { export default class UserStore {
root: RootStore; root: RootStore;
user?: User = undefined; user?: User = undefined;
@ -19,5 +20,6 @@ export class UserStore {
const { username, domain } = this.user; const { username, domain } = this.user;
return `${domain}\\${username}`; return `${domain}\\${username}`;
} }
return '';
} }
} }

View File

@ -3,8 +3,8 @@ body {
background-color: var(--color-background); background-color: var(--color-background);
padding: 0; padding: 0;
margin: 0; margin: 0;
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen, font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen, Ubuntu, Cantarell,
Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif; Fira Sans, Droid Sans, Helvetica Neue, sans-serif;
} }
a { a {