pages/index: revert getOwnerData back to server
This commit is contained in:
parent
32fa871238
commit
f03ba9d979
@ -5,7 +5,7 @@ import * as Calculation from 'Components/Calculation';
|
||||
import { CRMError } from 'Components/Common/Error';
|
||||
import Output from 'Components/Output';
|
||||
import Head from 'next/head';
|
||||
import { useInsuranceData, useMainData, useOwnerData } from 'process/init/get-data';
|
||||
import { getOwnerData, useInsuranceData, useMainData } from 'process/init/get-data';
|
||||
import { useReactions } from 'process/init/inject-reactions/hooks';
|
||||
import styled from 'styled-components';
|
||||
import { Box } from 'UIKit/grid';
|
||||
@ -35,8 +35,7 @@ const Grid = styled(Box)`
|
||||
}
|
||||
`;
|
||||
|
||||
function Home({ user }) {
|
||||
const { error } = useOwnerData(user);
|
||||
function Home({ error }) {
|
||||
useMainData();
|
||||
useInsuranceData();
|
||||
useReactions();
|
||||
@ -68,15 +67,25 @@ export const getServerSideProps = async ({ req }) => {
|
||||
const user = await queryClient.fetchQuery(['user'], queryGetUser);
|
||||
|
||||
const apolloClient = initializeApollo();
|
||||
try {
|
||||
const { data } = await getOwnerData(apolloClient, user);
|
||||
|
||||
return {
|
||||
props: {
|
||||
user,
|
||||
calculation: null,
|
||||
initialApolloState: apolloClient.cache.extract(),
|
||||
initialQueryState: dehydrate(queryClient),
|
||||
},
|
||||
};
|
||||
return {
|
||||
props: {
|
||||
calculation: {
|
||||
options: data,
|
||||
},
|
||||
initialApolloState: apolloClient.cache.extract(),
|
||||
initialQueryState: dehydrate(queryClient),
|
||||
},
|
||||
};
|
||||
} catch (error) {
|
||||
return {
|
||||
props: {
|
||||
error: JSON.stringify(error),
|
||||
},
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
export default Home;
|
||||
|
||||
@ -1,10 +1,9 @@
|
||||
/* eslint-disable import/prefer-default-export */
|
||||
import { gql, useQuery } from '@apollo/client';
|
||||
import type { ApolloClient } from '@apollo/client';
|
||||
import { gql } from '@apollo/client';
|
||||
|
||||
import type { User } from 'api/user/types';
|
||||
import type { GetOwnerDataQuery, GetOwnerDataQueryVariables } from 'graphql/crm.types';
|
||||
import { useStore } from 'stores/hooks';
|
||||
import { normalizeOptions } from 'tools/entity';
|
||||
|
||||
const QUERY_GET_OWNER_DATA = gql`
|
||||
query GetOwnerData($domainname: String) {
|
||||
@ -19,38 +18,11 @@ const QUERY_GET_OWNER_DATA = gql`
|
||||
}
|
||||
`;
|
||||
|
||||
export function useOwnerData(user: User) {
|
||||
const { $calculation } = useStore();
|
||||
|
||||
function handleOnStartFetch() {
|
||||
$calculation.$status.setStatus('selectLead', 'Loading');
|
||||
$calculation.$status.setStatus('selectOpportunity', 'Loading');
|
||||
}
|
||||
|
||||
function handleOnCompleted(data: GetOwnerDataQuery) {
|
||||
$calculation.element('selectLead').setOptions(normalizeOptions(data?.selectLead));
|
||||
$calculation.element('selectOpportunity').setOptions(normalizeOptions(data?.selectOpportunity));
|
||||
|
||||
$calculation.$status.setStatus('selectLead', 'Default');
|
||||
$calculation.$status.setStatus('selectOpportunity', 'Default');
|
||||
}
|
||||
|
||||
const { loading, error } = useQuery<GetOwnerDataQuery, GetOwnerDataQueryVariables>(
|
||||
QUERY_GET_OWNER_DATA,
|
||||
{
|
||||
variables: {
|
||||
domainname: user?.domainName,
|
||||
},
|
||||
|
||||
onCompleted: handleOnCompleted,
|
||||
}
|
||||
);
|
||||
|
||||
if (loading) {
|
||||
handleOnStartFetch();
|
||||
}
|
||||
|
||||
return {
|
||||
error,
|
||||
};
|
||||
export async function getOwnerData({ query }: ApolloClient<object>, user: User) {
|
||||
return query<GetOwnerDataQuery, GetOwnerDataQueryVariables>({
|
||||
query: QUERY_GET_OWNER_DATA,
|
||||
variables: {
|
||||
domainname: user?.domainName,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@ -1,3 +1,3 @@
|
||||
export { useInsuranceData } from './get-insurance-data';
|
||||
export { useMainData } from './get-main-data';
|
||||
export { useOwnerData } from './get-owner-data';
|
||||
export { getOwnerData } from './get-owner-data';
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user