diff --git a/frontend/src/app/main/ui/dashboard/subscription.cljs b/frontend/src/app/main/ui/dashboard/subscription.cljs index 4e94c9ce78..61c96506bc 100644 --- a/frontend/src/app/main/ui/dashboard/subscription.cljs +++ b/frontend/src/app/main/ui/dashboard/subscription.cljs @@ -35,11 +35,18 @@ "enterprise" (get-subscription-type (:subscription team)))) +(defn get-profile-subscription-type + [profile] + (if (dnt/is-valid-license? profile) + (dm/get-in profile [:subscription :type]) + (get-subscription-type (dm/get-in profile [:props :subscription])))) + (defn show-team-plan? - [is-owner team] + [is-owner team profile] (not (and is-owner (nil? (dm/get-in team [:organization :id])) - (= "enterprise" (get-subscription-type (:subscription team)))))) + (contains? #{"enterprise" "nitrate"} + (get-profile-subscription-type profile))))) (mf/defc cta-power-up* [{:keys [top-title top-description bottom-description bottom-button bottom-button-href has-dropdown is-highlighted]}] @@ -303,7 +310,7 @@ (let [nitrate? (dnt/is-valid-license? profile) nitrate-license (:subscription profile) subscription (-> profile :props :subscription) - subscription-type (if nitrate? (:type nitrate-license) (get-subscription-type subscription)) + subscription-type (get-profile-subscription-type profile) subscription-is-trial (= "trialing" (:status (if nitrate? nitrate-license subscription))) go-to-subscription (mf/use-fn #(st/emit! (rt/nav :settings-subscription)))] [:button {:class (stl/css :nitrate-current-plan) @@ -323,7 +330,7 @@ "enterprise" (tr "subscription.current-plan.enterprise"))]])) (mf/defc team* - [{:keys [is-owner team]}] + [{:keys [is-owner team profile]}] (let [subscription (:subscription team) subscription-type (get-subscription-type subscription) team-plan-type (get-team-plan-type team) @@ -341,7 +348,7 @@ href (str "payments/subscriptions/show?returnUrl=" href)] (st/emit! (rt/nav-raw :href href)))))] - (when (show-team-plan? is-owner team) + (when (show-team-plan? is-owner team profile) [:div {:class (stl/css :team)} [:div {:class (stl/css :team-label)} (tr "subscription.dashboard.team-plan")] diff --git a/frontend/src/app/main/ui/dashboard/team.cljs b/frontend/src/app/main/ui/dashboard/team.cljs index 4d74599557..0055548533 100644 --- a/frontend/src/app/main/ui/dashboard/team.cljs +++ b/frontend/src/app/main/ui/dashboard/team.cljs @@ -1779,4 +1779,6 @@ (tr "labels.num-of-files" (i18n/c (:files stats)))]]] (when (contains? cfg/flags :subscriptions) - [:> team* {:is-owner (:is-owner permissions) :team team}])]]])) + [:> team* {:is-owner (:is-owner permissions) + :team team + :profile profile}])]]])) diff --git a/frontend/test/frontend_tests/ui/subscription_test.cljs b/frontend/test/frontend_tests/ui/subscription_test.cljs index 7517720806..f85628dd15 100644 --- a/frontend/test/frontend_tests/ui/subscription_test.cljs +++ b/frontend/test/frontend_tests/ui/subscription_test.cljs @@ -6,6 +6,7 @@ (ns frontend-tests.ui.subscription-test (:require + [app.main.data.nitrate :as dnt] [app.main.ui.dashboard.subscription :as ds] [cljs.test :as t :include-macros true])) @@ -25,16 +26,42 @@ (t/deftest owner-enterprise-plan-is-hidden-for-team-outside-organization (t/is (false? (ds/show-team-plan? true {:subscription {:type "enterprise" - :status "active"}})))) + :status "active"}} + {:props {:subscription {:type "enterprise" + :status "active"}}})))) (t/deftest team-plan-is-visible-for-other-owner-and-organization-cases - (t/is (true? (ds/show-team-plan? true - {:subscription {:type "professional" - :status "active"}}))) + (doseq [owner-plan ["professional" "unlimited"]] + (t/is (true? (ds/show-team-plan? true + {:subscription {:type owner-plan + :status "active"}} + {:props {:subscription {:type owner-plan + :status "active"}}})))) (t/is (true? (ds/show-team-plan? true {:subscription {:type "enterprise" :status "active"} - :organization {:id "org-1"}}))) + :organization {:id "org-1"}} + {:props {:subscription {:type "enterprise" + :status "active"}}}))) (t/is (true? (ds/show-team-plan? false {:subscription {:type "enterprise" - :status "active"}})))) + :status "active"}} + {:props {:subscription {:type "enterprise" + :status "active"}}})))) + +(t/deftest owner-enterprise-plan-is-detected-even-when-team-subscription-falls-back + (t/is (false? (ds/show-team-plan? true + {:subscription {:type "professional" + :status "active"}} + {:props {:subscription {:type "enterprise" + :status "trialing"}}})))) + +(t/deftest nitrate-owner-plan-hides-team-plan-when-team-is-outside-organization + (with-redefs [dnt/is-valid-license? (constantly true)] + (t/is (false? (ds/show-team-plan? true + {:subscription {:type "professional" + :status "active"}} + {:subscription {:type "nitrate" + :status "active"} + :props {:subscription {:type "professional" + :status "active"}}})))))