process/supplier-agent: add validation
store/calculation: add validation
This commit is contained in:
parent
f54dd44810
commit
f02f785fb6
@ -295,6 +295,13 @@ export type GetRewardWithoutOtherAgentQueryVariables = Exact<{
|
||||
|
||||
export type GetRewardWithoutOtherAgentQuery = { __typename?: 'Query', evo_reward_condition?: { __typename?: 'evo_reward_condition', evo_agency_agreementidData?: { __typename?: 'evo_agency_agreement', evo_reward_without_other_agent?: boolean | null } | null } | null };
|
||||
|
||||
export type GetRewardConditionQueryVariables = Exact<{
|
||||
conditionId: Scalars['Uuid'];
|
||||
}>;
|
||||
|
||||
|
||||
export type GetRewardConditionQuery = { __typename?: 'Query', evo_reward_condition?: { __typename?: 'evo_reward_condition', evo_reward_summ?: any | null, evo_reduce_reward?: boolean | null, evo_min_reward_summ?: any | null } | null };
|
||||
|
||||
export type GetDealerPersonQueryVariables = Exact<{
|
||||
dealerId: Scalars['Uuid'];
|
||||
}>;
|
||||
|
||||
@ -2,6 +2,7 @@ import type { ApolloClient } from '@apollo/client';
|
||||
import type { QueryClient } from '@tanstack/react-query';
|
||||
import { reaction } from 'mobx';
|
||||
import type RootStore from 'stores/root';
|
||||
import type { RemoveError } from 'stores/validation';
|
||||
|
||||
export default function validationReactions(
|
||||
store: RootStore,
|
||||
@ -11,7 +12,7 @@ export default function validationReactions(
|
||||
const { $tables } = store;
|
||||
|
||||
const errorText = 'Неверно заполнены платежи';
|
||||
let removeError: () => void;
|
||||
let removeError: RemoveError | undefined;
|
||||
|
||||
reaction(
|
||||
() => {
|
||||
|
||||
@ -8,6 +8,7 @@ import { shift } from 'radash';
|
||||
import type { CalculationOptions } from 'stores/calculation/options/types';
|
||||
import type RootStore from 'stores/root';
|
||||
import type { Row } from 'stores/tables/payments/types';
|
||||
import type { RemoveError } from 'stores/validation';
|
||||
import { difference } from 'tools/array';
|
||||
import { makeDisposable } from 'tools/mobx';
|
||||
import * as seasonsConstants from './lib/seasons-constants';
|
||||
@ -557,7 +558,7 @@ export default function paymentsReactions(
|
||||
/**
|
||||
* Валидация
|
||||
*/
|
||||
let removeError: () => void;
|
||||
let removeError: RemoveError | undefined;
|
||||
|
||||
reaction(
|
||||
() => {
|
||||
|
||||
@ -481,4 +481,55 @@ export function commonReactions(store: RootStore, apolloClient: ApolloClient<obj
|
||||
);
|
||||
}
|
||||
|
||||
export function validationReactions(store: RootStore, apolloClient: ApolloClient<object>) {}
|
||||
export const QUERY_GET_REWARD_CONDITION = gql`
|
||||
query GetRewardCondition($conditionId: Uuid!) {
|
||||
evo_reward_condition(evo_reward_conditionid: $conditionId) {
|
||||
evo_reward_summ
|
||||
evo_reduce_reward
|
||||
evo_min_reward_summ
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
export function validationReactions(store: RootStore, apolloClient: ApolloClient<object>) {
|
||||
const { $calculation } = store;
|
||||
|
||||
reaction(
|
||||
() => $calculation.element('tbxDealerRewardSumm').getValue(),
|
||||
async (dealerRewardSumm) => {
|
||||
const {
|
||||
data: { evo_reward_condition },
|
||||
} = await apolloClient.query<
|
||||
CRMTypes.GetRewardConditionQuery,
|
||||
CRMTypes.GetRewardConditionQueryVariables
|
||||
>({
|
||||
query: QUERY_GET_REWARD_CONDITION,
|
||||
variables: {
|
||||
conditionId: $calculation.element('selectDealerRewardCondition').getValue(),
|
||||
},
|
||||
});
|
||||
|
||||
$calculation.element('tbxDealerRewardSumm').validate({
|
||||
invalid: () =>
|
||||
evo_reward_condition?.evo_reward_summ &&
|
||||
dealerRewardSumm > evo_reward_condition.evo_reward_summ,
|
||||
message: 'Вознаграждение ЮЛ поставщика указано больше условия по агентскому договору!',
|
||||
});
|
||||
|
||||
$calculation.element('tbxDealerRewardSumm').validate({
|
||||
invalid: () =>
|
||||
!evo_reward_condition?.evo_reduce_reward &&
|
||||
evo_reward_condition?.evo_reward_summ &&
|
||||
dealerRewardSumm < evo_reward_condition.evo_reward_summ,
|
||||
message: 'Вознаграждение ЮЛ поставщика указано меньше условия по агентскому договору!',
|
||||
});
|
||||
|
||||
$calculation.element('tbxDealerRewardSumm').validate({
|
||||
invalid: () =>
|
||||
evo_reward_condition?.evo_min_reward_summ &&
|
||||
dealerRewardSumm < evo_reward_condition?.evo_min_reward_summ,
|
||||
message: 'Вознаграждение ЮЛ поставщика указано меньше условия по агентскому договору!',
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@ -10,6 +10,11 @@ import OptionsStore from './options';
|
||||
import StatusStore from './statuses';
|
||||
import ValuesStore from './values';
|
||||
|
||||
type ValidateParams = {
|
||||
invalid: () => boolean;
|
||||
message: string;
|
||||
};
|
||||
|
||||
export default class CalculationStore {
|
||||
$values: ValuesStore;
|
||||
$status: StatusStore;
|
||||
@ -86,15 +91,18 @@ export default class CalculationStore {
|
||||
return this.element(elementName);
|
||||
},
|
||||
|
||||
addError: (message: string) => {
|
||||
if (!this.$validation[elementName]) {
|
||||
this.$validation[elementName] = new Validation({
|
||||
err_key: elementName,
|
||||
err_title: titles[elementName],
|
||||
});
|
||||
validate: ({ invalid, message }: ValidateParams) => {
|
||||
if (invalid()) {
|
||||
if (!this.$validation[elementName]) {
|
||||
this.$validation[elementName] = new Validation({
|
||||
err_key: elementName,
|
||||
err_title: titles[elementName],
|
||||
});
|
||||
}
|
||||
this.$validation[elementName]?.addError(message);
|
||||
} else {
|
||||
this.$validation[elementName]?.removeError(message);
|
||||
}
|
||||
|
||||
return this.$validation[elementName]?.addError(message);
|
||||
},
|
||||
|
||||
cleanErrors: () => {
|
||||
|
||||
@ -6,6 +6,8 @@ type Params = {
|
||||
err_title: string;
|
||||
};
|
||||
|
||||
export type RemoveError = () => void;
|
||||
|
||||
export default class Validation {
|
||||
params: Params;
|
||||
messages: Set<string>;
|
||||
@ -24,24 +26,25 @@ export default class Validation {
|
||||
return [...this.messages];
|
||||
}
|
||||
|
||||
removeError = (message: string) => {
|
||||
this.messages.delete(message);
|
||||
if (this.messages.size === 0) notification.close(this.params.err_key);
|
||||
};
|
||||
|
||||
addError = (message: string) => {
|
||||
this.messages.add(message);
|
||||
|
||||
const removeError = () => {
|
||||
this.messages.delete(message);
|
||||
notification.close(this.params.err_key);
|
||||
};
|
||||
|
||||
notification.error({
|
||||
key: this.params.err_key,
|
||||
message: this.params.err_title,
|
||||
description: message,
|
||||
});
|
||||
|
||||
return removeError;
|
||||
return () => this.removeError(message);
|
||||
};
|
||||
|
||||
clearErrors = () => {
|
||||
notification.close(this.params.err_key);
|
||||
this.messages.clear();
|
||||
};
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user