Skip to content
Snippets Groups Projects
Commit 9004a89b authored by xaralis's avatar xaralis
Browse files

feat: use form onSubmit over button clicks

parent 39c6d104
No related branches found
No related tags found
No related merge requests found
Pipeline #2079 passed
REACT_APP_STYLEGUIDE_URL=https://styleguide.pir-test.eu/2.3.3
REACT_APP_API_BASE_URL=https://cf2021.pir-test.eu/api
REACT_APP_API_BASE_URL=https://cf2021.pirati.cz/api
REACT_APP_MATOMO_ID=135
REACT_APP_SENTRY_DSN=https://aa80453ff4d54b9a9c1b49e79060498a@sentry.pir-test.eu/14
......@@ -20,6 +20,7 @@ export const fetch = async (
body,
method,
headers,
redirect: "follow",
});
if (!!expectedStatus && response.status !== expectedStatus) {
......
......@@ -46,6 +46,8 @@ const AddAnnouncementForm = ({ className }) => {
};
const onAdd = async (evt) => {
evt.preventDefault();
let preventAction = false;
const payload = {
content: text,
......@@ -82,7 +84,7 @@ const AddAnnouncementForm = ({ className }) => {
};
return (
<div className={className}>
<form className={className} onSubmit={onAdd}>
{addingError && (
<ErrorMessage>
Při přidávání oznámení došlo k problému: {addingError}.
......@@ -150,7 +152,7 @@ const AddAnnouncementForm = ({ className }) => {
</div>
<Button
onClick={onAdd}
type="submit"
className="text-sm mt-4"
hoverActive
loading={adding}
......@@ -159,7 +161,7 @@ const AddAnnouncementForm = ({ className }) => {
>
Přidat oznámení
</Button>
</div>
</form>
);
};
......
......@@ -74,6 +74,8 @@ const AddPostForm = ({ className, canAddProposal }) => {
};
const onAdd = async (evt) => {
evt.preventDefault();
if (!!text) {
if (!error) {
const result = await (type === "post" ? addPost : addProposal).run({
......@@ -125,7 +127,7 @@ const AddPostForm = ({ className, canAddProposal }) => {
"p-4 lg:p-8 " + (showAddConfirm || !expanded ? "hidden" : "")
}
>
<div className="space-y-4">
<form className="space-y-4" onSubmit={onAdd}>
{apiError && is429ApiError && (
<div className="alert alert--warning">
<i className="alert__icon ico--clock text-lg" />
......@@ -203,7 +205,7 @@ const AddPostForm = ({ className, canAddProposal }) => {
<div className="space-x-4">
<Button
onClick={onAdd}
type="submit"
disabled={error || addingPost || addingProposal}
loading={addingPost || addingProposal}
fullwidth
......@@ -227,7 +229,7 @@ const AddPostForm = ({ className, canAddProposal }) => {
.
</span>
</div>
</div>
</form>
</CardBody>
</Card>
);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment