modify all validation reactions to prev commit style

This commit is contained in:
vchikalkin 2023-04-11 12:37:49 +03:00
parent 7a9d8f5b94
commit 19a0ff0f68
9 changed files with 29 additions and 14 deletions

View File

@ -16,16 +16,17 @@ export default function reactions(context: ProcessContext) {
reaction(
() => $calculation.$values.getValues(['product', 'saleBonus']),
async (values) => {
helper.removeErrors();
const validationResult = await validationSchema.safeParseAsync(values);
if (!validationResult.success) {
if (validationResult.success === false) {
validationResult.error.errors.forEach(({ path, message }) => {
(path as Elements[]).forEach((elementName) => {
const removeError = $calculation.element(elementName).setError({ key, message });
if (removeError) helper.add(removeError);
});
});
} else {
helper.removeErrors();
}
},
{

View File

@ -16,16 +16,17 @@ export default function reactions(context: ProcessContext) {
reaction(
() => $calculation.$values.getValues(['parmentsDecreasePercent', 'tarif']),
async (values) => {
helper.removeErrors();
const validationResult = await validationSchema.safeParseAsync(values);
if (!validationResult.success) {
if (validationResult.success === false) {
validationResult.error.errors.forEach(({ path, message }) => {
(path as Elements[]).forEach((elementName) => {
const removeError = $calculation.element(elementName).setError({ key, message });
if (removeError) helper.add(removeError);
});
});
} else {
helper.removeErrors();
}
},
{

View File

@ -538,13 +538,15 @@ export function validation(context: ProcessContext) {
validationHelper.removeErrors();
const validationResult = await validationSchema.safeParseAsync(values);
if (!validationResult.success) {
if (validationResult.success === false) {
validationResult.error.errors.forEach(({ path, message }) => {
(path as Elements[]).forEach((elementName) => {
const removeError = $calculation.element(elementName).setError({ key, message });
if (removeError) validationHelper.add(removeError);
});
});
} else {
validationHelper.removeErrors();
}
},
{

View File

@ -1,3 +1,4 @@
/* eslint-disable sonarjs/cognitive-complexity */
import type { ProcessContext } from '../types';
import { createValidationSchema } from './validation';
import type { Elements } from '@/Components/Calculation/config/map/values';
@ -298,7 +299,7 @@ export function validation(context: ProcessContext) {
helper.removeErrors();
const validationResult = await validationSchema.safeParseAsync(values);
if (!validationResult.success) {
if (validationResult.success === false) {
validationResult.error.errors.forEach(({ path, message }) => {
(path as Array<Elements & 'insurance'>).forEach((elementName) => {
if (elementName === 'insurance') {
@ -310,6 +311,8 @@ export function validation(context: ProcessContext) {
}
});
});
} else {
helper.removeErrors();
}
},
{

View File

@ -46,16 +46,17 @@ export default function reactions(context: ProcessContext) {
'leaseObjectCategory',
]),
async (values) => {
helper.removeErrors();
const validationResult = await validationSchema.safeParseAsync(values);
if (!validationResult.success) {
if (validationResult.success === false) {
validationResult.error.errors.forEach(({ path, message }) => {
(path as Elements[]).forEach((elementName) => {
const removeError = $calculation.element(elementName).setError({ key, message });
if (removeError) helper.add(removeError);
});
});
} else {
helper.removeErrors();
}
},
{

View File

@ -1,3 +1,4 @@
/* eslint-disable sonarjs/cognitive-complexity */
import { createValidationSchema } from '../validation';
import type { Elements } from '@/Components/Calculation/config/map/values';
import type { ProcessContext } from '@/process/types';
@ -34,7 +35,7 @@ export default function reactions(context: ProcessContext) {
helper.removeErrors();
const validationResult = await validationSchema.safeParseAsync(values);
if (!validationResult.success) {
if (validationResult.success === false) {
validationResult.error.errors.forEach(({ path, message }) => {
(path as Array<Elements & 'payments'>).forEach((elementName) => {
if (elementName === 'payments') {
@ -46,6 +47,8 @@ export default function reactions(context: ProcessContext) {
}
});
});
} else {
helper.removeErrors();
}
},
{

View File

@ -25,16 +25,17 @@ export default function reactions(context: ProcessContext) {
'subsidySum',
]),
async (values) => {
helper.removeErrors();
const validationResult = await validationSchema.safeParseAsync(values);
if (!validationResult.success) {
if (validationResult.success === false) {
validationResult.error.errors.forEach(({ path, message }) => {
(path as Elements[]).forEach((elementName) => {
const removeError = $calculation.element(elementName).setError({ key, message });
if (removeError) helper.add(removeError);
});
});
} else {
helper.removeErrors();
}
},
{

View File

@ -54,13 +54,15 @@ export default function reactions(context: ProcessContext) {
helper.removeErrors();
const validationResult = await validationSchema.safeParseAsync(values);
if (!validationResult.success) {
if (validationResult.success === false) {
validationResult.error.errors.forEach(({ path, message }) => {
(path as Elements[]).forEach((elementName) => {
const removeError = $calculation.element(elementName).setError({ key, message });
if (removeError) helper.add(removeError);
});
});
} else {
helper.removeErrors();
}
},
{

View File

@ -259,16 +259,17 @@ export function validation(context: ProcessContext) {
'vin',
]),
async (values) => {
helper.removeErrors();
const validationResult = await validationSchema.safeParseAsync(values);
if (!validationResult.success) {
if (validationResult.success === false) {
validationResult.error.errors.forEach(({ path, message }) => {
(path as Elements[]).forEach((elementName) => {
const removeError = $calculation.element(elementName).setError({ key, message });
if (removeError) helper.add(removeError);
});
});
} else {
helper.removeErrors();
}
},
{