index.tsx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 [type, setType] = useState<any>(transfer.row?.type || '')
  18. const [name, setName] = useState<string>(transfer.row?.name || '')
  19. const [url, setUrl] = useState<string>(transfer.row?.url || '')
  20. const [method, setMethod] = useState<string>(transfer.row?.method || '')
  21. const options = [
  22. { name: '智能问答', value: 'QUESTION_ANSWER' },
  23. { name: '智能搜索', value: 'SEARCH' },
  24. { name: '智能推荐', value: 'RECOMMEND' },
  25. ]
  26. const handleSave = useCallback(async () => {
  27. try {
  28. let res: any = () => {}
  29. if (transfer.mode === 'add') {
  30. res = await addKnowledge({
  31. url: '/external_applications',
  32. body: { type, name, url, method, status: false },
  33. })
  34. }
  35. else {
  36. res = await editKnowledge({
  37. url: `/external_applications/${transfer.row.id}`,
  38. body: { type, name, url, method },
  39. })
  40. }
  41. const { id }: any = res
  42. if (id) {
  43. onCancel()
  44. onSend()
  45. }
  46. }
  47. catch (e) { }
  48. }, [type, name, url, method, onCancel, onSend, transfer])
  49. return (
  50. <div className={cn(s.wrap)}>
  51. <Modal overflowVisible isShow onClose={() => { }} className={cn(s.modal)}>
  52. <div className='mb-2 flex justify-between'>
  53. <div className='text-xl font-semibold text-text-primary'>{transfer.mode === 'add' ? '新增' : '编辑'}类型</div>
  54. <RiCloseLine className='h-4 w-4 cursor-pointer text-text-tertiary' onClick={onCancel} />
  55. </div>
  56. <div>
  57. <div className={cn('flex flex-wrap items-center justify-between')}>
  58. <div className='shrink-0 py-2 text-sm font-medium leading-[20px] text-text-primary'>
  59. 服务类型
  60. </div>
  61. <div className='w-full'>
  62. <SimpleSelect
  63. defaultValue={type}
  64. onSelect={(i) => { setType(i.value) }}
  65. items={options}
  66. allowSearch={false}
  67. />
  68. </div>
  69. </div>
  70. <div className={cn('flex flex-wrap items-center justify-between')}>
  71. <div className='shrink-0 py-2 text-sm font-medium leading-[20px] text-text-primary'>
  72. 系统名称
  73. </div>
  74. <Input
  75. value={name}
  76. onChange={e => setName(e.target.value)}
  77. className='h-9'
  78. placeholder='请输入系统名称'
  79. />
  80. </div>
  81. <div className={cn('flex flex-wrap items-center justify-between')}>
  82. <div className='shrink-0 py-2 text-sm font-medium leading-[20px] text-text-primary'>
  83. URL
  84. </div>
  85. <Input
  86. value={url}
  87. onChange={e => setUrl(e.target.value)}
  88. className='h-9'
  89. placeholder='请输入URL'
  90. />
  91. </div>
  92. <div className={cn('flex flex-wrap items-center justify-between')}>
  93. <div className='shrink-0 py-2 text-sm font-medium leading-[20px] text-text-primary'>
  94. 请求方式
  95. </div>
  96. <Input
  97. value={method}
  98. onChange={e => setMethod(e.target.value)}
  99. className='h-9'
  100. placeholder='请输入请求方式'
  101. />
  102. </div>
  103. <Button
  104. tabIndex={0}
  105. className='mt-4 w-full'
  106. onClick={handleSave}
  107. disabled={!type.length || !name.length || !url.length || !method.length}
  108. variant='primary'
  109. >
  110. 保存
  111. </Button>
  112. </div>
  113. </Modal>
  114. </div>
  115. )
  116. }
  117. export default InviteModal