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'
|
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
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-04-08 14:48:16 -04:00
|
|
|
if (window.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', {
|
|
|
|
_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-08 14:48:16 -04:00
|
|
|
const request = $http.put(`/subscription/invites/${window.inviteToken}/`, {
|
2020-05-19 05:02:56 -04:00
|
|
|
_csrf: window.csrfToken
|
|
|
|
})
|
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'))
|
|
|
|
})
|
|
|
|
})
|