Chika f85373689a add trpc server
get calculation values types from zod schema
add loadKP reaction
get base agents data from kp
2022-11-02 13:18:33 +03:00

46 lines
1.2 KiB
TypeScript

import type { ApolloClient } from '@apollo/client';
import type { QueryClient } from '@tanstack/react-query';
import message from 'Elements/message';
import { reaction, toJS } from 'mobx';
import type RootStore from 'stores/root';
import type { TRPCPureClient } from 'trpc/types';
export default function loadKpReactions(
store: RootStore,
apolloClient: ApolloClient<object>,
queryClient: QueryClient,
trpcClient: TRPCPureClient
) {
const { $calculation, $process } = store;
reaction(
() => $calculation.element('selectQuote').getValue(),
(quoteId) => {
if (!quoteId) return;
$process.add('LoadKP');
const quoteName = $calculation.element('selectQuote').getOption()?.label;
trpcClient.quote.getValues
.query({
values: toJS($calculation.$values.values),
})
.then(({ values }) => {
$calculation.$values.hydrate(values);
message.success({
content: `КП ${quoteName} загружено`,
});
})
.catch(() => {
message.error({
content: `Ошибка во время загрузки КП ${quoteName}`,
});
})
.finally(() => {
$process.delete('LoadKP');
});
}
);
}