overleaf/services/web/frontend/js/main/subscription/team-invite-controller.js
Alf Eaton 1be43911b4 Merge pull request #3942 from overleaf/prettier-trailing-comma
Set Prettier's "trailingComma" setting to "es5"

GitOrigin-RevId: 9f14150511929a855b27467ad17be6ab262fe5d5
2021-04-28 02:10:01 +00:00

62 lines
1.8 KiB
JavaScript

/* eslint-disable
max-len,
no-return-assign,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
import App from '../../base'
import getMeta from '../../utils/meta'
export default App.controller('TeamInviteController', function ($scope, $http) {
$scope.inflight = false
const hasIndividualRecurlySubscription = getMeta(
'ol-hasIndividualRecurlySubscription'
)
if (hasIndividualRecurlySubscription) {
$scope.view = 'hasIndividualRecurlySubscription'
} else {
$scope.view = 'teamInvite'
}
$scope.keepPersonalSubscription = () => ($scope.view = 'teamInvite')
$scope.cancelPersonalSubscription = function () {
$scope.inflight = true
const request = $http.post('/user/subscription/cancel', {
_csrf: window.csrfToken,
})
request.then(function () {
$scope.inflight = false
return ($scope.view = 'teamInvite')
})
return request.catch(() => {
$scope.inflight = false
$scope.cancel_error = true
console.log('the request failed')
})
}
return ($scope.joinTeam = function () {
$scope.inflight = true
const inviteToken = getMeta('ol-inviteToken')
const request = $http.put(`/subscription/invites/${inviteToken}/`, {
_csrf: window.csrfToken,
})
request.then(function (response) {
const { status } = response
$scope.inflight = false
$scope.view = 'inviteAccepted'
if (status !== 200) {
// assume request worked
return ($scope.requestSent = false)
}
})
return request.catch(() => console.log('the request failed'))
})
})