From 5e5b4901fee139e2fa6fe016e13d0530780c0b9d Mon Sep 17 00:00:00 2001 From: Lakshay Khattar <117038630+Lakszy@users.noreply.github.com> Date: Wed, 22 Nov 2023 13:27:19 +0530 Subject: [PATCH] Fixes Issue #682 Fixes Issue regarding the issue footer form validation. --- src/theme/DocItem/Footer/index.js | 106 ++++++++++++------------------ 1 file changed, 43 insertions(+), 63 deletions(-) diff --git a/src/theme/DocItem/Footer/index.js b/src/theme/DocItem/Footer/index.js index 27bb385dba..3a0351035a 100644 --- a/src/theme/DocItem/Footer/index.js +++ b/src/theme/DocItem/Footer/index.js @@ -1,12 +1,12 @@ -import React, { useState, useRef } from 'react' -import clsx from 'clsx' -import Footer from '@theme-original/DocItem/Footer' -import { useDoc } from '@docusaurus/theme-common/internal' -import styles from './styles.module.css' -import { trackStructEvent } from '@snowplow/browser-tracker' +import React, { useState, useRef } from 'react'; +import clsx from 'clsx'; +import Footer from '@theme-original/DocItem/Footer'; +import { useDoc } from '@docusaurus/theme-common/internal'; +import styles from './styles.module.css'; +import { trackStructEvent } from '@snowplow/browser-tracker'; function CommentBox({ handleSubmit, feedbackTextRef }) { - const placeholder = 'How can we improve it?' + const placeholder = 'How can we improve it?'; return (
@@ -16,99 +16,79 @@ function CommentBox({ handleSubmit, feedbackTextRef }) { rows={3} cols={34} maxLength="999" + required />
- ) + ); } function Feedback() { - const { permalink } = useDoc().metadata - const feedbackTextRef = useRef() - const buttonLikeRef = useRef() - const buttonDislikeRef = useRef() + const { permalink } = useDoc().metadata; + const feedbackTextRef = useRef(); + const buttonLikeRef = useRef(); + const buttonDislikeRef = useRef(); - const [isTextboxVisible, setIsTextboxVisible] = useState(false) - const [isThanksVisible, setIsThanksVisible] = useState(false) + const [isTextboxVisible, setIsTextboxVisible] = useState(false); + const [isThanksVisible, setIsThanksVisible] = useState(false); const handleLike = () => { - buttonLikeRef.current.blur() - setIsTextboxVisible(false) + buttonLikeRef.current.blur(); + setIsTextboxVisible(false); - setIsThanksVisible(true) + setIsThanksVisible(true); setTimeout(() => { - setIsThanksVisible(false) - }, 1000) + setIsThanksVisible(false); + }, 1000); trackStructEvent({ category: 'feedback', action: 'like', label: permalink, - }) - } + }); + }; const handleDislike = () => { - buttonDislikeRef.current.blur() - setIsTextboxVisible((current) => !current) - setIsThanksVisible(false) + buttonDislikeRef.current.blur(); + setIsTextboxVisible((current) => !current); + setIsThanksVisible(false); trackStructEvent({ category: 'feedback', action: 'dislike', label: permalink, - }) - } + }); + }; const handleSubmit = (event) => { - event.preventDefault() - const text = feedbackTextRef.current.value + event.preventDefault(); + const text = feedbackTextRef.current.value; + + if (text.trim() === '') { + alert('Please enter feedback before submitting.'); + return; + } trackStructEvent({ category: 'feedback', action: 'comment', label: permalink, property: text, - }) + }); - setIsTextboxVisible((current) => !current) - setIsThanksVisible(true) + setIsTextboxVisible((current) => !current); + setIsThanksVisible(true); setTimeout(() => { - setIsThanksVisible(false) - }, 1000) - } + setIsThanksVisible(false); + }, 1000); + }; return ( - ) + ); } export default function FooterWrapper(props) { @@ -131,5 +111,5 @@ export default function FooterWrapper(props) {