Skip to content

Commit 3b3f1f8

Browse files
committed
Clear confirmation dialog input via single useEffect; remove redundant
handler logic 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
1 parent 813b752 commit 3b3f1f8

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

web/src/components/ui/confirmation-input-dialog.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client'
22

3-
import { useState } from 'react'
3+
import { useEffect, useState } from 'react'
44
import { Button } from '@/components/ui/button'
55
import {
66
Dialog,
@@ -35,7 +35,11 @@ export function ConfirmationInputDialog({
3535
confirmButtonText,
3636
}: ConfirmationInputDialogProps) {
3737
const [inputValue, setInputValue] = useState('')
38-
38+
39+
useEffect(() => {
40+
if (!isOpen) setInputValue('')
41+
}, [isOpen])
42+
3943
const isConfirmationMatch = inputValue === confirmationText
4044

4145
const handleConfirm = () => {
@@ -46,9 +50,6 @@ export function ConfirmationInputDialog({
4650

4751
const handleOpenChange = (open: boolean) => {
4852
onOpenChange(open)
49-
if (!open) {
50-
setInputValue('')
51-
}
5253
}
5354

5455
return (
@@ -93,4 +94,4 @@ export function ConfirmationInputDialog({
9394
</DialogContent>
9495
</Dialog>
9596
)
96-
}
97+
}

0 commit comments

Comments
 (0)