import useWaitForI18n from '@/shared/hooks/use-wait-for-i18n' import { Trans, useTranslation } from 'react-i18next' import withErrorBoundary from '@/infrastructure/error-boundary' import { GenericErrorBoundaryFallback } from '@/shared/components/generic-error-boundary-fallback' import { useCallback, useState } from 'react' import getMeta from '@/utils/meta' import { postJSON } from '@/infrastructure/fetch-json' import { debugConsole } from '@/utils/debugging' import useAsync from '@/shared/hooks/use-async' import Notification from '@/shared/components/notification' import { sendMB } from '@/infrastructure/event-tracking' import LeaveProjectModal from './leave-project-modal' function SharingUpdatesRoot() { const [showModal, setShowModal] = useState(false) const { isReady } = useWaitForI18n() const { t } = useTranslation() const { isLoading, isSuccess, isError, runAsync } = useAsync() const projectId = getMeta('ol-project_id') const joinProject = useCallback(() => { sendMB('notification-click', { name: 'link-sharing-collaborator', button: 'ok', }) runAsync(postJSON(`/project/${projectId}/sharing-updates/join`)) .then(() => { location.assign(`/project/${projectId}`) }) .catch(debugConsole.error) }, [runAsync, projectId]) const viewProject = useCallback(() => { sendMB('notification-click', { name: 'link-sharing-collaborator', button: 'anonymous', }) runAsync(postJSON(`/project/${projectId}/sharing-updates/view`)) .then(() => { location.assign(`/project/${projectId}`) }) .catch(debugConsole.error) }, [runAsync, projectId]) const leaveProject = useCallback(() => { sendMB('notification-click', { name: 'link-sharing-collaborator', button: 'leave', }) runAsync(postJSON(`/project/${projectId}/leave`)) .then(() => { location.assign('/project') }) .catch(debugConsole.error) }, [runAsync, projectId]) if (!isReady) { return null } return (
setShowModal(false)} />

{t('updates_to_project_sharing')}

{ sendMB('notification-click', { name: 'link-sharing-collaborator', button: 'learn', }) }} />, ]} />

{isError && (
)}

viewProject()} disabled={isLoading || isSuccess} />, // eslint-disable-next-line react/jsx-key

) } export default withErrorBoundary( SharingUpdatesRoot, GenericErrorBoundaryFallback )