Skip to content

Commit

Permalink
fix: disable buttons on post
Browse files Browse the repository at this point in the history
fixes #76
  • Loading branch information
drodil committed Jul 31, 2023
1 parent 585fc1c commit 8dce2f4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
13 changes: 11 additions & 2 deletions plugins/qeta/src/components/AskForm/AskForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export const AskForm = (props: {
const navigate = useNavigate();
const analytics = useAnalytics();
const [entityRef, setEntityRef] = React.useState(entity);
const [posting, setPosting] = React.useState(false);
const [values, setValues] = React.useState(getDefaultValues());
const [error, setError] = React.useState(false);

Expand All @@ -102,6 +103,7 @@ export const AskForm = (props: {
});

const postQuestion = (data: QuestionForm) => {
setPosting(true);
if (id) {
qetaApi
.updateQuestion(id, formToRequest(data, images))
Expand All @@ -120,7 +122,10 @@ export const AskForm = (props: {
navigate(`${base_path}/qeta/questions/${q.id}`);
}
})
.catch(_e => setError(true));
.catch(_e => {
setError(true);
setPosting(false);
});
return;
}
qetaApi
Expand All @@ -138,7 +143,10 @@ export const AskForm = (props: {
navigate(`${base_path}/qeta/questions/${q.id}`);
}
})
.catch(_e => setError(true));
.catch(_e => {
setError(true);
setPosting(false);
});
};

useEffect(() => {
Expand Down Expand Up @@ -217,6 +225,7 @@ export const AskForm = (props: {
color="primary"
type="submit"
variant="contained"
disabled={posting}
className={`qetaAskFormSubmitBtn ${styles.postButton}`}
>
{id ? 'Save' : 'Post'}
Expand Down
5 changes: 5 additions & 0 deletions plugins/qeta/src/components/CommentSection/CommentSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const CommentSection = (props: {
const { answer, question, onCommentPost, onCommentDelete } = props;
const analytics = useAnalytics();
const qetaApi = useApi(qetaApiRef);
const [posting, setPosting] = React.useState(false);
const [formVisible, setFormVisible] = useState(false);
const {
handleSubmit,
Expand All @@ -27,11 +28,13 @@ export const CommentSection = (props: {
} = useForm<{ content: string }>({});

const postComment = (data: { content: string }) => {
setPosting(true);
if (answer) {
qetaApi.commentAnswer(question.id, answer.id, data.content).then(a => {
setFormVisible(false);
analytics.captureEvent('comment', 'answer');
reset();
setPosting(false);
onCommentPost(question, a);
});
return;
Expand All @@ -41,6 +44,7 @@ export const CommentSection = (props: {
setFormVisible(false);
analytics.captureEvent('comment', 'question');
reset();
setPosting(false);
onCommentPost(q);
});
};
Expand Down Expand Up @@ -96,6 +100,7 @@ export const CommentSection = (props: {
className="qetaCommentBtn"
type="submit"
color="primary"
disabled={posting}
>
Post
</Button>
Expand Down

0 comments on commit 8dce2f4

Please sign in to comment.