Skip to content
This repository was archived by the owner on Jun 26, 2026. It is now read-only.

Commit 567f4ba

Browse files
matejvasekclaude
andcommitted
fix: simplify PAT modal state cleanup
Replace the wasOpen render-time tracking with explicit cleanup at the two exit points: setPat('') after successful connect, and a handleClose callback that clears pat and error on cancel or dismiss. Addresses review feedback from PR #24. Signed-off-by: Matej Vašek <matejvasek@gmail.com> Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 8b51abc commit 567f4ba

1 file changed

Lines changed: 15 additions & 14 deletions

File tree

‎src/components/UserAvatar.tsx‎

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,13 @@ interface PatModalProps {
9090

9191
function PatModal({ isOpen, onClose, onConnect }: PatModalProps) {
9292
const { t } = useTranslation('plugin__console-functions-plugin');
93-
const { pat, isValidating, error, setPat, handleConnect } = usePatModal(isOpen, onConnect);
93+
const { pat, isValidating, error, setPat, handleConnect, handleClose } = usePatModal(
94+
onClose,
95+
onConnect,
96+
);
9497

9598
return (
96-
<Modal isOpen={isOpen} onClose={isValidating ? undefined : onClose} variant="small">
99+
<Modal isOpen={isOpen} onClose={isValidating ? undefined : handleClose} variant="small">
97100
<ModalHeader title={t('Connect to GitHub')} />
98101
<ModalBody>
99102
{error && (
@@ -120,39 +123,37 @@ function PatModal({ isOpen, onClose, onConnect }: PatModalProps) {
120123
>
121124
{t('Connect')}
122125
</Button>
123-
<Button variant="link" onClick={onClose} isDisabled={isValidating}>
126+
<Button variant="link" onClick={handleClose} isDisabled={isValidating}>
124127
{t('Cancel')}
125128
</Button>
126129
</ModalFooter>
127130
</Modal>
128131
);
129132
}
130133

131-
function usePatModal(isOpen: boolean, onConnect: (pat: string) => Promise<void>) {
134+
function usePatModal(onClose: () => void, onConnect: (pat: string) => Promise<void>) {
132135
const [pat, setPat] = useState('');
133136
const [isValidating, setIsValidating] = useState(false);
134137
const [error, setError] = useState<string | null>(null);
135-
const [wasOpen, setWasOpen] = useState(false);
136-
137-
if (isOpen && !wasOpen) {
138-
setWasOpen(true);
139-
setPat('');
140-
setError(null);
141-
} else if (!isOpen && wasOpen) {
142-
setWasOpen(false);
143-
}
144138

145139
const handleConnect = async () => {
146140
setIsValidating(true);
147141
setError(null);
148142
try {
149143
await onConnect(pat);
144+
setPat('');
150145
} catch (err) {
151146
setError(errorMessage(err));
152147
} finally {
153148
setIsValidating(false);
154149
}
155150
};
156151

157-
return { pat, isValidating, error, setPat, handleConnect };
152+
const handleClose = () => {
153+
setPat('');
154+
setError(null);
155+
onClose();
156+
};
157+
158+
return { pat, isValidating, error, setPat, handleConnect, handleClose };
158159
}

0 commit comments

Comments
 (0)