Skip to content

Commit 7e9bd35

Browse files
author
Apple\Apple
committed
♻️ refactor(auth): replace custom loading UI with shared Loading component and add i18n support
- Replace inline loading UI in OAuth2Callback with shared Loading component - Add internationalization support using useTranslation hook - Translate all hardcoded Chinese strings to support multiple languages - Remove unused processing state variable - Maintain consistent loading experience across the application - Support dynamic text content for retry attempts with parameter interpolation
1 parent 6e7249c commit 7e9bd35

File tree

1 file changed

+12
-21
lines changed

1 file changed

+12
-21
lines changed
Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import React, { useContext, useEffect, useState } from 'react';
2-
import { Spin, Typography, Space } from '@douyinfe/semi-ui';
32
import { useNavigate, useSearchParams } from 'react-router-dom';
3+
import { useTranslation } from 'react-i18next';
44
import { API, showError, showSuccess, updateAPI, setUserData } from '../../helpers';
55
import { UserContext } from '../../context/User';
6+
import Loading from '../common/Loading';
67

78
const OAuth2Callback = (props) => {
9+
const { t } = useTranslation();
810
const [searchParams, setSearchParams] = useSearchParams();
911

1012
const [userState, userDispatch] = useContext(UserContext);
11-
const [prompt, setPrompt] = useState('处理中...');
12-
const [processing, setProcessing] = useState(true);
13+
const [prompt, setPrompt] = useState(t('处理中...'));
1314

1415
let navigate = useNavigate();
1516

@@ -20,25 +21,25 @@ const OAuth2Callback = (props) => {
2021
const { success, message, data } = res.data;
2122
if (success) {
2223
if (message === 'bind') {
23-
showSuccess('绑定成功!');
24-
navigate('/setting');
24+
showSuccess(t('绑定成功!'));
25+
navigate('/console/setting');
2526
} else {
2627
userDispatch({ type: 'login', payload: data });
2728
localStorage.setItem('user', JSON.stringify(data));
2829
setUserData(data);
2930
updateAPI();
30-
showSuccess('登录成功!');
31-
navigate('/token');
31+
showSuccess(t('登录成功!'));
32+
navigate('/console/token');
3233
}
3334
} else {
3435
showError(message);
3536
if (count === 0) {
36-
setPrompt(`操作失败,重定向至登录界面中...`);
37-
navigate('/setting'); // in case this is failed to bind GitHub
37+
setPrompt(t('操作失败,重定向至登录界面中...'));
38+
navigate('/console/setting'); // in case this is failed to bind GitHub
3839
return;
3940
}
4041
count++;
41-
setPrompt(`出现错误,第 ${count} 次重试中...`);
42+
setPrompt(t('出现错误,第 ${count} 次重试中...', { count }));
4243
await new Promise((resolve) => setTimeout(resolve, count * 2000));
4344
await sendCode(code, state, count);
4445
}
@@ -50,17 +51,7 @@ const OAuth2Callback = (props) => {
5051
sendCode(code, state, 0).then();
5152
}, []);
5253

53-
return (
54-
<div className="flex items-center justify-center min-h-[300px] w-full bg-white rounded-lg shadow p-6">
55-
<Space vertical align="center">
56-
<Spin size="large" spinning={processing}>
57-
<div className="min-h-[200px] min-w-[200px] flex items-center justify-center">
58-
<Typography.Text type="secondary">{prompt}</Typography.Text>
59-
</div>
60-
</Spin>
61-
</Space>
62-
</div>
63-
);
54+
return <Loading prompt={prompt} />;
6455
};
6556

6657
export default OAuth2Callback;

0 commit comments

Comments
 (0)