104 lines
2.6 KiB
TypeScript
104 lines
2.6 KiB
TypeScript
/* eslint-disable object-curly-newline */
|
||
import { useApolloClient } from '@apollo/client';
|
||
import initializeApollo from 'apollo/client';
|
||
import * as Calculation from 'Components/Calculation';
|
||
import Output from 'Components/Output';
|
||
import defaultOptions from 'config/default-options';
|
||
import * as InsuranceTableConfig from 'config/tables/insurance-table';
|
||
import { merge } from 'lodash-es';
|
||
import type { GetServerSideProps } from 'next';
|
||
import Head from 'next/head';
|
||
import * as agentsReactions from 'process/agents/reactions';
|
||
import * as calculateReactions from 'process/calculate/reactions';
|
||
import { getCRMData } from 'process/init/get-data';
|
||
import * as leadOpportunityReactions from 'process/lead-opportunity/reactions';
|
||
import paymentsReactions from 'process/payments/reactions';
|
||
import { fetchUser } from 'services/user';
|
||
import { useStore } from 'stores/hooks';
|
||
import styled from 'styled-components';
|
||
import { Box } from 'UIKit/grid';
|
||
import { min } from 'UIKit/mq';
|
||
|
||
const Grid = styled(Box)`
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 10px;
|
||
|
||
${min('laptop')} {
|
||
display: grid;
|
||
align-items: flex-start;
|
||
grid-template-columns: 2fr 1fr;
|
||
}
|
||
|
||
${min('laptop-hd')} {
|
||
grid-template-columns: 2fr 1fr 1.5fr;
|
||
}
|
||
|
||
${min('desktop')} {
|
||
margin: 8px 5%;
|
||
}
|
||
|
||
${min('desktop-xl')} {
|
||
margin: 8px 10%;
|
||
}
|
||
`;
|
||
|
||
function Home() {
|
||
const store = useStore();
|
||
const apolloClient = useApolloClient();
|
||
|
||
/**
|
||
* add reactions to store
|
||
*/
|
||
|
||
setTimeout(() => {
|
||
leadOpportunityReactions.common(store, apolloClient);
|
||
leadOpportunityReactions.urls(store, apolloClient);
|
||
paymentsReactions(store, apolloClient);
|
||
calculateReactions.validation(store, apolloClient);
|
||
agentsReactions.common(store, apolloClient);
|
||
});
|
||
|
||
return (
|
||
<Grid>
|
||
<Head>
|
||
<title>Лизинговый калькулятор - Эволюция</title>
|
||
</Head>
|
||
<Calculation.Form />
|
||
<Calculation.Settings />
|
||
<Output />
|
||
</Grid>
|
||
);
|
||
}
|
||
|
||
export const getServerSideProps: GetServerSideProps = async ({ req }) => {
|
||
const { cookie = '' } = req.headers;
|
||
|
||
const user = await fetchUser({
|
||
headers: {
|
||
cookie,
|
||
},
|
||
});
|
||
|
||
const apolloClient = initializeApollo();
|
||
const { options, tables } = await getCRMData(apolloClient, user);
|
||
|
||
return {
|
||
props: {
|
||
user,
|
||
calculation: {
|
||
options: merge(defaultOptions, options),
|
||
},
|
||
tables: {
|
||
insurance: {
|
||
options: merge(InsuranceTableConfig.defaultOptions, tables.insurance),
|
||
},
|
||
},
|
||
|
||
initialApolloState: apolloClient.cache.extract(),
|
||
},
|
||
};
|
||
};
|
||
|
||
export default Home;
|