2024-06-26 06:35:43 -04:00
|
|
|
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'
|
2024-07-18 02:43:47 -04:00
|
|
|
import { useCallback, useState } from 'react'
|
2024-06-26 06:35:43 -04:00
|
|
|
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'
|
2024-07-01 04:28:46 -04:00
|
|
|
import { sendMB } from '@/infrastructure/event-tracking'
|
2024-06-26 06:35:43 -04:00
|
|
|
|
2024-07-18 02:43:47 -04:00
|
|
|
import LeaveProjectModal from './leave-project-modal'
|
|
|
|
|
2024-06-26 06:35:43 -04:00
|
|
|
function SharingUpdatesRoot() {
|
2024-07-18 02:43:47 -04:00
|
|
|
const [showModal, setShowModal] = useState(false)
|
2024-06-26 06:35:43 -04:00
|
|
|
const { isReady } = useWaitForI18n()
|
|
|
|
const { t } = useTranslation()
|
|
|
|
const { isLoading, isSuccess, isError, runAsync } = useAsync()
|
|
|
|
const projectId = getMeta('ol-project_id')
|
|
|
|
|
|
|
|
const joinProject = useCallback(() => {
|
2024-07-01 04:28:46 -04:00
|
|
|
sendMB('notification-click', {
|
|
|
|
name: 'link-sharing-collaborator',
|
|
|
|
button: 'ok',
|
|
|
|
})
|
2024-06-26 06:35:43 -04:00
|
|
|
runAsync(postJSON(`/project/${projectId}/sharing-updates/join`))
|
|
|
|
.then(() => {
|
|
|
|
location.assign(`/project/${projectId}`)
|
|
|
|
})
|
|
|
|
.catch(debugConsole.error)
|
|
|
|
}, [runAsync, projectId])
|
|
|
|
|
|
|
|
const viewProject = useCallback(() => {
|
2024-07-01 04:28:46 -04:00
|
|
|
sendMB('notification-click', {
|
|
|
|
name: 'link-sharing-collaborator',
|
|
|
|
button: 'anonymous',
|
|
|
|
})
|
2024-06-26 06:35:43 -04:00
|
|
|
runAsync(postJSON(`/project/${projectId}/sharing-updates/view`))
|
|
|
|
.then(() => {
|
|
|
|
location.assign(`/project/${projectId}`)
|
|
|
|
})
|
|
|
|
.catch(debugConsole.error)
|
|
|
|
}, [runAsync, projectId])
|
|
|
|
|
|
|
|
const leaveProject = useCallback(() => {
|
2024-07-01 04:28:46 -04:00
|
|
|
sendMB('notification-click', {
|
|
|
|
name: 'link-sharing-collaborator',
|
|
|
|
button: 'leave',
|
|
|
|
})
|
2024-06-26 06:35:43 -04:00
|
|
|
runAsync(postJSON(`/project/${projectId}/leave`))
|
|
|
|
.then(() => {
|
|
|
|
location.assign('/project')
|
|
|
|
})
|
|
|
|
.catch(debugConsole.error)
|
|
|
|
}, [runAsync, projectId])
|
|
|
|
|
|
|
|
if (!isReady) {
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="container">
|
2024-07-18 02:43:47 -04:00
|
|
|
<LeaveProjectModal
|
|
|
|
handleLeaveAction={leaveProject}
|
|
|
|
showModal={showModal}
|
|
|
|
handleCloseModal={() => setShowModal(false)}
|
|
|
|
/>
|
2024-06-26 06:35:43 -04:00
|
|
|
<div className="row">
|
|
|
|
<div className="col-md-6 col-md-offset-3">
|
|
|
|
<div className="card sharing-updates">
|
|
|
|
<div className="row">
|
|
|
|
<div className="col-md-12">
|
|
|
|
<h1 className="sharing-updates-h1">
|
|
|
|
{t('updates_to_project_sharing')}
|
|
|
|
</h1>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="row row-spaced">
|
|
|
|
<div className="col-md-12">
|
|
|
|
<p>
|
|
|
|
<Trans
|
|
|
|
i18nKey="were_making_some_changes_to_project_sharing_this_means_you_will_be_visible"
|
|
|
|
components={[
|
|
|
|
// eslint-disable-next-line jsx-a11y/anchor-has-content, react/jsx-key
|
|
|
|
<a
|
|
|
|
href="/blog/changes-to-project-sharing"
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
target="_blank"
|
2024-07-01 04:28:46 -04:00
|
|
|
onClick={() => {
|
|
|
|
sendMB('notification-click', {
|
|
|
|
name: 'link-sharing-collaborator',
|
|
|
|
button: 'learn',
|
|
|
|
})
|
|
|
|
}}
|
2024-06-26 06:35:43 -04:00
|
|
|
/>,
|
|
|
|
]}
|
|
|
|
/>
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="row row-spaced">
|
|
|
|
<div className="col-md-12">
|
|
|
|
<button
|
|
|
|
className="btn btn-primary"
|
|
|
|
onClick={() => joinProject()}
|
|
|
|
disabled={isLoading}
|
|
|
|
>
|
|
|
|
{t('ok_continue_to_project')}
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
{isError && (
|
|
|
|
<div className="row row-spaced">
|
|
|
|
<div className="col-md-12">
|
|
|
|
<Notification
|
|
|
|
type="error"
|
|
|
|
content={t('generic_something_went_wrong')}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
|
|
|
|
<div className="row row-spaced">
|
|
|
|
<div className="col-md-12">
|
|
|
|
<p>
|
|
|
|
<small>
|
|
|
|
<Trans
|
|
|
|
i18nKey="you_can_also_choose_to_view_anonymously_or_leave_the_project"
|
|
|
|
components={[
|
|
|
|
// eslint-disable-next-line react/jsx-key
|
|
|
|
<button
|
|
|
|
className="btn btn-inline-link"
|
|
|
|
onClick={() => viewProject()}
|
|
|
|
disabled={isLoading || isSuccess}
|
|
|
|
/>,
|
|
|
|
// eslint-disable-next-line react/jsx-key
|
|
|
|
<button
|
|
|
|
className="btn btn-inline-link"
|
2024-07-18 02:43:47 -04:00
|
|
|
onClick={() => setShowModal(true)}
|
2024-06-26 06:35:43 -04:00
|
|
|
disabled={isLoading || isSuccess}
|
|
|
|
/>,
|
|
|
|
]}
|
|
|
|
/>
|
|
|
|
</small>
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default withErrorBoundary(
|
|
|
|
SharingUpdatesRoot,
|
|
|
|
GenericErrorBoundaryFallback
|
|
|
|
)
|