new process/agents
This commit is contained in:
parent
6651d118e5
commit
a24b62739d
@ -8,6 +8,7 @@ import * as InsuranceTableConfig from 'config/tables/insurance-table';
|
||||
import { merge } from 'lodash-es';
|
||||
import type { GetServerSideProps } from 'next';
|
||||
import Head from 'next/head';
|
||||
import * as agentsReactions from 'process/agents/reactions';
|
||||
import * as calculateReactions from 'process/calculate/reactions';
|
||||
import { getCRMData } from 'process/init/get-data';
|
||||
import * as leadOpportunityReactions from 'process/lead-opportunity/reactions';
|
||||
@ -55,6 +56,7 @@ function Home() {
|
||||
leadOpportunityReactions.urls(store, apolloClient);
|
||||
paymentsReactions(store, apolloClient);
|
||||
calculateReactions.validation(store, apolloClient);
|
||||
agentsReactions.common(store, apolloClient);
|
||||
});
|
||||
|
||||
return (
|
||||
|
||||
22
process/agents/lib/__generated__/GetAgent.ts
generated
Normal file
22
process/agents/lib/__generated__/GetAgent.ts
generated
Normal file
@ -0,0 +1,22 @@
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
// @generated
|
||||
// This file was automatically generated and should not be edited.
|
||||
|
||||
// ====================================================
|
||||
// GraphQL query operation: GetAgent
|
||||
// ====================================================
|
||||
|
||||
export interface GetAgent_agent {
|
||||
__typename: "account";
|
||||
label: string | null;
|
||||
value: any | null;
|
||||
}
|
||||
|
||||
export interface GetAgent {
|
||||
agent: GetAgent_agent | null;
|
||||
}
|
||||
|
||||
export interface GetAgentVariables {
|
||||
evo_agent_accountid: any;
|
||||
}
|
||||
24
process/agents/lib/__generated__/GetAgentAccountId.ts
generated
Normal file
24
process/agents/lib/__generated__/GetAgentAccountId.ts
generated
Normal file
@ -0,0 +1,24 @@
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
// @generated
|
||||
// This file was automatically generated and should not be edited.
|
||||
|
||||
// ====================================================
|
||||
// GraphQL query operation: GetAgentAccountId
|
||||
// ====================================================
|
||||
|
||||
export interface GetAgentAccountId_lead {
|
||||
__typename: "lead";
|
||||
evo_agent_accountid: any | null;
|
||||
}
|
||||
|
||||
export interface GetAgentAccountId {
|
||||
/**
|
||||
* Лизинговые сделки. statecode по умолчанию 0, можно отфильтровать по ownerid и/или domainName
|
||||
*/
|
||||
lead: GetAgentAccountId_lead | null;
|
||||
}
|
||||
|
||||
export interface GetAgentAccountIdVariables {
|
||||
leadid: any;
|
||||
}
|
||||
63
process/agents/lib/fill-agents-from-lead.ts
Normal file
63
process/agents/lib/fill-agents-from-lead.ts
Normal file
@ -0,0 +1,63 @@
|
||||
/* eslint-disable import/prefer-default-export */
|
||||
import type { ApolloClient } from '@apollo/client';
|
||||
import { gql } from '@apollo/client';
|
||||
import type RootStore from 'stores/root';
|
||||
import { normalizeOptions } from 'tools/entity';
|
||||
import type { GetAgent } from './__generated__/GetAgent';
|
||||
import type { GetAgentAccountId } from './__generated__/GetAgentAccountId';
|
||||
|
||||
const QUERY_GET_AGENT_ACCOUNTID = gql`
|
||||
query GetAgentAccountId($leadid: Uuid!) {
|
||||
lead(leadid: $leadid) {
|
||||
evo_agent_accountid
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
const QUERY_GET_AGENT = gql`
|
||||
query GetAgent($evo_agent_accountid: Uuid!) {
|
||||
agent: account(accountid: $evo_agent_accountid) {
|
||||
label: name
|
||||
value: accountid
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
export async function fillIndAgent(
|
||||
{ $calculation }: RootStore,
|
||||
apolloClient: ApolloClient<object>,
|
||||
leadid: string | null
|
||||
) {
|
||||
if (!leadid) {
|
||||
$calculation.resetElement('selectIndAgent');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
const {
|
||||
data: { lead },
|
||||
} = await apolloClient.query<GetAgentAccountId>({
|
||||
query: QUERY_GET_AGENT_ACCOUNTID,
|
||||
variables: {
|
||||
leadid,
|
||||
},
|
||||
});
|
||||
|
||||
if (lead?.evo_agent_accountid) {
|
||||
const {
|
||||
data: { agent },
|
||||
} = await apolloClient.query<GetAgent>({
|
||||
query: QUERY_GET_AGENT,
|
||||
variables: {
|
||||
evo_agent_accountid: lead.evo_agent_accountid,
|
||||
},
|
||||
});
|
||||
|
||||
if (agent) {
|
||||
$calculation.$options.setElementOptions('selectIndAgent', normalizeOptions([agent]));
|
||||
$calculation.setElementValue('selectIndAgent', agent.value);
|
||||
}
|
||||
} else {
|
||||
$calculation.resetElement('selectIndAgent');
|
||||
}
|
||||
}
|
||||
14
process/agents/reactions/common.ts
Normal file
14
process/agents/reactions/common.ts
Normal file
@ -0,0 +1,14 @@
|
||||
import type { ApolloClient } from '@apollo/client';
|
||||
import { reaction } from 'mobx';
|
||||
import type RootStore from 'stores/root';
|
||||
import { fillIndAgent } from '../lib/fill-agents-from-lead';
|
||||
|
||||
export default function commonReactions(store: RootStore, apolloClient: ApolloClient<object>) {
|
||||
const { $calculation } = store;
|
||||
reaction(
|
||||
() => $calculation.getElementValue('selectLead'),
|
||||
(leadid) => {
|
||||
fillIndAgent(store, apolloClient, leadid);
|
||||
}
|
||||
);
|
||||
}
|
||||
2
process/agents/reactions/index.js
Normal file
2
process/agents/reactions/index.js
Normal file
@ -0,0 +1,2 @@
|
||||
/* eslint-disable import/prefer-default-export */
|
||||
export { default as common } from './common';
|
||||
Loading…
x
Reference in New Issue
Block a user