NewAppCard.tsx 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. 'use client'
  2. import { forwardRef, useState } from 'react'
  3. import { useTranslation } from 'react-i18next'
  4. import CreateAppTemplateDialog from '@/app/components/app/create-app-dialog'
  5. import CreateAppModal from '@/app/components/app/create-app-modal'
  6. import CreateFromDSLModal from '@/app/components/app/create-from-dsl-modal'
  7. import { useProviderContext } from '@/context/provider-context'
  8. import { FileArrow01, FilePlus01, FilePlus02 } from '@/app/components/base/icons/src/vender/line/files'
  9. export type CreateAppCardProps = {
  10. onSuccess?: () => void
  11. }
  12. // eslint-disable-next-line react/display-name
  13. const CreateAppCard = forwardRef<HTMLAnchorElement, CreateAppCardProps>(({ onSuccess }, ref) => {
  14. const { t } = useTranslation()
  15. const { onPlanInfoChanged } = useProviderContext()
  16. const [showNewAppTemplateDialog, setShowNewAppTemplateDialog] = useState(false)
  17. const [showNewAppModal, setShowNewAppModal] = useState(false)
  18. const [showCreateFromDSLModal, setShowCreateFromDSLModal] = useState(false)
  19. return (
  20. <a
  21. ref={ref}
  22. className='relative col-span-1 flex flex-col justify-between min-h-[160px] bg-gray-200 rounded-xl border-[0.5px] border-black/5'
  23. >
  24. <div className='grow p-2 rounded-t-xl'>
  25. <div className='px-6 pt-2 pb-1 text-xs font-medium leading-[18px] text-gray-500'>{t('app.createApp')}</div>
  26. <div className='flex items-center mb-1 px-6 py-[7px] rounded-lg text-[13px] font-medium leading-[18px] text-gray-600 cursor-pointer hover:text-primary-600 hover:bg-white' onClick={() => setShowNewAppModal(true)}>
  27. <FilePlus01 className='shrink-0 mr-2 w-4 h-4' />
  28. {t('app.newApp.startFromBlank')}
  29. </div>
  30. <div className='flex items-center px-6 py-[7px] rounded-lg text-[13px] font-medium leading-[18px] text-gray-600 cursor-pointer hover:text-primary-600 hover:bg-white' onClick={() => setShowNewAppTemplateDialog(true)}>
  31. <FilePlus02 className='shrink-0 mr-2 w-4 h-4' />
  32. {t('app.newApp.startFromTemplate')}
  33. </div>
  34. </div>
  35. <div
  36. className='p-2 border-t-[0.5px] border-black/5 rounded-b-xl'
  37. onClick={() => setShowCreateFromDSLModal(true)}
  38. >
  39. <div className='flex items-center px-6 py-[7px] rounded-lg text-[13px] font-medium leading-[18px] text-gray-600 cursor-pointer hover:text-primary-600 hover:bg-white'>
  40. <FileArrow01 className='shrink-0 mr-2 w-4 h-4' />
  41. {t('app.importDSL')}
  42. </div>
  43. </div>
  44. <CreateAppModal
  45. show={showNewAppModal}
  46. onClose={() => setShowNewAppModal(false)}
  47. onSuccess={() => {
  48. onPlanInfoChanged()
  49. if (onSuccess)
  50. onSuccess()
  51. }}
  52. />
  53. <CreateAppTemplateDialog
  54. show={showNewAppTemplateDialog}
  55. onClose={() => setShowNewAppTemplateDialog(false)}
  56. onSuccess={() => {
  57. onPlanInfoChanged()
  58. if (onSuccess)
  59. onSuccess()
  60. }}
  61. />
  62. <CreateFromDSLModal
  63. show={showCreateFromDSLModal}
  64. onClose={() => setShowCreateFromDSLModal(false)}
  65. onSuccess={() => {
  66. onPlanInfoChanged()
  67. if (onSuccess)
  68. onSuccess()
  69. }}
  70. />
  71. </a>
  72. )
  73. })
  74. export default CreateAppCard