Skip to content

Commit

Permalink
Apply review
Browse files Browse the repository at this point in the history
  • Loading branch information
djhi committed Feb 15, 2021
1 parent adb836a commit 54a08a2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
22 changes: 14 additions & 8 deletions packages/ra-ui-materialui/src/form/FormTabHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as React from 'react';
import { useEffect } from 'react';
import { Link, useLocation } from 'react-router-dom';
import MuiTab from '@material-ui/core/Tab';
import classnames from 'classnames';
Expand All @@ -18,14 +19,19 @@ export const FormTabHeader = ({
const formGroup = useFormGroup(value);
const form = useForm();
const [showError, setShowError] = React.useState(false);
form.subscribe(
state => {
if (!showError && (state.submitting || state.submitFailed)) {
setShowError(true);
}
},
{ submitting: true, submitFailed: true }
);

useEffect(() => {
const unsubscribe = form.subscribe(
state => {
if (!showError && (state.submitting || state.submitFailed)) {
setShowError(true);
}
},
{ submitting: true, submitFailed: true }
);

return unsubscribe;
}, [form, showError]);

return (
<MuiTab
Expand Down
1 change: 1 addition & 0 deletions packages/ra-ui-materialui/src/form/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import TabbedForm, { TabbedFormProps } from './TabbedForm';
import TabbedFormTabs from './TabbedFormTabs';
import Toolbar, { ToolbarProps } from './Toolbar';
import getFormInitialValues from './getFormInitialValues';
export * from './FormTabHeader';

export type {
SimpleFormProps,
Expand Down

0 comments on commit 54a08a2

Please sign in to comment.