39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
import * as CRMTypes from '@/graphql/crm.types';
|
|
import type { ProcessContext } from '@/process/types';
|
|
import { normalizeOptions } from '@/utils/entity';
|
|
import { disposableReaction } from '@/utils/mobx';
|
|
|
|
export default function unlimitedReactions({ store, apolloClient }: ProcessContext) {
|
|
const { $calculation, $process } = store;
|
|
|
|
disposableReaction(
|
|
() => !$process.has('Unlimited'),
|
|
() => $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));
|
|
}
|
|
);
|
|
}
|