diff --git a/apps/web/Components/Calculation/Output/Validation.jsx b/apps/web/Components/Calculation/Output/Validation.jsx index 052a375..3e775bf 100644 --- a/apps/web/Components/Calculation/Output/Validation.jsx +++ b/apps/web/Components/Calculation/Output/Validation.jsx @@ -23,73 +23,34 @@ const AlertWrapper = styled(Box)` margin: 0 0 5px 0; `; +function getAlerts(errors, title, $process) { + return errors.map(({ key, message }) => ( + + + + )); +} + function getElementsErrors({ $calculation, $process }) { return Object.values($calculation.$validation).map((validation) => { const elementErrors = validation.getErrors(); const elementTitle = validation.params.err_title; - return elementErrors.map(({ key, message }) => ( - - - - )); + return getAlerts(elementErrors, elementTitle, $process); }); } -function getPaymentsTableErrors({ $process, $tables }) { - const { payments } = $tables; - const errors = payments.validation.getErrors(); - const title = payments.validation.params.err_title; +function getTableErrors(tableName, { $process, $tables }) { + const table = $tables[tableName]; + const errors = table.validation.getErrors(); + const title = table.validation.params.err_title; - return errors.map(({ key, message }) => ( - - - - )); -} - -function getInsuranceTableErrors({ $process, $tables }) { - const { insurance } = $tables; - const errors = insurance.validation.getErrors(); - const title = insurance.validation.params.err_title; - - return errors.map(({ key, message }) => ( - - - - )); -} - -function getFingapTableErrors({ $process, $tables }) { - const { fingap } = $tables; - const errors = fingap.validation.getErrors(); - const title = fingap.validation.params.err_title; - - return errors.map(({ key, message }) => ( - - - - )); + return getAlerts(errors, title, $process); } const Errors = observer(() => { @@ -108,9 +69,9 @@ const Errors = observer(() => { } const elementsErrors = getElementsErrors(store); - const paymentsErrors = getPaymentsTableErrors(store); - const insuranceErrors = getInsuranceTableErrors(store); - const fingapErrors = getFingapTableErrors(store); + const paymentsErrors = getTableErrors('payments', store); + const insuranceErrors = getTableErrors('insurance', store); + const fingapErrors = getTableErrors('fingap', store); const errors = [...elementsErrors, ...paymentsErrors, ...insuranceErrors, ...fingapErrors];