index.tsx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. 'use client'
  2. import { useCallback, useState } from 'react'
  3. import { RiCloseLine } from '@remixicon/react'
  4. import s from './index.module.css'
  5. import cn from '@/utils/classnames'
  6. import Modal from '@/app/components/base/modal'
  7. import Button from '@/app/components/base/button'
  8. import { addKnowledge, editKnowledge } from '@/service/common'
  9. import 'react-multi-email/dist/style.css'
  10. import Input from '@/app/components/base/input'
  11. import { SimpleSelect } from '@/app/components/base/select'
  12. const InviteModal = ({
  13. transfer,
  14. onCancel,
  15. onSend,
  16. }: any) => {
  17. const [serviceType, setServiceType] = useState<any>(transfer.row?.serviceType || '')
  18. const [serviceName, setServiceName] = useState<string>(transfer.row?.serviceName || '')
  19. const [url, setUrl] = useState<string>(transfer.row?.url || '')
  20. const [method, setMethod] = useState<string>(transfer.row?.method || '')
  21. const options = [
  22. { name: '智能问答', value: 1 },
  23. { name: '智能搜索', value: 2 },
  24. { name: '智能推荐', value: 3 },
  25. ]
  26. const handleSave = useCallback(async () => {
  27. try {
  28. let res: any = () => {}
  29. if (transfer.mode === 'add') {
  30. res = await addKnowledge({
  31. url: '/workspaces/123123',
  32. body: { serviceType, serviceName, url, method },
  33. })
  34. }
  35. else {
  36. res = await editKnowledge({
  37. url: '/workspaces/123123',
  38. body: { id: transfer.id, serviceType, serviceName, url, method },
  39. })
  40. }
  41. const { result }: any = res
  42. console.log(result)
  43. if (result === 'success') {
  44. onCancel()
  45. onSend()
  46. }
  47. }
  48. catch (e) { }
  49. }, [name, onCancel, onSend, transfer])
  50. return (
  51. <div className={cn(s.wrap)}>
  52. <Modal overflowVisible isShow onClose={() => { }} className={cn(s.modal)}>
  53. <div className='mb-2 flex justify-between'>
  54. <div className='text-xl font-semibold text-text-primary'>{transfer.mode === 'add' ? '添加' : '编辑'}类型</div>
  55. <RiCloseLine className='h-4 w-4 cursor-pointer text-text-tertiary' onClick={onCancel} />
  56. </div>
  57. <div>
  58. <div className={cn('flex flex-wrap items-center justify-between')}>
  59. <div className='shrink-0 py-2 text-sm font-medium leading-[20px] text-text-primary'>
  60. 服务类型
  61. </div>
  62. <div className='w-full'>
  63. <SimpleSelect
  64. defaultValue={serviceType}
  65. onSelect={(i) => { setServiceType(i.value) }}
  66. items={options}
  67. allowSearch={false}
  68. />
  69. </div>
  70. </div>
  71. <div className={cn('flex flex-wrap items-center justify-between')}>
  72. <div className='shrink-0 py-2 text-sm font-medium leading-[20px] text-text-primary'>
  73. 系统名称
  74. </div>
  75. <Input
  76. value={serviceName}
  77. onChange={e => setServiceName(e.target.value)}
  78. className='h-9'
  79. placeholder='请输入系统名称'
  80. />
  81. </div>
  82. <div className={cn('flex flex-wrap items-center justify-between')}>
  83. <div className='shrink-0 py-2 text-sm font-medium leading-[20px] text-text-primary'>
  84. URL
  85. </div>
  86. <Input
  87. value={url}
  88. onChange={e => setUrl(e.target.value)}
  89. className='h-9'
  90. placeholder='请输入URL'
  91. />
  92. </div>
  93. <div className={cn('flex flex-wrap items-center justify-between')}>
  94. <div className='shrink-0 py-2 text-sm font-medium leading-[20px] text-text-primary'>
  95. 请求方式
  96. </div>
  97. <Input
  98. value={method}
  99. onChange={e => setMethod(e.target.value)}
  100. className='h-9'
  101. placeholder='请输入请求方式'
  102. />
  103. </div>
  104. <Button
  105. tabIndex={0}
  106. className='mt-4 w-full'
  107. onClick={handleSave}
  108. disabled={!serviceType.length || !serviceName.length || !url.length || !method.length}
  109. variant='primary'
  110. >
  111. 保存
  112. </Button>
  113. </div>
  114. </Modal>
  115. </div>
  116. )
  117. }
  118. export default InviteModal