import { useCallback, useState } from 'react'
import PropTypes from 'prop-types'
import { Button, Col, OverlayTrigger, Row, Tooltip } from 'react-bootstrap'
import { Trans } from 'react-i18next'
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'
export default function LinkSharing() {
const [inflight, setInflight] = useState(false)
const { monitorRequest } = useShareProjectContext()
const project = useProjectContext()
// set the access level of a project
const setAccessLevel = useCallback(
publicAccesLevel => {
setInflight(true)
monitorRequest(() => setProjectAccessLevel(project, publicAccesLevel))
.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 publicAccesLevel is 'tokenBased'
})
.finally(() => {
setInflight(false)
})
},
[monitorRequest, project]
)
switch (project.publicAccesLevel) {
// Private (with token-access available)
case 'private':
return (
…
)
}
const link = `${window.location.origin}${path}${token}`
return (
{link}) } AccessToken.propTypes = { token: PropTypes.string, tooltipId: PropTypes.string.isRequired, path: PropTypes.string.isRequired, } function LinkSharingInfo() { return (