валидация leaseObjectType
This commit is contained in:
parent
2fb342449d
commit
7647166d9b
@ -1,7 +1,10 @@
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
import * as CRMTypes from '@/graphql/crm.types';
|
||||
import type { ReactionsContext } from '@/process/types';
|
||||
import { autorun } from 'mobx';
|
||||
import { autorun, reaction } from 'mobx';
|
||||
import { pick } from 'radash';
|
||||
|
||||
export default function validationReactions({ store }: ReactionsContext) {
|
||||
export default function validationReactions({ store, apolloClient }: ReactionsContext) {
|
||||
const { $calculation } = store;
|
||||
|
||||
/**
|
||||
@ -20,4 +23,63 @@ export default function validationReactions({ store }: ReactionsContext) {
|
||||
delay: 10,
|
||||
}
|
||||
);
|
||||
|
||||
reaction(
|
||||
() =>
|
||||
pick($calculation.$values.values, [
|
||||
'leaseObjectType',
|
||||
'engineVolume',
|
||||
'engineType',
|
||||
'leaseObjectMotorPower',
|
||||
]),
|
||||
async ({
|
||||
engineType,
|
||||
engineVolume,
|
||||
leaseObjectType: leaseObjectTypeId,
|
||||
leaseObjectMotorPower,
|
||||
}) => {
|
||||
if (!leaseObjectTypeId) {
|
||||
$calculation.element('selectEngineType').unblock();
|
||||
$calculation.element('tbxEngineVolume').unblock();
|
||||
$calculation.element('tbxLeaseObjectMotorPower').unblock();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
const {
|
||||
data: { evo_leasingobject_type },
|
||||
} = await apolloClient.query({
|
||||
query: CRMTypes.GetLeaseObjectTypeDocument,
|
||||
variables: {
|
||||
leaseObjectTypeId,
|
||||
},
|
||||
});
|
||||
|
||||
if (evo_leasingobject_type?.evo_id === '8') {
|
||||
$calculation.element('selectEngineType').resetValue().block();
|
||||
$calculation.element('tbxEngineVolume').resetValue().block();
|
||||
$calculation.element('tbxLeaseObjectMotorPower').resetValue().block();
|
||||
} else {
|
||||
$calculation.element('selectEngineType').unblock();
|
||||
$calculation.element('tbxEngineVolume').unblock();
|
||||
$calculation.element('tbxLeaseObjectMotorPower').unblock();
|
||||
}
|
||||
|
||||
const isNotTrailer =
|
||||
evo_leasingobject_type?.evo_id !== null && evo_leasingobject_type?.evo_id !== '8';
|
||||
|
||||
$calculation.element('tbxEngineVolume').validate({
|
||||
invalid: isNotTrailer && engineVolume <= 0,
|
||||
message: 'Не заполнено поле',
|
||||
});
|
||||
$calculation.element('selectEngineType').validate({
|
||||
invalid: isNotTrailer && !engineType,
|
||||
message: 'Не заполнено поле',
|
||||
});
|
||||
$calculation.element('tbxLeaseObjectMotorPower').validate({
|
||||
invalid: isNotTrailer && leaseObjectMotorPower <= 0,
|
||||
message: 'Не заполнено поле',
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@ -26,9 +26,7 @@ export default class Validation {
|
||||
};
|
||||
|
||||
public addError = (message: string, silent?: boolean) => {
|
||||
this.messages.add(message);
|
||||
|
||||
if (!silent) {
|
||||
if (!silent && !this.messages.has(message)) {
|
||||
notification.error({
|
||||
description: message,
|
||||
key: this.params.err_key,
|
||||
@ -36,6 +34,8 @@ export default class Validation {
|
||||
});
|
||||
}
|
||||
|
||||
this.messages.add(message);
|
||||
|
||||
return () => this.removeError(message);
|
||||
};
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user