merge changes from refactor/remove-node-server
This commit is contained in:
parent
c4b9e8820a
commit
b56ec8bfb3
@ -1,10 +1,10 @@
|
||||
import { LoadingStatus } from 'client/common/loadingStatus';
|
||||
import Result from 'client/Components/Result';
|
||||
import Spinner from 'client/Components/Spinner';
|
||||
import Modal from 'client/Elements/Modal';
|
||||
import withModal from 'client/hocs/Calculation/withModal';
|
||||
import { useFetch } from 'client/hooks/Calculation/useFetch';
|
||||
import { Flex } from 'client/UIKit/grid';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import React from 'react';
|
||||
import Info from './Info';
|
||||
import fetchData from './lib/fetchData';
|
||||
import Results from './Results';
|
||||
@ -12,22 +12,13 @@ import ResultsTable from './ResultsTable';
|
||||
import Sections from './Sections';
|
||||
|
||||
const Calculation = () => {
|
||||
const [status, setStatus] = useState(LoadingStatus.loading);
|
||||
useEffect(() => {
|
||||
fetchData()
|
||||
.then(() => {
|
||||
setStatus(LoadingStatus.ready);
|
||||
})
|
||||
.catch(() => {
|
||||
setStatus(LoadingStatus.error);
|
||||
});
|
||||
}, []);
|
||||
const { isLoading, error } = useFetch({ fetchData });
|
||||
|
||||
if (status === LoadingStatus.loading) {
|
||||
if (isLoading) {
|
||||
return <Spinner />;
|
||||
}
|
||||
|
||||
if (status === LoadingStatus.error) {
|
||||
if (error) {
|
||||
const ServerError = Result[500];
|
||||
return <ServerError />;
|
||||
}
|
||||
|
||||
@ -10,7 +10,7 @@ import {
|
||||
validateInn,
|
||||
validateKpp,
|
||||
validatePhone,
|
||||
} from 'client/tools/validate';
|
||||
} from 'core/tools/validate';
|
||||
|
||||
import { DownloadOutlined } from '@ant-design/icons';
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import CrmService from 'client/services/CrmService';
|
||||
import CrmService from 'core/services/CrmService';
|
||||
import CalculationStore from 'client/stores/CalculationStore';
|
||||
import { getUser } from 'client/tools/user';
|
||||
import { getUser } from 'core/tools/user';
|
||||
import insuranceQuery from './queries/insuranceQuery';
|
||||
import optionsQuery from './queries/optionsQuery';
|
||||
import initialOwnerQuery from './queries/ownerQuery';
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { currentDate } from 'client/tools/date';
|
||||
import { currentDate } from 'core/tools/date';
|
||||
import { IQueryToCRMGQL } from 'core/types/Calculation/Requests';
|
||||
import { gql } from '@apollo/client';
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { IQueryToCRMGQL } from 'core/types/Calculation/Requests';
|
||||
import { currentDate } from 'client/tools/date';
|
||||
import { currentDate } from 'core/tools/date';
|
||||
import { gql } from '@apollo/client';
|
||||
|
||||
const query = gql`
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
import paths from 'client/common/paths';
|
||||
import paths from 'core/common/paths';
|
||||
import Spinner from 'client/Components/Spinner';
|
||||
import React, { Suspense } from 'react';
|
||||
import { Route, Switch } from 'react-router-dom';
|
||||
import { container as resolveContainer } from 'client/tools/resolve';
|
||||
import { container as resolveContainer } from 'core/tools/resolve';
|
||||
|
||||
export default () => (
|
||||
<Suspense fallback={<Spinner />}>
|
||||
|
||||
@ -1,5 +0,0 @@
|
||||
export enum LoadingStatus {
|
||||
loading,
|
||||
ready,
|
||||
error,
|
||||
}
|
||||
22
src/client/hooks/Calculation/useFetch.js
Normal file
22
src/client/hooks/Calculation/useFetch.js
Normal file
@ -0,0 +1,22 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
|
||||
export const useFetch = ({ fetchData }) => {
|
||||
const [response, setResponse] = useState();
|
||||
const [error, setError] = useState();
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
setIsLoading(true);
|
||||
fetchData()
|
||||
.then(res => {
|
||||
setResponse(res);
|
||||
})
|
||||
.catch(err => {
|
||||
setError(err);
|
||||
})
|
||||
.finally(() => {
|
||||
setIsLoading(false);
|
||||
});
|
||||
}, []);
|
||||
return { response, isLoading, error };
|
||||
};
|
||||
@ -1,6 +1,7 @@
|
||||
import { calculationUrls } from 'client/stores/CalculationStore';
|
||||
import { useStores } from '../useStores';
|
||||
|
||||
export const useUrl = ({ urlName }) => {
|
||||
const { calculationUrls } = useStores();
|
||||
const url = calculationUrls.urls[urlName];
|
||||
return { url };
|
||||
};
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
/* eslint-disable react-hooks/exhaustive-deps */
|
||||
|
||||
import { ValidateStatus } from 'antd/lib/form/FormItem';
|
||||
import { INVALID_INPUT as INVALID_INPUT_MESSAGE } from 'client/constants/errorMessages';
|
||||
import { INVALID_INPUT as INVALID_INPUT_MESSAGE } from 'core/constants/errorMessages';
|
||||
import { ElementsNames } from 'core/types/Calculation/Store/elements';
|
||||
import {
|
||||
TableNames,
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/* eslint-disable react-hooks/exhaustive-deps */
|
||||
import { DEFAULT_DEBOUNCE_DELAY } from 'client/constants/debounce';
|
||||
import { DEFAULT_DEBOUNCE_DELAY } from 'core/constants/debounce';
|
||||
import { Process } from 'core/types/Calculation/Store/process';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useDebouncedCallback } from 'use-debounce';
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { message } from 'antd';
|
||||
import { openNotification } from 'client/Elements/Notification';
|
||||
import CalculationService from 'client/services/CalculationService';
|
||||
import CalculationService from 'core/services/CalculationService';
|
||||
import { resultsValues } from 'core/types/Calculation/Store/values';
|
||||
import { ElementStatus } from 'core/types/statuses';
|
||||
import CalculationStore from '../../..';
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
import { gql } from '@apollo/client';
|
||||
import { message } from 'antd';
|
||||
import { openNotification } from 'client/Elements/Notification';
|
||||
import CrmService from 'client/services/CrmService';
|
||||
import { getUser } from 'client/tools/user';
|
||||
import CrmService from 'core/services/CrmService';
|
||||
import { getUser } from 'core/tools/user';
|
||||
import { CRM_PROXY_URL } from 'core/constants/urls';
|
||||
import { toJS } from 'mobx';
|
||||
import CalculationStore, { calculationUrls } from '../..';
|
||||
|
||||
@ -3,10 +3,10 @@
|
||||
import { message } from 'antd';
|
||||
import { elementsValues } from 'client/Containers/Calculation/lib/elements/values';
|
||||
import { openNotification } from 'client/Elements/Notification';
|
||||
import CrmService from 'client/services/CrmService';
|
||||
import CrmService from 'core/services/CrmService';
|
||||
import { calculationProcess } from 'client/stores/CalculationStore';
|
||||
import initialValues from 'client/stores/CalculationStore/config/initialValues';
|
||||
import { currentDate } from 'client/tools/date';
|
||||
import { currentDate } from 'core/tools/date';
|
||||
import { IReactionEffect } from 'core/types/Calculation/Store/effect';
|
||||
import { Process } from 'core/types/Calculation/Store/process';
|
||||
import { ElementStatus } from 'core/types/statuses';
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { gql } from '@apollo/client';
|
||||
import CrmService from 'client/services/CrmService';
|
||||
import { currentDate } from 'client/tools/date';
|
||||
import CrmService from 'core/services/CrmService';
|
||||
import { currentDate } from 'core/tools/date';
|
||||
import { IReactionEffect } from 'core/types/Calculation/Store/effect';
|
||||
import { ElementStatus } from 'core/types/statuses';
|
||||
import { Process } from 'core/types/Calculation/Store/process';
|
||||
|
||||
@ -1,9 +1,13 @@
|
||||
import CalculationStore, { calculationProcess } from './CalculationStore';
|
||||
import CalculationStore, {
|
||||
calculationProcess,
|
||||
calculationUrls,
|
||||
} from './CalculationStore';
|
||||
|
||||
class RootStore {
|
||||
constructor() {
|
||||
this.calculationStore = CalculationStore;
|
||||
this.calculationProcess = calculationProcess;
|
||||
this.calculationUrls = calculationUrls;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -2,6 +2,6 @@ import { ApolloClient, InMemoryCache } from '@apollo/client';
|
||||
import { CRM_PROXY_URL } from 'core/constants/urls';
|
||||
|
||||
export default new ApolloClient({
|
||||
uri: String.prototype.concat('/proxy', CRM_PROXY_URL, '/'),
|
||||
uri: String.prototype.concat(CRM_PROXY_URL, '/'),
|
||||
cache: new InMemoryCache(),
|
||||
});
|
||||
Reference in New Issue
Block a user