index.tsx 4.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. 'use client'
  2. import cn from 'classnames'
  3. import { useTranslation } from 'react-i18next'
  4. import { PlusIcon } from '@heroicons/react/20/solid'
  5. import Button from '../../base/button'
  6. import type { App } from '@/models/explore'
  7. import AppIcon from '@/app/components/base/app-icon'
  8. import { AiText, ChatBot, CuteRobote } from '@/app/components/base/icons/src/vender/solid/communication'
  9. import { Route } from '@/app/components/base/icons/src/vender/solid/mapsAndTravel'
  10. export type AppCardProps = {
  11. app: App
  12. canCreate: boolean
  13. onCreate: () => void
  14. isExplore: boolean
  15. }
  16. const AppCard = ({
  17. app,
  18. canCreate,
  19. onCreate,
  20. isExplore,
  21. }: AppCardProps) => {
  22. const { t } = useTranslation()
  23. const { app: appBasicInfo } = app
  24. return (
  25. <div className={cn('group flex col-span-1 bg-white border-2 border-solid border-transparent rounded-lg shadow-sm min-h-[160px] flex flex-col transition-all duration-200 ease-in-out cursor-pointer hover:shadow-lg')}>
  26. <div className='flex pt-[14px] px-[14px] pb-3 h-[66px] items-center gap-3 grow-0 shrink-0'>
  27. <div className='relative shrink-0'>
  28. <AppIcon size='large' icon={app.app.icon} background={app.app.icon_background} />
  29. <span className='absolute bottom-[-3px] right-[-3px] w-4 h-4 p-0.5 bg-white rounded border-[0.5px] border-[rgba(0,0,0,0.02)] shadow-sm'>
  30. {appBasicInfo.mode === 'advanced-chat' && (
  31. <ChatBot className='w-3 h-3 text-[#1570EF]' />
  32. )}
  33. {appBasicInfo.mode === 'agent-chat' && (
  34. <CuteRobote className='w-3 h-3 text-indigo-600' />
  35. )}
  36. {appBasicInfo.mode === 'chat' && (
  37. <ChatBot className='w-3 h-3 text-[#1570EF]' />
  38. )}
  39. {appBasicInfo.mode === 'completion' && (
  40. <AiText className='w-3 h-3 text-[#0E9384]' />
  41. )}
  42. {appBasicInfo.mode === 'workflow' && (
  43. <Route className='w-3 h-3 text-[#f79009]' />
  44. )}
  45. </span>
  46. </div>
  47. <div className='grow w-0 py-[1px]'>
  48. <div className='flex items-center text-sm leading-5 font-semibold text-gray-800'>
  49. <div className='truncate' title={appBasicInfo.name}>{appBasicInfo.name}</div>
  50. </div>
  51. <div className='flex items-center text-[10px] leading-[18px] text-gray-500 font-medium'>
  52. {appBasicInfo.mode === 'advanced-chat' && <div className='truncate'>{t('app.types.chatbot').toUpperCase()}</div>}
  53. {appBasicInfo.mode === 'chat' && <div className='truncate'>{t('app.types.chatbot').toUpperCase()}</div>}
  54. {appBasicInfo.mode === 'agent-chat' && <div className='truncate'>{t('app.types.agent').toUpperCase()}</div>}
  55. {appBasicInfo.mode === 'workflow' && <div className='truncate'>{t('app.types.workflow').toUpperCase()}</div>}
  56. {appBasicInfo.mode === 'completion' && <div className='truncate'>{t('app.types.completion').toUpperCase()}</div>}
  57. </div>
  58. </div>
  59. </div>
  60. <div className='mb-1 px-[14px] text-xs leading-normal text-gray-500 line-clamp-4 group-hover:line-clamp-2 group-hover:h-9'>{app.description}</div>
  61. {isExplore && canCreate && (
  62. <div className={cn('hidden items-center flex-wrap min-h-[42px] px-[14px] pt-2 pb-[10px] group-hover:flex')}>
  63. <div className={cn('flex items-center w-full space-x-2')}>
  64. <Button variant='primary' className='grow h-7' onClick={() => onCreate()}>
  65. <PlusIcon className='w-4 h-4 mr-1' />
  66. <span className='text-xs'>{t('explore.appCard.addToWorkspace')}</span>
  67. </Button>
  68. </div>
  69. </div>
  70. )}
  71. {!isExplore && (
  72. <div className={cn('hidden items-center flex-wrap min-h-[42px] px-[14px] pt-2 pb-[10px] group-hover:flex')}>
  73. <div className={cn('flex items-center w-full space-x-2')}>
  74. <Button variant='primary' className='grow h-7' onClick={() => onCreate()}>
  75. <PlusIcon className='w-4 h-4 mr-1' />
  76. <span className='text-xs'>{t('app.newApp.useTemplate')}</span>
  77. </Button>
  78. </div>
  79. </div>
  80. )}
  81. </div>
  82. )
  83. }
  84. export default AppCard