113 lines
2.5 KiB
JavaScript
113 lines
2.5 KiB
JavaScript
import { getUser } from '@/api/user/query';
|
|
import initializeApollo from '@/apollo/client';
|
|
import * as Calculation from '@/Components/Calculation';
|
|
import { Error } from '@/Components/Common/Error';
|
|
import Output from '@/Components/Output';
|
|
import { useReactions } from '@/process/hooks';
|
|
import * as CRMTypes from '@/graphql/crm.types';
|
|
import * as init from '@/process/init';
|
|
import { min } from '@/styles/mq';
|
|
import { dehydrate, QueryClient } from '@tanstack/react-query';
|
|
import Head from 'next/head';
|
|
import styled from 'styled-components';
|
|
import { Box } from 'ui/grid';
|
|
|
|
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(props) {
|
|
init.useMainData();
|
|
init.useInsuranceData();
|
|
useReactions();
|
|
|
|
if (props.statusCode !== 200) return <Error {...props} />;
|
|
|
|
return (
|
|
<Grid>
|
|
<Head>
|
|
<title>Лизинговый калькулятор - Эволюция</title>
|
|
</Head>
|
|
<Calculation.Form />
|
|
<Calculation.Settings />
|
|
<Output />
|
|
</Grid>
|
|
);
|
|
}
|
|
/** @type {import('next').GetServerSideProps} */
|
|
export const getServerSideProps = async ({ req }) => {
|
|
const { cookie = '' } = req.headers;
|
|
|
|
const queryClient = new QueryClient();
|
|
|
|
const user = await queryClient.fetchQuery(['user'], ({ signal }) =>
|
|
getUser({
|
|
headers: {
|
|
cookie,
|
|
},
|
|
signal,
|
|
})
|
|
);
|
|
|
|
const apolloClient = initializeApollo();
|
|
|
|
try {
|
|
const {
|
|
data: { systemuser },
|
|
} = await apolloClient.query({
|
|
query: CRMTypes.GetSystemUserDocument,
|
|
variables: {
|
|
domainname: user.domainName,
|
|
},
|
|
});
|
|
|
|
if (!systemuser.roles.some((x) => x.name === 'МПЛ')) {
|
|
return {
|
|
props: { statusCode: 403 },
|
|
};
|
|
}
|
|
const { values, options } = await init.getInitialData(apolloClient, user);
|
|
|
|
return {
|
|
props: {
|
|
calculation: {
|
|
options,
|
|
values,
|
|
},
|
|
initialApolloState: apolloClient.cache.extract(),
|
|
initialQueryState: dehydrate(queryClient),
|
|
statusCode: 200,
|
|
},
|
|
};
|
|
} catch (error) {
|
|
return {
|
|
props: {
|
|
error: JSON.stringify(error),
|
|
statusCode: 500,
|
|
},
|
|
};
|
|
}
|
|
};
|
|
|
|
export default Home;
|