team-invite-controller.js 1.8 KB

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