Browse Source

style: fix setInitialState async function (#8732)

pull/8751/head
陈帅 5 years ago
committed by GitHub
parent
commit
e211eac73b
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      package.json
  2. 6
      src/components/RightContent/AvatarDropdown.tsx
  3. 22
      src/pages/user/Login/index.tsx

2
package.json

@ -88,7 +88,7 @@
"@umijs/plugin-openapi": "^1.2.0",
"@umijs/preset-ant-design-pro": "^1.2.0",
"@umijs/preset-dumi": "^1.1.7",
"@umijs/preset-react": "^1.7.4",
"@umijs/preset-react": "^1.8.17",
"@umijs/yorkie": "^2.0.3",
"carlo": "^0.9.46",
"cross-env": "^7.0.0",

6
src/components/RightContent/AvatarDropdown.tsx

@ -36,14 +36,14 @@ const AvatarDropdown: React.FC<GlobalHeaderRightProps> = ({ menu }) => {
const onMenuClick = useCallback(
(event: MenuInfo) => {
const { key } = event;
if (key === 'logout' && initialState) {
setInitialState({ ...initialState, currentUser: undefined });
if (key === 'logout') {
setInitialState((s) => ({ ...s, currentUser: undefined }));
loginOut();
return;
}
history.push(`/account/${key}`);
},
[initialState, setInitialState],
[setInitialState],
);
const loading = (

22
src/pages/user/Login/index.tsx

@ -29,16 +29,6 @@ const LoginMessage: React.FC<{
/>
);
/** 此方法会跳转到 redirect 参数所在的位置 */
const goto = () => {
if (!history) return;
setTimeout(() => {
const { query } = history.location;
const { redirect } = query as { redirect: string };
history.push(redirect || '/');
}, 10);
};
const Login: React.FC = () => {
const [submitting, setSubmitting] = useState(false);
const [userLoginState, setUserLoginState] = useState<API.LoginResult>({});
@ -50,10 +40,10 @@ const Login: React.FC = () => {
const fetchUserInfo = async () => {
const userInfo = await initialState?.fetchUserInfo?.();
if (userInfo) {
setInitialState({
...initialState,
await setInitialState((s) => ({
...s,
currentUser: userInfo,
});
}));
}
};
@ -69,7 +59,11 @@ const Login: React.FC = () => {
});
message.success(defaultloginSuccessMessage);
await fetchUserInfo();
goto();
/** 此方法会跳转到 redirect 参数所在的位置 */
if (!history) return;
const { query } = history.location;
const { redirect } = query as { redirect: string };
history.push(redirect || '/');
return;
}
// 如果失败去设置用户错误信息

Loading…
Cancel
Save