balibabu commited on
Commit
598945f
·
1 Parent(s): 3c31ff9

fix: fetch user by @tanstack/react-query #1306 (#1709)

Browse files

### What problem does this PR solve?

fix: fetch user by @tanstack/react-query #1306

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)

web/src/components/chunk-method-modal/hooks.ts CHANGED
@@ -1,7 +1,4 @@
1
- import {
2
- useFetchTenantInfo,
3
- useSelectParserList,
4
- } from '@/hooks/user-setting-hooks';
5
  import { useEffect, useMemo, useState } from 'react';
6
 
7
  const ParserListMap = new Map([
@@ -71,8 +68,6 @@ export const useFetchParserListOnMount = (
71
  );
72
  }, [parserList, documentExtension]);
73
 
74
- useFetchTenantInfo();
75
-
76
  useEffect(() => {
77
  setSelectedTag(parserId);
78
  }, [parserId, documentId]);
 
1
+ import { useSelectParserList } from '@/hooks/user-setting-hooks';
 
 
 
2
  import { useEffect, useMemo, useState } from 'react';
3
 
4
  const ParserListMap = new Map([
 
68
  );
69
  }, [parserList, documentExtension]);
70
 
 
 
71
  useEffect(() => {
72
  setSelectedTag(parserId);
73
  }, [parserId, documentId]);
web/src/hooks/llm-hooks.ts CHANGED
@@ -16,7 +16,6 @@ import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
16
  import { message } from 'antd';
17
  import { useMemo } from 'react';
18
  import { useTranslation } from 'react-i18next';
19
- import { useSelector } from 'umi';
20
 
