Chika 222b0b0e74 pages: add CRM graphql connection error
pages: use fetch data hooks (fetch all gql data on client)
mocks: use process.env variables
2022-11-07 17:43:14 +03:00

82 lines
1.9 KiB
JavaScript

import { dehydrate, QueryClient } from '@tanstack/react-query';
import { getUser } from 'api/user/query';
import initializeApollo from 'apollo/client';
import * as Calculation from 'Components/Calculation';
import { CRMError } from 'Components/Common/Error';
import Output from 'Components/Output';
import Head from 'next/head';
import { useCRMData, useOwnerData } from 'process/init/get-data/hooks';
import { useReactions } from 'process/init/inject-reactions/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({ user }) {
const { error } = useOwnerData(user);
useReactions();
useCRMData(user);
if (error) return <CRMError />;
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;
// prettier-ignore
const queryGetUser = () => getUser({
headers: {
cookie,
},
});
const queryClient = new QueryClient();
const user = await queryClient.fetchQuery(['user'], queryGetUser);
const apolloClient = initializeApollo();
return {
props: {
user,
calculation: null,
initialApolloState: apolloClient.cache.extract(),
initialQueryState: dehydrate(queryClient),
},
};
};
export default Home;