Skip to content

Commit

Permalink
fix: remain in form when there's errors on sending form
Browse files Browse the repository at this point in the history
  • Loading branch information
giuliaghisini committed Feb 28, 2024
1 parent 9ab6221 commit c6fe827
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/components/FormView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ const FormView = ({
return text;
};

const submit = (e) => {
resetFormOnError();
onSubmit(e);
};

return (
<div className="block form">
<div className="public-ui">
Expand All @@ -86,17 +91,7 @@ const FormView = ({
{data.description && (
<p className="description">{data.description}</p>
)}
{formState.error ? (
<Message error role="alert">
<Message.Header as="h4">
{intl.formatMessage(messages.error)}
</Message.Header>
<p>{formState.error}</p>
<Button secondary type="clear" onClick={resetFormOnError}>
{intl.formatMessage(messages.reset)}
</Button>
</Message>
) : formState.result ? (
{formState.result ? (
<Message positive role="alert">
{/* Custom message */}
{data.send_message ? (
Expand All @@ -123,7 +118,7 @@ const FormView = ({
<Form
id={id}
loading={formState.loading}
onSubmit={onSubmit}
onSubmit={submit}
autoComplete="off"
method="post"
>
Expand Down Expand Up @@ -203,6 +198,15 @@ const FormView = ({
<p>{intl.formatMessage(messages.empty_values)}</p>
</Message>
)}

{formState.error && (
<Message error role="alert">
<Message.Header as="h4">
{intl.formatMessage(messages.error)}
</Message.Header>
<p>{formState.error}</p>
</Message>
)}
<Grid.Row centered className="row-padded-top">
<Grid.Column textAlign="center">
{data?.show_cancel && (
Expand Down

0 comments on commit c6fe827

Please sign in to comment.