NewAppCard.tsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. import style from './style.module.css'
  14. import cn from '@/utils/classnames'
  15. import {
  16. RiStickyNoteAddLine
  17. } from '@remixicon/react'
  18. export type CreateAppCardProps = {
  19. onSuccess?: () => void
  20. }
  21. // eslint-disable-next-line react/display-name
  22. const CreateAppCard = forwardRef<HTMLAnchorElement, CreateAppCardProps>(({ onSuccess }, ref) => {
  23. const { t } = useTranslation()
  24. const { onPlanInfoChanged } = useProviderContext()
  25. const searchParams = useSearchParams()
  26. const { replace } = useRouter()
  27. const dslUrl = searchParams.get('remoteInstallUrl') || undefined
  28. const [showNewAppTemplateDialog, setShowNewAppTemplateDialog] = useState(false)
  29. const [showNewAppModal, setShowNewAppModal] = useState(false)
  30. const [showCreateFromDSLModal, setShowCreateFromDSLModal] = useState(!!dslUrl)
  31. const activeTab = useMemo(() => {
  32. if (dslUrl)
  33. return CreateFromDSLModalTab.FROM_URL
  34. return undefined
  35. }, [dslUrl])
  36. return (
  37. <a
  38. ref={ref}
  39. className={cn('relative col-span-1 flex flex-col justify-between min-h-[160px] rounded-xl border-[0.5px] border-black/5', style.background)}
  40. >
  41. <div className='grow p-2 rounded-t-xl'>
  42. <div className='px-6 pt-2 pb-1 text-sm font-semibold font-medium leading-[18px]'>{t('app.createApp')}</div>
  43. <div style={{marginTop:'5px'}} className='flex items-center px-6 py-[7px] rounded-lg text-[13px] font-medium leading-[18px] text-gray-600 cursor-pointer hover:bg-white' onClick={() => setShowNewAppModal(true)}>
  44. <RiStickyNoteAddLine className='shrink-0 mr-2 w-4 h-4' />
  45. {t('app.newApp.startFromBlank')}
  46. </div>
  47. {/* <div className='flex items-center px-6 py-[7px] rounded-lg text-[13px] font-medium leading-[18px] text-gray-600 cursor-pointer hover:bg-white' onClick={() => setShowNewAppTemplateDialog(true)}>
  48. <FilePlus02 className='shrink-0 mr-2 w-4 h-4' />
  49. {t('app.newApp.startFromTemplate')}
  50. </div> */}
  51. {/* <div
  52. className='rounded-b-xl'
  53. onClick={() => setShowCreateFromDSLModal(true)}
  54. >
  55. <div className='flex items-center px-6 py-[7px] rounded-lg text-[13px] font-medium leading-[18px] text-gray-600 cursor-pointer hover:bg-white'>
  56. <FileArrow01 className='shrink-0 mr-2 w-4 h-4' />
  57. {t('app.importDSL')}
  58. </div>
  59. </div> */}
  60. </div>
  61. <CreateAppModal
  62. show={showNewAppModal}
  63. onClose={() => setShowNewAppModal(false)}
  64. onSuccess={() => {
  65. onPlanInfoChanged()
  66. if (onSuccess)
  67. onSuccess()
  68. }}
  69. />
  70. <CreateAppTemplateDialog
  71. show={showNewAppTemplateDialog}
  72. onClose={() => setShowNewAppTemplateDialog(false)}
  73. onSuccess={() => {
  74. onPlanInfoChanged()
  75. if (onSuccess)
  76. onSuccess()
  77. }}
  78. />
  79. <CreateFromDSLModal
  80. show={showCreateFromDSLModal}
  81. onClose={() => {
  82. setShowCreateFromDSLModal(false)
  83. if (dslUrl)
  84. replace('/')
  85. }}
  86. activeTab={activeTab}
  87. dslUrl={dslUrl}
  88. onSuccess={() => {
  89. onPlanInfoChanged()
  90. if (onSuccess)
  91. onSuccess()
  92. }}
  93. />
  94. </a>
  95. )
  96. })
  97. export default CreateAppCard