mirror of
https://github.com/penpot/penpot.git
synced 2026-09-11 06:28:47 +00:00
✨ Add subscription info for nitrate
This commit is contained in:
parent
4bfd5194f6
commit
3141f67cd7
@ -3,6 +3,8 @@
|
|||||||
(:require
|
(:require
|
||||||
[app.common.logging :as l]
|
[app.common.logging :as l]
|
||||||
[app.common.schema :as sm]
|
[app.common.schema :as sm]
|
||||||
|
[app.common.schema.generators :as sg]
|
||||||
|
[app.common.time :as ct]
|
||||||
[app.config :as cf]
|
[app.config :as cf]
|
||||||
[app.http.client :as http]
|
[app.http.client :as http]
|
||||||
[app.rpc :as-alias rpc]
|
[app.rpc :as-alias rpc]
|
||||||
@ -83,9 +85,73 @@
|
|||||||
[:id ::sm/text]
|
[:id ::sm/text]
|
||||||
[:name ::sm/text]])
|
[:name ::sm/text]])
|
||||||
|
|
||||||
(def ^:private schema:user
|
;; TODO Unify with schemas on backend/src/app/http/management.clj
|
||||||
[:map
|
(def ^:private schema:timestamp
|
||||||
[:valid ::sm/boolean]])
|
(sm/type-schema
|
||||||
|
{:type ::timestamp
|
||||||
|
:pred ct/inst?
|
||||||
|
:type-properties
|
||||||
|
{:title "inst"
|
||||||
|
:description "The same as :app.common.time/inst but encodes to epoch"
|
||||||
|
:error/message "should be an instant"
|
||||||
|
:gen/gen (->> (sg/small-int)
|
||||||
|
(sg/fmap (fn [v] (ct/inst v))))
|
||||||
|
:decode/string ct/inst
|
||||||
|
:encode/string inst-ms
|
||||||
|
:decode/json ct/inst
|
||||||
|
:encode/json inst-ms}}))
|
||||||
|
|
||||||
|
(def ^:private schema:subscription
|
||||||
|
[:map {:title "Subscription"}
|
||||||
|
[:id ::sm/text]
|
||||||
|
[:customer-id ::sm/text]
|
||||||
|
[:type [:enum
|
||||||
|
"unlimited"
|
||||||
|
"professional"
|
||||||
|
"enterprise"
|
||||||
|
"nitrate"]]
|
||||||
|
[:status [:enum
|
||||||
|
"active"
|
||||||
|
"canceled"
|
||||||
|
"incomplete"
|
||||||
|
"incomplete_expired"
|
||||||
|
"past_due"
|
||||||
|
"paused"
|
||||||
|
"trialing"
|
||||||
|
"unpaid"]]
|
||||||
|
|
||||||
|
[:billing-period [:enum
|
||||||
|
"month"
|
||||||
|
"day"
|
||||||
|
"week"
|
||||||
|
"year"]]
|
||||||
|
[:quantity :int]
|
||||||
|
[:description [:maybe ::sm/text]]
|
||||||
|
[:created-at schema:timestamp]
|
||||||
|
[:start-date [:maybe schema:timestamp]]
|
||||||
|
[:ended-at [:maybe schema:timestamp]]
|
||||||
|
[:trial-end [:maybe schema:timestamp]]
|
||||||
|
[:trial-start [:maybe schema:timestamp]]
|
||||||
|
[:cancel-at [:maybe schema:timestamp]]
|
||||||
|
[:canceled-at [:maybe schema:timestamp]]
|
||||||
|
[:current-period-end [:maybe schema:timestamp]]
|
||||||
|
[:current-period-start [:maybe schema:timestamp]]
|
||||||
|
[:cancel-at-period-end :boolean]
|
||||||
|
|
||||||
|
[:cancellation-details
|
||||||
|
[:map {:title "CancellationDetails"}
|
||||||
|
[:comment [:maybe ::sm/text]]
|
||||||
|
[:reason [:maybe ::sm/text]]
|
||||||
|
[:feedback [:maybe
|
||||||
|
[:enum
|
||||||
|
"customer_service"
|
||||||
|
"low_quality"
|
||||||
|
"missing_feature"
|
||||||
|
"other"
|
||||||
|
"switched_service"
|
||||||
|
"too_complex"
|
||||||
|
"too_expensive"
|
||||||
|
"unused"]]]]]])
|
||||||
|
|
||||||
(def ^:private schema:connectivity
|
(def ^:private schema:connectivity
|
||||||
[:map
|
[:map
|
||||||
@ -96,10 +162,10 @@
|
|||||||
(let [baseuri (cf/get :nitrate-backend-uri)]
|
(let [baseuri (cf/get :nitrate-backend-uri)]
|
||||||
(request-to-nitrate cfg :get (str baseuri "/api/teams/" (str team-id)) schema:organization params)))
|
(request-to-nitrate cfg :get (str baseuri "/api/teams/" (str team-id)) schema:organization params)))
|
||||||
|
|
||||||
(defn- is-valid-user
|
(defn- get-subscription
|
||||||
[cfg {:keys [profile-id] :as params}]
|
[cfg {:keys [profile-id] :as params}]
|
||||||
(let [baseuri (cf/get :nitrate-backend-uri)]
|
(let [baseuri (cf/get :nitrate-backend-uri)]
|
||||||
(request-to-nitrate cfg :get (str baseuri "/api/users/" (str profile-id)) schema:user params)))
|
(request-to-nitrate cfg :get (str baseuri "/api/subscriptions/" (str profile-id)) schema:subscription params)))
|
||||||
|
|
||||||
(defn- get-connectivity
|
(defn- get-connectivity
|
||||||
[cfg params]
|
[cfg params]
|
||||||
@ -113,9 +179,9 @@
|
|||||||
(defmethod ig/init-key ::client
|
(defmethod ig/init-key ::client
|
||||||
[_ cfg]
|
[_ cfg]
|
||||||
(when (contains? cf/flags :nitrate)
|
(when (contains? cf/flags :nitrate)
|
||||||
{:get-team-org (partial get-team-org cfg)
|
{:get-team-org (partial get-team-org cfg)
|
||||||
:is-valid-user (partial is-valid-user cfg)
|
:get-subscription (partial get-subscription cfg)
|
||||||
:connectivity (partial get-connectivity cfg)}))
|
:connectivity (partial get-connectivity cfg)}))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; UTILS
|
;; UTILS
|
||||||
@ -125,9 +191,8 @@
|
|||||||
(defn add-nitrate-licence-to-profile
|
(defn add-nitrate-licence-to-profile
|
||||||
[cfg profile]
|
[cfg profile]
|
||||||
(try
|
(try
|
||||||
(let [nitrate-licence (call cfg :is-valid-user {:profile-id (:id profile)})]
|
(let [subscription (call cfg :get-subscription {:profile-id (:id profile)})]
|
||||||
(assoc-in profile [:props :nitrate-license]
|
(assoc profile :subscription subscription))
|
||||||
(select-keys nitrate-licence [:valid :created-at])))
|
|
||||||
(catch Throwable cause
|
(catch Throwable cause
|
||||||
(l/error :hint "failed to get nitrate licence"
|
(l/error :hint "failed to get nitrate licence"
|
||||||
:profile-id (:id profile)
|
:profile-id (:id profile)
|
||||||
|
|||||||
@ -39,4 +39,11 @@
|
|||||||
|
|
||||||
(def go-to-subscription-url (u/join cf/public-uri "#/settings/subscriptions"))
|
(def go-to-subscription-url (u/join cf/public-uri "#/settings/subscriptions"))
|
||||||
|
|
||||||
|
(defn is-valid-license?
|
||||||
|
[profile]
|
||||||
|
(and (contains? cf/flags :nitrate)
|
||||||
|
;; Possible values: "active" "canceled" "incomplete" "incomplete_expired" "past_due" "paused" "trialing" "unpaid"
|
||||||
|
(contains? #{"active" "past_due" "trialing"}
|
||||||
|
(dm/get-in profile [:subscription :status]))))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -302,7 +302,7 @@
|
|||||||
on-create-org-click
|
on-create-org-click
|
||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
(fn []
|
(fn []
|
||||||
(if (dm/get-in profile [:props :nitrate-license :valid])
|
(if (dnt/is-valid-license? profile)
|
||||||
(dnt/go-to-nitrate-cc)
|
(dnt/go-to-nitrate-cc)
|
||||||
(st/emit! (dnt/show-nitrate-popup :nitrate-form)))))]
|
(st/emit! (dnt/show-nitrate-popup :nitrate-form)))))]
|
||||||
|
|
||||||
@ -547,7 +547,7 @@
|
|||||||
on-create-org-click
|
on-create-org-click
|
||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
(fn []
|
(fn []
|
||||||
(if (dm/get-in profile [:props :nitrate-license :valid])
|
(if (dnt/is-valid-license? profile)
|
||||||
(dnt/go-to-nitrate-cc)
|
(dnt/go-to-nitrate-cc)
|
||||||
(st/emit! (dnt/show-nitrate-popup :nitrate-form)))))]
|
(st/emit! (dnt/show-nitrate-popup :nitrate-form)))))]
|
||||||
(if empty?
|
(if empty?
|
||||||
|
|||||||
@ -120,10 +120,7 @@
|
|||||||
(mf/defc nitrate-sidebar*
|
(mf/defc nitrate-sidebar*
|
||||||
{::mf/props :obj}
|
{::mf/props :obj}
|
||||||
[{:keys [profile teams]}]
|
[{:keys [profile teams]}]
|
||||||
(let [nitrate-license (dm/get-in profile [:props :nitrate-license])
|
(let [nitrate? (dnt/is-valid-license? profile)
|
||||||
nitrate? (and (contains? cf/flags :nitrate)
|
|
||||||
(:valid nitrate-license))
|
|
||||||
|
|
||||||
orgs (mf/with-memo [teams]
|
orgs (mf/with-memo [teams]
|
||||||
(let [orgs (->> teams
|
(let [orgs (->> teams
|
||||||
vals
|
vals
|
||||||
|
|||||||
@ -389,13 +389,10 @@
|
|||||||
|
|
||||||
(mf/defc subscription-page*
|
(mf/defc subscription-page*
|
||||||
[{:keys [profile]}]
|
[{:keys [profile]}]
|
||||||
(let [route (mf/deref refs/route)
|
(let [route (mf/deref refs/route)
|
||||||
authenticated? (da/is-authenticated? profile)
|
authenticated? (da/is-authenticated? profile)
|
||||||
|
nitrate-license (:subscription profile)
|
||||||
nitrate-license (dm/get-in profile [:props :nitrate-license])
|
nitrate? (dnt/is-valid-license? profile)
|
||||||
|
|
||||||
nitrate? (and (contains? cf/flags :nitrate)
|
|
||||||
(:valid nitrate-license))
|
|
||||||
|
|
||||||
params-subscription
|
params-subscription
|
||||||
(-> route :params :query :subscription)
|
(-> route :params :query :subscription)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user