Show reset/copy errors in identity dialog
This commit is contained in:
@@ -158,11 +158,13 @@ function App() {
|
||||
const [identityDialogOpen, setIdentityDialogOpen] = useState(false);
|
||||
const [identityToken, setIdentityToken] = useState('');
|
||||
const [identityVisible, setIdentityVisible] = useState(false);
|
||||
const [identityError, setIdentityError] = useState('');
|
||||
|
||||
useEffect(() => {
|
||||
const handler = () => {
|
||||
setIdentityToken(localStorage.getItem('identity_token') || '');
|
||||
setIdentityVisible(false);
|
||||
setIdentityError('');
|
||||
setIdentityDialogOpen(true);
|
||||
};
|
||||
window.addEventListener('identity_invalid', handler as EventListener);
|
||||
@@ -208,10 +210,17 @@ function App() {
|
||||
disabled={!identityVisible}
|
||||
onClick={() => {
|
||||
if (!identityVisible || !identityToken) return;
|
||||
navigator.clipboard.writeText(identityToken).catch(() => {});
|
||||
navigator.clipboard.writeText(identityToken).catch(() => {
|
||||
setIdentityError('复制失败,请手动选择内容');
|
||||
});
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
{identityError && (
|
||||
<Text block style={{ marginTop: tokens.spacingVerticalXS, color: tokens.colorPaletteRedForeground1 }}>
|
||||
{identityError}
|
||||
</Text>
|
||||
)}
|
||||
</div>
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
@@ -227,9 +236,11 @@ function App() {
|
||||
try {
|
||||
const token = await reset_identity_token();
|
||||
setIdentityToken(token);
|
||||
setIdentityError('');
|
||||
setIdentityDialogOpen(false);
|
||||
} catch (err) {
|
||||
console.error('Failed to reset identity token:', err);
|
||||
setIdentityError('重置失败,请稍后重试');
|
||||
}
|
||||
}}
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user