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_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_MATOMO_ID=135
REACT_APP_SENTRY_DSN=https://aa80453ff4d54b9a9c1b49e79060498a@sentry.pir-test.eu/14 REACT_APP_SENTRY_DSN=https://aa80453ff4d54b9a9c1b49e79060498a@sentry.pir-test.eu/14
...@@ -20,6 +20,7 @@ export const fetch = async ( ...@@ -20,6 +20,7 @@ export const fetch = async (
body, body,
method, method,
headers, headers,
redirect: "follow",
}); });
if (!!expectedStatus && response.status !== expectedStatus) { if (!!expectedStatus && response.status !== expectedStatus) {
......
...@@ -46,6 +46,8 @@ const AddAnnouncementForm = ({ className }) => { ...@@ -46,6 +46,8 @@ const AddAnnouncementForm = ({ className }) => {
}; };
const onAdd = async (evt) => { const onAdd = async (evt) => {
evt.preventDefault();
let preventAction = false; let preventAction = false;
const payload = { const payload = {
content: text, content: text,
...@@ -82,7 +84,7 @@ const AddAnnouncementForm = ({ className }) => { ...@@ -82,7 +84,7 @@ const AddAnnouncementForm = ({ className }) => {
}; };
return ( return (
<div className={className}> <form className={className} onSubmit={onAdd}>
{addingError && ( {addingError && (
<ErrorMessage> <ErrorMessage>
Při přidávání oznámení došlo k problému: {addingError}. Při přidávání oznámení došlo k problému: {addingError}.
...@@ -150,7 +152,7 @@ const AddAnnouncementForm = ({ className }) => { ...@@ -150,7 +152,7 @@ const AddAnnouncementForm = ({ className }) => {
</div> </div>
<Button <Button
onClick={onAdd} type="submit"
className="text-sm mt-4" className="text-sm mt-4"
hoverActive hoverActive
loading={adding} loading={adding}
...@@ -159,7 +161,7 @@ const AddAnnouncementForm = ({ className }) => { ...@@ -159,7 +161,7 @@ const AddAnnouncementForm = ({ className }) => {
> >
Přidat oznámení Přidat oznámení
</Button> </Button>
</div> </form>
); );
}; };
......
...@@ -74,6 +74,8 @@ const AddPostForm = ({ className, canAddProposal }) => { ...@@ -74,6 +74,8 @@ const AddPostForm = ({ className, canAddProposal }) => {
}; };
const onAdd = async (evt) => { const onAdd = async (evt) => {
evt.preventDefault();
if (!!text) { if (!!text) {
if (!error) { if (!error) {
const result = await (type === "post" ? addPost : addProposal).run({ const result = await (type === "post" ? addPost : addProposal).run({
...@@ -125,7 +127,7 @@ const AddPostForm = ({ className, canAddProposal }) => { ...@@ -125,7 +127,7 @@ const AddPostForm = ({ className, canAddProposal }) => {
"p-4 lg:p-8 " + (showAddConfirm || !expanded ? "hidden" : "") "p-4 lg:p-8 " + (showAddConfirm || !expanded ? "hidden" : "")
} }
> >
<div className="space-y-4"> <form className="space-y-4" onSubmit={onAdd}>
{apiError && is429ApiError && ( {apiError && is429ApiError && (
<div className="alert alert--warning"> <div className="alert alert--warning">
<i className="alert__icon ico--clock text-lg" /> <i className="alert__icon ico--clock text-lg" />
...@@ -203,7 +205,7 @@ const AddPostForm = ({ className, canAddProposal }) => { ...@@ -203,7 +205,7 @@ const AddPostForm = ({ className, canAddProposal }) => {
<div className="space-x-4"> <div className="space-x-4">
<Button <Button
onClick={onAdd} type="submit"
disabled={error || addingPost || addingProposal} disabled={error || addingPost || addingProposal}
loading={addingPost || addingProposal} loading={addingPost || addingProposal}
fullwidth fullwidth
...@@ -227,7 +229,7 @@ const AddPostForm = ({ className, canAddProposal }) => { ...@@ -227,7 +229,7 @@ const AddPostForm = ({ className, canAddProposal }) => {
. .
</span> </span>
</div> </div>
</div> </form>
</CardBody> </CardBody>
</Card> </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