| 
									
										
										
										
											2024-01-23 19:31:56 +08:00
										 |  |  | 'use client' | 
					
						
							|  |  |  | import type { FC } from 'react' | 
					
						
							|  |  |  | import React, { useEffect, useState } from 'react' | 
					
						
							|  |  |  | import { useTranslation } from 'react-i18next' | 
					
						
							|  |  |  | import { useDebounce, useGetState } from 'ahooks' | 
					
						
							| 
									
										
										
										
											2025-02-17 17:05:13 +08:00
										 |  |  | import { RiSettings2Line } from '@remixicon/react' | 
					
						
							| 
									
										
										
										
											2024-03-04 15:20:20 +08:00
										 |  |  | import produce from 'immer' | 
					
						
							| 
									
										
										
										
											2025-02-17 17:05:13 +08:00
										 |  |  | import { LinkExternal02 } from '../../base/icons/src/vender/line/general' | 
					
						
							| 
									
										
										
										
											2024-01-23 19:31:56 +08:00
										 |  |  | import type { Credential, CustomCollectionBackend, CustomParamSchema, Emoji } from '../types' | 
					
						
							| 
									
										
										
										
											2024-02-28 23:19:08 +08:00
										 |  |  | import { AuthHeaderPrefix, AuthType } from '../types' | 
					
						
							| 
									
										
										
										
											2024-01-23 19:31:56 +08:00
										 |  |  | import GetSchema from './get-schema' | 
					
						
							|  |  |  | import ConfigCredentials from './config-credentials' | 
					
						
							|  |  |  | import TestApi from './test-api' | 
					
						
							| 
									
										
										
										
											2024-07-09 15:05:40 +08:00
										 |  |  | import cn from '@/utils/classnames' | 
					
						
							| 
									
										
										
										
											2024-01-23 19:31:56 +08:00
										 |  |  | import Drawer from '@/app/components/base/drawer-plus' | 
					
						
							|  |  |  | import Button from '@/app/components/base/button' | 
					
						
							| 
									
										
										
										
											2024-10-21 10:32:37 +08:00
										 |  |  | import Input from '@/app/components/base/input' | 
					
						
							|  |  |  | import Textarea from '@/app/components/base/textarea' | 
					
						
							| 
									
										
										
										
											2024-01-23 19:31:56 +08:00
										 |  |  | import EmojiPicker from '@/app/components/base/emoji-picker' | 
					
						
							|  |  |  | import AppIcon from '@/app/components/base/app-icon' | 
					
						
							|  |  |  | import { parseParamsSchema } from '@/service/tools' | 
					
						
							| 
									
										
										
										
											2024-05-27 21:57:08 +08:00
										 |  |  | import LabelSelector from '@/app/components/tools/labels/selector' | 
					
						
							| 
									
										
										
										
											2024-07-11 11:08:50 +08:00
										 |  |  | import Toast from '@/app/components/base/toast' | 
					
						
							| 
									
										
										
										
											2024-01-23 19:31:56 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | type Props = { | 
					
						
							| 
									
										
										
										
											2024-05-27 21:57:08 +08:00
										 |  |  |   positionLeft?: boolean | 
					
						
							| 
									
										
										
										
											2024-01-23 19:31:56 +08:00
										 |  |  |   payload: any | 
					
						
							|  |  |  |   onHide: () => void | 
					
						
							|  |  |  |   onAdd?: (payload: CustomCollectionBackend) => void | 
					
						
							|  |  |  |   onRemove?: () => void | 
					
						
							|  |  |  |   onEdit?: (payload: CustomCollectionBackend) => void | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | // Add and Edit
 | 
					
						
							|  |  |  | const EditCustomCollectionModal: FC<Props> = ({ | 
					
						
							| 
									
										
										
										
											2024-05-27 21:57:08 +08:00
										 |  |  |   positionLeft, | 
					
						
							| 
									
										
										
										
											2024-01-23 19:31:56 +08:00
										 |  |  |   payload, | 
					
						
							|  |  |  |   onHide, | 
					
						
							|  |  |  |   onAdd, | 
					
						
							|  |  |  |   onEdit, | 
					
						
							|  |  |  |   onRemove, | 
					
						
							|  |  |  | }) => { | 
					
						
							|  |  |  |   const { t } = useTranslation() | 
					
						
							|  |  |  |   const isAdd = !payload | 
					
						
							|  |  |  |   const isEdit = !!payload | 
					
						
							| 
									
										
										
										
											2024-02-28 23:19:08 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-23 19:31:56 +08:00
										 |  |  |   const [editFirst, setEditFirst] = useState(!isAdd) | 
					
						
							|  |  |  |   const [paramsSchemas, setParamsSchemas] = useState<CustomParamSchema[]>(payload?.tools || []) | 
					
						
							|  |  |  |   const [customCollection, setCustomCollection, getCustomCollection] = useGetState<CustomCollectionBackend>(isAdd | 
					
						
							|  |  |  |     ? { | 
					
						
							|  |  |  |       provider: '', | 
					
						
							|  |  |  |       credentials: { | 
					
						
							|  |  |  |         auth_type: AuthType.none, | 
					
						
							| 
									
										
										
										
											2024-02-28 23:19:08 +08:00
										 |  |  |         api_key_header: 'Authorization', | 
					
						
							|  |  |  |         api_key_header_prefix: AuthHeaderPrefix.basic, | 
					
						
							| 
									
										
										
										
											2024-01-23 19:31:56 +08:00
										 |  |  |       }, | 
					
						
							|  |  |  |       icon: { | 
					
						
							|  |  |  |         content: '🕵️', | 
					
						
							|  |  |  |         background: '#FEF7C3', | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       schema_type: '', | 
					
						
							|  |  |  |       schema: '', | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     : payload) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const originalProvider = isEdit ? payload.provider : '' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const [showEmojiPicker, setShowEmojiPicker] = useState(false) | 
					
						
							|  |  |  |   const emoji = customCollection.icon | 
					
						
							|  |  |  |   const setEmoji = (emoji: Emoji) => { | 
					
						
							|  |  |  |     const newCollection = produce(customCollection, (draft) => { | 
					
						
							|  |  |  |       draft.icon = emoji | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  |     setCustomCollection(newCollection) | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   const schema = customCollection.schema | 
					
						
							|  |  |  |   const debouncedSchema = useDebounce(schema, { wait: 500 }) | 
					
						
							| 
									
										
										
										
											2024-10-21 10:32:37 +08:00
										 |  |  |   const setSchema = (schema: any) => { | 
					
						
							| 
									
										
										
										
											2024-01-23 19:31:56 +08:00
										 |  |  |     const newCollection = produce(customCollection, (draft) => { | 
					
						
							|  |  |  |       draft.schema = schema | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  |     setCustomCollection(newCollection) | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   useEffect(() => { | 
					
						
							|  |  |  |     if (!debouncedSchema) | 
					
						
							|  |  |  |       return | 
					
						
							|  |  |  |     if (isEdit && editFirst) { | 
					
						
							|  |  |  |       setEditFirst(false) | 
					
						
							|  |  |  |       return | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     (async () => { | 
					
						
							|  |  |  |       try { | 
					
						
							| 
									
										
										
										
											2024-02-01 18:07:26 +08:00
										 |  |  |         const { parameters_schema, schema_type } = await parseParamsSchema(debouncedSchema) | 
					
						
							| 
									
										
										
										
											2024-07-18 19:02:23 +08:00
										 |  |  |         const customCollection = getCustomCollection() | 
					
						
							| 
									
										
										
										
											2024-01-23 19:31:56 +08:00
										 |  |  |         const newCollection = produce(customCollection, (draft) => { | 
					
						
							|  |  |  |           draft.schema_type = schema_type | 
					
						
							|  |  |  |         }) | 
					
						
							|  |  |  |         setCustomCollection(newCollection) | 
					
						
							|  |  |  |         setParamsSchemas(parameters_schema) | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2025-04-14 11:27:14 +08:00
										 |  |  |       catch { | 
					
						
							| 
									
										
										
										
											2024-07-18 19:02:23 +08:00
										 |  |  |         const customCollection = getCustomCollection() | 
					
						
							| 
									
										
										
										
											2024-01-23 19:31:56 +08:00
										 |  |  |         const newCollection = produce(customCollection, (draft) => { | 
					
						
							|  |  |  |           draft.schema_type = '' | 
					
						
							|  |  |  |         }) | 
					
						
							|  |  |  |         setCustomCollection(newCollection) | 
					
						
							|  |  |  |         setParamsSchemas([]) | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     })() | 
					
						
							|  |  |  |   }, [debouncedSchema]) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const [credentialsModalShow, setCredentialsModalShow] = useState(false) | 
					
						
							|  |  |  |   const credential = customCollection.credentials | 
					
						
							|  |  |  |   const setCredential = (credential: Credential) => { | 
					
						
							|  |  |  |     const newCollection = produce(customCollection, (draft) => { | 
					
						
							|  |  |  |       draft.credentials = credential | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  |     setCustomCollection(newCollection) | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const [currTool, setCurrTool] = useState<CustomParamSchema | null>(null) | 
					
						
							|  |  |  |   const [isShowTestApi, setIsShowTestApi] = useState(false) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-27 21:57:08 +08:00
										 |  |  |   const [labels, setLabels] = useState<string[]>(payload?.labels || []) | 
					
						
							|  |  |  |   const handleLabelSelect = (value: string[]) => { | 
					
						
							|  |  |  |     setLabels(value) | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-23 19:31:56 +08:00
										 |  |  |   const handleSave = () => { | 
					
						
							| 
									
										
										
										
											2024-03-04 15:20:20 +08:00
										 |  |  |     // const postData = clone(customCollection)
 | 
					
						
							|  |  |  |     const postData = produce(customCollection, (draft) => { | 
					
						
							|  |  |  |       delete draft.tools | 
					
						
							| 
									
										
										
										
											2024-02-29 12:58:12 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-04 15:20:20 +08:00
										 |  |  |       if (draft.credentials.auth_type === AuthType.none) { | 
					
						
							|  |  |  |         delete draft.credentials.api_key_header | 
					
						
							|  |  |  |         delete draft.credentials.api_key_header_prefix | 
					
						
							|  |  |  |         delete draft.credentials.api_key_value | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2024-05-27 21:57:08 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |       draft.labels = labels | 
					
						
							| 
									
										
										
										
											2024-03-04 15:20:20 +08:00
										 |  |  |     }) | 
					
						
							| 
									
										
										
										
											2024-02-29 12:58:12 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-11 11:08:50 +08:00
										 |  |  |     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 | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-23 19:31:56 +08:00
										 |  |  |     if (isAdd) { | 
					
						
							|  |  |  |       onAdd?.(postData) | 
					
						
							|  |  |  |       return | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     onEdit?.({ | 
					
						
							|  |  |  |       ...postData, | 
					
						
							|  |  |  |       original_provider: originalProvider, | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-31 14:04:54 +08:00
										 |  |  |   const getPath = (url: string) => { | 
					
						
							|  |  |  |     if (!url) | 
					
						
							|  |  |  |       return '' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     try { | 
					
						
							| 
									
										
										
										
											2024-08-16 14:09:25 +08:00
										 |  |  |       const path = decodeURI(new URL(url).pathname) | 
					
						
							| 
									
										
										
										
											2024-01-31 14:04:54 +08:00
										 |  |  |       return path || '' | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2025-04-14 11:27:14 +08:00
										 |  |  |     catch { | 
					
						
							| 
									
										
										
										
											2024-01-31 14:04:54 +08:00
										 |  |  |       return url | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-23 19:31:56 +08:00
										 |  |  |   return ( | 
					
						
							|  |  |  |     <> | 
					
						
							|  |  |  |       <Drawer | 
					
						
							|  |  |  |         isShow | 
					
						
							| 
									
										
										
										
											2024-05-27 21:57:08 +08:00
										 |  |  |         positionCenter={isAdd && !positionLeft} | 
					
						
							| 
									
										
										
										
											2024-01-23 19:31:56 +08:00
										 |  |  |         onHide={onHide} | 
					
						
							|  |  |  |         title={t(`tools.createTool.${isAdd ? 'title' : 'editTitle'}`)!} | 
					
						
							| 
									
										
										
										
											2024-11-07 18:10:41 +08:00
										 |  |  |         panelClassName='mt-2 !w-[640px]' | 
					
						
							|  |  |  |         maxWidthClassName='!max-w-[640px]' | 
					
						
							| 
									
										
										
										
											2024-01-23 19:31:56 +08:00
										 |  |  |         height='calc(100vh - 16px)' | 
					
						
							| 
									
										
										
										
											2025-02-17 17:05:13 +08:00
										 |  |  |         headerClassName='!border-b-divider-regular' | 
					
						
							| 
									
										
										
										
											2024-01-23 19:31:56 +08:00
										 |  |  |         body={ | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |           <div className='flex h-full flex-col'> | 
					
						
							|  |  |  |             <div className='h-0 grow space-y-4 overflow-y-auto px-6 py-3'> | 
					
						
							| 
									
										
										
										
											2024-01-23 19:31:56 +08:00
										 |  |  |               <div> | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |                 <div className='system-sm-medium py-2 text-text-primary'>{t('tools.createTool.name')} <span className='ml-1 text-red-500'>*</span></div> | 
					
						
							| 
									
										
										
										
											2024-01-23 19:31:56 +08:00
										 |  |  |                 <div className='flex items-center justify-between gap-3'> | 
					
						
							|  |  |  |                   <AppIcon size='large' onClick={() => { setShowEmojiPicker(true) }} className='cursor-pointer' icon={emoji.content} background={emoji.background} /> | 
					
						
							| 
									
										
										
										
											2024-10-21 10:32:37 +08:00
										 |  |  |                   <Input | 
					
						
							|  |  |  |                     className='h-10 grow' placeholder={t('tools.createTool.toolNamePlaceHolder')!} | 
					
						
							| 
									
										
										
										
											2024-01-23 19:31:56 +08:00
										 |  |  |                     value={customCollection.provider} | 
					
						
							|  |  |  |                     onChange={(e) => { | 
					
						
							|  |  |  |                       const newCollection = produce(customCollection, (draft) => { | 
					
						
							|  |  |  |                         draft.provider = e.target.value | 
					
						
							|  |  |  |                       }) | 
					
						
							|  |  |  |                       setCustomCollection(newCollection) | 
					
						
							|  |  |  |                     }} | 
					
						
							|  |  |  |                   /> | 
					
						
							|  |  |  |                 </div> | 
					
						
							|  |  |  |               </div> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |               {/* Schema */} | 
					
						
							|  |  |  |               <div className='select-none'> | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |                 <div className='flex items-center justify-between'> | 
					
						
							| 
									
										
										
										
											2024-01-23 19:31:56 +08:00
										 |  |  |                   <div className='flex items-center'> | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |                     <div className='system-sm-medium py-2 text-text-primary'>{t('tools.createTool.schema')}<span className='ml-1 text-red-500'>*</span></div> | 
					
						
							|  |  |  |                     <div className='mx-2 h-3 w-px bg-divider-regular'></div> | 
					
						
							| 
									
										
										
										
											2024-01-23 19:31:56 +08:00
										 |  |  |                     <a | 
					
						
							|  |  |  |                       href="https://swagger.io/specification/" | 
					
						
							| 
									
										
										
										
											2024-02-02 15:24:17 +08:00
										 |  |  |                       target='_blank' rel='noopener noreferrer' | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |                       className='flex h-[18px] items-center space-x-1  text-text-accent' | 
					
						
							| 
									
										
										
										
											2024-01-23 19:31:56 +08:00
										 |  |  |                     > | 
					
						
							|  |  |  |                       <div className='text-xs font-normal'>{t('tools.createTool.viewSchemaSpec')}</div> | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |                       <LinkExternal02 className='h-3 w-3' /> | 
					
						
							| 
									
										
										
										
											2024-01-23 19:31:56 +08:00
										 |  |  |                     </a> | 
					
						
							|  |  |  |                   </div> | 
					
						
							|  |  |  |                   <GetSchema onChange={setSchema} /> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 </div> | 
					
						
							| 
									
										
										
										
											2024-10-21 10:32:37 +08:00
										 |  |  |                 <Textarea | 
					
						
							|  |  |  |                   className='h-[240px] resize-none' | 
					
						
							| 
									
										
										
										
											2024-01-23 19:31:56 +08:00
										 |  |  |                   value={schema} | 
					
						
							|  |  |  |                   onChange={e => setSchema(e.target.value)} | 
					
						
							|  |  |  |                   placeholder={t('tools.createTool.schemaPlaceHolder')!} | 
					
						
							| 
									
										
										
										
											2024-10-21 10:32:37 +08:00
										 |  |  |                 /> | 
					
						
							| 
									
										
										
										
											2024-01-23 19:31:56 +08:00
										 |  |  |               </div> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |               {/* Available Tools  */} | 
					
						
							|  |  |  |               <div> | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |                 <div className='system-sm-medium py-2 text-text-primary'>{t('tools.createTool.availableTools.title')}</div> | 
					
						
							|  |  |  |                 <div className='w-full overflow-x-auto rounded-lg border border-divider-regular'> | 
					
						
							|  |  |  |                   <table className='system-xs-regular w-full text-text-secondary'> | 
					
						
							|  |  |  |                     <thead className='uppercase text-text-tertiary'> | 
					
						
							| 
									
										
										
										
											2025-02-17 17:05:13 +08:00
										 |  |  |                       <tr className={cn(paramsSchemas.length > 0 && 'border-b', 'border-divider-regular')}> | 
					
						
							| 
									
										
										
										
											2024-01-23 19:31:56 +08:00
										 |  |  |                         <th className="p-2 pl-3 font-medium">{t('tools.createTool.availableTools.name')}</th> | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |                         <th className="w-[236px] p-2 pl-3 font-medium">{t('tools.createTool.availableTools.description')}</th> | 
					
						
							| 
									
										
										
										
											2024-01-23 19:31:56 +08:00
										 |  |  |                         <th className="p-2 pl-3 font-medium">{t('tools.createTool.availableTools.method')}</th> | 
					
						
							|  |  |  |                         <th className="p-2 pl-3 font-medium">{t('tools.createTool.availableTools.path')}</th> | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |                         <th className="w-[54px] p-2 pl-3 font-medium">{t('tools.createTool.availableTools.action')}</th> | 
					
						
							| 
									
										
										
										
											2024-01-23 19:31:56 +08:00
										 |  |  |                       </tr> | 
					
						
							|  |  |  |                     </thead> | 
					
						
							|  |  |  |                     <tbody> | 
					
						
							|  |  |  |                       {paramsSchemas.map((item, index) => ( | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |                         <tr key={index} className='border-b border-divider-regular last:border-0'> | 
					
						
							| 
									
										
										
										
											2024-01-23 19:31:56 +08:00
										 |  |  |                           <td className="p-2 pl-3">{item.operation_id}</td> | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |                           <td className="w-[236px] p-2 pl-3">{item.summary}</td> | 
					
						
							| 
									
										
										
										
											2024-01-23 19:31:56 +08:00
										 |  |  |                           <td className="p-2 pl-3">{item.method}</td> | 
					
						
							| 
									
										
										
										
											2024-01-31 14:04:54 +08:00
										 |  |  |                           <td className="p-2 pl-3">{getPath(item.server_url)}</td> | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |                           <td className="w-[62px] p-2 pl-3"> | 
					
						
							| 
									
										
										
										
											2024-01-23 19:31:56 +08:00
										 |  |  |                             <Button | 
					
						
							| 
									
										
										
										
											2024-06-21 14:17:45 +08:00
										 |  |  |                               size='small' | 
					
						
							| 
									
										
										
										
											2024-01-23 19:31:56 +08:00
										 |  |  |                               onClick={() => { | 
					
						
							|  |  |  |                                 setCurrTool(item) | 
					
						
							|  |  |  |                                 setIsShowTestApi(true) | 
					
						
							|  |  |  |                               }} | 
					
						
							|  |  |  |                             > | 
					
						
							|  |  |  |                               {t('tools.createTool.availableTools.test')} | 
					
						
							|  |  |  |                             </Button> | 
					
						
							|  |  |  |                           </td> | 
					
						
							|  |  |  |                         </tr> | 
					
						
							|  |  |  |                       ))} | 
					
						
							|  |  |  |                     </tbody> | 
					
						
							|  |  |  |                   </table> | 
					
						
							|  |  |  |                 </div> | 
					
						
							|  |  |  |               </div> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |               {/* Authorization method */} | 
					
						
							|  |  |  |               <div> | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |                 <div className='system-sm-medium py-2 text-text-primary'>{t('tools.createTool.authMethod.title')}</div> | 
					
						
							|  |  |  |                 <div className='flex h-9 cursor-pointer items-center justify-between rounded-lg bg-components-input-bg-normal px-2.5' onClick={() => setCredentialsModalShow(true)}> | 
					
						
							| 
									
										
										
										
											2025-02-17 17:05:13 +08:00
										 |  |  |                   <div className='system-xs-regular text-text-primary'>{t(`tools.createTool.authMethod.types.${credential.auth_type}`)}</div> | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |                   <RiSettings2Line className='h-4 w-4 text-text-secondary' /> | 
					
						
							| 
									
										
										
										
											2024-01-23 19:31:56 +08:00
										 |  |  |                 </div> | 
					
						
							|  |  |  |               </div> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-27 21:57:08 +08:00
										 |  |  |               {/* Labels */} | 
					
						
							|  |  |  |               <div> | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |                 <div className='system-sm-medium py-2 text-text-primary'>{t('tools.createTool.toolInput.label')}</div> | 
					
						
							| 
									
										
										
										
											2024-05-27 21:57:08 +08:00
										 |  |  |                 <LabelSelector value={labels} onChange={handleLabelSelect} /> | 
					
						
							|  |  |  |               </div> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |               {/* Privacy Policy */} | 
					
						
							| 
									
										
										
										
											2024-01-23 19:31:56 +08:00
										 |  |  |               <div> | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |                 <div className='system-sm-medium py-2 text-text-primary'>{t('tools.createTool.privacyPolicy')}</div> | 
					
						
							| 
									
										
										
										
											2024-10-21 10:32:37 +08:00
										 |  |  |                 <Input | 
					
						
							| 
									
										
										
										
											2024-01-23 19:31:56 +08:00
										 |  |  |                   value={customCollection.privacy_policy} | 
					
						
							|  |  |  |                   onChange={(e) => { | 
					
						
							|  |  |  |                     const newCollection = produce(customCollection, (draft) => { | 
					
						
							|  |  |  |                       draft.privacy_policy = e.target.value | 
					
						
							|  |  |  |                     }) | 
					
						
							|  |  |  |                     setCustomCollection(newCollection) | 
					
						
							|  |  |  |                   }} | 
					
						
							| 
									
										
										
										
											2024-10-21 10:32:37 +08:00
										 |  |  |                   className='h-10 grow' placeholder={t('tools.createTool.privacyPolicyPlaceholder') || ''} /> | 
					
						
							| 
									
										
										
										
											2024-01-23 19:31:56 +08:00
										 |  |  |               </div> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-18 04:52:48 +02:00
										 |  |  |               <div> | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |                 <div className='system-sm-medium py-2 text-text-primary'>{t('tools.createTool.customDisclaimer')}</div> | 
					
						
							| 
									
										
										
										
											2024-10-21 10:32:37 +08:00
										 |  |  |                 <Input | 
					
						
							| 
									
										
										
										
											2024-05-18 04:52:48 +02:00
										 |  |  |                   value={customCollection.custom_disclaimer} | 
					
						
							|  |  |  |                   onChange={(e) => { | 
					
						
							|  |  |  |                     const newCollection = produce(customCollection, (draft) => { | 
					
						
							|  |  |  |                       draft.custom_disclaimer = e.target.value | 
					
						
							|  |  |  |                     }) | 
					
						
							|  |  |  |                     setCustomCollection(newCollection) | 
					
						
							|  |  |  |                   }} | 
					
						
							| 
									
										
										
										
											2024-10-21 10:32:37 +08:00
										 |  |  |                   className='h-10 grow' placeholder={t('tools.createTool.customDisclaimerPlaceholder') || ''} /> | 
					
						
							| 
									
										
										
										
											2024-05-18 04:52:48 +02:00
										 |  |  |               </div> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-23 19:31:56 +08:00
										 |  |  |             </div> | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |             <div className={cn(isEdit ? 'justify-between' : 'justify-end', 'mt-2 flex shrink-0 rounded-b-[10px] border-t border-divider-regular bg-background-section-burn px-6 py-4')} > | 
					
						
							| 
									
										
										
										
											2024-01-23 19:31:56 +08:00
										 |  |  |               { | 
					
						
							|  |  |  |                 isEdit && ( | 
					
						
							| 
									
										
										
										
											2025-02-17 17:05:13 +08:00
										 |  |  |                   <Button variant='warning' onClick={onRemove}>{t('common.operation.delete')}</Button> | 
					
						
							| 
									
										
										
										
											2024-01-23 19:31:56 +08:00
										 |  |  |                 ) | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |               <div className='flex space-x-2 '> | 
					
						
							| 
									
										
										
										
											2024-06-21 14:17:45 +08:00
										 |  |  |                 <Button onClick={onHide}>{t('common.operation.cancel')}</Button> | 
					
						
							|  |  |  |                 <Button variant='primary' onClick={handleSave}>{t('common.operation.save')}</Button> | 
					
						
							| 
									
										
										
										
											2024-01-23 19:31:56 +08:00
										 |  |  |               </div> | 
					
						
							|  |  |  |             </div> | 
					
						
							| 
									
										
										
										
											2024-08-15 10:31:34 +08:00
										 |  |  |             {showEmojiPicker && <EmojiPicker | 
					
						
							|  |  |  |               onSelect={(icon, icon_background) => { | 
					
						
							|  |  |  |                 setEmoji({ content: icon, background: icon_background }) | 
					
						
							|  |  |  |                 setShowEmojiPicker(false) | 
					
						
							|  |  |  |               }} | 
					
						
							|  |  |  |               onClose={() => { | 
					
						
							|  |  |  |                 setShowEmojiPicker(false) | 
					
						
							|  |  |  |               }} | 
					
						
							|  |  |  |             />} | 
					
						
							|  |  |  |             {credentialsModalShow && ( | 
					
						
							|  |  |  |               <ConfigCredentials | 
					
						
							|  |  |  |                 positionCenter={isAdd} | 
					
						
							|  |  |  |                 credential={credential} | 
					
						
							|  |  |  |                 onChange={setCredential} | 
					
						
							|  |  |  |                 onHide={() => setCredentialsModalShow(false)} | 
					
						
							|  |  |  |               />) | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             {isShowTestApi && ( | 
					
						
							|  |  |  |               <TestApi | 
					
						
							|  |  |  |                 positionCenter={isAdd} | 
					
						
							|  |  |  |                 tool={currTool as CustomParamSchema} | 
					
						
							|  |  |  |                 customCollection={customCollection} | 
					
						
							|  |  |  |                 onHide={() => setIsShowTestApi(false)} | 
					
						
							|  |  |  |               /> | 
					
						
							|  |  |  |             )} | 
					
						
							| 
									
										
										
										
											2024-01-23 19:31:56 +08:00
										 |  |  |           </div> | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         isShowMask={true} | 
					
						
							|  |  |  |         clickOutsideNotOpen={true} | 
					
						
							|  |  |  |       /> | 
					
						
							|  |  |  |     </> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   ) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | export default React.memo(EditCustomCollectionModal) |