process: add set default values reactions:
selectSupplierCurrency: set default RUB value
This commit is contained in:
parent
c8b3b9a090
commit
52277cae30
@ -241,6 +241,11 @@ export type GetOwnerDataQueryVariables = Exact<{
|
||||
|
||||
export type GetOwnerDataQuery = { __typename?: 'Query', selectLead?: Array<{ __typename?: 'lead', label?: string | null, value?: any | null } | null> | null, selectOpportunity?: Array<{ __typename?: 'opportunity', label?: string | null, value?: any | null } | null> | null };
|
||||
|
||||
export type GetTransactionCurrenciesQueryVariables = Exact<{ [key: string]: never; }>;
|
||||
|
||||
|
||||
export type GetTransactionCurrenciesQuery = { __typename?: 'Query', transactioncurrencies?: Array<{ __typename?: 'transactioncurrency', isocurrencycode?: string | null, transactioncurrencyid?: any | null } | null> | null };
|
||||
|
||||
export type GetOpportunityByLeadQueryVariables = Exact<{
|
||||
leadid: Scalars['Uuid'];
|
||||
}>;
|
||||
|
||||
@ -4,6 +4,7 @@ import fingapReactions from '../../fingap/reactions';
|
||||
import * as leadOpportunityReactions from '../../lead-opportunity/reactions';
|
||||
import paymentsReactions from '../../payments/reactions';
|
||||
import * as priceReactions from '../../price/reactions';
|
||||
import setInitialValuesReactions from '../set-values/reactions';
|
||||
|
||||
export default function injectDefaultReactions(store, apolloClient, queryClient) {
|
||||
leadOpportunityReactions.common(store, apolloClient, queryClient);
|
||||
@ -13,4 +14,5 @@ export default function injectDefaultReactions(store, apolloClient, queryClient)
|
||||
agentsReactions.common(store, apolloClient, queryClient);
|
||||
priceReactions.computed(store, apolloClient, queryClient);
|
||||
fingapReactions(store, apolloClient, queryClient);
|
||||
setInitialValuesReactions(store, apolloClient, queryClient);
|
||||
}
|
||||
|
||||
44
process/init/set-values/reactions.ts
Normal file
44
process/init/set-values/reactions.ts
Normal file
@ -0,0 +1,44 @@
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
import type { ApolloClient } from '@apollo/client';
|
||||
import { gql } from '@apollo/client';
|
||||
import type { QueryClient } from '@tanstack/react-query';
|
||||
import type { GetTransactionCurrenciesQuery } from 'graphql/crm.types';
|
||||
import { when } from 'mobx';
|
||||
import type RootStore from 'stores/root';
|
||||
|
||||
export default function setInitialValuesReactions(
|
||||
store: RootStore,
|
||||
apolloClient: ApolloClient<object>,
|
||||
queryClient: QueryClient
|
||||
) {
|
||||
const QUERY_GET_TRANSACTION_CURRENCIES = gql`
|
||||
query GetTransactionCurrencies {
|
||||
transactioncurrencies {
|
||||
isocurrencycode
|
||||
transactioncurrencyid
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
const { $calculation } = store;
|
||||
|
||||
when(
|
||||
() => $calculation.$options.getOptions('selectSupplierCurrency').length > 0,
|
||||
async () => {
|
||||
const {
|
||||
data: { transactioncurrencies },
|
||||
} = await apolloClient.query<GetTransactionCurrenciesQuery>({
|
||||
query: QUERY_GET_TRANSACTION_CURRENCIES,
|
||||
});
|
||||
|
||||
const transactioncurrency_rub = transactioncurrencies?.find(
|
||||
(x) => x?.isocurrencycode === 'RUB'
|
||||
);
|
||||
|
||||
$calculation.setElementValue(
|
||||
'selectSupplierCurrency',
|
||||
transactioncurrency_rub?.transactioncurrencyid
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user