Skip to content

Commit 24fffa0

Browse files
Copilotalexr00
andcommitted
Fix review button disable logic - prevent empty review submission
Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
1 parent 47b310c commit 24fffa0

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

webviews/components/timeline.tsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,10 +273,11 @@ function AddReviewSummaryComment() {
273273
const { isAuthor } = pr;
274274
const comment = useRef<HTMLTextAreaElement>();
275275
const [isBusy, setBusy] = useState(false);
276+
const [commentText, setCommentText] = useState('');
276277

277278
async function submitAction(event: React.MouseEvent | React.KeyboardEvent, action: ReviewType): Promise<void> {
278279
event.preventDefault();
279-
const { value } = comment.current!;
280+
const value = commentText;
280281
setBusy(true);
281282
switch (action) {
282283
case ReviewType.RequestChanges:
@@ -297,20 +298,29 @@ function AddReviewSummaryComment() {
297298
}
298299
};
299300

301+
const onTextareaChange = (event: React.ChangeEvent<HTMLTextAreaElement>) => {
302+
setCommentText(event.target.value);
303+
};
304+
305+
// Disable buttons when summary comment is empty AND there are no review comments
306+
const shouldDisableButtons = !commentText.trim() && !pr.hasReviewDraft;
307+
300308
return (
301309
<form>
302310
<textarea
303311
id='pending-review'
304312
ref={comment}
305313
placeholder="Leave a review summary comment"
306314
onKeyDown={onKeyDown}
315+
onChange={onTextareaChange}
316+
value={commentText}
307317
></textarea>
308318
<div className="form-actions">
309319
{isAuthor ? null : (
310320
<button
311321
id="request-changes"
312322
className='secondary'
313-
disabled={isBusy || pr.busy}
323+
disabled={isBusy || pr.busy || shouldDisableButtons}
314324
onClick={(event) => submitAction(event, ReviewType.RequestChanges)}
315325
>
316326
Request Changes
@@ -319,14 +329,14 @@ function AddReviewSummaryComment() {
319329
{isAuthor ? null : (
320330
<button
321331
id="approve" className='secondary'
322-
disabled={isBusy || pr.busy}
332+
disabled={isBusy || pr.busy || shouldDisableButtons}
323333
onClick={(event) => submitAction(event, ReviewType.Approve)}
324334
>
325335
Approve
326336
</button>
327337
)}
328338
<button
329-
disabled={isBusy || pr.busy}
339+
disabled={isBusy || pr.busy || shouldDisableButtons}
330340
onClick={(event) => submitAction(event, ReviewType.Comment)}
331341
>Submit Review</button>
332342
</div>

0 commit comments

Comments
 (0)