Skip to content

Commit

Permalink
🍀 fix(QandA):input getting cleared and auto closing the pop after the…
Browse files Browse the repository at this point in the history
… submission (#1046)

input should not get cleared if validaion is not matched and also question pop up should be closed if question is uploaded successfully

fix issue #977
  • Loading branch information
ayushpatel1248 authored Jun 14, 2024
1 parent 7b0f3d4 commit 89a7d74
Showing 1 changed file with 30 additions and 8 deletions.
38 changes: 30 additions & 8 deletions frontend/src/pages/Q&A/Q&A.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import "./Ques.scss";
import Joi from "joi-browser";
import Loader from "../../components/util/Loader/index";
import { SimpleToast } from "../../components/util/Toast";
import { getAllQuestion, uploadData, upvote, downvote } from "../../service/Faq";
import {
getAllQuestion,
uploadData,
upvote,
downvote,
} from "../../service/Faq";
import { showToast, hideToast } from "../../service/toastService";

function Ques(props) {
Expand Down Expand Up @@ -109,6 +114,7 @@ function Ques(props) {
});
setFormErrors({});
setCheckedState(new Array(Tags.length).fill(false));
setButtonPressed(false);
})
.catch(() => {
setIsUploadingData(false);
Expand All @@ -129,7 +135,7 @@ function Ques(props) {
await upvote(questionId, setToast);
fetchQuestions();
};

const handleDownvote = async (questionId) => {
await downvote(questionId, setToast);
fetchQuestions();
Expand Down Expand Up @@ -164,7 +170,10 @@ function Ques(props) {
<p>Created At {new Date(item.createdAt).toLocaleString()}</p>
</div>
<div>
<button className="vote-btn" onClick={() => handleUpvote(item._id)}>
<button
className="vote-btn"
onClick={() => handleUpvote(item._id)}
>
👍{item.upvotes}
</button>
<button
Expand Down Expand Up @@ -197,7 +206,10 @@ function Ques(props) {
}
>
<form className="question_form" onSubmit={handleSubmit}>
<button className="close-popup" onClick={() => setButtonPressed(false)}>
<button
className="close-popup"
onClick={() => setButtonPressed(false)}
>
X
</button>
<h3
Expand Down Expand Up @@ -228,7 +240,9 @@ function Ques(props) {
onChange={handleChange}
/>
<i className="fas fa-heading"></i>
<div className={`${style["validation"]} validation d-sm-none d-md-block`}>
<div
className={`${style["validation"]} validation d-sm-none d-md-block`}
>
{formerrors["title"] ? (
<div>* {formerrors["title"]}</div>
) : (
Expand All @@ -254,8 +268,13 @@ function Ques(props) {
value={formdata.description}
onChange={handleChange}
/>
<i className="fas fa-envelope" style={{ marginTop: 27 }}></i>
<div className={`${style["validation"]} validation d-sm-none d-md-block`}>
<i
className="fas fa-envelope"
style={{ marginTop: 27 }}
></i>
<div
className={`${style["validation"]} validation d-sm-none d-md-block`}
>
{formerrors["body"] ? (
<div>* {formerrors["body"]}</div>
) : (
Expand Down Expand Up @@ -322,7 +341,10 @@ function Ques(props) {
</div>
</div>

<div className={style["submit-btn"]} style={{ justifyContent: "space-around", marginBottom: "1rem" }}>
<div
className={style["submit-btn"]}
style={{ justifyContent: "space-around", marginBottom: "1rem" }}
>
<div className="data-loader">
{isUploadingData ? (
<Loader />
Expand Down

0 comments on commit 89a7d74

Please sign in to comment.