diff --git a/web/app/components/tools/edit-custom-collection-modal/index.tsx b/web/app/components/tools/edit-custom-collection-modal/index.tsx index daed41332..c354bb919 100644 --- a/web/app/components/tools/edit-custom-collection-modal/index.tsx +++ b/web/app/components/tools/edit-custom-collection-modal/index.tsx @@ -17,6 +17,7 @@ import EmojiPicker from '@/app/components/base/emoji-picker' import AppIcon from '@/app/components/base/app-icon' import { parseParamsSchema } from '@/service/tools' import LabelSelector from '@/app/components/tools/labels/selector' +import Toast from '@/app/components/base/toast' const fieldNameClassNames = 'py-2 leading-5 text-sm font-medium text-gray-900' type Props = { @@ -136,6 +137,21 @@ const EditCustomCollectionModal: FC = ({ draft.labels = labels }) + let errorMessage = '' + if (!postData.provider) + errorMessage = t('common.errorMsg.fieldRequired', { field: t('tools.createTool.name') }) + + if (!postData.schema) + errorMessage = t('common.errorMsg.fieldRequired', { field: t('tools.createTool.schema') }) + + if (errorMessage) { + Toast.notify({ + type: 'error', + message: errorMessage, + }) + return + } + if (isAdd) { onAdd?.(postData) return @@ -175,7 +191,7 @@ const EditCustomCollectionModal: FC = ({
-
{t('tools.createTool.name')}
+
{t('tools.createTool.name')} *
{ setShowEmojiPicker(true) }} className='cursor-pointer' icon={emoji.content} background={emoji.background} /> = ({
-
{t('tools.createTool.schema')}
+
{t('tools.createTool.schema')}*
= ({ const [showModal, setShowModal] = useState(false) const isNameValid = (name: string) => { + // when the user has not input anything, no need for a warning + if (name === '') + return true + return /^[a-zA-Z0-9_]+$/.test(name) } const onConfirm = () => { - if (!label) { - return Toast.notify({ + let errorMessage = '' + if (!label) + errorMessage = t('common.errorMsg.fieldRequired', { field: t('tools.createTool.name') }) + + if (!name) + errorMessage = t('common.errorMsg.fieldRequired', { field: t('tools.createTool.nameForToolCall') }) + + if (!isNameValid(name)) + errorMessage = t('tools.createTool.nameForToolCall') + t('tools.createTool.nameForToolCallTip') + + if (errorMessage) { + Toast.notify({ type: 'error', - message: 'Please enter the tool name', - }) - } - if (!name) { - return Toast.notify({ - type: 'error', - message: 'Please enter the name for tool call', - }) - } - else if (!isNameValid(name)) { - return Toast.notify({ - type: 'error', - message: 'Name for tool call can only contain numbers, letters, and underscores', + message: errorMessage, }) + return } + const requestParams = { name, description, @@ -127,7 +131,7 @@ const WorkflowToolAsModal: FC = ({
{/* name & icon */}
-
{t('tools.createTool.name')}
+
{t('tools.createTool.name')} *
{ setShowEmojiPicker(true) }} className='cursor-pointer' icon={emoji.content} background={emoji.background} /> = ({ {/* name for tool call */}
- {t('tools.createTool.nameForToolCall')} + {t('tools.createTool.nameForToolCall')} * @@ -162,7 +166,7 @@ const WorkflowToolAsModal: FC = ({ onChange={e => setName(e.target.value)} /> {!isNameValid(name) && ( -
{t('tools.createTool.nameForToolCallTip')}
+
{t('tools.createTool.nameForToolCallTip')}
)}
{/* description */} @@ -248,7 +252,7 @@ const WorkflowToolAsModal: FC = ({ )}
-