feat: error handling for the tables and wizards

This commit is contained in:
Taranto 2020-10-30 17:51:57 +00:00 committed by Josh Harvey
parent 7d5d963685
commit 96b8e3d9a2
10 changed files with 55 additions and 44 deletions

View file

@ -34,10 +34,15 @@ const ActionCol = ({ disabled, editing }) => {
onToggle,
toggleWidth,
forceAdd,
clearError,
actionColSize
} = useContext(TableCtx)
const disableEdit = disabled || (disableRowEdit && disableRowEdit(values))
const cancel = () => {
clearError()
resetForm()
}
return (
<>
@ -51,7 +56,7 @@ const ActionCol = ({ disabled, editing }) => {
Save
</Link>
{!forceAdd && (
<Link color="secondary" onClick={resetForm}>
<Link color="secondary" onClick={cancel}>
Cancel
</Link>
)}
@ -170,6 +175,7 @@ const ERow = ({ editing, disabled, lastOfGroup }) => {
elements,
enableEdit,
enableDelete,
error,
enableToggle,
rowSize,
stripeWhen
@ -199,13 +205,18 @@ const ERow = ({ editing, disabled, lastOfGroup }) => {
}
const touchedErrors = R.pick(R.keys(touched), errors)
const hasTouchedErrors = touchedErrors && R.keys(touchedErrors).length > 0
const hasErrors = hasTouchedErrors || !!error
const errorMessage =
error || (touchedErrors && R.values(touchedErrors).join(', '))
return (
<Tr
className={classnames(classNames)}
size={rowSize}
error={touchedErrors && R.keys(touchedErrors).length > 0}
errorMessage={touchedErrors && R.values(touchedErrors).join(', ')}>
error={editing && hasErrors}
errorMessage={errorMessage}>
{innerElements.map((it, idx) => {
return (
<ECol