modify all validation reactions to prev commit style
This commit is contained in:
parent
7a9d8f5b94
commit
19a0ff0f68
@ -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();
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
@ -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();
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
@ -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();
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
@ -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();
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
@ -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();
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
@ -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();
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
@ -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();
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
@ -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();
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
@ -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();
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user