fix: Error on chat api,<BadRequestKeyError '400: Bad Request'> #1918 (#1923)

### What problem does this PR solve?

fix: Error on chat api,<BadRequestKeyError '400: Bad Request'> #1918

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
balibabu 2024-08-13 10:51:51 +08:00 committed by GitHub
parent 8badf3f423
commit b75115264d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 3 deletions

View File

@ -1,6 +1,5 @@
import { import {
useCreateNextToken, useCreateNextToken,
useFetchNextStats,
useFetchTokenList, useFetchTokenList,
useRemoveNextToken, useRemoveNextToken,
} from '@/hooks/chat-hooks'; } from '@/hooks/chat-hooks';
@ -10,6 +9,7 @@ import {
useTranslate, useTranslate,
} from '@/hooks/common-hooks'; } from '@/hooks/common-hooks';
import { IStats } from '@/interfaces/database/chat'; import { IStats } from '@/interfaces/database/chat';
import { useQueryClient } from '@tanstack/react-query';
import { message } from 'antd'; import { message } from 'antd';
import { useCallback } from 'react'; import { useCallback } from 'react';
@ -46,7 +46,9 @@ type ChartStatsType = {
}; };
export const useSelectChartStatsList = (): ChartStatsType => { export const useSelectChartStatsList = (): ChartStatsType => {
const { data: stats } = useFetchNextStats(); const queryClient = useQueryClient();
const data = queryClient.getQueriesData({ queryKey: ['fetchStats'] });
const stats: IStats = data[0][1] as IStats;
return Object.keys(stats).reduce((pre, cur) => { return Object.keys(stats).reduce((pre, cur) => {
const item = stats[cur as keyof IStats]; const item = stats[cur as keyof IStats];

View File

@ -260,8 +260,8 @@ const getDay = (date?: Dayjs) => date?.format('YYYY-MM-DD');
export const useFetchNextStats = () => { export const useFetchNextStats = () => {
const [pickerValue, setPickerValue] = useState<RangeValue>([ const [pickerValue, setPickerValue] = useState<RangeValue>([
dayjs(),
dayjs().subtract(7, 'day'), dayjs().subtract(7, 'day'),
dayjs(),
]); ]);
const { data, isFetching: loading } = useQuery<IStats>({ const { data, isFetching: loading } = useQuery<IStats>({
queryKey: ['fetchStats', pickerValue], queryKey: ['fetchStats', pickerValue],