24 lines
716 B
TypeScript
24 lines
716 B
TypeScript
import type { Elements } from '@/Components/Calculation/config/map/values';
|
|
import { useStore } from '@/stores/hooks';
|
|
import type { ComponentProps, ReactNode } from 'react';
|
|
import type { Form } from 'ui/elements';
|
|
|
|
export function useValidation(elementName: Elements): {
|
|
help: ReactNode;
|
|
validateStatus: ComponentProps<(typeof Form)['Item']>['validateStatus'];
|
|
} {
|
|
const { $calculation, $process } = useStore();
|
|
const hasErrors = $calculation.$validation?.[elementName]?.hasErrors;
|
|
if (hasErrors) {
|
|
return {
|
|
help: 'Некорректные данные',
|
|
validateStatus: $process.has('Unlimited') ? 'warning' : 'error',
|
|
};
|
|
}
|
|
|
|
return {
|
|
help: '',
|
|
validateStatus: '',
|
|
};
|
|
}
|