### 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)
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import { useOneNamespaceEffectsLoading } from '@/hooks/store-hooks';
|
||||
import { Form } from 'antd';
|
||||
import { useEffect, useState } from 'react';
|
||||
|
||||
@@ -18,9 +17,3 @@ export const useValidateSubmittable = () => {
|
||||
|
||||
return { submittable, form };
|
||||
};
|
||||
|
||||
export const useSelectSubmitUserInfoLoading = () =>
|
||||
useOneNamespaceEffectsLoading('settingModel', ['setting']);
|
||||
|
||||
export const useSelectUserInfoLoading = () =>
|
||||
useOneNamespaceEffectsLoading('settingModel', ['getUserInfo']);
|
||||
|
||||
@@ -1,183 +0,0 @@
|
||||
import { LanguageTranslationMap } from '@/constants/common';
|
||||
import { ITenantInfo } from '@/interfaces/database/knowledge';
|
||||
import {
|
||||
IFactory,
|
||||
IMyLlmValue,
|
||||
IThirdOAIModelCollection as IThirdAiModelCollection,
|
||||
} from '@/interfaces/database/llm';
|
||||
import { IUserInfo } from '@/interfaces/database/userSetting';
|
||||
import i18n from '@/locales/config';
|
||||
import userService from '@/services/user-service';
|
||||
import { message } from 'antd';
|
||||
import { DvaModel } from 'umi';
|
||||
|
||||
export interface SettingModelState {
|
||||
llm_factory: string;
|
||||
tenantIfo: Nullable<ITenantInfo>;
|
||||
llmInfo: IThirdAiModelCollection;
|
||||
myLlmList: Record<string, IMyLlmValue>;
|
||||
factoryList: IFactory[];
|
||||
userInfo: IUserInfo;
|
||||
}
|
||||
|
||||
const model: DvaModel<SettingModelState> = {
|
||||
namespace: 'settingModel',
|
||||
state: {
|
||||
llm_factory: '',
|
||||
tenantIfo: null,
|
||||
llmInfo: {},
|
||||
myLlmList: {},
|
||||
factoryList: [],
|
||||
userInfo: {} as IUserInfo,
|
||||
},
|
||||
reducers: {
|
||||
updateState(state, { payload }) {
|
||||
return {
|
||||
...state,
|
||||
...payload,
|
||||
};
|
||||
},
|
||||
setUserInfo(state, { payload }) {
|
||||
return {
|
||||
...state,
|
||||
userInfo: payload,
|
||||
};
|
||||
},
|
||||
},
|
||||
effects: {
|
||||
*setting({ payload = {} }, { call, put }) {
|
||||
const { data } = yield call(userService.setting, payload);
|
||||
const { retcode } = data;
|
||||
if (retcode === 0) {
|
||||
message.success(i18n.t('message.modified'));
|
||||
|
||||
yield put({
|
||||
type: 'getUserInfo',
|
||||
});
|
||||
}
|
||||
},
|
||||
*getUserInfo({ payload = {} }, { call, put }) {
|
||||
const { data } = yield call(userService.user_info, payload);
|
||||
const { retcode, data: res } = data;
|
||||
|
||||
// const userInfo = {
|
||||
// avatar: res.avatar,
|
||||
// name: res.nickname,
|
||||
// email: res.email,
|
||||
// };
|
||||
// authorizationUtil.setUserInfo(userInfo);
|
||||
if (retcode === 0) {
|
||||
i18n.changeLanguage(
|
||||
LanguageTranslationMap[
|
||||
res.language as keyof typeof LanguageTranslationMap
|
||||
],
|
||||
);
|
||||
yield put({ type: 'setUserInfo', payload: res });
|
||||
// localStorage.setItem('userInfo',res.)
|
||||
}
|
||||
},
|
||||
*getTenantInfo({ payload = {} }, { call, put }) {
|
||||
const { data } = yield call(userService.get_tenant_info, payload);
|
||||
const { retcode, data: res } = data;
|
||||
// llm_id 对应chat_id
|
||||
// asr_id 对应speech2txt
|
||||
|
||||
if (retcode === 0) {
|
||||
res.chat_id = res.llm_id;
|
||||
res.speech2text_id = res.asr_id;
|
||||
yield put({
|
||||
type: 'updateState',
|
||||
payload: {
|
||||
tenantIfo: res,
|
||||
},
|
||||
});
|
||||
}
|
||||
},
|
||||
*set_tenant_info({ payload = {} }, { call, put }) {
|
||||
const { data } = yield call(userService.set_tenant_info, payload);
|
||||
const { retcode } = data;
|
||||
if (retcode === 0) {
|
||||
message.success(i18n.t('message.modified'));
|
||||
|
||||
yield put({
|
||||
type: 'getTenantInfo',
|
||||
});
|
||||
}
|
||||
return retcode;
|
||||
},
|
||||
|
||||
*factories_list({ payload = {} }, { call, put }) {
|
||||
const { data } = yield call(userService.factories_list);
|
||||
const { retcode, data: res } = data;
|
||||
if (retcode === 0) {
|
||||
yield put({
|
||||
type: 'updateState',
|
||||
payload: {
|
||||
factoryList: res,
|
||||
},
|
||||
});
|
||||
}
|
||||
},
|
||||
*llm_list({ payload = {} }, { call, put }) {
|
||||
const { data } = yield call(userService.llm_list, payload);
|
||||
const { retcode, data: res } = data;
|
||||
if (retcode === 0) {
|
||||
yield put({
|
||||
type: 'updateState',
|
||||
payload: {
|
||||
llmInfo: res,
|
||||
},
|
||||
});
|
||||
}
|
||||
},
|
||||
*my_llm({ payload = {} }, { call, put }) {
|
||||
const { data } = yield call(userService.my_llm);
|
||||
const { retcode, data: res } = data;
|
||||
if (retcode === 0) {
|
||||
yield put({
|
||||
type: 'updateState',
|
||||
payload: {
|
||||
myLlmList: res,
|
||||
},
|
||||
});
|
||||
}
|
||||
},
|
||||
*set_api_key({ payload = {} }, { call, put }) {
|
||||
const { data } = yield call(userService.set_api_key, payload);
|
||||
const { retcode } = data;
|
||||
if (retcode === 0) {
|
||||
message.success(i18n.t('message.modified'));
|
||||
|
||||
yield put({ type: 'my_llm' });
|
||||
yield put({ type: 'factories_list' });
|
||||
yield put({
|
||||
type: 'updateState',
|
||||
});
|
||||
}
|
||||
return retcode;
|
||||
},
|
||||
*add_llm({ payload = {} }, { call, put }) {
|
||||
const { data } = yield call(userService.add_llm, payload);
|
||||
const { retcode } = data;
|
||||
if (retcode === 0) {
|
||||
message.success(i18n.t('message.modified'));
|
||||
|
||||
yield put({ type: 'my_llm' });
|
||||
yield put({ type: 'factories_list' });
|
||||
}
|
||||
return retcode;
|
||||
},
|
||||
*delete_llm({ payload = {} }, { call, put }) {
|
||||
const { data } = yield call(userService.delete_llm, payload);
|
||||
const { retcode } = data;
|
||||
if (retcode === 0) {
|
||||
message.success(i18n.t('message.deleted'));
|
||||
|
||||
yield put({ type: 'my_llm' });
|
||||
yield put({ type: 'factories_list' });
|
||||
}
|
||||
return retcode;
|
||||
},
|
||||
},
|
||||
};
|
||||
export default model;
|
||||
@@ -8,12 +8,9 @@ import {
|
||||
useSaveTenantInfo,
|
||||
useSelectLlmOptionsByModelType,
|
||||
} from '@/hooks/llm-hooks';
|
||||
import {
|
||||
useFetchTenantInfo,
|
||||
useSelectTenantInfo,
|
||||
} from '@/hooks/user-setting-hooks';
|
||||
import { useFetchTenantInfo } from '@/hooks/user-setting-hooks';
|
||||
import { IAddLlmRequestBody } from '@/interfaces/request/llm';
|
||||
import { useCallback, useEffect, useState } from 'react';
|
||||
import { useCallback, useState } from 'react';
|
||||
import { ApiKeyPostBody } from '../interface';
|
||||
|
||||
type SavingParamsState = Omit<IApiKeySavingParams, 'api_key'>;
|
||||
@@ -63,7 +60,7 @@ export const useSubmitApiKey = () => {
|
||||
};
|
||||
|
||||
export const useSubmitSystemModelSetting = () => {
|
||||
const systemSetting = useSelectTenantInfo();
|
||||
const { data: systemSetting } = useFetchTenantInfo();
|
||||
const { saveTenantInfo: saveSystemModelSetting, loading } =
|
||||
useSaveTenantInfo();
|
||||
const {
|
||||
@@ -98,16 +95,9 @@ export const useSubmitSystemModelSetting = () => {
|
||||
};
|
||||
};
|
||||
|
||||
export const useFetchSystemModelSettingOnMount = (visible: boolean) => {
|
||||
const systemSetting = useSelectTenantInfo();
|
||||
export const useFetchSystemModelSettingOnMount = () => {
|
||||
const { data: systemSetting } = useFetchTenantInfo();
|
||||
const allOptions = useSelectLlmOptionsByModelType();
|
||||
const fetchTenantInfo = useFetchTenantInfo();
|
||||
|
||||
useEffect(() => {
|
||||
if (visible) {
|
||||
fetchTenantInfo();
|
||||
}
|
||||
}, [fetchTenantInfo, visible]);
|
||||
|
||||
return { systemSetting, allOptions };
|
||||
};
|
||||
|
||||
@@ -264,12 +264,14 @@ const UserSettingModel = () => {
|
||||
onOk={onApiKeySavingOk}
|
||||
llmFactory={llmFactory}
|
||||
></ApiKeyModal>
|
||||
<SystemModelSettingModal
|
||||
visible={systemSettingVisible}
|
||||
onOk={onSystemSettingSavingOk}
|
||||
hideModal={hideSystemSettingModal}
|
||||
loading={saveSystemModelSettingLoading}
|
||||
></SystemModelSettingModal>
|
||||
{systemSettingVisible && (
|
||||
<SystemModelSettingModal
|
||||
visible={systemSettingVisible}
|
||||
onOk={onSystemSettingSavingOk}
|
||||
hideModal={hideSystemSettingModal}
|
||||
loading={saveSystemModelSettingLoading}
|
||||
></SystemModelSettingModal>
|
||||
)}
|
||||
<OllamaModal
|
||||
visible={llmAddingVisible}
|
||||
hideModal={hideLlmAddingModal}
|
||||
|
||||
@@ -21,7 +21,7 @@ const SystemModelSettingModal = ({
|
||||
}: IProps) => {
|
||||
const [form] = Form.useForm();
|
||||
const { systemSetting: initialValues, allOptions } =
|
||||
useFetchSystemModelSettingOnMount(visible);
|
||||
useFetchSystemModelSettingOnMount();
|
||||
const { t } = useTranslate('setting');
|
||||
|
||||
const handleOk = async () => {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { useOneNamespaceEffectsLoading } from '@/hooks/store-hooks';
|
||||
import { useSaveSetting } from '@/hooks/user-setting-hooks';
|
||||
import { rsaPsw } from '@/utils';
|
||||
import { Button, Divider, Form, Input, Space } from 'antd';
|
||||
@@ -19,9 +18,8 @@ const tailLayout = {
|
||||
};
|
||||
|
||||
const UserSettingPassword = () => {
|
||||
const loading = useOneNamespaceEffectsLoading('settingModel', ['setting']);
|
||||
const { form, submittable } = useValidateSubmittable();
|
||||
const saveSetting = useSaveSetting();
|
||||
const { saveSetting, loading } = useSaveSetting();
|
||||
const { t } = useTranslate('setting');
|
||||
|
||||
const onFinish = (values: any) => {
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
import {
|
||||
useFetchUserInfo,
|
||||
useSaveSetting,
|
||||
useSelectUserInfo,
|
||||
} from '@/hooks/user-setting-hooks';
|
||||
import { useFetchUserInfo, useSaveSetting } from '@/hooks/user-setting-hooks';
|
||||
import {
|
||||
getBase64FromUploadFileList,
|
||||
getUploadFileListFromBase64,
|
||||
@@ -24,11 +20,7 @@ import camelCase from 'lodash/camelCase';
|
||||
import { useEffect } from 'react';
|
||||
import SettingTitle from '../components/setting-title';
|
||||
import { TimezoneList } from '../constants';
|
||||
import {
|
||||
useSelectSubmitUserInfoLoading,
|
||||
useSelectUserInfoLoading,
|
||||
useValidateSubmittable,
|
||||
} from '../hooks';
|
||||
import { useValidateSubmittable } from '../hooks';
|
||||
|
||||
import { LanguageList } from '@/constants/common';
|
||||
import { useTranslate } from '@/hooks/common-hooks';
|
||||
@@ -52,12 +44,9 @@ const tailLayout = {
|
||||
};
|
||||
|
||||
const UserSettingProfile = () => {
|
||||
const userInfo = useSelectUserInfo();
|
||||
const saveSetting = useSaveSetting();
|
||||
const submitLoading = useSelectSubmitUserInfoLoading();
|
||||
const { data: userInfo, loading } = useFetchUserInfo();
|
||||
const { saveSetting, loading: submitLoading } = useSaveSetting();
|
||||
const { form, submittable } = useValidateSubmittable();
|
||||
const loading = useSelectUserInfoLoading();
|
||||
useFetchUserInfo();
|
||||
const { t } = useTranslate('setting');
|
||||
const changeLanguage = useChangeLanguage();
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { Button, Card, Flex } from 'antd';
|
||||
|
||||
import { useTranslate } from '@/hooks/common-hooks';
|
||||
import { useSelectUserInfo } from '@/hooks/user-setting-hooks';
|
||||
import { useFetchUserInfo } from '@/hooks/user-setting-hooks';
|
||||
import styles from './index.less';
|
||||
|
||||
const UserSettingTeam = () => {
|
||||
const userInfo = useSelectUserInfo();
|
||||
const { data: userInfo } = useFetchUserInfo();
|
||||
const { t } = useTranslate('setting');
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user