actions-copy-project.tsx 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. type ProjectCopyResponse = {
  8. project_id: string
  9. }
  10. export default function ActionsCopyProject() {
  11. const [showModal, setShowModal] = useState(false)
  12. const { t } = useTranslation()
  13. const location = useLocation()
  14. const openProject = useCallback(
  15. ({ project_id: projectId }: ProjectCopyResponse) => {
  16. location.assign(`/project/${projectId}`)
  17. },
  18. [location]
  19. )
  20. const handleShowModal = useCallback(() => {
  21. eventTracking.sendMB('left-menu-copy')
  22. setShowModal(true)
  23. }, [])
  24. return (
  25. <>
  26. <LeftMenuButton onClick={handleShowModal} icon="file_copy">
  27. {t('copy_project')}
  28. </LeftMenuButton>
  29. <EditorCloneProjectModalWrapper
  30. show={showModal}
  31. handleHide={() => setShowModal(false)}
  32. openProject={openProject}
  33. />
  34. </>
  35. )
  36. }