44 lines
1.2 KiB
TypeScript
44 lines
1.2 KiB
TypeScript
/* 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
|
|
.element('selectSupplierCurrency')
|
|
.setValue(transactioncurrency_rub?.transactioncurrencyid);
|
|
}
|
|
);
|
|
}
|