2024-04-16 17:38:34 +03:00

51 lines
1.4 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 } = await apolloClient.query({
query: CRMTypes.GetLeadsDocument,
variables: { domainname },
});
const systemuser = data?.systemusers?.[0];
if (systemuser) {
const { leads } = systemuser;
$calculation.element('selectLead').setOptions(normalizeOptions(leads));
}
}
{
const { data } = await apolloClient.query({
query: CRMTypes.GetOpportunitiesDocument,
variables: { domainname },
});
const systemuser = data?.systemusers?.[0];
if (systemuser) {
const { opportunities } = systemuser;
$calculation.element('selectOpportunity').setOptions(normalizeOptions(opportunities));
}
}
}
);
}