From 1e1c69f72c77d7a0bfd6013defe19b0554b8de90 Mon Sep 17 00:00:00 2001 From: vchikalkin Date: Thu, 16 Feb 2023 13:16:48 +0300 Subject: [PATCH] stores/calcualtion/values: add defaultValues object --- apps/web/graphql/crm.query.graphql | 14 ++++++++ apps/web/graphql/crm.types.ts | 24 ++++++++----- apps/web/pages/index.jsx | 9 +++-- .../process/init/get-data/get-initial-data.ts | 36 +++++++++++++++++++ .../process/init/get-data/get-main-data.js | 11 ------ .../process/init/get-data/get-owner-data.ts | 26 -------------- apps/web/process/init/get-data/index.js | 2 +- .../process/init/inject-reactions/default.js | 2 -- apps/web/process/init/set-values/reactions.ts | 28 --------------- apps/web/process/load-kp/reactions.ts | 6 ++-- apps/web/stores/calculation/values/index.ts | 12 +++---- 11 files changed, 81 insertions(+), 89 deletions(-) create mode 100644 apps/web/process/init/get-data/get-initial-data.ts delete mode 100644 apps/web/process/init/get-data/get-owner-data.ts delete mode 100644 apps/web/process/init/set-values/reactions.ts diff --git a/apps/web/graphql/crm.query.graphql b/apps/web/graphql/crm.query.graphql index 98b3c72..89c4423 100644 --- a/apps/web/graphql/crm.query.graphql +++ b/apps/web/graphql/crm.query.graphql @@ -22,6 +22,13 @@ query GetCurrencyChanges($currentDate: DateTime) { } } +query GetLeads($domainname: String) { + leads(owner_domainname: $domainname) { + label: fullname + value: leadid + } +} + query GetLead($leadid: Uuid!) { lead(leadid: $leadid) { evo_agent_accountid @@ -41,6 +48,13 @@ query GetOpportunity($opportunityid: Uuid!) { } } +query GetOpportunities($domainname: String) { + opportunities(owner_domainname: $domainname) { + label: name + value: opportunityid + } +} + query GetQuotes($leadid: Uuid!) { quotes(evo_leadid: $leadid) { label: evo_quotename diff --git a/apps/web/graphql/crm.types.ts b/apps/web/graphql/crm.types.ts index 98436de..0b5d5bf 100644 --- a/apps/web/graphql/crm.types.ts +++ b/apps/web/graphql/crm.types.ts @@ -135,6 +135,13 @@ export type GetCurrencyChangesQueryVariables = Exact<{ export type GetCurrencyChangesQuery = { __typename?: 'Query', evo_currencychanges: Array<{ __typename?: 'evo_currencychange', evo_currencychange: number | null, evo_ref_transactioncurrency: string | null } | null> | null }; +export type GetLeadsQueryVariables = Exact<{ + domainname: InputMaybe; +}>; + + +export type GetLeadsQuery = { __typename?: 'Query', leads: Array<{ __typename?: 'lead', label: string | null, value: string | null } | null> | null }; + export type GetLeadQueryVariables = Exact<{ leadid: Scalars['Uuid']; }>; @@ -149,6 +156,13 @@ export type GetOpportunityQueryVariables = Exact<{ export type GetOpportunityQuery = { __typename?: 'Query', opportunity: { __typename?: 'opportunity', evo_leadid: string | null } | null }; +export type GetOpportunitiesQueryVariables = Exact<{ + domainname: InputMaybe; +}>; + + +export type GetOpportunitiesQuery = { __typename?: 'Query', opportunities: Array<{ __typename?: 'opportunity', label: string | null, value: string | null } | null> | null }; + export type GetQuotesQueryVariables = Exact<{ leadid: Scalars['Uuid']; }>; @@ -393,13 +407,6 @@ export type GetAddproductTypesQueryVariables = Exact<{ export type GetAddproductTypesQuery = { __typename?: 'Query', evo_addproduct_types: Array<{ __typename?: 'evo_addproduct_type', evo_graph_price: number | null, evo_product_type: number | null, label: string | null, value: string | null } | null> | null }; -export type GetOwnerDataQueryVariables = Exact<{ - domainname: InputMaybe; -}>; - - -export type GetOwnerDataQuery = { __typename?: 'Query', selectLead: Array<{ __typename?: 'lead', label: string | null, value: string | null } | null> | null, selectOpportunity: Array<{ __typename?: 'opportunity', label: string | null, value: string | null } | null> | null }; - export type GetLeadUrlQueryVariables = Exact<{ id: Scalars['Uuid']; }>; @@ -467,8 +474,10 @@ export type GetAgentsDataFromQuoteQuery = { __typename?: 'Query', quote: { __typ export const GetTransactionCurrenciesDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetTransactionCurrencies"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"transactioncurrencies"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","alias":{"kind":"Name","value":"label"},"name":{"kind":"Name","value":"currencyname"}},{"kind":"Field","alias":{"kind":"Name","value":"value"},"name":{"kind":"Name","value":"transactioncurrencyid"}},{"kind":"Field","name":{"kind":"Name","value":"transactioncurrencyid"}},{"kind":"Field","name":{"kind":"Name","value":"isocurrencycode"}},{"kind":"Field","name":{"kind":"Name","value":"currencysymbol"}}]}}]}}]} as unknown as DocumentNode; export const GetTransactionCurrencyDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetTransactionCurrency"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"currencyid"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Uuid"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"transactioncurrency"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"transactioncurrencyid"},"value":{"kind":"Variable","name":{"kind":"Name","value":"currencyid"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"currencysymbol"}},{"kind":"Field","name":{"kind":"Name","value":"isocurrencycode"}}]}}]}}]} as unknown as DocumentNode; export const GetCurrencyChangesDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetCurrencyChanges"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"currentDate"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"DateTime"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_currencychanges"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"statecode"},"value":{"kind":"IntValue","value":"0"}},{"kind":"Argument","name":{"kind":"Name","value":"evo_coursedate_param"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"eq"},"value":{"kind":"Variable","name":{"kind":"Name","value":"currentDate"}}}]}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_currencychange"}},{"kind":"Field","name":{"kind":"Name","value":"evo_ref_transactioncurrency"}}]}}]}}]} as unknown as DocumentNode; +export const GetLeadsDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetLeads"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"domainname"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"leads"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"owner_domainname"},"value":{"kind":"Variable","name":{"kind":"Name","value":"domainname"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","alias":{"kind":"Name","value":"label"},"name":{"kind":"Name","value":"fullname"}},{"kind":"Field","alias":{"kind":"Name","value":"value"},"name":{"kind":"Name","value":"leadid"}}]}}]}}]} as unknown as DocumentNode; export const GetLeadDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetLead"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"leadid"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Uuid"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"lead"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"leadid"},"value":{"kind":"Variable","name":{"kind":"Name","value":"leadid"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_agent_accountid"}},{"kind":"Field","name":{"kind":"Name","value":"evo_double_agent_accountid"}},{"kind":"Field","name":{"kind":"Name","value":"evo_broker_accountid"}},{"kind":"Field","name":{"kind":"Name","value":"evo_fin_department_accountid"}},{"kind":"Field","name":{"kind":"Name","value":"evo_opportunityidData"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","alias":{"kind":"Name","value":"label"},"name":{"kind":"Name","value":"name"}},{"kind":"Field","alias":{"kind":"Name","value":"value"},"name":{"kind":"Name","value":"opportunityid"}}]}}]}}]}}]} as unknown as DocumentNode; export const GetOpportunityDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetOpportunity"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"opportunityid"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Uuid"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"opportunity"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"opportunityid"},"value":{"kind":"Variable","name":{"kind":"Name","value":"opportunityid"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_leadid"}}]}}]}}]} as unknown as DocumentNode; +export const GetOpportunitiesDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetOpportunities"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"domainname"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"opportunities"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"owner_domainname"},"value":{"kind":"Variable","name":{"kind":"Name","value":"domainname"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","alias":{"kind":"Name","value":"label"},"name":{"kind":"Name","value":"name"}},{"kind":"Field","alias":{"kind":"Name","value":"value"},"name":{"kind":"Name","value":"opportunityid"}}]}}]}}]} as unknown as DocumentNode; export const GetQuotesDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetQuotes"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"leadid"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Uuid"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"quotes"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"evo_leadid"},"value":{"kind":"Variable","name":{"kind":"Name","value":"leadid"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","alias":{"kind":"Name","value":"label"},"name":{"kind":"Name","value":"evo_quotename"}},{"kind":"Field","alias":{"kind":"Name","value":"value"},"name":{"kind":"Name","value":"quoteid"}}]}}]}}]} as unknown as DocumentNode; export const GetQuoteDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetQuote"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"quoteId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Uuid"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"quote"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"quoteId"},"value":{"kind":"Variable","name":{"kind":"Name","value":"quoteId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_baseproductid"}}]}}]}}]} as unknown as DocumentNode; export const GetTarifsDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetTarifs"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"currentDate"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"DateTime"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_tarifs"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"statecode"},"value":{"kind":"IntValue","value":"0"}},{"kind":"Argument","name":{"kind":"Name","value":"evo_datefrom_param"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"lte"},"value":{"kind":"Variable","name":{"kind":"Name","value":"currentDate"}}}]}},{"kind":"Argument","name":{"kind":"Name","value":"evo_dateto_param"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"gte"},"value":{"kind":"Variable","name":{"kind":"Name","value":"currentDate"}}}]}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","alias":{"kind":"Name","value":"label"},"name":{"kind":"Name","value":"evo_name"}},{"kind":"Field","alias":{"kind":"Name","value":"value"},"name":{"kind":"Name","value":"evo_tarifid"}},{"kind":"Field","name":{"kind":"Name","value":"evo_tarifid"}},{"kind":"Field","name":{"kind":"Name","value":"evo_baseproductid"}},{"kind":"Field","name":{"kind":"Name","value":"evo_min_period"}},{"kind":"Field","name":{"kind":"Name","value":"evo_max_period"}},{"kind":"Field","name":{"kind":"Name","value":"evo_delivery_time"}},{"kind":"Field","name":{"kind":"Name","value":"evo_min_first_payment"}},{"kind":"Field","name":{"kind":"Name","value":"evo_max_first_payment"}},{"kind":"Field","name":{"kind":"Name","value":"evo_min_last_payment"}},{"kind":"Field","name":{"kind":"Name","value":"evo_max_last_payment"}},{"kind":"Field","name":{"kind":"Name","value":"evo_used"}}]}}]}}]} as unknown as DocumentNode; @@ -505,7 +514,6 @@ export const GetFingapDataFromQuoteDocument = {"kind":"Document","definitions":[ export const GetFinGapAddProductTypesDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetFinGAPAddProductTypes"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"currentDate"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"DateTime"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_addproduct_types"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"statecode"},"value":{"kind":"IntValue","value":"0"}},{"kind":"Argument","name":{"kind":"Name","value":"evo_datefrom_param"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"lte"},"value":{"kind":"Variable","name":{"kind":"Name","value":"currentDate"}}}]}},{"kind":"Argument","name":{"kind":"Name","value":"evo_dateto_param"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"gte"},"value":{"kind":"Variable","name":{"kind":"Name","value":"currentDate"}}}]}},{"kind":"Argument","name":{"kind":"Name","value":"evo_product_type"},"value":{"kind":"IntValue","value":"100000006"}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_addproduct_typeid"}},{"kind":"Field","name":{"kind":"Name","value":"evo_name"}},{"kind":"Field","name":{"kind":"Name","value":"evo_type_calc_cerebellum"}},{"kind":"Field","name":{"kind":"Name","value":"evo_cost_service_provider_withoutnds"}},{"kind":"Field","name":{"kind":"Name","value":"evo_addproduct_types"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_addproduct_typeid"}}]}}]}}]}}]} as unknown as DocumentNode; export const GetInsuranceDataDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetInsuranceData"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"evo_account_type"}},"type":{"kind":"ListType","type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Int"}}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","alias":{"kind":"Name","value":"osago"},"name":{"kind":"Name","value":"accounts"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"evo_account_type"},"value":{"kind":"Variable","name":{"kind":"Name","value":"evo_account_type"}}},{"kind":"Argument","name":{"kind":"Name","value":"evo_type_ins_policy"},"value":{"kind":"ListValue","values":[{"kind":"IntValue","value":"100000001"}]}},{"kind":"Argument","name":{"kind":"Name","value":"statecode"},"value":{"kind":"IntValue","value":"0"}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","alias":{"kind":"Name","value":"value"},"name":{"kind":"Name","value":"accountid"}},{"kind":"Field","alias":{"kind":"Name","value":"label"},"name":{"kind":"Name","value":"name"}}]}},{"kind":"Field","alias":{"kind":"Name","value":"kasko"},"name":{"kind":"Name","value":"accounts"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"evo_account_type"},"value":{"kind":"Variable","name":{"kind":"Name","value":"evo_account_type"}}},{"kind":"Argument","name":{"kind":"Name","value":"evo_type_ins_policy"},"value":{"kind":"ListValue","values":[{"kind":"IntValue","value":"100000000"}]}},{"kind":"Argument","name":{"kind":"Name","value":"statecode"},"value":{"kind":"IntValue","value":"0"}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","alias":{"kind":"Name","value":"value"},"name":{"kind":"Name","value":"accountid"}},{"kind":"Field","alias":{"kind":"Name","value":"label"},"name":{"kind":"Name","value":"name"}}]}},{"kind":"Field","alias":{"kind":"Name","value":"fingap"},"name":{"kind":"Name","value":"accounts"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"evo_account_type"},"value":{"kind":"Variable","name":{"kind":"Name","value":"evo_account_type"}}},{"kind":"Argument","name":{"kind":"Name","value":"evo_type_ins_policy"},"value":{"kind":"ListValue","values":[{"kind":"IntValue","value":"100000002"}]}},{"kind":"Argument","name":{"kind":"Name","value":"statecode"},"value":{"kind":"IntValue","value":"0"}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","alias":{"kind":"Name","value":"value"},"name":{"kind":"Name","value":"accountid"}},{"kind":"Field","alias":{"kind":"Name","value":"label"},"name":{"kind":"Name","value":"name"}}]}}]}}]} as unknown as DocumentNode; export const GetAddproductTypesDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetAddproductTypes"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"currentDate"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"DateTime"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evo_addproduct_types"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"statecode"},"value":{"kind":"IntValue","value":"0"}},{"kind":"Argument","name":{"kind":"Name","value":"evo_datefrom_param"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"lte"},"value":{"kind":"Variable","name":{"kind":"Name","value":"currentDate"}}}]}},{"kind":"Argument","name":{"kind":"Name","value":"evo_dateto_param"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"gte"},"value":{"kind":"Variable","name":{"kind":"Name","value":"currentDate"}}}]}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","alias":{"kind":"Name","value":"label"},"name":{"kind":"Name","value":"evo_name"}},{"kind":"Field","alias":{"kind":"Name","value":"value"},"name":{"kind":"Name","value":"evo_addproduct_typeid"}},{"kind":"Field","name":{"kind":"Name","value":"evo_graph_price"}},{"kind":"Field","name":{"kind":"Name","value":"evo_product_type"}}]}}]}}]} as unknown as DocumentNode; -export const GetOwnerDataDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetOwnerData"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"domainname"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","alias":{"kind":"Name","value":"selectLead"},"name":{"kind":"Name","value":"leads"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"owner_domainname"},"value":{"kind":"Variable","name":{"kind":"Name","value":"domainname"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","alias":{"kind":"Name","value":"label"},"name":{"kind":"Name","value":"fullname"}},{"kind":"Field","alias":{"kind":"Name","value":"value"},"name":{"kind":"Name","value":"leadid"}}]}},{"kind":"Field","alias":{"kind":"Name","value":"selectOpportunity"},"name":{"kind":"Name","value":"opportunities"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"owner_domainname"},"value":{"kind":"Variable","name":{"kind":"Name","value":"domainname"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","alias":{"kind":"Name","value":"label"},"name":{"kind":"Name","value":"name"}},{"kind":"Field","alias":{"kind":"Name","value":"value"},"name":{"kind":"Name","value":"opportunityid"}}]}}]}}]} as unknown as DocumentNode; export const GetLeadUrlDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetLeadUrl"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"id"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Uuid"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","alias":{"kind":"Name","value":"entity"},"name":{"kind":"Name","value":"lead"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"leadid"},"value":{"kind":"Variable","name":{"kind":"Name","value":"id"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"link"}}]}}]}}]} as unknown as DocumentNode; export const GetOpportunityUrlDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetOpportunityUrl"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"id"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Uuid"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","alias":{"kind":"Name","value":"entity"},"name":{"kind":"Name","value":"opportunity"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"opportunityid"},"value":{"kind":"Variable","name":{"kind":"Name","value":"id"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"link"}}]}}]}}]} as unknown as DocumentNode; export const GetQuoteUrlDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetQuoteUrl"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"id"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Uuid"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","alias":{"kind":"Name","value":"entity"},"name":{"kind":"Name","value":"quote"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"quoteId"},"value":{"kind":"Variable","name":{"kind":"Name","value":"id"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"link"}}]}}]}}]} as unknown as DocumentNode; diff --git a/apps/web/pages/index.jsx b/apps/web/pages/index.jsx index ab62819..5671f53 100644 --- a/apps/web/pages/index.jsx +++ b/apps/web/pages/index.jsx @@ -3,7 +3,7 @@ import initializeApollo from '@/apollo/client'; import * as Calculation from '@/Components/Calculation'; import { CRMError } from '@/Components/Common/Error'; import Output from '@/Components/Output'; -import { getOwnerData, useInsuranceData, useMainData } from '@/process/init/get-data'; +import * as getData from '@/process/init/get-data'; import { useReactions } from '@/process/init/inject-reactions/hooks'; import { min } from '@/styles/mq'; import { dehydrate, QueryClient } from '@tanstack/react-query'; @@ -11,6 +11,8 @@ import Head from 'next/head'; import styled from 'styled-components'; import { Box } from 'ui/grid'; +const { getInitialData, useInsuranceData, useMainData } = getData; + const Grid = styled(Box)` display: flex; flex-direction: column; @@ -69,12 +71,13 @@ export const getServerSideProps = async ({ req }) => { const apolloClient = initializeApollo(); try { - const { data } = await getOwnerData(apolloClient, user); + const { values, options } = await getInitialData(apolloClient, user); return { props: { calculation: { - options: data, + options, + values, }, initialApolloState: apolloClient.cache.extract(), initialQueryState: dehydrate(queryClient), diff --git a/apps/web/process/init/get-data/get-initial-data.ts b/apps/web/process/init/get-data/get-initial-data.ts new file mode 100644 index 0000000..6bc8b6e --- /dev/null +++ b/apps/web/process/init/get-data/get-initial-data.ts @@ -0,0 +1,36 @@ +/* eslint-disable @typescript-eslint/naming-convention */ +import type { User } from '@/api/user/types'; +import * as CRMTypes from '@/graphql/crm.types'; +import type { ApolloClient } from '@apollo/client'; + +export async function getInitialData({ query }: ApolloClient, user: User) { + const { + data: { leads }, + } = await query({ query: CRMTypes.GetLeadsDocument, variables: { domainname: user.domainName } }); + + const { + data: { opportunities }, + } = await query({ + query: CRMTypes.GetOpportunitiesDocument, + variables: { domainname: user.domainName }, + }); + + const { + data: { transactioncurrencies }, + } = await query({ + query: CRMTypes.GetTransactionCurrenciesDocument, + }); + + const transactioncurrency_rub = transactioncurrencies?.find((x) => x?.isocurrencycode === 'RUB'); + + return { + options: { + selectLead: leads, + selectOpportunity: opportunities, + selectSupplierCurrency: transactioncurrencies, + }, + values: { + supplierCurrency: transactioncurrency_rub?.transactioncurrencyid ?? null, + }, + }; +} diff --git a/apps/web/process/init/get-data/get-main-data.js b/apps/web/process/init/get-data/get-main-data.js index 88ab981..00edb19 100644 --- a/apps/web/process/init/get-data/get-main-data.js +++ b/apps/web/process/init/get-data/get-main-data.js @@ -32,17 +32,6 @@ const currentDate = dayjs().utc(false).toISOString(); * @param {*} onCompleted */ function getMainData({ query }, onCompleted) { - query({ - query: CRMTypes.GetTransactionCurrenciesDocument, - variables: { - currentDate, - }, - }).then(({ data }) => { - onCompleted({ - selectSupplierCurrency: data?.transactioncurrencies, - }); - }); - query({ query: CRMTypes.GetLeaseObjectTypesDocument, variables: { diff --git a/apps/web/process/init/get-data/get-owner-data.ts b/apps/web/process/init/get-data/get-owner-data.ts deleted file mode 100644 index fcb3ba4..0000000 --- a/apps/web/process/init/get-data/get-owner-data.ts +++ /dev/null @@ -1,26 +0,0 @@ -import type { User } from '@/api/user/types'; -import type { GetOwnerDataQuery, GetOwnerDataQueryVariables } from '@/graphql/crm.types'; -import type { ApolloClient } from '@apollo/client'; -import { gql } from '@apollo/client'; - -const QUERY_GET_OWNER_DATA = gql` - query GetOwnerData($domainname: String) { - selectLead: leads(owner_domainname: $domainname) { - label: fullname - value: leadid - } - selectOpportunity: opportunities(owner_domainname: $domainname) { - label: name - value: opportunityid - } - } -`; - -export async function getOwnerData({ query }: ApolloClient, user: User) { - return query({ - query: QUERY_GET_OWNER_DATA, - variables: { - domainname: user?.domainName, - }, - }); -} diff --git a/apps/web/process/init/get-data/index.js b/apps/web/process/init/get-data/index.js index 0dbd66f..8829509 100644 --- a/apps/web/process/init/get-data/index.js +++ b/apps/web/process/init/get-data/index.js @@ -1,3 +1,3 @@ +export { getInitialData } from './get-initial-data'; export { useInsuranceData } from './get-insurance-data'; export { useMainData } from './get-main-data'; -export { getOwnerData } from './get-owner-data'; diff --git a/apps/web/process/init/inject-reactions/default.js b/apps/web/process/init/inject-reactions/default.js index cca85d1..2e66b1a 100644 --- a/apps/web/process/init/inject-reactions/default.js +++ b/apps/web/process/init/inject-reactions/default.js @@ -14,7 +14,6 @@ import * as agentsReactions from '../../supplier-agent/reactions/agents'; import leasebackReactions from '../../supplier-agent/reactions/leaseback'; import * as supplierReactions from '../../supplier-agent/reactions/supplier'; import * as usedPl from '../../used-pl/reactions'; -import setInitialValuesReactions from '../set-values/reactions'; export default function injectDefaultReactions(context) { leadOpportunityReactions.common(context); @@ -34,7 +33,6 @@ export default function injectDefaultReactions(context) { priceReactions.validation(context); fingapReactions.common(context); fingapReactions.validation(context); - setInitialValuesReactions(context); loadKpReactions(context); leasingWithoutKaskoReactions.common(context); subsidyReactions.computedReactions(context); diff --git a/apps/web/process/init/set-values/reactions.ts b/apps/web/process/init/set-values/reactions.ts deleted file mode 100644 index 17d700f..0000000 --- a/apps/web/process/init/set-values/reactions.ts +++ /dev/null @@ -1,28 +0,0 @@ -/* eslint-disable @typescript-eslint/naming-convention */ -import { GetTransactionCurrenciesDocument } from '@/graphql/crm.types'; -import type { ReactionsContext } from '@/process/types'; -import { when } from 'mobx'; - -export default function setInitialValuesReactions({ store, apolloClient }: ReactionsContext) { - const { $calculation } = store; - - when( - () => $calculation.$options.getOptions('selectSupplierCurrency').length > 0, - async () => { - const { - data: { transactioncurrencies }, - } = await apolloClient.query({ - query: GetTransactionCurrenciesDocument, - }); - - const transactioncurrency_rub = transactioncurrencies?.find( - (x) => x?.isocurrencycode === 'RUB' - ); - if (transactioncurrency_rub) { - $calculation - .element('selectSupplierCurrency') - .setValue(transactioncurrency_rub.transactioncurrencyid); - } - } - ); -} diff --git a/apps/web/process/load-kp/reactions.ts b/apps/web/process/load-kp/reactions.ts index 8faa363..87cb263 100644 --- a/apps/web/process/load-kp/reactions.ts +++ b/apps/web/process/load-kp/reactions.ts @@ -43,10 +43,8 @@ export default function loadKpReactions({ store, trpcClient }: ReactionsContext) ]); $calculation.$values.setValues({ - values: { - ...values, - ...savedValues, - }, + ...values, + ...savedValues, }); $tables.payments.setValues(payments.values); diff --git a/apps/web/stores/calculation/values/index.ts b/apps/web/stores/calculation/values/index.ts index bcbcb9c..1dd85c5 100644 --- a/apps/web/stores/calculation/values/index.ts +++ b/apps/web/stores/calculation/values/index.ts @@ -6,7 +6,8 @@ import { pick } from 'radash'; export default class ValuesStore { private root: RootStore; - public values: CalculationValues = defaultValues; + public values = defaultValues; + private defaultValues = defaultValues; constructor(rootStore: RootStore) { makeAutoObservable(this); @@ -14,14 +15,13 @@ export default class ValuesStore { } public hydrate = (initialValues: CalculationValues) => { - this.values = initialValues; + this.values = { ...defaultValues, ...initialValues }; + this.defaultValues = { ...defaultValues, ...initialValues }; }; public getValues = (keys: K[]) => pick(this.values, keys); - public setValues = (params: { values: CalculationValues }) => { - const { values } = params; - + public setValues = (values: CalculationValues) => { this.values = values; }; @@ -34,6 +34,6 @@ export default class ValuesStore { }; public resetValue = (valueName: Values) => { - this.setValue(valueName, defaultValues[valueName]); + this.setValue(valueName, this.defaultValues[valueName]); }; }