2023-05-15 08:51:32 +08:00
|
|
|
'use client'
|
|
|
|
|
2023-05-20 21:55:47 +08:00
|
|
|
import { forwardRef, useState } from 'react'
|
2023-05-15 08:51:32 +08:00
|
|
|
import { useTranslation } from 'react-i18next'
|
2024-04-08 18:51:46 +08:00
|
|
|
import CreateAppTemplateDialog from '@/app/components/app/create-app-dialog'
|
|
|
|
import CreateAppModal from '@/app/components/app/create-app-modal'
|
|
|
|
import CreateFromDSLModal from '@/app/components/app/create-from-dsl-modal'
|
2024-01-26 11:16:50 +08:00
|
|
|
import { useProviderContext } from '@/context/provider-context'
|
2024-04-08 18:51:46 +08:00
|
|
|
import { FileArrow01, FilePlus01, FilePlus02 } from '@/app/components/base/icons/src/vender/line/files'
|
2023-05-15 08:51:32 +08:00
|
|
|
|
2023-05-20 21:55:47 +08:00
|
|
|
export type CreateAppCardProps = {
|
|
|
|
onSuccess?: () => void
|
|
|
|
}
|
|
|
|
|
2024-04-08 18:51:46 +08:00
|
|
|
// eslint-disable-next-line react/display-name
|
2023-05-20 21:55:47 +08:00
|
|
|
const CreateAppCard = forwardRef<HTMLAnchorElement, CreateAppCardProps>(({ onSuccess }, ref) => {
|
2023-05-15 08:51:32 +08:00
|
|
|
const { t } = useTranslation()
|
2024-01-26 11:16:50 +08:00
|
|
|
const { onPlanInfoChanged } = useProviderContext()
|
|
|
|
|
2024-04-08 18:51:46 +08:00
|
|
|
const [showNewAppTemplateDialog, setShowNewAppTemplateDialog] = useState(false)
|
|
|
|
const [showNewAppModal, setShowNewAppModal] = useState(false)
|
|
|
|
const [showCreateFromDSLModal, setShowCreateFromDSLModal] = useState(false)
|
2023-05-15 08:51:32 +08:00
|
|
|
return (
|
2024-04-08 18:51:46 +08:00
|
|
|
<a
|
|
|
|
ref={ref}
|
|
|
|
className='relative col-span-1 flex flex-col justify-between min-h-[160px] bg-gray-200 rounded-xl border-[0.5px] border-black/5'
|
|
|
|
>
|
|
|
|
<div className='grow p-2 rounded-t-xl'>
|
|
|
|
<div className='px-6 pt-2 pb-1 text-xs font-medium leading-[18px] text-gray-500'>{t('app.createApp')}</div>
|
|
|
|
<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)}>
|
|
|
|
<FilePlus01 className='shrink-0 mr-2 w-4 h-4' />
|
|
|
|
{t('app.newApp.startFromBlank')}
|
|
|
|
</div>
|
|
|
|
<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)}>
|
|
|
|
<FilePlus02 className='shrink-0 mr-2 w-4 h-4' />
|
|
|
|
{t('app.newApp.startFromTemplate')}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div
|
|
|
|
className='p-2 border-t-[0.5px] border-black/5 rounded-b-xl'
|
|
|
|
onClick={() => setShowCreateFromDSLModal(true)}
|
|
|
|
>
|
|
|
|
<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'>
|
|
|
|
<FileArrow01 className='shrink-0 mr-2 w-4 h-4' />
|
|
|
|
{t('app.importDSL')}
|
2023-05-15 08:51:32 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
2024-04-08 18:51:46 +08:00
|
|
|
<CreateAppModal
|
|
|
|
show={showNewAppModal}
|
|
|
|
onClose={() => setShowNewAppModal(false)}
|
|
|
|
onSuccess={() => {
|
|
|
|
onPlanInfoChanged()
|
|
|
|
if (onSuccess)
|
|
|
|
onSuccess()
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
<CreateAppTemplateDialog
|
|
|
|
show={showNewAppTemplateDialog}
|
|
|
|
onClose={() => setShowNewAppTemplateDialog(false)}
|
|
|
|
onSuccess={() => {
|
|
|
|
onPlanInfoChanged()
|
|
|
|
if (onSuccess)
|
|
|
|
onSuccess()
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
<CreateFromDSLModal
|
|
|
|
show={showCreateFromDSLModal}
|
|
|
|
onClose={() => setShowCreateFromDSLModal(false)}
|
|
|
|
onSuccess={() => {
|
2024-01-26 11:16:50 +08:00
|
|
|
onPlanInfoChanged()
|
|
|
|
if (onSuccess)
|
|
|
|
onSuccess()
|
2024-04-08 18:51:46 +08:00
|
|
|
}}
|
|
|
|
/>
|
2023-05-15 08:51:32 +08:00
|
|
|
</a>
|
|
|
|
)
|
2023-05-20 21:55:47 +08:00
|
|
|
})
|
2023-05-15 08:51:32 +08:00
|
|
|
|
|
|
|
export default CreateAppCard
|