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