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

### 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:
balibabu
2024-07-25 18:53:10 +08:00
committed by GitHub
parent 375f621405
commit 935687998e
22 changed files with 107 additions and 340 deletions

View File

@@ -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 };
};

View File

@@ -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}

View File

@@ -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 () => {