From 329e6e637a57b63dc4c9715ba272e44d9f6e9bea Mon Sep 17 00:00:00 2001
From: chauhan-varun
Date: Sat, 28 Jun 2025 22:39:08 +0530
Subject: [PATCH 1/7] Enhance DocsHelp component with comment validation and
state management
---
components/DocsHelp.tsx | 38 ++++++++++++++++++++++++++++++++++----
1 file changed, 34 insertions(+), 4 deletions(-)
diff --git a/components/DocsHelp.tsx b/components/DocsHelp.tsx
index 2709bd2d3..8e699d610 100644
--- a/components/DocsHelp.tsx
+++ b/components/DocsHelp.tsx
@@ -56,6 +56,8 @@ export function DocsHelp({
const [feedbackStatus, setFeedbackStatus] = useState('');
const [isSubmitting, setIsSubmitting] = useState(false);
const [error, setError] = useState('');
+ const [commentValue, setCommentValue] = useState('');
+ const [commentError, setCommentError] = useState(false);
const feedbackFormRef = useRef(null);
// Generate GitHub redirect URL
@@ -85,6 +87,13 @@ export function DocsHelp({
async function createFeedbackHandler(event: FormEvent) {
event.preventDefault();
+
+ // Validate comment is not empty
+ if (!commentValue.trim()) {
+ setCommentError(true);
+ return;
+ }
+
const formData = new FormData(feedbackFormRef.current!);
formData.append('feedback-page', router.asPath);
setIsSubmitting(true);
@@ -99,7 +108,7 @@ export function DocsHelp({
body: JSON.stringify({
feedbackPage: formData.get('feedback-page'),
feedbackVote: formData.get('feedback-vote'),
- feedbackComment: formData.get('feedback-comment'),
+ feedbackComment: commentValue,
}),
},
);
@@ -117,11 +126,17 @@ export function DocsHelp({
}
const createGitHubIssueHandler = () => {
+ // Validate comment is not empty
+ if (!commentValue.trim()) {
+ setCommentError(true);
+ return;
+ }
+
const formData = new FormData(feedbackFormRef.current!);
setIsSubmitting(true);
try {
const title = encodeURIComponent('Feedback on Documentation');
- const body = encodeURIComponent(`${formData.get('feedback-comment')}`);
+ const body = encodeURIComponent(`${commentValue}`);
const url = `https://github.com/json-schema-org/website/issues/new?title=${title}&body=${body}`;
window.open(url, '_blank');
submitFeedbackHandler('github_issue');
@@ -136,6 +151,8 @@ export function DocsHelp({
setIsFormOpen(false);
setFeedbackStatus(status);
setError('');
+ setCommentValue('');
+ setCommentError(false);
feedbackFormRef.current!.reset();
};
@@ -237,16 +254,29 @@ export function DocsHelp({
Let us know your Feedback
- Optional
+ Required