vchikalkin 29fdb70509 add Errors tab
move calculation content to file
2024-07-02 17:38:19 +03:00

65 lines
1.6 KiB
JavaScript

import initializeApollo from '@/apollo/client';
import { Content } from '@/Components/Calculation';
import { Error } from '@/Components/Common/Error';
import * as hooks from '@/process/hooks';
import { makeGetUserType } from '@/utils/user';
import { dehydrate, QueryClient } from '@tanstack/react-query';
export default function Page(props) {
if (props.statusCode !== 200) return <Error {...props} />;
return (
<Content
title="Без ограничений"
initHooks={() => {
hooks.useSentryScope();
hooks.useMainData();
hooks.useGetUsers();
hooks.useInsuranceData();
hooks.useReactions();
}}
/>
);
}
/** @type {import('next').GetServerSideProps} */
export async function getServerSideProps({ req }) {
const { cookie = '' } = req.headers;
const queryClient = new QueryClient();
const apolloClient = initializeApollo(null, req.headers);
const getUserType = makeGetUserType({ apolloClient, queryClient });
try {
const user = await getUserType({ cookie });
if (!user.unlimited) {
return {
props: {
initialQueryState: dehydrate(queryClient),
statusCode: 403,
},
};
}
return {
props: {
calculation: {},
initialApolloState: apolloClient.cache.extract(),
initialQueryState: dehydrate(queryClient),
mode: 'unlimited',
statusCode: 200,
user,
},
};
} catch (error) {
return {
props: {
error: JSON.stringify(error),
initialQueryState: dehydrate(queryClient),
statusCode: 500,
},
};
}
}