42 lines
1.3 KiB
TypeScript
42 lines
1.3 KiB
TypeScript
import * as CRMTypes from '@/graphql/crm.types';
|
|
import type { ProcessContext } from '@/process/types';
|
|
import { reaction } from 'mobx';
|
|
import { makeDisposable, normalizeOptions } from 'tools';
|
|
|
|
export default function unlimitedReactions({ store, apolloClient }: ProcessContext) {
|
|
const { $calculation, $process } = store;
|
|
|
|
makeDisposable(
|
|
() =>
|
|
reaction(
|
|
() => $calculation.element('selectUser').getValue(),
|
|
async (domainname) => {
|
|
if (!domainname) {
|
|
$calculation.element('selectLead').reset();
|
|
$calculation.element('selectOpportunity').reset();
|
|
|
|
return;
|
|
}
|
|
const {
|
|
data: { leads },
|
|
} = await apolloClient.query({
|
|
query: CRMTypes.GetLeadsDocument,
|
|
variables: { domainname },
|
|
});
|
|
|
|
$calculation.element('selectLead').setOptions(normalizeOptions(leads));
|
|
|
|
const {
|
|
data: { opportunities },
|
|
} = await apolloClient.query({
|
|
query: CRMTypes.GetOpportunitiesDocument,
|
|
variables: { domainname },
|
|
});
|
|
|
|
$calculation.element('selectOpportunity').setOptions(normalizeOptions(opportunities));
|
|
}
|
|
),
|
|
() => !$process.has('Unlimited')
|
|
);
|
|
}
|