Merge pull request #1904 from RedwindA/fix/wechat-display

Fix third-party binding states and unify Telegram button styling in Account Management
This commit is contained in:
Seefs
2025-09-29 12:14:23 +08:00
committed by GitHub
2 changed files with 92 additions and 30 deletions

View File

@@ -19,7 +19,14 @@ For commercial licensing, please contact support@quantumnous.com
import React, { useContext, useEffect, useState } from 'react'; import React, { useContext, useEffect, useState } from 'react';
import { useNavigate } from 'react-router-dom'; import { useNavigate } from 'react-router-dom';
import { API, copy, showError, showInfo, showSuccess } from '../../helpers'; import {
API,
copy,
showError,
showInfo,
showSuccess,
setStatusData,
} from '../../helpers';
import { UserContext } from '../../context/User'; import { UserContext } from '../../context/User';
import { Modal } from '@douyinfe/semi-ui'; import { Modal } from '@douyinfe/semi-ui';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
@@ -71,18 +78,40 @@ const PersonalSetting = () => {
}); });
useEffect(() => { useEffect(() => {
let status = localStorage.getItem('status'); let saved = localStorage.getItem('status');
if (status) { if (saved) {
status = JSON.parse(status); const parsed = JSON.parse(saved);
setStatus(status); setStatus(parsed);
if (status.turnstile_check) { if (parsed.turnstile_check) {
setTurnstileEnabled(true); setTurnstileEnabled(true);
setTurnstileSiteKey(status.turnstile_site_key); setTurnstileSiteKey(parsed.turnstile_site_key);
} else {
setTurnstileEnabled(false);
setTurnstileSiteKey('');
} }
} }
getUserData().then((res) => { // Always refresh status from server to avoid stale flags (e.g., admin just enabled OAuth)
console.log(userState); (async () => {
}); try {
const res = await API.get('/api/status');
const { success, data } = res.data;
if (success && data) {
setStatus(data);
setStatusData(data);
if (data.turnstile_check) {
setTurnstileEnabled(true);
setTurnstileSiteKey(data.turnstile_site_key);
} else {
setTurnstileEnabled(false);
setTurnstileSiteKey('');
}
}
} catch (e) {
// ignore and keep local status
}
})();
getUserData();
}, []); }, []);
useEffect(() => { useEffect(() => {

View File

@@ -28,6 +28,7 @@ import {
Tabs, Tabs,
TabPane, TabPane,
Popover, Popover,
Modal,
} from '@douyinfe/semi-ui'; } from '@douyinfe/semi-ui';
import { import {
IconMail, IconMail,
@@ -83,6 +84,9 @@ const AccountManagement = ({
</Popover> </Popover>
); );
}; };
const isBound = (accountId) => Boolean(accountId);
const [showTelegramBindModal, setShowTelegramBindModal] = React.useState(false);
return ( return (
<Card className='!rounded-2xl'> <Card className='!rounded-2xl'>
{/* 卡片头部 */} {/* 卡片头部 */}
@@ -142,7 +146,7 @@ const AccountManagement = ({
size='small' size='small'
onClick={() => setShowEmailBindModal(true)} onClick={() => setShowEmailBindModal(true)}
> >
{userState.user && userState.user.email !== '' {isBound(userState.user?.email)
? t('修改绑定') ? t('修改绑定')
: t('绑定')} : t('绑定')}
</Button> </Button>
@@ -165,9 +169,11 @@ const AccountManagement = ({
{t('微信')} {t('微信')}
</div> </div>
<div className='text-sm text-gray-500 truncate'> <div className='text-sm text-gray-500 truncate'>
{userState.user && userState.user.wechat_id !== '' {!status.wechat_login
? t('已绑定') ? t('未启用')
: t('未绑定')} : isBound(userState.user?.wechat_id)
? t('已绑定')
: t('未绑定')}
</div> </div>
</div> </div>
</div> </div>
@@ -179,7 +185,7 @@ const AccountManagement = ({
disabled={!status.wechat_login} disabled={!status.wechat_login}
onClick={() => setShowWeChatBindModal(true)} onClick={() => setShowWeChatBindModal(true)}
> >
{userState.user && userState.user.wechat_id !== '' {isBound(userState.user?.wechat_id)
? t('修改绑定') ? t('修改绑定')
: status.wechat_login : status.wechat_login
? t('绑定') ? t('绑定')
@@ -220,8 +226,7 @@ const AccountManagement = ({
onGitHubOAuthClicked(status.github_client_id) onGitHubOAuthClicked(status.github_client_id)
} }
disabled={ disabled={
(userState.user && userState.user.github_id !== '') || isBound(userState.user?.github_id) || !status.github_oauth
!status.github_oauth
} }
> >
{status.github_oauth ? t('绑定') : t('未启用')} {status.github_oauth ? t('绑定') : t('未启用')}
@@ -264,8 +269,7 @@ const AccountManagement = ({
) )
} }
disabled={ disabled={
(userState.user && userState.user.oidc_id !== '') || isBound(userState.user?.oidc_id) || !status.oidc_enabled
!status.oidc_enabled
} }
> >
{status.oidc_enabled ? t('绑定') : t('未启用')} {status.oidc_enabled ? t('绑定') : t('未启用')}
@@ -298,26 +302,56 @@ const AccountManagement = ({
</div> </div>
<div className='flex-shrink-0'> <div className='flex-shrink-0'>
{status.telegram_oauth ? ( {status.telegram_oauth ? (
userState.user.telegram_id !== '' ? ( isBound(userState.user?.telegram_id) ? (
<Button disabled={true} size='small'> <Button
disabled
size='small'
type='primary'
theme='outline'
>
{t('已绑定')} {t('已绑定')}
</Button> </Button>
) : ( ) : (
<div className='scale-75'> <Button
<TelegramLoginButton type='primary'
dataAuthUrl='/api/oauth/telegram/bind' theme='outline'
botName={status.telegram_bot_name} size='small'
/> onClick={() => setShowTelegramBindModal(true)}
</div> >
{t('绑定')}
</Button>
) )
) : ( ) : (
<Button disabled={true} size='small'> <Button
disabled
size='small'
type='primary'
theme='outline'
>
{t('未启用')} {t('未启用')}
</Button> </Button>
)} )}
</div> </div>
</div> </div>
</Card> </Card>
<Modal
title={t('绑定 Telegram')}
visible={showTelegramBindModal}
onCancel={() => setShowTelegramBindModal(false)}
footer={null}
>
<div className='my-3 text-sm text-gray-600'>
{t('点击下方按钮通过 Telegram 完成绑定')}
</div>
<div className='flex justify-center'>
<div className='scale-90'>
<TelegramLoginButton
dataAuthUrl='/api/oauth/telegram/bind'
botName={status.telegram_bot_name}
/>
</div>
</div>
</Modal>
{/* LinuxDO绑定 */} {/* LinuxDO绑定 */}
<Card className='!rounded-xl'> <Card className='!rounded-xl'>
@@ -350,8 +384,7 @@ const AccountManagement = ({
onLinuxDOOAuthClicked(status.linuxdo_client_id) onLinuxDOOAuthClicked(status.linuxdo_client_id)
} }
disabled={ disabled={
(userState.user && userState.user.linux_do_id !== '') || isBound(userState.user?.linux_do_id) || !status.linuxdo_oauth
!status.linuxdo_oauth
} }
> >
{status.linuxdo_oauth ? t('绑定') : t('未启用')} {status.linuxdo_oauth ? t('绑定') : t('未启用')}