diff --git a/pages/__generated__/GetOwnerData.ts b/pages/__generated__/GetOwnerData.ts index fb93e8a..9651514 100644 --- a/pages/__generated__/GetOwnerData.ts +++ b/pages/__generated__/GetOwnerData.ts @@ -8,15 +8,15 @@ // ==================================================== export interface GetOwnerData_leads { - __typename: 'lead'; - fullname: string | null; - leadid: any | null; + __typename: "lead"; + label: string | null; + value: any | null; } export interface GetOwnerData_opportunities { - __typename: 'opportunity'; - name: string | null; - opportunityid: any | null; + __typename: "opportunity"; + label: string | null; + value: any | null; } export interface GetOwnerData { diff --git a/pages/index.tsx b/pages/index.jsx similarity index 69% rename from pages/index.tsx rename to pages/index.jsx index b386842..a6b7f29 100644 --- a/pages/index.tsx +++ b/pages/index.jsx @@ -2,18 +2,14 @@ import { gql, useApolloClient } from '@apollo/client'; import initializeApollo from 'apollo/client'; import * as Calculation from 'Components/Calculation'; import Output from 'Components/Output'; -import type { GetServerSideProps } from 'next'; 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 { convertEntitiesToOptions } from 'tools/entity'; -import type { BasePageProps } from 'types/page'; import { Box } from 'UIKit/grid'; import { min } from 'UIKit/mq'; -import type { GetOwnerData, GetOwnerDataVariables } from './__generated__/GetOwnerData'; const Grid = styled(Box)` display: flex; @@ -36,9 +32,7 @@ const Grid = styled(Box)` } `; -type PageProps = BasePageProps & { graphQLData: GraphQLData }; - -function Home({ graphQLData }: PageProps) { +function Home({ graphQLData }) { const store = useStore(); const apolloClient = useApolloClient(); @@ -51,16 +45,12 @@ function Home({ graphQLData }: PageProps) { * set owner data to store */ const { ownerData } = graphQLData; - const leads = ownerData.leads ? convertEntitiesToOptions(ownerData.leads) : []; - const opportunities = ownerData.opportunities - ? convertEntitiesToOptions(ownerData.opportunities) - : []; const { $calculation } = store; $calculation.$options.setOptions({ - selectLead: leads, - selectOpportunity: opportunities, + selectLead: ownerData?.leads || [], + selectOpportunity: ownerData.opportunities || [], }); return ( @@ -75,24 +65,20 @@ function Home({ graphQLData }: PageProps) { ); } -type GraphQLData = { - ownerData: GetOwnerData; -}; - const QUERY_GET_OWNER_DATA = gql` query GetOwnerData($domainname: String) { leads(owner_domainname: $domainname) { - fullname - leadid + label: fullname + value: leadid } opportunities(owner_domainname: $domainname) { - name - opportunityid + label: name + value: opportunityid } } `; -export const getServerSideProps: GetServerSideProps = async (ctx) => { +export const getServerSideProps = async (ctx) => { const user = await fetchUser({ headers: ctx?.req?.headers?.cookie ? { @@ -103,7 +89,7 @@ export const getServerSideProps: GetServerSideProps = async (ctx) => const apolloClient = initializeApollo(); - const { data: ownerData } = await apolloClient.query({ + const { data: ownerData } = await apolloClient.query({ query: QUERY_GET_OWNER_DATA, variables: { domainname: getDomainName(user), @@ -112,7 +98,6 @@ export const getServerSideProps: GetServerSideProps = async (ctx) => return { props: { - user, graphQLData: { ownerData, }, diff --git a/tools/entity.ts b/tools/entity.ts deleted file mode 100644 index ff9a739..0000000 --- a/tools/entity.ts +++ /dev/null @@ -1,31 +0,0 @@ -/* eslint-disable import/prefer-default-export */ - -import type { BaseOption } from 'Elements/types'; - -const propsMap = { - lead: { - name: 'fullname', - value: 'leadid', - }, - opportunity: { - name: 'name', - value: 'opportunityid', - }, -}; - -type PropsMap = typeof propsMap; - -function getEntityName(entities: any[]): keyof PropsMap { - // eslint-disable-next-line no-underscore-dangle - return entities.at(0)?.__typename; -} - -export function convertEntitiesToOptions(entities: any[]): BaseOption[] { - const entityName = getEntityName(entities); - const map = propsMap[entityName]; - - return entities.map((entity) => ({ - label: entity[map.name], - value: entity[map.value], - })); -} diff --git a/types/page.ts b/types/page.ts deleted file mode 100644 index 707f2eb..0000000 --- a/types/page.ts +++ /dev/null @@ -1,19 +0,0 @@ -import type { NormalizedCacheObject } from '@apollo/client'; -import type { User } from 'services/user/types'; -import type { CalculationOptions } from 'stores/calculation/options/types'; -import type { CalculationStatuses } from 'stores/calculation/statuses/types'; -import type { CalculationValues } from 'stores/calculation/values/types'; -import type { InsuranceTableData } from 'stores/tables/insurance'; - -export interface BasePageProps { - user: User; - initialApolloState: NormalizedCacheObject; - calculation?: { - values: CalculationValues; - statuses: CalculationStatuses; - options: CalculationOptions; - }; - tables?: { - insurance: InsuranceTableData; - }; -}