'use client' import React, { useCallback, useEffect, useState } from 'react' import { RiAddLine, RiCloseLine, RiRefreshLine, RiSearchLine } from '@remixicon/react' import Modal from '@/app/components/base/modal' import Button from '@/app/components/base/button' import { delCorpus, fetchIntentType, fetchTypes } from '@/service/common' import 'react-multi-email/dist/style.css' import Input from '@/app/components/base/input' import useSWR from 'swr' import cn from '@/utils/classnames' import Confirm from '@/app/components/base/confirm' import Pagination from '@/app/components/base/pagination' import { SimpleSelect } from '@/app/components/base/select' const TypeModal = ({ onCancel, onSend, }: any) => { const [page, setPage] = React.useState(0) const [limit, setLimit] = useState(10) const [name, setName] = useState('') const [query, setQuery] = useState({}) const { data, mutate }: any = useSWR( { url: '/xxx', params: { page: page + 1, limit, ...query, }, }, fetchIntentType, ) const list: any = data?.data || [] const total = data?.total || 0 const handleSearch = (reset = false) => { if (reset) setIntentType('') const params: any = {} if (intentType) params.intentType = intentType setQuery(params) setPage(0) } useEffect(() => { mutate() }, [page, limit]) const [showConfirmDelete, setShowConfirmDelete] = useState(false) const [row, setRow] = useState({}) const handleDel = async () => { try { await delCorpus({ url: `/tags/${row.id}`, body: {}, }) setShowConfirmDelete(false) } catch (e) { } } const [showDetail, setShowDetail] = useState(false) const [mode, setMode] = useState('add') const [editIntentType, setEditIntentType] = useState('') const [selectUser, setSelectUser] = useState('') const [userOptions, setUserOptions] = useState([]) useEffect(() => { fetchTypes({ url: '/tags/page', params: { page: 1, limit: 99999, tag_type: 'knowledge_category', }, }).then((res: any) => { setUserOptions(res.data.map((v: any) => ({ name: v.name, value: v.id })) || []) }) }, []) const handleSave = useCallback(async () => { // try { // let res // if (transfer.mode === 'add') { // res = await addCorpus({ // url: '/xxx', // body: { name, type: 'knowledge_category' }, // }) // } // else { // res = await editCorpus({ // url: '/xxx', // body: { name }, // }) // } // const { id }: any = res // if (id) { // onCancel() // onSend() // } // } // catch (e) { } }, [mode, editIntentType, onCancel, onSend]) return (
{ }} className="p-[24px 32px] w-[800px] max-w-[800px]">
关联用户
用户名称 setName(e.target.value)} onClear={() => setName('')} />
{list.map((item: any) => ( ))}
用户名称 操作
{item.name}
{/* Show Pagination only if the total is more than the limit */} {total && ( )}
{showConfirmDelete && ( setShowConfirmDelete(false)} /> )} { showDetail && ( { }} className="p-[24px 32px] w-[400px]">
添加用户
setShowDetail(false)} />
选择用户
{ setSelectUser(i.value) }} items={userOptions} allowSearch={false} />
) }
) } export default TypeModal