overleaf/services/web/frontend/js/features/share-project-modal/controllers/react-share-project-modal-controller.js
Miguel Serrano 01e3409eb4 Merge pull request #13485 from overleaf/msm-share-modal-fetch-tokens
[web] Fetch share tokens instead of sending via websocket

GitOrigin-RevId: f97bb91ca3ceb410fe860bf1c7802d8157d9f8b4
2023-07-17 10:48:10 +00:00

64 lines
1.6 KiB
JavaScript

import App from '../../../base'
import { react2angular } from 'react2angular'
import ShareProjectModal from '../components/share-project-modal'
import { rootContext } from '../../../shared/context/root-context'
import { listProjectInvites, listProjectMembers } from '../utils/api'
App.component(
'shareProjectModal',
react2angular(
rootContext.use(ShareProjectModal),
Object.keys(ShareProjectModal.propTypes)
)
)
export default App.controller(
'ReactShareProjectModalController',
function ($scope, eventTracking, ide) {
$scope.show = false
$scope.handleHide = () => {
$scope.$applyAsync(() => {
$scope.show = false
})
}
$scope.openShareProjectModal = () => {
eventTracking.sendMBOnce('ide-open-share-modal-once')
$scope.$applyAsync(() => {
$scope.show = true
})
}
ide.socket.on('project:membership:changed', data => {
if (data.members) {
listProjectMembers($scope.project._id)
.then(({ members }) => {
if (members) {
$scope.$applyAsync(() => {
$scope.project.members = members
})
}
})
.catch(() => {
console.error('Error fetching members for project')
})
}
if (data.invites) {
listProjectInvites($scope.project._id)
.then(({ invites }) => {
if (invites) {
$scope.$applyAsync(() => {
$scope.project.invites = invites
})
}
})
.catch(() => {
console.error('Error fetching invites for project')
})
}
})
}
)