import { useCallback, useState } from 'react' import PropTypes from 'prop-types' import { Button, Col, Row } from 'react-bootstrap' import { Trans, useTranslation } from 'react-i18next' import Tooltip from '../../../shared/components/tooltip' import Icon from '../../../shared/components/icon' import { useShareProjectContext } from './share-project-modal' import { setProjectAccessLevel } from '../utils/api' import CopyLink from '../../../shared/components/copy-link' import { useProjectContext } from '../../../shared/context/project-context' import * as eventTracking from '../../../infrastructure/event-tracking' import { useUserContext } from '../../../shared/context/user-context' import StartFreeTrialButton from '../../../shared/components/start-free-trial-button' import { useSplitTestContext } from '../../../shared/context/split-test-context' export default function LinkSharing({ canAddCollaborators }) { const [inflight, setInflight] = useState(false) const { monitorRequest } = useShareProjectContext() const { _id: projectId, publicAccessLevel } = useProjectContext() // set the access level of a project const setAccessLevel = useCallback( newPublicAccessLevel => { setInflight(true) monitorRequest(() => setProjectAccessLevel(projectId, newPublicAccessLevel) ) .then(() => { // NOTE: not calling `updateProject` here as it receives data via // project:publicAccessLevel:changed and project:tokens:changed // over the websocket connection // TODO: eventTracking.sendMB('project-make-token-based') when newPublicAccessLevel is 'tokenBased' }) .finally(() => { setInflight(false) }) }, [monitorRequest, projectId] ) switch (publicAccessLevel) { // Private (with token-access available) case 'private': return ( ) // Token-based access case 'tokenBased': return ( ) // Legacy public-access case 'readAndWrite': case 'readOnly': return ( ) default: return null } } LinkSharing.propTypes = { canAddCollaborators: PropTypes.bool, } function PrivateSharing({ setAccessLevel, inflight }) { return (       ) } PrivateSharing.propTypes = { setAccessLevel: PropTypes.func.isRequired, inflight: PropTypes.bool, } function TokenBasedSharing({ setAccessLevel, inflight, canAddCollaborators }) { const { tokens } = useProjectContext() return (      
) } TokenBasedSharing.propTypes = { setAccessLevel: PropTypes.func.isRequired, inflight: PropTypes.bool, canAddCollaborators: PropTypes.bool, } function LegacySharing({ accessLevel, setAccessLevel, inflight }) { return ( {accessLevel === 'readAndWrite' && ( )} {accessLevel === 'readOnly' && ( )}       ) } LegacySharing.propTypes = { accessLevel: PropTypes.string.isRequired, setAccessLevel: PropTypes.func.isRequired, inflight: PropTypes.bool, } export function ReadOnlyTokenLink() { const { tokens } = useProjectContext() return (
) } function AccessToken({ token, path, tooltipId }) { const { isAdmin } = useUserContext() if (!token) { return (
        
          
      
) } let origin = window.location.origin if (isAdmin) { origin = window.ExposedSettings.siteUrl } const link = `${origin}${path}${token}` return (
      {link}
      
    
) } AccessToken.propTypes = { token: PropTypes.string, tooltipId: PropTypes.string.isRequired, path: PropTypes.string.isRequired, } function LinkSharingInfo() { return ( } > ) } function LinkSharingUpgradePrompt({ canAddCollaborators }) { const [startedFreeTrial, setStartedFreeTrial] = useState(false) const { t } = useTranslation() const { splitTestVariants } = useSplitTestContext() const linkSharingUpgradePromptActive = splitTestVariants['link-sharing-upgrade-prompt'] === 'active' const user = useUserContext({ allowedFreeTrial: PropTypes.bool, }) const showLinkSharingUpgradePrompt = linkSharingUpgradePromptActive && user.allowedFreeTrial && canAddCollaborators if (!showLinkSharingUpgradePrompt) { return null } return ( <>

, , ]} // eslint-disable-line react/jsx-key />

{startedFreeTrial && (

{t('refresh_page_after_starting_free_trial')}

)} ) } LinkSharingUpgradePrompt.propTypes = { canAddCollaborators: PropTypes.bool, }