2022-07-12 11:03:01 +03:00

101 lines
2.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/* 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 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.urls(store, apolloClient);
paymentsReactions(store, apolloClient);
calculateReactions.validation(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;