21
  export const useFetchLlmList = (
22
  modelType?: LlmModelType,
@@ -34,14 +33,6 @@ export const useFetchLlmList = (
34
  return data;
35
  };
36
 
37
- export const useSelectLlmInfo = () => {
38
- const llmInfo: IThirdOAIModelCollection = useSelector(
39
- (state: any) => state.settingModel.llmInfo,
40
- );
41
-
42
- return llmInfo;
43
- };
44
-
45
  export const useSelectLlmOptions = () => {
46
  const llmInfo: IThirdOAIModelCollection = useFetchLlmList();
47
 
 
16
  import { message } from 'antd';
17
  import { useMemo } from 'react';
18
  import { useTranslation } from 'react-i18next';
 
19
 
20
  export const useFetchLlmList = (
21
  modelType?: LlmModelType,
 
33
  return data;
34
  };
35
 
 
 
 
 
 
 
 
 
36
  export const useSelectLlmOptions = () => {
37
  const llmInfo: IThirdOAIModelCollection = useFetchLlmList();
38
 
web/src/hooks/logic-hooks.ts CHANGED
@@ -24,11 +24,7 @@ import { useSetModalState, useTranslate } from './common-hooks';
24
  import { useSetDocumentParser } from './document-hooks';
25
  import { useSetPaginationParams } from './route-hook';
26
  import { useOneNamespaceEffectsLoading } from './store-hooks';
27
- import {
28
- useFetchTenantInfo,
29
- useSaveSetting,
30
- useSelectTenantInfo,
31
- } from './user-setting-hooks';
32
 
33
  export const useChangeDocumentParser = (documentId: string) => {
34
  const setDocumentParser = useSetDocumentParser();
@@ -87,7 +83,7 @@ export const useHandleSearchChange = () => {
87
 
88
  export const useChangeLanguage = () => {
89
  const { i18n } = useTranslation();
90
- const saveSetting = useSaveSetting();
91
 
92
  const changeLanguage = (lng: string) => {
93
  i18n.changeLanguage(
@@ -333,15 +329,8 @@ export const useSelectItem = (defaultId?: string) => {
333
  return { selectedId, handleItemClick };
334
  };
335
 
336
- export const useFetchModelId = (visible: boolean) => {
337
- const fetchTenantInfo = useFetchTenantInfo(false);
338
- const tenantInfo = useSelectTenantInfo();
339
-
340
- useEffect(() => {
341
- if (visible) {
342
- fetchTenantInfo();
343
- }
344
- }, [visible, fetchTenantInfo]);
345
 
346
  return tenantInfo?.llm_id ?? '';
347
  };
 
24
  import { useSetDocumentParser } from './document-hooks';
25
  import { useSetPaginationParams } from './route-hook';
26
  import { useOneNamespaceEffectsLoading } from './store-hooks';
27
+ import { useFetchTenantInfo, useSaveSetting } from './user-setting-hooks';
 
 
 
 
28
 
29
  export const useChangeDocumentParser = (documentId: string) => {
30
  const setDocumentParser = useSetDocumentParser();
 
83
 
84
  export const useChangeLanguage = () => {
85
  const { i18n } = useTranslation();
86
+ const { saveSetting } = useSaveSetting();
87
 
88
  const changeLanguage = (lng: string) => {
89
  i18n.changeLanguage(
 
329
  return { selectedId, handleItemClick };
330
  };
331
 
332
+ export const useFetchModelId = () => {
333
+ const { data: tenantInfo } = useFetchTenantInfo();
 
 
 
 
 
 
 
334
 
335
  return tenantInfo?.llm_id ?? '';
336
  };
web/src/hooks/user-setting-hooks.ts CHANGED
@@ -1,62 +1,68 @@
 
 
1
  import { ITenantInfo } from '@/interfaces/database/knowledge';
2
  import { ISystemStatus, IUserInfo } from '@/interfaces/database/userSetting';
3
  import userService from '@/services/user-service';
4
- import { useCallback, useEffect, useMemo, useState } from 'react';
5
- import { useDispatch, useSelector } from 'umi';
6
-
7
- export const useFetchUserInfo = () => {
8
- const dispatch = useDispatch();
9
- const fetchUserInfo = useCallback(() => {
10
- dispatch({ type: 'settingModel/getUserInfo' });
11
- }, [dispatch]);
12
-
13
- useEffect(() => {
14
- fetchUserInfo();
15
- }, [fetchUserInfo]);
16
- };
17
-
18
- export const useSelectUserInfo = () => {
19
- const userInfo: IUserInfo = useSelector(
20
- (state: any) => state.settingModel.userInfo,
21
- );
22
-
23
- return userInfo;
24
- };
25
-
26
- export const useSelectTenantInfo = () => {
27
- const tenantInfo: ITenantInfo = useSelector(
28
- (state: any) => state.settingModel.tenantIfo,
29
- );
30
 
31
- return tenantInfo;
32
  };
33
 
34
- export const useFetchTenantInfo = (isOnMountFetching: boolean = true) => {
35
- const dispatch = useDispatch();
36
-
37
- const fetchTenantInfo = useCallback(() => {
38
- dispatch({
39
- type: 'settingModel/getTenantInfo',
40
- });
41
- }, [dispatch]);
 
 
 
 
 
 
 
 
42
 
43
- useEffect(() => {
44
- if (isOnMountFetching) {
45
- fetchTenantInfo();
46
- }
47
- }, [fetchTenantInfo, isOnMountFetching]);
48
 
49
- return fetchTenantInfo;
50
  };
51
 
52
  export const useSelectParserList = (): Array<{
53
  value: string;
54
  label: string;
55
  }> => {
56
- const tenantInfo: ITenantInfo = useSelectTenantInfo();
57
 
58
  const parserList = useMemo(() => {
59
- const parserArray: Array<string> = tenantInfo?.parser_ids.split(',') ?? [];
60
  return parserArray.map((x) => {
61
  const arr = x.split(':');
62
  return { value: arr[0], label: arr[1] };
@@ -67,16 +73,27 @@ export const useSelectParserList = (): Array<{
67
  };
68
 
69
  export const useSaveSetting = () => {
70
- const dispatch = useDispatch();
71
-
72
- const saveSetting = useCallback(
73
- (userInfo: { new_password: string } | Partial<IUserInfo>): number => {
74
- return dispatch<any>({ type: 'settingModel/setting', payload: userInfo });
 
 
 
 
 
 
 
 
 
 
 
 
75
  },
76
- [dispatch],
77
- );
78
 
79
- return saveSetting;
80
  };
81
 
82
  export const useFetchSystemVersion = () => {
 
1
+ import { LanguageTranslationMap } from '@/constants/common';
2
+ import { ResponseGetType } from '@/interfaces/database/base';
3
  import { ITenantInfo } from '@/interfaces/database/knowledge';
4
  import { ISystemStatus, IUserInfo } from '@/interfaces/database/userSetting';
5
  import userService from '@/services/user-service';
6
+ import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
7
+ import { message } from 'antd';
8
+ import { useCallback, useMemo, useState } from 'react';
9
+ import { useTranslation } from 'react-i18next';
10
+
11
+ export const useFetchUserInfo = (): ResponseGetType<IUserInfo> => {
12
+ const { i18n } = useTranslation();
13
+
14
+ const { data, isFetching: loading } = useQuery({
15
+ queryKey: ['userInfo'],
16
+ initialData: {},
17
+ gcTime: 0,
18
+ queryFn: async () => {
19
+ const { data } = await userService.user_info();
20
+ if (data.retcode === 0) {
21
+ i18n.changeLanguage(
22
+ LanguageTranslationMap[
23
+ data.language as keyof typeof LanguageTranslationMap
24
+ ],
25
+ );
26
+ }
27
+ return data?.data ?? {};
28
+ },
29
+ });
 
 
30
 
31
+ return { data, loading };
32
  };
33
 
34
+ export const useFetchTenantInfo = (): ResponseGetType<ITenantInfo> => {
35
+ const { data, isFetching: loading } = useQuery({
36
+ queryKey: ['tenantInfo'],
37
+ initialData: {},
38
+ gcTime: 0,
39
+ queryFn: async () => {
40
+ const { data: res } = await userService.get_tenant_info();
41
+ if (res.retcode === 0) {
42
+ // llm_id is chat_id
43
+ // asr_id is speech2txt
44
+ const { data } = res;
45
+ data.chat_id = data.llm_id;
46
+ data.speech2text_id = data.asr_id;
47
+
48
+ return data;
49
+ }
50
 
51
+ return res;
52
+ },
53
+ });
 
 
54
 
55
+ return { data, loading };
56
  };
57
 
58
  export const useSelectParserList = (): Array<{
59
  value: string;
60
  label: string;
61
  }> => {
62
+ const { data: tenantInfo } = useFetchTenantInfo();
63
 
64
  const parserList = useMemo(() => {
65
+ const parserArray: Array<string> = tenantInfo?.parser_ids?.split(',') ?? [];
66
  return parserArray.map((x) => {
67
  const arr = x.split(':');
68
  return { value: arr[0], label: arr[1] };
 
73
  };
74
 
75
  export const useSaveSetting = () => {
76
+ const queryClient = useQueryClient();
77
+ const { t } = useTranslation();
78
+ const {
79
+ data,
80
+ isPending: loading,
81
+ mutateAsync,
82
+ } = useMutation({
83
+ mutationKey: ['saveSetting'],
84
+ mutationFn: async (
85
+ userInfo: { new_password: string } | Partial<IUserInfo>,
86
+ ) => {
87
+ const { data } = await userService.setting(userInfo);
88
+ if (data.retcode === 0) {
89
+ message.success(t('message.modified'));
90
+ queryClient.invalidateQueries({ queryKey: ['userInfo'] });
91
+ }
92
+ return data?.retcode;
93
  },
94
+ });
 
95
 
96
+ return { data, loading, saveSetting: mutateAsync };
97
  };
98
 
99
  export const useFetchSystemVersion = () => {
web/src/layouts/components/right-toolbar/index.tsx CHANGED
@@ -7,7 +7,7 @@ import User from '../user';
7
 
8
  import { LanguageList } from '@/constants/common';
9
  import { useChangeLanguage } from '@/hooks/logic-hooks';
10
- import { useSelector } from 'umi';
11
  import styled from './index.less';
12
 
13
  const Circle = ({ children, ...restProps }: React.PropsWithChildren) => {
@@ -25,9 +25,9 @@ const handleGithubCLick = () => {
25
  const RightToolBar = () => {
26
  const { t } = useTranslate('common');
27
  const changeLanguage = useChangeLanguage();
28
- const { language = 'English' } = useSelector(
29
- (state) => state.settingModel.userInfo,
30
- );
31
 
32
  const handleItemClick: MenuProps['onClick'] = ({ key }) => {
33
  changeLanguage(key);
 
7
 
8
  import { LanguageList } from '@/constants/common';
9
  import { useChangeLanguage } from '@/hooks/logic-hooks';
10
+ import { useFetchUserInfo } from '@/hooks/user-setting-hooks';
11
  import styled from './index.less';
12
 
13
  const Circle = ({ children, ...restProps }: React.PropsWithChildren) => {
 
25
  const RightToolBar = () => {
26
  const { t } = useTranslate('common');
27
  const changeLanguage = useChangeLanguage();
28
+ const {
29
+ data: { language = 'English' },
30
+ } = useFetchUserInfo();
31
 
32
  const handleItemClick: MenuProps['onClick'] = ({ key }) => {
33
  changeLanguage(key);
web/src/layouts/components/user/index.tsx CHANGED
@@ -1,7 +1,4 @@
1
- import {
2
- useFetchUserInfo,
3
- useSelectUserInfo,
4
- } from '@/hooks/user-setting-hooks';
5
  import { Avatar } from 'antd';
6
  import React from 'react';
7
  import { history } from 'umi';
@@ -9,14 +6,12 @@ import { history } from 'umi';
9
  import styles from '../../index.less';
10
 
11
  const App: React.FC = () => {
12
- const userInfo = useSelectUserInfo();
13
 
14
  const toSetting = () => {
15
  history.push('/user-setting');
16
  };
17
 
18
- useFetchUserInfo();
19
-
20
  return (
21
  <Avatar
22
  size={32}
 
1
+ import { useFetchUserInfo } from '@/hooks/user-setting-hooks';
 
 
 
2
  import { Avatar } from 'antd';
3
  import React from 'react';
4
  import { history } from 'umi';
 
6
  import styles from '../../index.less';
7
 
8
  const App: React.FC = () => {
9
+ const { data: userInfo } = useFetchUserInfo();
10
 
11
  const toSetting = () => {
12
  history.push('/user-setting');
13
  };
14
 
 
 
15
  return (
16
  <Avatar
17
  size={32}
web/src/pages/add-knowledge/components/knowledge-file/hooks.ts CHANGED
@@ -11,7 +11,6 @@ import {
11
  } from '@/hooks/document-hooks';
12
  import { useGetKnowledgeSearchParams } from '@/hooks/route-hook';
13
  import { useOneNamespaceEffectsLoading } from '@/hooks/store-hooks';
14
- import { useFetchTenantInfo } from '@/hooks/user-setting-hooks';
15
  import { Pagination } from '@/interfaces/common';
16
  import { IChangeParserConfigRequestBody } from '@/interfaces/request/document';
17
  import { getUnSupportedFilesCount } from '@/utils/document-util';
@@ -25,8 +24,6 @@ export const useFetchDocumentListOnMount = () => {
25
  const fetchDocumentList = useFetchDocumentList();
26
  const dispatch = useDispatch();
27
 
28
- useFetchTenantInfo();
29
-
30
  useEffect(() => {
31
  if (knowledgeId) {
32
  fetchDocumentList();
 
11
  } from '@/hooks/document-hooks';
12
  import { useGetKnowledgeSearchParams } from '@/hooks/route-hook';
13
  import { useOneNamespaceEffectsLoading } from '@/hooks/store-hooks';
 
14
  import { Pagination } from '@/interfaces/common';
15
  import { IChangeParserConfigRequestBody } from '@/interfaces/request/document';
16
  import { getUnSupportedFilesCount } from '@/utils/document-util';
 
24
  const fetchDocumentList = useFetchDocumentList();
25
  const dispatch = useDispatch();
26
 
 
 
27
  useEffect(() => {
28
  if (knowledgeId) {
29
  fetchDocumentList();
web/src/pages/add-knowledge/components/knowledge-setting/hooks.ts CHANGED
@@ -4,10 +4,7 @@ import {
4
  } from '@/hooks/knowledge-hooks';
5
  import { useSelectLlmOptions } from '@/hooks/llm-hooks';
6
  import { useNavigateToDataset } from '@/hooks/route-hook';
7
- import {
8
- useFetchTenantInfo,
9
- useSelectParserList,
10
- } from '@/hooks/user-setting-hooks';
11
  import {
12
  getBase64FromUploadFileList,
13
  getUploadFileListFromBase64,
@@ -43,7 +40,6 @@ export const useFetchKnowledgeConfigurationOnMount = (form: FormInstance) => {
43
  const parserList = useSelectParserList();
44
  const embeddingModelOptions = useSelectLlmOptions();
45
 
46
- useFetchTenantInfo();
47
  const { data: knowledgeDetails } = useFetchKnowledgeBaseConfiguration();
48
 
49
  useEffect(() => {
 
4
  } from '@/hooks/knowledge-hooks';
5
  import { useSelectLlmOptions } from '@/hooks/llm-hooks';
6
  import { useNavigateToDataset } from '@/hooks/route-hook';
7
+ import { useSelectParserList } from '@/hooks/user-setting-hooks';
 
 
 
8
  import {
9
  getBase64FromUploadFileList,
10
  getUploadFileListFromBase64,
 
40
  const parserList = useSelectParserList();
41
  const embeddingModelOptions = useSelectLlmOptions();
42
 
 
43
  const { data: knowledgeDetails } = useFetchKnowledgeBaseConfiguration();
44
 
45
  useEffect(() => {
web/src/pages/chat/chat-configuration-modal/index.tsx CHANGED
@@ -69,7 +69,7 @@ const ChatConfigurationModal = ({
69
  ConfigurationSegmented.AssistantSetting,
70
  );
71
  const promptEngineRef = useRef<Array<IPromptConfigParameters>>([]);
72
- const modelId = useFetchModelId(visible);
73
  const { t } = useTranslate('chat');
74
 
75
  const handleOk = async () => {
 
69
  ConfigurationSegmented.AssistantSetting,
70
  );
71
  const promptEngineRef = useRef<Array<IPromptConfigParameters>>([]);
72
+ const modelId = useFetchModelId();
73
  const { t } = useTranslate('chat');
74
 
75
  const handleOk = async () => {
web/src/pages/chat/chat-container/index.tsx CHANGED
@@ -14,7 +14,7 @@ import {
14
  } from '../hooks';
15
  import { buildMessageItemReference } from '../utils';
16
 
17
- import { useSelectUserInfo } from '@/hooks/user-setting-hooks';
18
  import styles from './index.less';
19
 
20
  const ChatContainer = () => {
@@ -43,7 +43,7 @@ const ChatContainer = () => {
43
  useGetFileIcon();
44
  const loading = useSelectConversationLoading();
45
  const { t } = useTranslate('chat');
46
- const userInfo = useSelectUserInfo();
47
 
48
  return (
49
  <>
 
14
  } from '../hooks';
15
  import { buildMessageItemReference } from '../utils';
16
 
17
+ import { useFetchUserInfo } from '@/hooks/user-setting-hooks';
18
  import styles from './index.less';
19
 
20
  const ChatContainer = () => {
 
43
  useGetFileIcon();
44
  const loading = useSelectConversationLoading();
45
  const { t } = useTranslate('chat');
46
+ const { data: userInfo } = useFetchUserInfo();
47
 
48
  return (
49
  <>
web/src/pages/flow/chat/box.tsx CHANGED
@@ -8,7 +8,7 @@ import { Button, Drawer, Flex, Input, Spin } from 'antd';
8
 
9
  import { useSelectCurrentMessages, useSendMessage } from './hooks';
10
 
11
- import { useSelectUserInfo } from '@/hooks/user-setting-hooks';
12
  import styles from './index.less';
13
 
14
  const FlowChatBox = () => {
@@ -32,7 +32,7 @@ const FlowChatBox = () => {
32
  useClickDrawer();
33
  useGetFileIcon();
34
  const { t } = useTranslate('chat');
35
- const userInfo = useSelectUserInfo();
36
 
37
  return (
38
  <>
 
8
 
9
  import { useSelectCurrentMessages, useSendMessage } from './hooks';
10
 
11
+ import { useFetchUserInfo } from '@/hooks/user-setting-hooks';
12
  import styles from './index.less';
13
 
14
  const FlowChatBox = () => {
 
32
  useClickDrawer();
33
  useGetFileIcon();
34
  const { t } = useTranslate('chat');
35
+ const { data: userInfo } = useFetchUserInfo();
36
 
37
  return (
38
  <>
web/src/pages/flow/hooks.ts CHANGED
@@ -69,7 +69,7 @@ export const useSelectCanvasData = () => {
69
  };
70
 
71
  export const useInitializeOperatorParams = () => {
72
- const llmId = useFetchModelId(true);
73
 
74
  const initialFormValuesMap = useMemo(() => {
75
  return {
 
69
  };
70
 
71
  export const useInitializeOperatorParams = () => {
72
+ const llmId = useFetchModelId();
73
 
74
  const initialFormValuesMap = useMemo(() => {
75
  return {
web/src/pages/knowledge/index.tsx CHANGED
@@ -1,5 +1,5 @@
1
  import { useNextFetchKnowledgeList } from '@/hooks/knowledge-hooks';
2
- import { useSelectUserInfo } from '@/hooks/user-setting-hooks';
3
  import { PlusOutlined, SearchOutlined } from '@ant-design/icons';
4
  import { Button, Empty, Flex, Input, Space, Spin } from 'antd';
5
  import KnowledgeCard from './knowledge-card';
@@ -13,7 +13,7 @@ const KnowledgeList = () => {
13
  const { searchString, handleInputChange } = useSearchKnowledge();
14
  const { loading, list: data } = useNextFetchKnowledgeList();
15
  const list = data.filter((x) => x.name.includes(searchString));
16
- const userInfo = useSelectUserInfo();
17
  const { t } = useTranslation('translation', { keyPrefix: 'knowledgeList' });
18
  const {
19
  visible,
 
1
  import { useNextFetchKnowledgeList } from '@/hooks/knowledge-hooks';
2
+ import { useFetchUserInfo } from '@/hooks/user-setting-hooks';
3
  import { PlusOutlined, SearchOutlined } from '@ant-design/icons';
4
  import { Button, Empty, Flex, Input, Space, Spin } from 'antd';
5
  import KnowledgeCard from './knowledge-card';
 
13
  const { searchString, handleInputChange } = useSearchKnowledge();
14
  const { loading, list: data } = useNextFetchKnowledgeList();
15
  const list = data.filter((x) => x.name.includes(searchString));
16
+ const { data: userInfo } = useFetchUserInfo();
17
  const { t } = useTranslation('translation', { keyPrefix: 'knowledgeList' });
18
  const {
19
  visible,
web/src/pages/user-setting/hooks.ts CHANGED
@@ -1,4 +1,3 @@
1
- import { useOneNamespaceEffectsLoading } from '@/hooks/store-hooks';
2
  import { Form } from 'antd';
3
  import { useEffect, useState } from 'react';
4
 
@@ -18,9 +17,3 @@ export const useValidateSubmittable = () => {
18
 
19
  return { submittable, form };
20
  };
21
-
22
- export const useSelectSubmitUserInfoLoading = () =>
23
- useOneNamespaceEffectsLoading('settingModel', ['setting']);
24
-
25
- export const useSelectUserInfoLoading = () =>
26
- useOneNamespaceEffectsLoading('settingModel', ['getUserInfo']);
 
 
1
  import { Form } from 'antd';
2
  import { useEffect, useState } from 'react';
3
 
 
17
 
18
  return { submittable, form };
19
  };
 
 
 
 
 
 
web/src/pages/user-setting/model.ts DELETED
@@ -1,183 +0,0 @@
1
- import { LanguageTranslationMap } from '@/constants/common';
2
- import { ITenantInfo } from '@/interfaces/database/knowledge';
3
- import {
4
- IFactory,
5
- IMyLlmValue,
6
- IThirdOAIModelCollection as IThirdAiModelCollection,
7
- } from '@/interfaces/database/llm';
8
- import { IUserInfo } from '@/interfaces/database/userSetting';
9
- import i18n from '@/locales/config';
10
- import userService from '@/services/user-service';
11
- import { message } from 'antd';
12
- import { DvaModel } from 'umi';
13
-
14
- export interface SettingModelState {
15
- llm_factory: string;
16
- tenantIfo: Nullable<ITenantInfo>;
17
- llmInfo: IThirdAiModelCollection;
18
- myLlmList: Record<string, IMyLlmValue>;
19
- factoryList: IFactory[];
20
- userInfo: IUserInfo;
21
- }
22
-
23
- const model: DvaModel<SettingModelState> = {
24
- namespace: 'settingModel',
25
- state: {
26
- llm_factory: '',
27
- tenantIfo: null,
28
- llmInfo: {},
29
- myLlmList: {},
30
- factoryList: [],
31
- userInfo: {} as IUserInfo,
32
- },
33
- reducers: {
34
- updateState(state, { payload }) {
35
- return {
36
- ...state,
37
- ...payload,
38
- };
39
- },
40
- setUserInfo(state, { payload }) {
41
- return {
42
- ...state,
43
- userInfo: payload,
44
- };
45
- },
46
- },
47
- effects: {
48
- *setting({ payload = {} }, { call, put }) {
49
- const { data } = yield call(userService.setting, payload);
50
- const { retcode } = data;
51
- if (retcode === 0) {
52
- message.success(i18n.t('message.modified'));
53
-
54
- yield put({
55
- type: 'getUserInfo',
56
- });
57
- }
58
- },
59
- *getUserInfo({ payload = {} }, { call, put }) {
60
- const { data } = yield call(userService.user_info, payload);
61
- const { retcode, data: res } = data;
62
-
63
- // const userInfo = {
64
- // avatar: res.avatar,
65
- // name: res.nickname,
66
- // email: res.email,
67
- // };
68
- // authorizationUtil.setUserInfo(userInfo);
69
- if (retcode === 0) {
70
- i18n.changeLanguage(
71
- LanguageTranslationMap[
72
- res.language as keyof typeof LanguageTranslationMap
73
- ],
74
- );
75
- yield put({ type: 'setUserInfo', payload: res });
76
- // localStorage.setItem('userInfo',res.)
77
- }
78
- },
79
- *getTenantInfo({ payload = {} }, { call, put }) {
80
- const { data } = yield call(userService.get_tenant_info, payload);
81
- const { retcode, data: res } = data;
82
- // llm_id 对应chat_id
83
- // asr_id 对应speech2txt
84
-
85
- if (retcode === 0) {
86
- res.chat_id = res.llm_id;
87
- res.speech2text_id = res.asr_id;
88
- yield put({
89
- type: 'updateState',
90
- payload: {
91
- tenantIfo: res,
92
- },
93
- });
94
- }
95
- },
96
- *set_tenant_info({ payload = {} }, { call, put }) {
97
- const { data } = yield call(userService.set_tenant_info, payload);
98
- const { retcode } = data;
99
- if (retcode === 0) {
100
- message.success(i18n.t('message.modified'));
101
-
102
- yield put({
103
- type: 'getTenantInfo',
104
- });
105
- }
106
- return retcode;
107
- },
108
-
109
- *factories_list({ payload = {} }, { call, put }) {
110
- const { data } = yield call(userService.factories_list);
111
- const { retcode, data: res } = data;
112
- if (retcode === 0) {
113
- yield put({
114
- type: 'updateState',
115
- payload: {
116
- factoryList: res,
117
- },
118
- });
119
- }
120
- },
121
- *llm_list({ payload = {} }, { call, put }) {
122
- const { data } = yield call(userService.llm_list, payload);
123
- const { retcode, data: res } = data;
124
- if (retcode === 0) {
125
- yield put({
126
- type: 'updateState',
127
- payload: {
128
- llmInfo: res,
129
- },
130
- });
131
- }
132
- },
133
- *my_llm({ payload = {} }, { call, put }) {
134
- const { data } = yield call(userService.my_llm);
135
- const { retcode, data: res } = data;
136
- if (retcode === 0) {
137
- yield put({
138
- type: 'updateState',
139
- payload: {
140
- myLlmList: res,
141
- },
142
- });
143
- }
144
- },
145
- *set_api_key({ payload = {} }, { call, put }) {
146
- const { data } = yield call(userService.set_api_key, payload);
147
- const { retcode } = data;
148
- if (retcode === 0) {
149
- message.success(i18n.t('message.modified'));
150
-
151
- yield put({ type: 'my_llm' });
152
- yield put({ type: 'factories_list' });
153
- yield put({
154
- type: 'updateState',
155
- });
156
- }
157
- return retcode;
158
- },
159
- *add_llm({ payload = {} }, { call, put }) {
160
- const { data } = yield call(userService.add_llm, payload);
161
- const { retcode } = data;
162
- if (retcode === 0) {
163
- message.success(i18n.t('message.modified'));
164
-
165
- yield put({ type: 'my_llm' });
166
- yield put({ type: 'factories_list' });
167
- }
168
- return retcode;
169
- },
170
- *delete_llm({ payload = {} }, { call, put }) {
171
- const { data } = yield call(userService.delete_llm, payload);
172
- const { retcode } = data;
173
- if (retcode === 0) {
174
- message.success(i18n.t('message.deleted'));
175
-
176
- yield put({ type: 'my_llm' });
177
- yield put({ type: 'factories_list' });
178
- }
179
- return retcode;
180
- },
181
- },
182
- };
183
- export default model;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
web/src/pages/user-setting/setting-model/hooks.ts CHANGED
@@ -8,12 +8,9 @@ import {
8
  useSaveTenantInfo,
9
  useSelectLlmOptionsByModelType,
10
  } from '@/hooks/llm-hooks';
11
- import {
12
- useFetchTenantInfo,
13
- useSelectTenantInfo,
14
- } from '@/hooks/user-setting-hooks';
15
  import { IAddLlmRequestBody } from '@/interfaces/request/llm';
16
- import { useCallback, useEffect, useState } from 'react';
17
  import { ApiKeyPostBody } from '../interface';
18
 
19
  type SavingParamsState = Omit<IApiKeySavingParams, 'api_key'>;
@@ -63,7 +60,7 @@ export const useSubmitApiKey = () => {
63
  };
64
 
65
  export const useSubmitSystemModelSetting = () => {
66
- const systemSetting = useSelectTenantInfo();
67
  const { saveTenantInfo: saveSystemModelSetting, loading } =
68
  useSaveTenantInfo();
69
  const {
@@ -98,16 +95,9 @@ export const useSubmitSystemModelSetting = () => {
98
  };
99
  };
100
 
101
- export const useFetchSystemModelSettingOnMount = (visible: boolean) => {
102
- const systemSetting = useSelectTenantInfo();
103
  const allOptions = useSelectLlmOptionsByModelType();
104
- const fetchTenantInfo = useFetchTenantInfo();
105
-
106
- useEffect(() => {
107
- if (visible) {
108
- fetchTenantInfo();
109
- }
110
- }, [fetchTenantInfo, visible]);
111
 
112
  return { systemSetting, allOptions };
113
  };
 
8
  useSaveTenantInfo,
9
  useSelectLlmOptionsByModelType,
10
  } from '@/hooks/llm-hooks';
11
+ import { useFetchTenantInfo } from '@/hooks/user-setting-hooks';
 
 
 
12
  import { IAddLlmRequestBody } from '@/interfaces/request/llm';
13
+ import { useCallback, useState } from 'react';
14
  import { ApiKeyPostBody } from '../interface';
15
 
16
  type SavingParamsState = Omit<IApiKeySavingParams, 'api_key'>;
 
60
  };
61
 
62
  export const useSubmitSystemModelSetting = () => {
63
+ const { data: systemSetting } = useFetchTenantInfo();
64
  const { saveTenantInfo: saveSystemModelSetting, loading } =
65
  useSaveTenantInfo();
66
  const {
 
95
  };
96
  };
97
 
98
+ export const useFetchSystemModelSettingOnMount = () => {
99
+ const { data: systemSetting } = useFetchTenantInfo();
100
  const allOptions = useSelectLlmOptionsByModelType();
 
 
 
 
 
 
 
101
 
102
  return { systemSetting, allOptions };
103
  };
web/src/pages/user-setting/setting-model/index.tsx CHANGED
@@ -264,12 +264,14 @@ const UserSettingModel = () => {
264
  onOk={onApiKeySavingOk}
265
  llmFactory={llmFactory}
266
  ></ApiKeyModal>
267
- <SystemModelSettingModal
268
- visible={systemSettingVisible}
269
- onOk={onSystemSettingSavingOk}
270
- hideModal={hideSystemSettingModal}
271
- loading={saveSystemModelSettingLoading}
272
- ></SystemModelSettingModal>
 
 
273
  <OllamaModal
274
  visible={llmAddingVisible}
275
  hideModal={hideLlmAddingModal}
 
264
  onOk={onApiKeySavingOk}
265
  llmFactory={llmFactory}
266
  ></ApiKeyModal>
267
+ {systemSettingVisible && (
268
+ <SystemModelSettingModal
269
+ visible={systemSettingVisible}
270
+ onOk={onSystemSettingSavingOk}
271
+ hideModal={hideSystemSettingModal}
272
+ loading={saveSystemModelSettingLoading}
273
+ ></SystemModelSettingModal>
274
+ )}
275
  <OllamaModal
276
  visible={llmAddingVisible}
277
  hideModal={hideLlmAddingModal}
web/src/pages/user-setting/setting-model/system-model-setting-modal/index.tsx CHANGED
@@ -21,7 +21,7 @@ const SystemModelSettingModal = ({
21
  }: IProps) => {
22
  const [form] = Form.useForm();
23
  const { systemSetting: initialValues, allOptions } =
24
- useFetchSystemModelSettingOnMount(visible);
25
  const { t } = useTranslate('setting');
26
 
27
  const handleOk = async () => {
 
21
  }: IProps) => {
22
  const [form] = Form.useForm();
23
  const { systemSetting: initialValues, allOptions } =
24
+ useFetchSystemModelSettingOnMount();
25
  const { t } = useTranslate('setting');
26
 
27
  const handleOk = async () => {
web/src/pages/user-setting/setting-password/index.tsx CHANGED
@@ -1,4 +1,3 @@
1
- import { useOneNamespaceEffectsLoading } from '@/hooks/store-hooks';
2
  import { useSaveSetting } from '@/hooks/user-setting-hooks';
3
  import { rsaPsw } from '@/utils';
4
  import { Button, Divider, Form, Input, Space } from 'antd';
@@ -19,9 +18,8 @@ const tailLayout = {
19
  };
20
 
21
  const UserSettingPassword = () => {
22
- const loading = useOneNamespaceEffectsLoading('settingModel', ['setting']);
23
  const { form, submittable } = useValidateSubmittable();
24
- const saveSetting = useSaveSetting();
25
  const { t } = useTranslate('setting');
26
 
27
  const onFinish = (values: any) => {
 
 
1
  import { useSaveSetting } from '@/hooks/user-setting-hooks';
2
  import { rsaPsw } from '@/utils';
3
  import { Button, Divider, Form, Input, Space } from 'antd';
 
18
  };
19
 
20
  const UserSettingPassword = () => {
 
21
  const { form, submittable } = useValidateSubmittable();
22
+ const { saveSetting, loading } = useSaveSetting();
23
  const { t } = useTranslate('setting');
24
 
25
  const onFinish = (values: any) => {
web/src/pages/user-setting/setting-profile/index.tsx CHANGED
@@ -1,8 +1,4 @@
1
- import {
2
- useFetchUserInfo,
3
- useSaveSetting,
4
- useSelectUserInfo,
5
- } from '@/hooks/user-setting-hooks';
6
  import {
7
  getBase64FromUploadFileList,
8
  getUploadFileListFromBase64,
@@ -24,11 +20,7 @@ import camelCase from 'lodash/camelCase';
24
  import { useEffect } from 'react';
25
  import SettingTitle from '../components/setting-title';
26
  import { TimezoneList } from '../constants';
27
- import {
28
- useSelectSubmitUserInfoLoading,
29
- useSelectUserInfoLoading,
30
- useValidateSubmittable,
31
- } from '../hooks';
32
 
33
  import { LanguageList } from '@/constants/common';
34
  import { useTranslate } from '@/hooks/common-hooks';
@@ -52,12 +44,9 @@ const tailLayout = {
52
  };
53
 
54
  const UserSettingProfile = () => {
55
- const userInfo = useSelectUserInfo();
56
- const saveSetting = useSaveSetting();
57
- const submitLoading = useSelectSubmitUserInfoLoading();
58
  const { form, submittable } = useValidateSubmittable();
59
- const loading = useSelectUserInfoLoading();
60
- useFetchUserInfo();
61
  const { t } = useTranslate('setting');
62
  const changeLanguage = useChangeLanguage();
63
 
 
1
+ import { useFetchUserInfo, useSaveSetting } from '@/hooks/user-setting-hooks';
 
 
 
 
2
  import {
3
  getBase64FromUploadFileList,
4
  getUploadFileListFromBase64,
 
20
  import { useEffect } from 'react';
21
  import SettingTitle from '../components/setting-title';
22
  import { TimezoneList } from '../constants';
23
+ import { useValidateSubmittable } from '../hooks';
 
 
 
 
24
 
25
  import { LanguageList } from '@/constants/common';
26
  import { useTranslate } from '@/hooks/common-hooks';
 
44
  };
45
 
46
  const UserSettingProfile = () => {
47
+ const { data: userInfo, loading } = useFetchUserInfo();
48
+ const { saveSetting, loading: submitLoading } = useSaveSetting();
 
49
  const { form, submittable } = useValidateSubmittable();
 
 
50
  const { t } = useTranslate('setting');
51
  const changeLanguage = useChangeLanguage();
52
 
web/src/pages/user-setting/setting-team/index.tsx CHANGED
@@ -1,11 +1,11 @@
1
  import { Button, Card, Flex } from 'antd';
2
 
3
  import { useTranslate } from '@/hooks/common-hooks';
4
- import { useSelectUserInfo } from '@/hooks/user-setting-hooks';
5
  import styles from './index.less';
6
 
7
  const UserSettingTeam = () => {
8
- const userInfo = useSelectUserInfo();
9
  const { t } = useTranslate('setting');
10
 
11
  return (
 
1
  import { Button, Card, Flex } from 'antd';
2
 
3
  import { useTranslate } from '@/hooks/common-hooks';
4
+ import { useFetchUserInfo } from '@/hooks/user-setting-hooks';
5
  import styles from './index.less';
6
 
7
  const UserSettingTeam = () => {
8
+ const { data: userInfo } = useFetchUserInfo();
9
  const { t } = useTranslate('setting');
10
 
11
  return (
web/typings.d.ts CHANGED
@@ -3,7 +3,6 @@ import { KFModelState } from '@/pages/add-knowledge/components/knowledge-file/mo
3
  import { TestingModelState } from '@/pages/add-knowledge/components/knowledge-testing/model';
4
  import { kAModelState } from '@/pages/add-knowledge/model';
5
  import { ChatModelState } from '@/pages/chat/model';
6
- import { SettingModelState } from '@/pages/user-setting/model';
7
 
8
  declare module 'lodash';
9
 
@@ -14,7 +13,6 @@ function useSelector<TState = RootState, TSelected = unknown>(
14
 
15
  export interface RootState {
16
  chatModel: ChatModelState;
17
- settingModel: SettingModelState;
18
  kFModel: KFModelState;
19
  kAModel: kAModelState;
20
  chunkModel: ChunkModelState;
 
3
  import { TestingModelState } from '@/pages/add-knowledge/components/knowledge-testing/model';
4
  import { kAModelState } from '@/pages/add-knowledge/model';
5
  import { ChatModelState } from '@/pages/chat/model';
 
6
 
7
  declare module 'lodash';
8
 
 
13
 
14
  export interface RootState {
15
  chatModel: ChatModelState;
 
16
  kFModel: KFModelState;
17
  kAModel: kAModelState;
18
  chunkModel: ChunkModelState;