diff --git a/src/client/stores/CalculationStore/Effects/autorun.ts b/src/client/stores/CalculationStore/Effects/autorun.ts index 24ccb77..c425bd7 100644 --- a/src/client/stores/CalculationStore/Effects/autorun.ts +++ b/src/client/stores/CalculationStore/Effects/autorun.ts @@ -199,115 +199,6 @@ const autorunEffects: IAutorunEffect[] = [ } } }, - - calculationStore => () => { - const { leaseObjectType: leaseObjectTypeId } = calculationStore.values; - - calculationStore.setValidation('tbxCountSeats', true); - calculationStore.setValidation('tbxMaxMass', true); - - if (!leaseObjectTypeId) { - return; - } - - const leaseObjectType = calculationStore.options.selectLeaseObjectType?.find( - x => x.evo_leasingobject_typeid === leaseObjectTypeId, - ); - - if (leaseObjectType) { - switch (leaseObjectType.evo_id) { - case '1': { - calculationStore.setValue('leaseObjectCategory', 100000001); - calculationStore.setStatus( - 'selectLeaseObjectCategory', - ElementStatus.Disabled, - ); - - const { countSeats } = calculationStore.values; - if (countSeats && countSeats >= 9) { - calculationStore.setValidation('tbxCountSeats', false); - openNotification({ - type: 'error', - title: 'Ошибка', - description: 'Количество мест должно быть меньше 9', - })(); - } - break; - } - - case '2': { - calculationStore.setStatus( - 'selectLeaseObjectCategory', - ElementStatus.Default, - ); - calculationStore.setFilter('selectLeaseObjectCategory', options => - options.filter(x => x.value === 100000001 || x.value === 100000002), - ); - - const { maxMass } = calculationStore.values; - if (!maxMass) { - calculationStore.setValidation('tbxMaxMass', false); - openNotification({ - type: 'error', - title: 'Ошибка', - description: - 'Разрешенная максимальная масса должна быть больше 0', - })(); - } - break; - } - - case '4': - case '5': { - calculationStore.setStatus( - 'selectLeaseObjectCategory', - ElementStatus.Default, - ); - calculationStore.setFilter('selectLeaseObjectCategory', options => - options.filter(x => x.value === 100000001 || x.value === 100000003), - ); - - const { countSeats } = calculationStore.values; - if (countSeats <= 8) { - calculationStore.setValidation('tbxCountSeats', false); - openNotification({ - type: 'error', - title: 'Ошибка', - description: 'Кол-во мест должно быть больше 8', - })(); - } - break; - } - - case '3': - case '7': { - calculationStore.setValue('leaseObjectCategory', 100000002); - calculationStore.setStatus( - 'selectLeaseObjectCategory', - ElementStatus.Disabled, - ); - break; - } - - case '8': { - calculationStore.setValue('leaseObjectCategory', 100000004); - calculationStore.setStatus( - 'selectLeaseObjectCategory', - ElementStatus.Disabled, - ); - break; - } - - default: { - calculationStore.setStatus( - 'selectLeaseObjectCategory', - ElementStatus.Default, - ); - break; - } - } - } - }, ]; export default autorunEffects; diff --git a/src/client/stores/CalculationStore/Effects/reactions/otherReactions.ts b/src/client/stores/CalculationStore/Effects/reactions/otherReactions.ts index 64ec2be..b036363 100644 --- a/src/client/stores/CalculationStore/Effects/reactions/otherReactions.ts +++ b/src/client/stores/CalculationStore/Effects/reactions/otherReactions.ts @@ -1643,7 +1643,7 @@ const reactionEffects: IReactionEffect[] = [ } }, }), - + calculationStore => ({ expression: () => { const { selectLeaseObjectCategory } = calculationStore.filters; @@ -1660,6 +1660,127 @@ const reactionEffects: IReactionEffect[] = [ } }, }), + + calculationStore => ({ + expression: () => { + const { + leaseObjectType: leaseObjectTypeId, + countSeats, + maxMass, + } = calculationStore.values; + return { leaseObjectTypeId, countSeats, maxMass }; + }, + effect: ({ leaseObjectTypeId, countSeats, maxMass }) => { + calculationStore.setValidation('tbxCountSeats', undefined); + calculationStore.setValidation('tbxMaxMass', undefined); + + if (!leaseObjectTypeId) { + return; + } + + const leaseObjectType = calculationStore.options.selectLeaseObjectType?.find( + x => x.evo_leasingobject_typeid === leaseObjectTypeId, + ); + + if (leaseObjectType) { + switch (leaseObjectType.evo_id) { + case '1': { + calculationStore.setValue('leaseObjectCategory', 100000001); + calculationStore.setStatus( + 'selectLeaseObjectCategory', + ElementStatus.Disabled, + ); + + const { countSeats } = calculationStore.values; + if (countSeats && countSeats >= 9) { + calculationStore.setValidation('tbxCountSeats', false); + openNotification({ + type: 'error', + title: 'Ошибка', + description: 'Количество мест должно быть меньше 9', + })(); + } + break; + } + + case '2': { + calculationStore.setStatus( + 'selectLeaseObjectCategory', + ElementStatus.Default, + ); + calculationStore.setFilter('selectLeaseObjectCategory', options => + options.filter( + x => x.value === 100000001 || x.value === 100000002, + ), + ); + + const { maxMass } = calculationStore.values; + if (!maxMass) { + calculationStore.setValidation('tbxMaxMass', false); + openNotification({ + type: 'error', + title: 'Ошибка', + description: + 'Разрешенная максимальная масса должна быть больше 0', + })(); + } + break; + } + + case '4': + case '5': { + calculationStore.setStatus( + 'selectLeaseObjectCategory', + ElementStatus.Default, + ); + calculationStore.setFilter('selectLeaseObjectCategory', options => + options.filter( + x => x.value === 100000001 || x.value === 100000003, + ), + ); + + const { countSeats } = calculationStore.values; + if (countSeats <= 8) { + calculationStore.setValidation('tbxCountSeats', false); + openNotification({ + type: 'error', + title: 'Ошибка', + description: 'Кол-во мест должно быть больше 8', + })(); + } + break; + } + + case '3': + case '7': { + calculationStore.setValue('leaseObjectCategory', 100000002); + calculationStore.setStatus( + 'selectLeaseObjectCategory', + ElementStatus.Disabled, + ); + break; + } + + case '8': { + calculationStore.setValue('leaseObjectCategory', 100000004); + calculationStore.setStatus( + 'selectLeaseObjectCategory', + ElementStatus.Disabled, + ); + break; + } + + default: { + calculationStore.setStatus( + 'selectLeaseObjectCategory', + ElementStatus.Default, + ); + break; + } + } + } + }, + }), ]; export default reactionEffects;