team-invite-controller.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. import getMeta from '../../utils/meta'
  14. export default App.controller('TeamInviteController', function ($scope, $http) {
  15. $scope.inflight = false
  16. const hideJoinSubscription = getMeta('ol-cannot-join-subscription')
  17. const hasIndividualRecurlySubscription = getMeta(
  18. 'ol-hasIndividualRecurlySubscription'
  19. )
  20. if (hideJoinSubscription) {
  21. $scope.view = 'restrictedByManagedGroup'
  22. } else if (hasIndividualRecurlySubscription) {
  23. $scope.view = 'hasIndividualRecurlySubscription'
  24. } else {
  25. $scope.view = 'teamInvite'
  26. }
  27. $scope.keepPersonalSubscription = () => ($scope.view = 'teamInvite')
  28. $scope.cancelPersonalSubscription = function () {
  29. $scope.inflight = true
  30. const request = $http.post('/user/subscription/cancel', {
  31. _csrf: window.csrfToken,
  32. })
  33. request.then(function () {
  34. $scope.inflight = false
  35. return ($scope.view = 'teamInvite')
  36. })
  37. return request.catch(() => {
  38. $scope.inflight = false
  39. $scope.cancel_error = true
  40. console.log('the request failed')
  41. })
  42. }
  43. return ($scope.joinTeam = function () {
  44. $scope.inflight = true
  45. const inviteToken = getMeta('ol-inviteToken')
  46. const request = $http.put(`/subscription/invites/${inviteToken}/`, {
  47. _csrf: window.csrfToken,
  48. })
  49. request.then(function (response) {
  50. const { status } = response
  51. $scope.inflight = false
  52. $scope.view = 'inviteAccepted'
  53. if (status !== 200) {
  54. // assume request worked
  55. return ($scope.requestSent = false)
  56. }
  57. })
  58. return request.catch(() => console.log('the request failed'))
  59. })
  60. })