diff --git a/src/component/HelpFulArticle.js b/src/component/HelpFulArticle.js
index 917a7438e..c6faf220c 100644
--- a/src/component/HelpFulArticle.js
+++ b/src/component/HelpFulArticle.js
@@ -1,197 +1,222 @@
-import React from 'react';
-import { useEffect, useRef, useState } from "react";
-import useBaseUrl from '@docusaurus/useBaseUrl';
-import ThemedImage from '@theme/ThemedImage'
-
+import React from "react";
+import useBaseUrl from "@docusaurus/useBaseUrl";
+import ThemedImage from "@theme/ThemedImage";
export default function HelpFulArticle() {
- const [feedback, SetFeedback] = useState();
- const [feedbackSubmitted, SetFeedbackSubmitted] = useState(false);
- const [isContactFormSubmitted, setIsContactFormSubmitted] = useState(false);
-
- const feedbackSubmit = () => {
- var myHeaders = new Headers();
- myHeaders.append("Content-Type", "application/json");
-
- var raw = JSON.stringify({
- "url": window.location.href,
- });
-
- var requestOptions = {
- method: 'POST',
- headers: myHeaders,
- body: raw,
- redirect: 'follow'
+ const thumbsUpLight = useBaseUrl("/img/thumbsUp_light.svg");
+ const thumbsUpDark = useBaseUrl("/img/thumbsUp_dark.svg");
+ const thumbsDownLight = useBaseUrl("/img/thumbsDown_light.svg");
+ const thumbsDownDark = useBaseUrl("/img/thumbsDown_dark.svg");
+ return (
+
+ );
+}
+class HelpFulArticleClass extends React.Component {
+ constructor(props) {
+ super(props);
+ this.state = {
+ feedback: null,
+ feedbackSubmitted: false,
+ isContactFormSubmitted: false,
+ selectedOption: "",
+ message: "",
+ formMsgError: false,
+ feedbackOptionErr: false
};
-
- fetch(`https://test-backend.lambdatest.com/api/website_feed/thumbs_up`, requestOptions)
- .then(response => response.text())
- .then(result => console.log(result))
- .catch(error => console.log('error', error));
- SetFeedback("")
- SetFeedbackSubmitted(true)
+
+ this.handleThumbsUp = this.handleThumbsUp.bind(this);
+ this.handleThumbsDown = this.handleThumbsDown.bind(this);
+ this.handleOptionChange = this.handleOptionChange.bind(this);
+ this.handleMessageChange = this.handleMessageChange.bind(this);
+ this.handleSubmit = this.handleSubmit.bind(this);
+ this.getCookie = this.getCookie.bind(this);
}
-
-
- const handleOptionChange = (e) => {
- if(e.target.value) {
- setFeedbackOptionErr(false);
- }
- if(e.target.value === 'other') {
- setOtherSelected(true);
- } else {
- setOtherSelected(false);
- setFormMsgError(false);
- }
+
+ getCookie(name) {
+ const cookies = document.cookie.split("; ");
+ const cookie = cookies.find((c) => c.startsWith(name + "="));
+ return cookie ? decodeURIComponent(cookie.split("=")[1]) : null;
}
-
- let form = useRef();
- const [formMsgError, setFormMsgError] = useState(false);
- const [feedbackOptionErr, setFeedbackOptionErr] = useState(false);
- const [otherSelected, setOtherSelected] = useState(false);
- const getContactFormResponse = (res) => {
- setIsContactFormSubmitted(res);
+
+ handleThumbsUp() {
+
+ fetch("https://test-backend.lambdatest.com/api/website_feed/thumbs_up", {
+ method: "POST",
+ headers: { "Content-Type": "application/json" },
+ body: JSON.stringify({ url: window.location.href }),
+ })
+ .then(() => this.setState({ feedbackSubmitted: true }))
+ .catch((error) => console.error("Error:", error));
+ }
+
+ handleThumbsDown() {
+ this.setState({ feedback: "Negative" });
+ }
+
+ handleOptionChange(e) {
+ this.setState({
+ selectedOption: e.target.value,
+ feedbackOptionErr: false,
+ formMsgError: e.target.value !== "other" ? false : this.state.formMsgError
+ });
+ }
+
+ handleMessageChange(e) {
+ this.setState({
+ message: e.target.value,
+ formMsgError: e.target.value.trim() ? false : this.state.formMsgError
+ });
}
- const handleSubmit = (e) => {
+
+ handleSubmit(e) {
e.preventDefault();
- let utmJsonTemp = getCookie("utm")
- const { message, feedback_option } = form.current;
- console.log("feedback_option.value", feedback_option.value)
- let feedBackString = "";
- if(feedback_option.value == '' || feedback_option.value == null) {
- setFeedbackOptionErr(true);
- return
+
+ if (!this.state.selectedOption) {
+ this.setState({ feedbackOptionErr: true });
+ return;
}
- feedBackString = feedback_option.value;
- if(feedback_option.value === 'other') {
- setOtherSelected(true);
- if(message.value == '' || message.value == null) {
- setFormMsgError(true);
- return
- } else {
- setFormMsgError(false);
- feedBackString = message.value;
- }
+
+ if (this.state.selectedOption === "other" && !this.state.message.trim()) {
+ this.setState({ formMsgError: true });
+ return;
}
-
-
- var myHeaders = new Headers();
- myHeaders.append("Content-Type", "application/json");
-
- var raw = JSON.stringify({
- feedback: feedBackString,
- url: window.location.href,
- utm: utmJsonTemp
- });
-
- var requestOptions = {
- method: 'POST',
- headers: myHeaders,
- body: raw,
- redirect: 'follow'
- };
-
- fetch(`https://test-backend.lambdatest.com/api/website_feed/thumbs_down`, requestOptions)
- .then(response => response.text())
- .then(result => {
- getContactFormResponse(true);
- })
- .catch(error => console.log('error', error));
-
- };
- useEffect(() => {
- // console.log('isContactFormSubmitted', isContactFormSubmitted)
- }, [isContactFormSubmitted])
-
- return (
+ fetch("https://test-backend.lambdatest.com/api/website_feed/thumbs_down", {
+ method: "POST",
+ headers: { "Content-Type": "application/json" },
+ body: JSON.stringify({
+ feedback: this.state.selectedOption === "other" ? this.state.message : this.state.selectedOption,
+ url: window.location.href,
+ utm: this.getCookie("utm"),
+ }),
+ })
+ .then(() => this.setState({ isContactFormSubmitted: true }))
+ .catch((error) => console.error("Error:", error));
+ }
+
+ render() {
+ const {
+ feedback,
+ feedbackSubmitted,
+ isContactFormSubmitted,
+ selectedOption,
+ message,
+ formMsgError,
+ feedbackOptionErr
+ } = this.state;
+
+ const {
+ thumbsUpLight,
+ thumbsUpDark,
+ thumbsDownLight,
+ thumbsDownDark
+ } = this.props;
+
+ const otherSelected = selectedOption === "other";
+
+ return (
-
-
-
+
-
Do you find this helpful?
- {!feedbackSubmitted && !isContactFormSubmitted &&
-
-
-
-
+ ) : (
+
+
Thanks for your feedback!
+
+ )}
+
+
-
-
- {feedback == "Negative" && !isContactFormSubmitted &&
-
+
+ {feedback === "Negative" && !isContactFormSubmitted && (
+
- }
-
-
+ ))}
+
+
+ Other (please tell us more below)
+
+
+ {feedbackOptionErr &&
Please select an option.
}
+ {otherSelected && (
+ <>
+
+ {formMsgError &&
Please write your feedback
}
+ >
+ )}
+
+ Submit
+
+
+ )}
- );
-}
+ );
+ }
+}
\ No newline at end of file