From 2b880d322a18993adf3a4c983191c9dd39450e40 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Fri, 7 Apr 2017 14:15:11 -0400 Subject: [PATCH] use ngif so that form elements are not on page --- .../settingsCreateOrganizationController.js | 46 ++++++++++++------- .../views/settingsCreateOrganization.html | 22 ++++----- 2 files changed, 41 insertions(+), 27 deletions(-) diff --git a/src/app/settings/settingsCreateOrganizationController.js b/src/app/settings/settingsCreateOrganizationController.js index 7b78adc61c..0a6f036fd9 100644 --- a/src/app/settings/settingsCreateOrganizationController.js +++ b/src/app/settings/settingsCreateOrganizationController.js @@ -57,27 +57,41 @@ $scope.submit = function (model) { var shareKey = cryptoService.makeShareKey(); - $scope.submitPromise = stripe.card.createToken(model.card).then(function (response) { - var request = { + if (model.plan === 'free') { + var freeRequest = { name: model.name, planType: model.plan, key: shareKey, - cardToken: response.id, - additionalUsers: model.additionalUsers, - billingEmail: model.billingEmail, - businessName: model.ownedBusiness ? model.businessName : null, - monthly: model.interval === 'month' + billingEmail: model.billingEmail }; - return apiService.organizations.post(request).$promise; - }).then(function (result) { - $scope.model.card = null; + $scope.submitPromise = apiService.organizations.post(freeRequest).$promise.then(finalizeCreate); + } + else { + $scope.submitPromise = stripe.card.createToken(model.card).then(function (response) { + var paidRequest = { + name: model.name, + planType: model.plan, + key: shareKey, + cardToken: response.id, + additionalUsers: model.additionalUsers, + billingEmail: model.billingEmail, + businessName: model.ownedBusiness ? model.businessName : null, + monthly: model.interval === 'month' + }; - $analytics.eventTrack('Created Organization'); - authService.addProfileOrganizationOwner(result, shareKey); - $state.go('backend.org.dashboard', { orgId: result.Id }).then(function () { - toastr.success('Your new organization is ready to go!', 'Organization Created'); - }); - }); + return apiService.organizations.post(paidRequest).$promise; + }).then(finalizeCreate); + } }; + + function finalizeCreate(result) { + $scope.model.card = null; + + $analytics.eventTrack('Created Organization'); + authService.addProfileOrganizationOwner(result, shareKey); + $state.go('backend.org.dashboard', { orgId: result.Id }).then(function () { + toastr.success('Your new organization is ready to go!', 'Organization Created'); + }); + } }); diff --git a/src/app/settings/views/settingsCreateOrganization.html b/src/app/settings/views/settingsCreateOrganization.html index 1eebd16806..0f6a65a11c 100644 --- a/src/app/settings/views/settingsCreateOrganization.html +++ b/src/app/settings/views/settingsCreateOrganization.html @@ -29,8 +29,8 @@
- +
@@ -44,8 +44,8 @@
- +
@@ -56,7 +56,7 @@

Choose Your Plan

-
+
-
+
-
+

Additional Users

@@ -115,14 +115,14 @@
- +
-
+

Billing Summary

@@ -164,7 +164,7 @@ {{totalPrice() | currency:"USD $":2}} /{{model.interval}}
-
+

Payment Information