NewAppCard.tsx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. 'use client'
  2. import { forwardRef, useMemo, useState } from 'react'
  3. import {
  4. useRouter,
  5. useSearchParams,
  6. } from 'next/navigation'
  7. import { useTranslation } from 'react-i18next'
  8. import CreateAppTemplateDialog from '@/app/components/app/create-app-dialog'
  9. import CreateAppModal from '@/app/components/app/create-app-modal'
  10. import CreateFromDSLModal, { CreateFromDSLModalTab } from '@/app/components/app/create-from-dsl-modal'
  11. import { useProviderContext } from '@/context/provider-context'
  12. import { FileArrow01, FilePlus01, FilePlus02 } from '@/app/components/base/icons/src/vender/line/files'
  13. export type CreateAppCardProps = {
  14. onSuccess?: () => void
  15. }
  16. // eslint-disable-next-line react/display-name
  17. const CreateAppCard = forwardRef<HTMLAnchorElement, CreateAppCardProps>(({ onSuccess }, ref) => {
  18. const { t } = useTranslation()
  19. const { onPlanInfoChanged } = useProviderContext()
  20. const searchParams = useSearchParams()
  21. const { replace } = useRouter()
  22. const dslUrl = searchParams.get('remoteInstallUrl') || undefined
  23. const [showNewAppTemplateDialog, setShowNewAppTemplateDialog] = useState(false)
  24. const [showNewAppModal, setShowNewAppModal] = useState(false)
  25. const [showCreateFromDSLModal, setShowCreateFromDSLModal] = useState(!!dslUrl)
  26. const activeTab = useMemo(() => {
  27. if (dslUrl)
  28. return CreateFromDSLModalTab.FROM_URL
  29. return undefined
  30. }, [dslUrl])
  31. return (
  32. <a
  33. ref={ref}
  34. className='relative col-span-1 flex flex-col justify-between min-h-[160px] bg-gray-200 rounded-xl border-[0.5px] border-black/5'
  35. >
  36. <div className='grow p-2 rounded-t-xl'>
  37. <div className='px-6 pt-2 pb-1 text-xs font-medium leading-[18px] text-gray-500'>{t('app.createApp')}</div>
  38. <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)}>
  39. <FilePlus01 className='shrink-0 mr-2 w-4 h-4' />
  40. {t('app.newApp.startFromBlank')}
  41. </div>
  42. <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)}>
  43. <FilePlus02 className='shrink-0 mr-2 w-4 h-4' />
  44. {t('app.newApp.startFromTemplate')}
  45. </div>
  46. </div>
  47. <div
  48. className='p-2 border-t-[0.5px] border-black/5 rounded-b-xl'
  49. onClick={() => setShowCreateFromDSLModal(true)}
  50. >
  51. <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'>
  52. <FileArrow01 className='shrink-0 mr-2 w-4 h-4' />
  53. {t('app.importDSL')}
  54. </div>
  55. </div>
  56. <CreateAppModal
  57. show={showNewAppModal}
  58. onClose={() => setShowNewAppModal(false)}
  59. onSuccess={() => {
  60. onPlanInfoChanged()
  61. if (onSuccess)
  62. onSuccess()
  63. }}
  64. />
  65. <CreateAppTemplateDialog
  66. show={showNewAppTemplateDialog}
  67. onClose={() => setShowNewAppTemplateDialog(false)}
  68. onSuccess={() => {
  69. onPlanInfoChanged()
  70. if (onSuccess)
  71. onSuccess()
  72. }}
  73. />
  74. <CreateFromDSLModal
  75. show={showCreateFromDSLModal}
  76. onClose={() => {
  77. setShowCreateFromDSLModal(false)
  78. if (dslUrl)
  79. replace('/')
  80. }}
  81. activeTab={activeTab}
  82. dslUrl={dslUrl}
  83. onSuccess={() => {
  84. onPlanInfoChanged()
  85. if (onSuccess)
  86. onSuccess()
  87. }}
  88. />
  89. </a>
  90. )
  91. })
  92. export default CreateAppCard