index.tsx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. 'use client'
  2. import { useTranslation } from 'react-i18next'
  3. import { PlusIcon } from '@heroicons/react/20/solid'
  4. import Button from '../../base/button'
  5. import cn from '@/utils/classnames'
  6. import type { App } from '@/models/explore'
  7. import AppIcon from '@/app/components/base/app-icon'
  8. import { AiText, ChatBot, CuteRobot } 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('relative overflow-hidden pb-2 group col-span-1 bg-white border-2 border-solid border-transparent rounded-lg shadow-sm 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
  29. size='large'
  30. iconType={app.app.icon_type}
  31. icon={app.app.icon}
  32. background={app.app.icon_background}
  33. imageUrl={app.app.icon_url}
  34. />
  35. <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'>
  36. {appBasicInfo.mode === 'advanced-chat' && (
  37. <ChatBot className='w-3 h-3 text-[#1570EF]' />
  38. )}
  39. {appBasicInfo.mode === 'agent-chat' && (
  40. <CuteRobot className='w-3 h-3 text-indigo-600' />
  41. )}
  42. {appBasicInfo.mode === 'chat' && (
  43. <ChatBot className='w-3 h-3 text-[#1570EF]' />
  44. )}
  45. {appBasicInfo.mode === 'completion' && (
  46. <AiText className='w-3 h-3 text-[#0E9384]' />
  47. )}
  48. {appBasicInfo.mode === 'workflow' && (
  49. <Route className='w-3 h-3 text-[#f79009]' />
  50. )}
  51. </span>
  52. </div>
  53. <div className='grow w-0 py-[1px]'>
  54. <div className='flex items-center text-sm leading-5 font-semibold text-gray-800'>
  55. <div className='truncate' title={appBasicInfo.name}>{appBasicInfo.name}</div>
  56. </div>
  57. <div className='flex items-center text-[10px] leading-[18px] text-gray-500 font-medium'>
  58. {appBasicInfo.mode === 'advanced-chat' && <div className='truncate'>{t('app.types.chatbot').toUpperCase()}</div>}
  59. {appBasicInfo.mode === 'chat' && <div className='truncate'>{t('app.types.chatbot').toUpperCase()}</div>}
  60. {appBasicInfo.mode === 'agent-chat' && <div className='truncate'>{t('app.types.agent').toUpperCase()}</div>}
  61. {appBasicInfo.mode === 'workflow' && <div className='truncate'>{t('app.types.workflow').toUpperCase()}</div>}
  62. {appBasicInfo.mode === 'completion' && <div className='truncate'>{t('app.types.completion').toUpperCase()}</div>}
  63. </div>
  64. </div>
  65. </div>
  66. <div className="description-wrapper h-[90px] px-[14px] text-xs leading-normal text-gray-500 ">
  67. <div className='line-clamp-4 group-hover:line-clamp-2'>
  68. {app.description}
  69. </div>
  70. </div>
  71. {isExplore && canCreate && (
  72. <div className={cn('hidden items-center flex-wrap min-h-[42px] px-[14px] pt-2 pb-[10px] bg-white group-hover:flex absolute bottom-0 left-0 right-0')}>
  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('explore.appCard.addToWorkspace')}</span>
  77. </Button>
  78. </div>
  79. </div>
  80. )}
  81. {!isExplore && (
  82. <div className={cn('hidden items-center flex-wrap min-h-[42px] px-[14px] pt-2 pb-[10px] bg-white group-hover:flex absolute bottom-0 left-0 right-0')}>
  83. <div className={cn('flex items-center w-full space-x-2')}>
  84. <Button variant='primary' className='grow h-7' onClick={() => onCreate()}>
  85. <PlusIcon className='w-4 h-4 mr-1' />
  86. <span className='text-xs'>{t('app.newApp.useTemplate')}</span>
  87. </Button>
  88. </div>
  89. </div>
  90. )}
  91. </div>
  92. )
  93. }
  94. export default AppCard