2018-11-05 05:06:39 -05:00
|
|
|
/* 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
|
|
|
|
*/
|
2020-05-19 05:02:56 -04:00
|
|
|
import App from '../../base'
|
2021-04-15 10:23:12 -04:00
|
|
|
import getMeta from '../../utils/meta'
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
export default App.controller('TeamInviteController', function ($scope, $http) {
|
2020-05-19 05:02:56 -04:00
|
|
|
$scope.inflight = false
|
2021-04-15 10:23:12 -04:00
|
|
|
const hasIndividualRecurlySubscription = getMeta(
|
|
|
|
'ol-hasIndividualRecurlySubscription'
|
|
|
|
)
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-15 10:23:12 -04:00
|
|
|
if (hasIndividualRecurlySubscription) {
|
2020-05-19 05:02:56 -04:00
|
|
|
$scope.view = 'hasIndividualRecurlySubscription'
|
|
|
|
} else {
|
|
|
|
$scope.view = 'teamInvite'
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
$scope.keepPersonalSubscription = () => ($scope.view = 'teamInvite')
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
$scope.cancelPersonalSubscription = function () {
|
2020-05-19 05:02:56 -04:00
|
|
|
$scope.inflight = true
|
|
|
|
const request = $http.post('/user/subscription/cancel', {
|
2021-04-27 03:52:58 -04:00
|
|
|
_csrf: window.csrfToken,
|
2018-11-05 05:06:39 -05:00
|
|
|
})
|
2021-04-14 09:17:21 -04:00
|
|
|
request.then(function () {
|
2020-05-19 05:02:56 -04:00
|
|
|
$scope.inflight = false
|
|
|
|
return ($scope.view = 'teamInvite')
|
|
|
|
})
|
|
|
|
return request.catch(() => {
|
|
|
|
$scope.inflight = false
|
|
|
|
$scope.cancel_error = true
|
|
|
|
console.log('the request failed')
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
return ($scope.joinTeam = function () {
|
2020-05-19 05:02:56 -04:00
|
|
|
$scope.inflight = true
|
2021-04-15 10:23:12 -04:00
|
|
|
const inviteToken = getMeta('ol-inviteToken')
|
|
|
|
const request = $http.put(`/subscription/invites/${inviteToken}/`, {
|
2021-04-27 03:52:58 -04:00
|
|
|
_csrf: window.csrfToken,
|
2020-05-19 05:02:56 -04:00
|
|
|
})
|
2021-04-14 09:17:21 -04:00
|
|
|
request.then(function (response) {
|
2020-05-19 05:02:56 -04:00
|
|
|
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'))
|
|
|
|
})
|
|
|
|
})
|