diff --git a/components/feedback.tsx b/components/feedback.tsx new file mode 100644 index 000000000..fa8bb512b --- /dev/null +++ b/components/feedback.tsx @@ -0,0 +1,104 @@ +import React, { useState, useEffect } from "react"; + +const FeedbackComponent = ({ pageUrl }: { pageUrl: string }) => { + const [feedback, setFeedback] = useState(""); + const [isFeedbackSubmitted, setIsFeedbackSubmitted] = useState(false); + const [isInputVisible, setInputVisible] = useState(false); + const [feedbackType, setFeedbackType] = useState(""); // State to track feedback type + + const resetState = () => { + setFeedback(""); + setIsFeedbackSubmitted(false); + setInputVisible(false); + setFeedbackType(""); + }; + + useEffect(() => { + // When the component mounts, reset its state + resetState(); + }, [pageUrl]); // Reset the state whenever the pageUrl changes + + const handleThumbsClick = (type) => { + // Set the feedback type and open the input box when thumbs up or thumbs down is clicked + setFeedbackType(type); + setInputVisible(true); + }; + + const handleFeedbackSubmit = async () => { + // Now you can associate feedback type, feedback and page + try { + const response = await fetch( + "https://profilio-staging.sandbox-london-b.fetch-ai.com/api/feedback", + { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + feedbackType, + description: feedback, + pageUrl, + }), + }, + ); + + if (response.ok) { + setIsFeedbackSubmitted(true); + } else { + // Handle error + console.log("---something went wrong----"); + } + } catch (error) { + // Handle errors + console.log("---oops, something went wrong----", error); + } + }; + + return ( +
+ {isFeedbackSubmitted ? ( +

Thank you for your feedback!

+ ) : ( + <> +

+ Was this page helpful? +

+
+
handleThumbsClick("positive")} + > + 👍 +
+
handleThumbsClick("negative")} + > + 👎 +
+
+ {isInputVisible && ( +
+