From 0de8f761d36a790bb3863445cdeefcfdcebb9409 Mon Sep 17 00:00:00 2001 From: Mounika-max-348 Date: Fri, 5 Dec 2025 22:03:43 +0530 Subject: [PATCH] Fix: prevent empty feedback submission and improve UI (#1415) --- components/DocsHelp.tsx | 74 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 68 insertions(+), 6 deletions(-) diff --git a/components/DocsHelp.tsx b/components/DocsHelp.tsx index 2709bd2d3..411ce4b10 100644 --- a/components/DocsHelp.tsx +++ b/components/DocsHelp.tsx @@ -58,6 +58,11 @@ export function DocsHelp({ const [error, setError] = useState(''); const feedbackFormRef = useRef(null); + // Popup state + const [showPopup, setShowPopup] = useState(false); + const [popupMessage, setPopupMessage] = useState(''); + const [popupType, setPopupType] = useState<'success' | 'error' | ''>(''); + // Generate GitHub redirect URL const getGitRedirect = () => { if ( @@ -85,9 +90,24 @@ export function DocsHelp({ async function createFeedbackHandler(event: FormEvent) { event.preventDefault(); + const formData = new FormData(feedbackFormRef.current!); + + // 🔍 Validation for empty feedback comment + const feedbackComment = formData.get('feedback-comment')?.toString().trim(); + if (!feedbackComment) { + const message = 'Please enter a feedback comment before submitting.'; + setError('Feedback comment cannot be empty.'); + setPopupMessage(message); + setPopupType('error'); + setShowPopup(true); + return; + } + formData.append('feedback-page', router.asPath); + setIsSubmitting(true); + setError(''); try { const response = await fetch( @@ -99,18 +119,30 @@ export function DocsHelp({ body: JSON.stringify({ feedbackPage: formData.get('feedback-page'), feedbackVote: formData.get('feedback-vote'), - feedbackComment: formData.get('feedback-comment'), + // use trimmed, non-empty comment + feedbackComment, }), }, ); if (response.ok) { submitFeedbackHandler('feedback'); + setPopupMessage('Thanks for the feedback!'); + setPopupType('success'); + setShowPopup(true); } else { - setError('An error occurred. Please try again later.'); + const message = 'An error occurred. Please try again later.'; + setError(message); + setPopupMessage(message); + setPopupType('error'); + setShowPopup(true); } } catch (error) { - setError('An error occurred. Please try again later.'); + const message = 'An error occurred. Please try again later.'; + setError(message); + setPopupMessage(message); + setPopupType('error'); + setShowPopup(true); } finally { setIsSubmitting(false); } @@ -254,13 +286,17 @@ export function DocsHelp({ type='submit' variant='outline' size='sm' - className={`px-[16px] py-[7px] cursor-pointer border-solid border-[#aaaaaa] border rounded-md ${isSubmitting ? 'cursor-not-allowed opacity-50' : 'hover:bg-gray-200 dark:hover:bg-gray-600'}`} + className={`px-[16px] py-[7px] cursor-pointer border-solid border-[#aaaaaa] border rounded-md ${ + isSubmitting + ? 'cursor-not-allowed opacity-50' + : 'hover:bg-gray-200 dark:hover:bg-gray-600' + }`} disabled={isSubmitting} data-test='feedback-submit-button' > - + Submit Feedback @@ -272,7 +308,11 @@ export function DocsHelp({ type='button' variant='outline' size='sm' - className={`px-[16px] py-[7px] cursor-pointer border-solid border-[#aaaaaa] border rounded-md ${isSubmitting ? 'cursor-not-allowed opacity-50' : 'hover:bg-gray-200 dark:hover:bg-gray-600'}`} + className={`px-[16px] py-[7px] cursor-pointer border-solid border-[#aaaaaa] border rounded-md ${ + isSubmitting + ? 'cursor-not-allowed opacity-50' + : 'hover:bg-gray-200 dark:hover:bg-gray-600' + }`} disabled={isSubmitting} onClick={createGitHubIssueHandler} data-test='create-github-issue-button' @@ -424,6 +464,28 @@ export function DocsHelp({ + + {/* Popup modal */} + {showPopup && ( +
+
+

+ {popupMessage} +

+ +
+
+ )} ); }