Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions components/DocsHelp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,17 @@
async function createFeedbackHandler(event: FormEvent) {
event.preventDefault();
const formData = new FormData(feedbackFormRef.current!);
const feedbackComment = formData.get('feedback-comment') as string;

// Validate that feedback comment is not empty
if (!feedbackComment || feedbackComment.trim() === '') {
setError('Please provide feedback before submitting.');
return;

Check warning on line 42 in components/DocsHelp.tsx

View check run for this annotation

Codecov / codecov/patch

components/DocsHelp.tsx#L41-L42

Added lines #L41 - L42 were not covered by tests
}

formData.append('feedback-page', router.asPath);
setIsSubmitting(true);
setError(''); // Clear any previous errors

try {
const response = await fetch(
Expand All @@ -49,7 +58,7 @@
body: JSON.stringify({
feedbackPage: formData.get('feedback-page'),
feedbackVote: formData.get('feedback-vote'),
feedbackComment: formData.get('feedback-comment'),
feedbackComment: feedbackComment,
}),
},
);
Expand All @@ -71,10 +80,20 @@

const createGitHubIssueHandler = () => {
const formData = new FormData(feedbackFormRef.current!);
const feedbackComment = formData.get('feedback-comment') as string;

// Validate that feedback comment is not empty
if (!feedbackComment || feedbackComment.trim() === '') {
setError('Please provide feedback before creating an issue.');
return;

Check warning on line 88 in components/DocsHelp.tsx

View check run for this annotation

Codecov / codecov/patch

components/DocsHelp.tsx#L87-L88

Added lines #L87 - L88 were not covered by tests
}

setIsSubmitting(true);
setError(''); // Clear any previous errors

try {
const title = encodeURIComponent('Feedback on Documentation');
const body = encodeURIComponent(`${formData.get('feedback-comment')}`);
const body = encodeURIComponent(feedbackComment);
const url = `https://github.com/json-schema-org/website/issues/new?title=${title}&body=${body}`;

window.open(url, '_blank');
Expand Down Expand Up @@ -192,7 +211,7 @@
Let us know your Feedback
</span>
<span className='float-right text-[#7d8590] text-[14px] block'>
Optional
Required
</span>
</label>
</p>
Expand All @@ -201,6 +220,7 @@
name='feedback-comment'
id='feedback-comment'
data-test='feedback-form-input'
required
/>
</div>

Expand Down Expand Up @@ -292,7 +312,7 @@
)}

{error && (
<div className='my-6 text-[14px]'>
<div className='my-6 text-[14px] text-red-500'>
<p data-test='feedback-form-error-message'>{error}</p>
</div>
)}
Expand Down