You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

custom-create-card.tsx 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. 'use client'
  2. import { useMemo, useState } from 'react'
  3. import { useTranslation } from 'react-i18next'
  4. import { useContext } from 'use-context-selector'
  5. import {
  6. RiAddCircleFill,
  7. RiArrowRightUpLine,
  8. RiBookOpenLine,
  9. } from '@remixicon/react'
  10. import type { CustomCollectionBackend } from '../types'
  11. import I18n from '@/context/i18n'
  12. import { getLanguage } from '@/i18n/language'
  13. import EditCustomToolModal from '@/app/components/tools/edit-custom-collection-modal'
  14. import { createCustomCollection } from '@/service/tools'
  15. import Toast from '@/app/components/base/toast'
  16. import { useAppContext } from '@/context/app-context'
  17. import { useDocLink } from '@/context/i18n'
  18. type Props = {
  19. onRefreshData: () => void
  20. }
  21. const Contribute = ({ onRefreshData }: Props) => {
  22. const { t } = useTranslation()
  23. const { locale } = useContext(I18n)
  24. const language = getLanguage(locale)
  25. const { isCurrentWorkspaceManager } = useAppContext()
  26. const docLink = useDocLink()
  27. const linkUrl = useMemo(() => {
  28. return docLink('/guides/tools#how-to-create-custom-tools', {
  29. 'zh-Hans': '/guides/tools#ru-he-chuang-jian-zi-ding-yi-gong-ju',
  30. })
  31. }, [language])
  32. const [isShowEditCollectionToolModal, setIsShowEditCustomCollectionModal] = useState(false)
  33. const doCreateCustomToolCollection = async (data: CustomCollectionBackend) => {
  34. await createCustomCollection(data)
  35. Toast.notify({
  36. type: 'success',
  37. message: t('common.api.actionSuccess'),
  38. })
  39. setIsShowEditCustomCollectionModal(false)
  40. onRefreshData()
  41. }
  42. return (
  43. <>
  44. {isCurrentWorkspaceManager && (
  45. <div className='col-span-1 flex min-h-[135px] cursor-pointer flex-col rounded-xl bg-background-default-dimmed transition-all duration-200 ease-in-out'>
  46. <div className='group grow rounded-t-xl' onClick={() => setIsShowEditCustomCollectionModal(true)}>
  47. <div className='flex shrink-0 items-center p-4 pb-3'>
  48. <div className='flex h-10 w-10 items-center justify-center rounded-lg border border-dashed border-divider-deep group-hover:border-solid group-hover:border-state-accent-hover-alt group-hover:bg-state-accent-hover'>
  49. <RiAddCircleFill className='h-4 w-4 text-text-quaternary group-hover:text-text-accent'/>
  50. </div>
  51. <div className='system-md-semibold ml-3 text-text-secondary group-hover:text-text-accent'>{t('tools.createCustomTool')}</div>
  52. </div>
  53. </div>
  54. <div className='rounded-b-xl border-t-[0.5px] border-divider-subtle px-4 py-3 text-text-tertiary hover:text-text-accent'>
  55. <a href={linkUrl} target='_blank' rel='noopener noreferrer' className='flex items-center space-x-1'>
  56. <RiBookOpenLine className='h-3 w-3 shrink-0' />
  57. <div className='system-xs-regular grow truncate' title={t('tools.customToolTip') || ''}>{t('tools.customToolTip')}</div>
  58. <RiArrowRightUpLine className='h-3 w-3 shrink-0' />
  59. </a>
  60. </div>
  61. </div>
  62. )}
  63. {isShowEditCollectionToolModal && (
  64. <EditCustomToolModal
  65. payload={null}
  66. onHide={() => setIsShowEditCustomCollectionModal(false)}
  67. onAdd={doCreateCustomToolCollection}
  68. />
  69. )}
  70. </>
  71. )
  72. }
  73. export default Contribute