Skip to content

Commit

Permalink
feat: do not reset the form when a backend error happens
Browse files Browse the repository at this point in the history
  • Loading branch information
erral committed Sep 30, 2022
1 parent 479300b commit ff33951
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/components/FormView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const FormView = ({
data,
onSubmit,
resetFormState,
resetFormOnError,
captcha,
}) => {
const intl = useIntl();
Expand Down Expand Up @@ -74,7 +75,7 @@ const FormView = ({
{intl.formatMessage(messages.error)}
</Message.Header>
<p>{formState.error}</p>
<Button secondary type="clear" onClick={resetFormState}>
<Button secondary type="clear" onClick={resetFormOnError}>
{intl.formatMessage(messages.reset)}
</Button>
</Message>
Expand Down
5 changes: 5 additions & 0 deletions src/components/View.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ const View = ({ data, id, path }) => {
setFormState({ type: FORM_STATES.normal });
};

const resetFormOnError = () => {
setFormState({ type: FORM_STATES.normal });
};

const captcha = new Captcha({
captchaToken,
captcha: data.captcha,
Expand Down Expand Up @@ -231,6 +235,7 @@ const View = ({ data, id, path }) => {
data={data}
onSubmit={submit}
resetFormState={resetFormState}
resetFormOnError={resetFormOnError}
/>
);
};
Expand Down

0 comments on commit ff33951

Please sign in to comment.