Files
ragflow/web/src/hooks/use-warn-empty-model.tsx
balibabu 9c14e3f377 Fix: When adding a chat in the main interface, a warning will automatically pop up (#15685)
### What problem does this PR solve?

Fix: When adding a chat in the main interface, a warning will
automatically pop up (even if embedding and LLM model have already been
configured).
### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
2026-06-05 19:09:22 +08:00

46 lines
1.2 KiB
TypeScript

import { Modal } from '@/components/ui/modal/modal';
import DOMPurify from 'dompurify';
import { isEmpty } from 'lodash';
import { useEffect, useRef } from 'react';
import { useTranslation } from 'react-i18next';
import { useNavigatePage } from './logic-hooks/navigate-hooks';
export const useWarnEmptyModel = (
showEmptyModelWarn: boolean,
embdId?: string,
llmId?: string,
loading?: boolean,
) => {
const { t } = useTranslation();
const warnedRef = useRef(false);
const { navigateToModelSetting } = useNavigatePage();
useEffect(() => {
if (
showEmptyModelWarn &&
!warnedRef.current &&
!loading &&
(isEmpty(embdId) || isEmpty(llmId)) &&
typeof embdId === 'string' &&
typeof llmId === 'string'
) {
warnedRef.current = true;
Modal.warning({
title: t('common.warn'),
content: (
<div
dangerouslySetInnerHTML={{
__html: DOMPurify.sanitize(t('setting.modelProvidersWarn')),
}}
></div>
),
closable: false,
showCancel: false,
onOk() {
navigateToModelSetting();
},
});
}
}, [showEmptyModelWarn, embdId, llmId, loading, navigateToModelSetting, t]);
};