team-invite-controller.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /* eslint-disable
  2. max-len,
  3. no-return-assign,
  4. */
  5. // TODO: This file was created by bulk-decaffeinate.
  6. // Fix any style issues and re-enable lint.
  7. /*
  8. * decaffeinate suggestions:
  9. * DS102: Remove unnecessary code created because of implicit returns
  10. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  11. */
  12. import App from '../../base'
  13. export default App.controller('TeamInviteController', function($scope, $http) {
  14. $scope.inflight = false
  15. if (window.hasIndividualRecurlySubscription) {
  16. $scope.view = 'hasIndividualRecurlySubscription'
  17. } else {
  18. $scope.view = 'teamInvite'
  19. }
  20. $scope.keepPersonalSubscription = () => ($scope.view = 'teamInvite')
  21. $scope.cancelPersonalSubscription = function() {
  22. $scope.inflight = true
  23. const request = $http.post('/user/subscription/cancel', {
  24. _csrf: window.csrfToken
  25. })
  26. request.then(function() {
  27. $scope.inflight = false
  28. return ($scope.view = 'teamInvite')
  29. })
  30. return request.catch(() => {
  31. $scope.inflight = false
  32. $scope.cancel_error = true
  33. console.log('the request failed')
  34. })
  35. }
  36. return ($scope.joinTeam = function() {
  37. $scope.inflight = true
  38. const request = $http.put(`/subscription/invites/${window.inviteToken}/`, {
  39. _csrf: window.csrfToken
  40. })
  41. request.then(function(response) {
  42. const { status } = response
  43. $scope.inflight = false
  44. $scope.view = 'inviteAccepted'
  45. if (status !== 200) {
  46. // assume request worked
  47. return ($scope.requestSent = false)
  48. }
  49. })
  50. return request.catch(() => console.log('the request failed'))
  51. })
  52. })