actions-copy-project.tsx 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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
  27. onClick={handleShowModal}
  28. icon={{
  29. type: 'copy',
  30. fw: true,
  31. }}
  32. >
  33. {t('copy_project')}
  34. </LeftMenuButton>
  35. <EditorCloneProjectModalWrapper
  36. show={showModal}
  37. handleHide={() => setShowModal(false)}
  38. openProject={openProject}
  39. />
  40. </>
  41. )
  42. }