From 7fdd21af224899fbf3ed250c6c782af669c60446 Mon Sep 17 00:00:00 2001 From: Chika Date: Fri, 15 Jul 2022 17:38:42 +0300 Subject: [PATCH] process/agents: fill selectDealerRewardCondition --- .../__generated__/GetDealerRewardCondition.ts | 24 ++++++ .../__generated__/GetDealerRewardSumm.ts | 21 +++++ process/agents/reactions/common.ts | 81 ++++++++++++++++++- 3 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 process/agents/reactions/__generated__/GetDealerRewardCondition.ts create mode 100644 process/agents/reactions/__generated__/GetDealerRewardSumm.ts diff --git a/process/agents/reactions/__generated__/GetDealerRewardCondition.ts b/process/agents/reactions/__generated__/GetDealerRewardCondition.ts new file mode 100644 index 0000000..c5a8378 --- /dev/null +++ b/process/agents/reactions/__generated__/GetDealerRewardCondition.ts @@ -0,0 +1,24 @@ +/* tslint:disable */ +/* eslint-disable */ +// @generated +// This file was automatically generated and should not be edited. + +// ==================================================== +// GraphQL query operation: GetDealerRewardCondition +// ==================================================== + +export interface GetDealerRewardCondition_evo_reward_conditions { + __typename: "evo_reward_condition"; + label: string | null; + value: any | null; + evo_reward_summ: any | null; +} + +export interface GetDealerRewardCondition { + evo_reward_conditions: (GetDealerRewardCondition_evo_reward_conditions | null)[] | null; +} + +export interface GetDealerRewardConditionVariables { + agentid: any; + currentDate?: any | null; +} diff --git a/process/agents/reactions/__generated__/GetDealerRewardSumm.ts b/process/agents/reactions/__generated__/GetDealerRewardSumm.ts new file mode 100644 index 0000000..6dc6f7c --- /dev/null +++ b/process/agents/reactions/__generated__/GetDealerRewardSumm.ts @@ -0,0 +1,21 @@ +/* tslint:disable */ +/* eslint-disable */ +// @generated +// This file was automatically generated and should not be edited. + +// ==================================================== +// GraphQL query operation: GetDealerRewardSumm +// ==================================================== + +export interface GetDealerRewardSumm_evo_reward_condition { + __typename: "evo_reward_condition"; + evo_reward_summ: any | null; +} + +export interface GetDealerRewardSumm { + evo_reward_condition: GetDealerRewardSumm_evo_reward_condition | null; +} + +export interface GetDealerRewardSummVariables { + conditionId: any; +} diff --git a/process/agents/reactions/common.ts b/process/agents/reactions/common.ts index 127b5b0..29d1eab 100644 --- a/process/agents/reactions/common.ts +++ b/process/agents/reactions/common.ts @@ -1,5 +1,8 @@ +/* eslint-disable @typescript-eslint/naming-convention */ import type { ApolloClient } from '@apollo/client'; import { gql } from '@apollo/client'; +import dayjs from 'dayjs'; +import utc from 'dayjs/plugin/utc'; import { reaction } from 'mobx'; import type RootStore from 'stores/root'; import { normalizeOptions } from 'tools/entity'; @@ -8,6 +11,10 @@ import QUERY_GET_AGENT from '../lib/query/get-agent'; import type { GetAgent } from '../lib/query/__generated__/GetAgent'; import type { GetBrokerAccountIdFromDealer } from './__generated__/GetBrokerAccountIdFromDealer'; import type { GetDealerPerson } from './__generated__/GetDealerPerson'; +import type { GetDealerRewardCondition } from './__generated__/GetDealerRewardCondition'; +import type { GetDealerRewardSumm } from './__generated__/GetDealerRewardSumm'; + +dayjs.extend(utc); export default function commonReactions(store: RootStore, apolloClient: ApolloClient) { const { $calculation } = store; @@ -51,7 +58,6 @@ export default function commonReactions(store: RootStore, apolloClient: ApolloCl } const { - // eslint-disable-next-line @typescript-eslint/naming-convention data: { salon_providers }, } = await apolloClient.query({ query: QUERY_GET_DEALER_PERSON, @@ -117,6 +123,79 @@ export default function commonReactions(store: RootStore, apolloClient: ApolloCl * Заполняем selectDealerRewardCondition */ + const QUERY_GET_DEALER_REWARD_CONDITIONS = gql` + query GetDealerRewardCondition($agentid: Uuid!, $currentDate: DateTime) { + evo_reward_conditions( + evo_agent_accountid: $agentid + evo_datefrom_param: { lte: $currentDate } + evo_dateto_param: { gte: $currentDate } + statecode: 0 + evo_agency_agreementid_param: { has: true } + ) { + label: evo_name + value: evo_reward_conditionid + evo_reward_summ + } + } + `; + + reaction( + () => $calculation.getElementValue('selectDealerPerson'), + async (dealerPersonId) => { + if (!dealerPersonId) { + $calculation.resetElement('selectDealerRewardCondition'); + + return; + } + const { + data: { evo_reward_conditions }, + } = await apolloClient.query({ + query: QUERY_GET_DEALER_REWARD_CONDITIONS, + variables: { + agentid: dealerPersonId, + currentDate: dayjs().toISOString(), + }, + }); + + if (evo_reward_conditions?.length) { + $calculation.setElementOptions( + 'selectDealerRewardCondition', + normalizeOptions(evo_reward_conditions) + ); + } + } + ); + + const QUERY_GET_DEALER_REWARD_SUMM = gql` + query GetDealerRewardSumm($conditionId: Uuid!) { + evo_reward_condition(evo_reward_conditionid: $conditionId) { + evo_reward_summ + } + } + `; + + reaction( + () => $calculation.getElementValue('selectDealerRewardCondition'), + async (dealerRewardConditionId) => { + if (!dealerRewardConditionId) { + $calculation.resetElement('tbxDealerRewardSumm'); + + return; + } + + const { + data: { evo_reward_condition }, + } = await apolloClient.query({ + query: QUERY_GET_DEALER_REWARD_SUMM, + variables: { + conditionId: dealerRewardConditionId, + }, + }); + + $calculation.setElementValue('tbxDealerRewardSumm', evo_reward_condition?.evo_reward_summ); + } + ); + /** * Заполняем selectDealerBrokerRewardCondition */