Skip to content

Commit

Permalink
Add error message display to form submit
Browse files Browse the repository at this point in the history
  • Loading branch information
renatodellosso committed Dec 30, 2024
1 parent 771fd76 commit 4e0def3
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions components/forms/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export default function Form(props: FormProps) {
const [syncing, setSyncing] = useState(false);
const [changeNumber, setChangeNumber, getChangeNumber] = useDynamicState(0);
const [submitting, setSubmitting] = useState(false);
const [submitErrorMsg, setSubmitErrorMsg] = useState<string>();

const alliance = props.report?.color;

Expand All @@ -57,6 +58,7 @@ export default function Form(props: FormProps) {
.catch((err) => {
console.error("Failed to submit form. Error:", err);
toast.error("Failed to submit form. Please try again. Error:", err);
setSubmitErrorMsg(err.toString());

setSubmitting(false);
});
Expand Down Expand Up @@ -287,6 +289,11 @@ export default function Form(props: FormProps) {
"Submit"
)}
</button>
{submitErrorMsg ? (
<p className="text-red-500 text-lg">{submitErrorMsg}</p>
) : (
<></>
)}
</FormPage>,
);

Expand Down

0 comments on commit 4e0def3

Please sign in to comment.