actions-copy-project.tsx 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { useCallback, useState } from 'react'
  2. import { useTranslation } from 'react-i18next'
  3. import EditorCloneProjectModalWrapper from '../../clone-project-modal/components/editor-clone-project-modal-wrapper'
  4. import LeftMenuButton from './left-menu-button'
  5. import { useLocation } from '../../../shared/hooks/use-location'
  6. import * as eventTracking from '../../../infrastructure/event-tracking'
  7. import { bsVersionIcon } from '@/features/utils/bootstrap-5'
  8. type ProjectCopyResponse = {
  9. project_id: string
  10. }
  11. export default function ActionsCopyProject() {
  12. const [showModal, setShowModal] = useState(false)
  13. const { t } = useTranslation()
  14. const location = useLocation()
  15. const openProject = useCallback(
  16. ({ project_id: projectId }: ProjectCopyResponse) => {
  17. location.assign(`/project/${projectId}`)
  18. },
  19. [location]
  20. )
  21. const handleShowModal = useCallback(() => {
  22. eventTracking.sendMB('left-menu-copy')
  23. setShowModal(true)
  24. }, [])
  25. return (
  26. <>
  27. <LeftMenuButton
  28. onClick={handleShowModal}
  29. icon={bsVersionIcon({
  30. bs5: { type: 'file_copy' },
  31. bs3: { type: 'copy', fw: true },
  32. })}
  33. >
  34. {t('copy_project')}
  35. </LeftMenuButton>
  36. <EditorCloneProjectModalWrapper
  37. show={showModal}
  38. handleHide={() => setShowModal(false)}
  39. openProject={openProject}
  40. />
  41. </>
  42. )
  43. }