From 67b4b5eb7b2d826ea5c3038ca6c8a68d602f53c1 Mon Sep 17 00:00:00 2001 From: wanghong Date: Mon, 23 Oct 2023 16:25:35 +0800 Subject: [PATCH 1/4] fix: remove guidance segment and fix logout --- .../page/Home/DefaultScene/DefaultScene.tsx | 31 +------------------ .../src/page/Home/DefaultScene/StepBox.tsx | 4 +-- .../src/page/Nav/SideMenu/UserNavigate.tsx | 7 ++--- .../lib/api/common/authInvalid/index.ts | 4 ++- .../shared/lib/global/useUserInfo/index.tsx | 1 + 5 files changed, 10 insertions(+), 37 deletions(-) diff --git a/packages/base/src/page/Home/DefaultScene/DefaultScene.tsx b/packages/base/src/page/Home/DefaultScene/DefaultScene.tsx index 0261366a2..d97f85c1a 100644 --- a/packages/base/src/page/Home/DefaultScene/DefaultScene.tsx +++ b/packages/base/src/page/Home/DefaultScene/DefaultScene.tsx @@ -1,36 +1,7 @@ import StepBox from './StepBox'; -import useUserTypeHooks from './hooks/useUserTypeHooks'; -import { UserTypeDictionary } from '.'; -import { BasicSegmented } from '@actiontech/shared'; -import { DefaultSceneSegmentedWrapper } from '../style'; const DefaultScene: React.FC = () => { - const { userType, onUserTypeChange } = useUserTypeHooks(); - - return ( -
- - { - onUserTypeChange(e as typeof userType); - }} - options={[ - { - label: UserTypeDictionary.admin, - value: 'admin' - }, - { - label: UserTypeDictionary.normal, - value: 'normal' - } - ]} - /> - - - -
- ); + return ; }; export default DefaultScene; diff --git a/packages/base/src/page/Home/DefaultScene/StepBox.tsx b/packages/base/src/page/Home/DefaultScene/StepBox.tsx index cfd54ac10..d136899f6 100644 --- a/packages/base/src/page/Home/DefaultScene/StepBox.tsx +++ b/packages/base/src/page/Home/DefaultScene/StepBox.tsx @@ -1,14 +1,14 @@ import { Row, Col, Space } from 'antd5'; import { useNavigate } from 'react-router-dom'; -import useUserTypeHooks from './hooks/useUserTypeHooks'; import { AdminUserDevopsSteps, NormalUserDevopsSteps } from '.'; import { DefaultSceneStepContainerWrapper } from '../style'; import GuidanceButton from '../components/GuidanceButton'; import useRecentlyOpenedProjects from '../../Nav/SideMenu/useRecentlyOpenedProjects'; import { DEFAULT_PROJECT_ID } from '@actiontech/shared/lib/data/common'; +import { useCurrentUser } from '@actiontech/shared/lib/global'; const StepBox: React.FC = () => { - const { isAdmin } = useUserTypeHooks(); + const { isAdmin } = useCurrentUser(); const navigate = useNavigate(); let currentProjectID = ''; diff --git a/packages/base/src/page/Nav/SideMenu/UserNavigate.tsx b/packages/base/src/page/Nav/SideMenu/UserNavigate.tsx index 1594c99f5..7cafe9278 100644 --- a/packages/base/src/page/Nav/SideMenu/UserNavigate.tsx +++ b/packages/base/src/page/Nav/SideMenu/UserNavigate.tsx @@ -2,22 +2,21 @@ import { Popover } from 'antd5'; import { PopoverInnerStyleWrapper } from './style'; import { IconAccount } from '../../../icon/sideMenu'; import { useTranslation } from 'react-i18next'; -import { useDispatch } from 'react-redux'; -import { updateToken } from '../../../store/user'; import { AvatarStyleWrapper } from '@actiontech/shared/lib/components/AvatarCom/style'; import { useState } from 'react'; import { useNavigate } from 'react-router-dom'; +import { useUserInfo } from '@actiontech/shared/lib/global'; const UserNavigate: React.FC<{ username: string; setVersionModalOpen: () => void; }> = ({ username, setVersionModalOpen }) => { const { t } = useTranslation(); - const dispatch = useDispatch(); + const { clearUserInfo } = useUserInfo(); const [open, setOpen] = useState(false); const navigate = useNavigate(); const logout = () => { - dispatch(updateToken({ token: '' })); + clearUserInfo(); }; return ( diff --git a/packages/shared/lib/api/common/authInvalid/index.ts b/packages/shared/lib/api/common/authInvalid/index.ts index 293fb81fc..ae6ba7df1 100644 --- a/packages/shared/lib/api/common/authInvalid/index.ts +++ b/packages/shared/lib/api/common/authInvalid/index.ts @@ -4,7 +4,8 @@ import { updateManagementPermissions, updateToken, updateUser, - updateUserUid + updateUserUid, + updateUserInfoFetchStatus } from '../../../../../base/src/store/user'; import { createBrowserHistory } from 'history'; @@ -14,6 +15,7 @@ const globalAuthInvalid = () => { store.dispatch(updateUserUid({ uid: '' })); store.dispatch(updateManagementPermissions({ managementPermissions: [] })); store.dispatch(updateBindProjects({ bindProjects: [] })); + store.dispatch(updateUserInfoFetchStatus(false)); const history = createBrowserHistory(); history.push('/login'); }; diff --git a/packages/shared/lib/global/useUserInfo/index.tsx b/packages/shared/lib/global/useUserInfo/index.tsx index 086e64a9f..8abf729ad 100644 --- a/packages/shared/lib/global/useUserInfo/index.tsx +++ b/packages/shared/lib/global/useUserInfo/index.tsx @@ -47,6 +47,7 @@ const useUserInfo = () => { managementPermissions: [] }) ); + dispatch(updateUserInfoFetchStatus(false)); }, [dispatch]); const { From 5982277bfcbd2f217da4509f45b032898da86900 Mon Sep 17 00:00:00 2001 From: wanghong Date: Mon, 23 Oct 2023 16:38:40 +0800 Subject: [PATCH 2/4] fix: remove useless hooks --- .../DefaultScene/hooks/useUserTypeHooks.tsx | 22 ------------------- 1 file changed, 22 deletions(-) delete mode 100644 packages/base/src/page/Home/DefaultScene/hooks/useUserTypeHooks.tsx diff --git a/packages/base/src/page/Home/DefaultScene/hooks/useUserTypeHooks.tsx b/packages/base/src/page/Home/DefaultScene/hooks/useUserTypeHooks.tsx deleted file mode 100644 index e94d062c4..000000000 --- a/packages/base/src/page/Home/DefaultScene/hooks/useUserTypeHooks.tsx +++ /dev/null @@ -1,22 +0,0 @@ -import { SystemRole } from '@actiontech/shared/lib/enum'; -import { useSelector, useDispatch } from 'react-redux'; -import { IReduxState } from '../../../../store'; -import { updateUserType } from '../../../../store/home'; - -const useUserTypeHooks = () => { - const dispatch = useDispatch(); - const userType = useSelector((state: IReduxState) => state.home.userType); - const onUserTypeChange = (type: string) => { - dispatch(updateUserType({ userType: type })); - }; - - const isAdmin = userType === SystemRole.admin; - - return { - isAdmin, - onUserTypeChange, - userType - }; -}; - -export default useUserTypeHooks; From 132d50857d1dde7ca1776985c5c4c28e1bf28b32 Mon Sep 17 00:00:00 2001 From: wanghong Date: Mon, 23 Oct 2023 16:46:27 +0800 Subject: [PATCH 3/4] fix: remove useless redux --- packages/base/src/store/home/index.test.ts | 18 --------------- packages/base/src/store/home/index.ts | 26 ---------------------- packages/base/src/store/index.ts | 2 -- packages/shared/lib/testUtil/mockRedux.tsx | 8 ------- 4 files changed, 54 deletions(-) delete mode 100644 packages/base/src/store/home/index.test.ts delete mode 100644 packages/base/src/store/home/index.ts diff --git a/packages/base/src/store/home/index.test.ts b/packages/base/src/store/home/index.test.ts deleted file mode 100644 index f9b3cf798..000000000 --- a/packages/base/src/store/home/index.test.ts +++ /dev/null @@ -1,18 +0,0 @@ -import reducers, { updateUserType } from '.'; - -describe('store/home', () => { - it('should create action', () => { - expect(updateUserType({ userType: 'admin' })).toEqual({ - payload: { - userType: 'admin' - }, - type: 'home/updateUserType' - }); - }); - - it('should update userType when dispatch updateUserType action', () => { - const state = { userType: 'admin' }; - const newState = reducers(state, updateUserType({ userType: 'normal' })); - expect(newState.userType).toBe('normal'); - }); -}); diff --git a/packages/base/src/store/home/index.ts b/packages/base/src/store/home/index.ts deleted file mode 100644 index 0a2cfb8bf..000000000 --- a/packages/base/src/store/home/index.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { createSlice, PayloadAction } from '@reduxjs/toolkit'; - -type HomeReduxState = { - userType: string; -}; - -const initialState: HomeReduxState = { - userType: 'admin' -}; - -const home = createSlice({ - name: 'home', - initialState, - reducers: { - updateUserType: ( - state, - { payload: { userType } }: PayloadAction<{ userType: string }> - ) => { - state.userType = userType; - } - } -}); - -export const { updateUserType } = home.actions; - -export default home.reducer; diff --git a/packages/base/src/store/index.ts b/packages/base/src/store/index.ts index fa33aec79..4c8f90849 100644 --- a/packages/base/src/store/index.ts +++ b/packages/base/src/store/index.ts @@ -1,5 +1,4 @@ import { configureStore } from '@reduxjs/toolkit'; -import home from './home'; import user from './user'; import userCenter from './userCenter'; import member from './member'; @@ -19,7 +18,6 @@ import projectManage from 'sqle/src/store/projectManage'; const store = configureStore({ reducer: { - home, user, userCenter, member, diff --git a/packages/shared/lib/testUtil/mockRedux.tsx b/packages/shared/lib/testUtil/mockRedux.tsx index c19d7a7ef..6f6a90ac6 100644 --- a/packages/shared/lib/testUtil/mockRedux.tsx +++ b/packages/shared/lib/testUtil/mockRedux.tsx @@ -1,13 +1,11 @@ import { combineReducers, configureStore } from '@reduxjs/toolkit'; import { Dictionary } from '../types/common.type'; -import home from '../../../base/src/store/home'; import user from '../../../base/src/store/user'; import userCenter from '../../../base/src/store/userCenter'; import member from '../../../base/src/store/member'; import project from '../../../base/src/store/project'; const reducers = combineReducers({ - home, user, userCenter, member, @@ -17,9 +15,3 @@ const reducers = combineReducers({ export const storeFactory = (initStore: Dictionary = {}) => { return configureStore({ reducer: reducers, preloadedState: initStore }); }; - -export const getBaseHomeInitialState = () => ({ - home: { - userType: 'admin' - } -}); From f3e7b5f48591d03878b7bc6a0c9a5b27d7847e63 Mon Sep 17 00:00:00 2001 From: wanghong Date: Mon, 23 Oct 2023 16:49:09 +0800 Subject: [PATCH 4/4] fix: remove userType in test --- packages/base/src/App.test.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/base/src/App.test.tsx b/packages/base/src/App.test.tsx index ada80449c..14f56c71d 100644 --- a/packages/base/src/App.test.tsx +++ b/packages/base/src/App.test.tsx @@ -47,8 +47,7 @@ describe.skip('App', () => { project_name: 'default' } ] - }, - home: { userType: 'admin' } + } }); }); (useDispatch as jest.Mock).mockImplementation(() => scopeDispatch);