110 lines
2.4 KiB
JavaScript
110 lines
2.4 KiB
JavaScript
import { gql, useApolloClient } from '@apollo/client';
|
|
import initializeApollo from 'apollo/client';
|
|
import * as Calculation from 'Components/Calculation';
|
|
import Output from 'Components/Output';
|
|
import Head from 'next/head';
|
|
import leadOpportunityUrlsReactions from 'process/lead-opportunity/reactions/urls';
|
|
import { fetchUser } from 'services/user';
|
|
import { getDomainName } from 'services/user/tools';
|
|
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('desktop')} {
|
|
grid-template-columns: 2fr 1fr 1.5fr;
|
|
margin: 8px 5%;
|
|
}
|
|
|
|
${min('desktop-xl')} {
|
|
margin: 8px 10%;
|
|
}
|
|
`;
|
|
|
|
function Home({ graphQLData }) {
|
|
const store = useStore();
|
|
const apolloClient = useApolloClient();
|
|
|
|
/**
|
|
* add reactions to store
|
|
*/
|
|
leadOpportunityUrlsReactions(store, apolloClient);
|
|
|
|
/**
|
|
* set owner data to store
|
|
*/
|
|
const { ownerData } = graphQLData;
|
|
|
|
const { $calculation } = store;
|
|
|
|
$calculation.$options.setOptions({
|
|
selectLead: ownerData?.leads || [],
|
|
selectOpportunity: ownerData.opportunities || [],
|
|
});
|
|
|
|
return (
|
|
<Grid>
|
|
<Head>
|
|
<title>Лизинговый калькулятор - Эволюция</title>
|
|
</Head>
|
|
<Calculation.Form />
|
|
<Calculation.Settings />
|
|
<Output />
|
|
</Grid>
|
|
);
|
|
}
|
|
|
|
const QUERY_GET_OWNER_DATA = gql`
|
|
query GetOwnerData($domainname: String) {
|
|
leads(owner_domainname: $domainname) {
|
|
label: fullname
|
|
value: leadid
|
|
}
|
|
opportunities(owner_domainname: $domainname) {
|
|
label: name
|
|
value: opportunityid
|
|
}
|
|
}
|
|
`;
|
|
|
|
export const getServerSideProps = async (ctx) => {
|
|
const user = await fetchUser({
|
|
headers: ctx?.req?.headers?.cookie
|
|
? {
|
|
cookie: ctx.req.headers.cookie,
|
|
}
|
|
: undefined,
|
|
});
|
|
|
|
const apolloClient = initializeApollo();
|
|
|
|
const { data: ownerData } = await apolloClient.query({
|
|
query: QUERY_GET_OWNER_DATA,
|
|
variables: {
|
|
domainname: getDomainName(user),
|
|
},
|
|
});
|
|
|
|
return {
|
|
props: {
|
|
graphQLData: {
|
|
ownerData,
|
|
},
|
|
initialApolloState: apolloClient.cache.extract(),
|
|
},
|
|
};
|
|
};
|
|
|
|
export default Home;
|