mirror of
https://github.com/penpot/penpot.git
synced 2025-12-11 22:14:05 +01:00
🐛 Fix logic preventing incorrect trial flow in subscription modal (#7831)
Some checks failed
Commit Message Check / Check Commit Message (push) Has been cancelled
CI / Code Linter (push) Has been cancelled
CI / Common Tests (push) Has been cancelled
CI / Frontend Tests (push) Has been cancelled
CI / Backend Tests (push) Has been cancelled
CI / Library Tests (push) Has been cancelled
CI / Build Integration Bundle (push) Has been cancelled
CI / Integration Tests 1/4 (push) Has been cancelled
CI / Integration Tests 2/4 (push) Has been cancelled
CI / Integration Tests 3/4 (push) Has been cancelled
Some checks failed
Commit Message Check / Check Commit Message (push) Has been cancelled
CI / Code Linter (push) Has been cancelled
CI / Common Tests (push) Has been cancelled
CI / Frontend Tests (push) Has been cancelled
CI / Backend Tests (push) Has been cancelled
CI / Library Tests (push) Has been cancelled
CI / Build Integration Bundle (push) Has been cancelled
CI / Integration Tests 1/4 (push) Has been cancelled
CI / Integration Tests 2/4 (push) Has been cancelled
CI / Integration Tests 3/4 (push) Has been cancelled
This commit is contained in:
@@ -64,19 +64,24 @@
|
|||||||
:on-click cta-link-with-icon} cta-text-with-icon
|
:on-click cta-link-with-icon} cta-text-with-icon
|
||||||
[:> icon* {:icon-id "open-link"
|
[:> icon* {:icon-id "open-link"
|
||||||
:size "s"}]])
|
:size "s"}]])
|
||||||
(when (and cta-link cta-text (not show-button-cta)) [:button {:class (stl/css-case :cta-button true
|
(when (and cta-link cta-text (not show-button-cta))
|
||||||
|
[:button {:class (stl/css-case :cta-button true
|
||||||
:bottom-link (not (and cta-link-trial cta-text-trial)))
|
:bottom-link (not (and cta-link-trial cta-text-trial)))
|
||||||
:on-click cta-link} cta-text])
|
:on-click cta-link} cta-text])
|
||||||
(when (and cta-link cta-text show-button-cta) [:> button* {:variant "primary"
|
(when (and cta-link cta-text show-button-cta)
|
||||||
|
[:> button* {:variant "primary"
|
||||||
:type "button"
|
:type "button"
|
||||||
:class (stl/css-case :bottom-button (not (and cta-link-trial cta-text-trial)))
|
:class (stl/css-case :bottom-button (not (and cta-link-trial cta-text-trial)))
|
||||||
:on-click cta-link} cta-text])
|
:on-click cta-link} cta-text])
|
||||||
(when (and cta-link-trial cta-text-trial) [:button {:class (stl/css :cta-button :bottom-link)
|
(when (and cta-link-trial cta-text-trial)
|
||||||
|
[:button {:class (stl/css :cta-button :bottom-link)
|
||||||
:on-click cta-link-trial} cta-text-trial])])
|
:on-click cta-link-trial} cta-text-trial])])
|
||||||
|
|
||||||
(defn schema:seats-form [min-editors]
|
(defn schema:seats-form [min-editors]
|
||||||
[:map {:title "SeatsForm"}
|
[:map {:title "SeatsForm"}
|
||||||
[:min-members [::sm/number {:min min-editors
|
[:min-members [::sm/number {:min min-editors
|
||||||
:max 9999}]]])
|
:max 9999}]]
|
||||||
|
[:redirect-to-payment-details :boolean]])
|
||||||
|
|
||||||
(mf/defc subscribe-management-dialog
|
(mf/defc subscribe-management-dialog
|
||||||
{::mf/register modal/components
|
{::mf/register modal/components
|
||||||
@@ -104,32 +109,30 @@
|
|||||||
|
|
||||||
initial
|
initial
|
||||||
(mf/with-memo [min-editors]
|
(mf/with-memo [min-editors]
|
||||||
{:min-members min-editors})
|
{:min-members min-editors
|
||||||
|
:redirect-to-payment-details false})
|
||||||
|
|
||||||
form
|
form
|
||||||
(fm/use-form :schema (schema:seats-form min-editors)
|
(fm/use-form :schema (schema:seats-form min-editors)
|
||||||
:initial initial)
|
:initial initial)
|
||||||
|
|
||||||
form-data-min-editors
|
submit-in-progress
|
||||||
(-> @form :clean-data :min-members)
|
(mf/use-ref false)
|
||||||
|
|
||||||
submit-in-progress*
|
|
||||||
(mf/use-state false)
|
|
||||||
|
|
||||||
subscribe-to-unlimited
|
subscribe-to-unlimited
|
||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
(mf/deps form-data-min-editors)
|
(fn [min-members add-payment-details?]
|
||||||
(fn [add-payment-details]
|
(when-not (mf/ref-val submit-in-progress)
|
||||||
(when (not @submit-in-progress*)
|
(mf/set-ref-val! submit-in-progress true)
|
||||||
(let [return-url (-> (rt/get-current-href) (rt/encode-url))
|
(let [return-url (-> (rt/get-current-href)
|
||||||
href (if add-payment-details
|
(rt/encode-url))
|
||||||
(dm/str "payments/subscriptions/create?type=unlimited&show=true&quantity=" form-data-min-editors "&returnUrl=" return-url)
|
href (dm/str "payments/subscriptions/create?type=unlimited&show="
|
||||||
(dm/str "payments/subscriptions/create?type=unlimited&show=false&quantity=" form-data-min-editors "&returnUrl=" return-url))]
|
add-payment-details? "&quantity="
|
||||||
(reset! submit-in-progress* true)
|
min-members "&returnUrl=" return-url)]
|
||||||
(reset! form nil)
|
(reset! form nil)
|
||||||
(st/emit! (ptk/event ::ev/event {::ev/name "create-trial-subscription"
|
(st/emit! (ptk/event ::ev/event {::ev/name "create-trial-subscription"
|
||||||
:type "unlimited"
|
:type "unlimited"
|
||||||
:quantity form-data-min-editors})
|
:quantity min-members})
|
||||||
(rt/nav-raw :href href))))))
|
(rt/nav-raw :href href))))))
|
||||||
|
|
||||||
subscribe-to-enterprise
|
subscribe-to-enterprise
|
||||||
@@ -144,7 +147,7 @@
|
|||||||
handle-accept-dialog
|
handle-accept-dialog
|
||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
(fn []
|
(fn []
|
||||||
(st/emit! (ptk/event ::ev/event {::ev/name "open-subscription-management"
|
(st/emit! (ev/event {::ev/name "open-subscription-management"
|
||||||
::ev/origin "settings"
|
::ev/origin "settings"
|
||||||
:section "subscription-management-modal"}))
|
:section "subscription-management-modal"}))
|
||||||
(let [current-href (rt/get-current-href)
|
(let [current-href (rt/get-current-href)
|
||||||
@@ -159,14 +162,6 @@
|
|||||||
(st/emit! (ptk/event ::ev/event {::ev/name "close-subscription-modal"}))
|
(st/emit! (ptk/event ::ev/event {::ev/name "close-subscription-modal"}))
|
||||||
(modal/hide!)))
|
(modal/hide!)))
|
||||||
|
|
||||||
handle-unlimited-modal-step
|
|
||||||
(mf/use-fn
|
|
||||||
(mf/deps unlimited-modal-step)
|
|
||||||
(fn []
|
|
||||||
(if (= unlimited-modal-step 1)
|
|
||||||
(reset! unlimited-modal-step* 2)
|
|
||||||
(reset! unlimited-modal-step* 1))))
|
|
||||||
|
|
||||||
show-editors-list*
|
show-editors-list*
|
||||||
(mf/use-state false)
|
(mf/use-state false)
|
||||||
|
|
||||||
@@ -177,7 +172,24 @@
|
|||||||
(mf/use-fn
|
(mf/use-fn
|
||||||
(fn [event]
|
(fn [event]
|
||||||
(dom/stop-propagation event)
|
(dom/stop-propagation event)
|
||||||
(swap! show-editors-list* not)))]
|
(swap! show-editors-list* not)))
|
||||||
|
|
||||||
|
on-submit
|
||||||
|
(mf/use-fn
|
||||||
|
(mf/deps current-subscription unlimited-modal-step*)
|
||||||
|
(fn [form]
|
||||||
|
(let [clean-data (get @form :clean-data)
|
||||||
|
min-members (get clean-data :min-members)
|
||||||
|
redirect? (get clean-data :redirect-to-payment-details)]
|
||||||
|
(if (or (contains? #{"unpaid" "canceled"} (:status current-subscription))
|
||||||
|
(= @unlimited-modal-step* 2))
|
||||||
|
(subscribe-to-unlimited min-members redirect?)
|
||||||
|
(swap! unlimited-modal-step* inc)))))
|
||||||
|
|
||||||
|
on-add-payments-click
|
||||||
|
(mf/use-fn
|
||||||
|
(fn []
|
||||||
|
(swap! form update :data assoc :redirect-to-payment-details true)))]
|
||||||
|
|
||||||
[:div {:class (stl/css :modal-overlay)}
|
[:div {:class (stl/css :modal-overlay)}
|
||||||
[:div {:class (stl/css :modal-dialog)}
|
[:div {:class (stl/css :modal-dialog)}
|
||||||
@@ -207,7 +219,8 @@
|
|||||||
[:li {:key (dm/str (:id editor)) :class (stl/css :team-name)} "- " (:name editor)])]])])
|
[:li {:key (dm/str (:id editor)) :class (stl/css :team-name)} "- " (:name editor)])]])])
|
||||||
|
|
||||||
(when (and
|
(when (and
|
||||||
(or (and (= subscription-type "professional") (contains? #{"unlimited" "enterprise"} (:type current-subscription)))
|
(or (and (= subscription-type "professional")
|
||||||
|
(contains? #{"unlimited" "enterprise"} (:type current-subscription)))
|
||||||
(and (= subscription-type "unlimited") (= (:type current-subscription) "enterprise")))
|
(and (= subscription-type "unlimited") (= (:type current-subscription) "enterprise")))
|
||||||
(not (contains? #{"unpaid" "canceled"} (:status current-subscription)))
|
(not (contains? #{"unpaid" "canceled"} (:status current-subscription)))
|
||||||
(not subscribe-to-trial))
|
(not subscribe-to-trial))
|
||||||
@@ -216,7 +229,7 @@
|
|||||||
|
|
||||||
(if (and (= subscription-type "unlimited")
|
(if (and (= subscription-type "unlimited")
|
||||||
(or subscribe-to-trial (contains? #{"unpaid" "canceled"} (:status current-subscription))))
|
(or subscribe-to-trial (contains? #{"unpaid" "canceled"} (:status current-subscription))))
|
||||||
[:& fm/form {:on-submit handle-unlimited-modal-step
|
[:& fm/form {:on-submit on-submit
|
||||||
:class (stl/css :seats-form)
|
:class (stl/css :seats-form)
|
||||||
:form form}
|
:form form}
|
||||||
(when (= unlimited-modal-step 1)
|
(when (= unlimited-modal-step 1)
|
||||||
@@ -259,7 +272,9 @@
|
|||||||
:on-click handle-close-dialog}]
|
:on-click handle-close-dialog}]
|
||||||
|
|
||||||
[:> fm/submit-button*
|
[:> fm/submit-button*
|
||||||
{:label (tr "labels.continue")
|
{:label (if (contains? #{"unpaid" "canceled"} (:status current-subscription))
|
||||||
|
(tr "subscription.settings.subscribe")
|
||||||
|
(tr "labels.continue"))
|
||||||
:class (stl/css :primary-button)}]]]])
|
:class (stl/css :primary-button)}]]]])
|
||||||
|
|
||||||
(when (= unlimited-modal-step 2)
|
(when (= unlimited-modal-step 2)
|
||||||
@@ -272,15 +287,14 @@
|
|||||||
|
|
||||||
[:input
|
[:input
|
||||||
{:class (stl/css :cancel-button)
|
{:class (stl/css :cancel-button)
|
||||||
:type "button"
|
:type "submit"
|
||||||
:value (tr "subscription.settings.management-dialog.step-2-skip-button")
|
:value (tr "subscription.settings.management-dialog.step-2-skip-button")}]
|
||||||
:on-click #(subscribe-to-unlimited false)}]
|
|
||||||
|
|
||||||
[:input
|
[:input
|
||||||
{:class (stl/css :primary-button)
|
{:class (stl/css :primary-button)
|
||||||
:type "button"
|
:type "submit"
|
||||||
:value (tr "subscription.settings.management-dialog.step-2-add-payment-button")
|
:value (tr "subscription.settings.management-dialog.step-2-add-payment-button")
|
||||||
:on-click #(subscribe-to-unlimited true)}]]]])]
|
:on-click on-add-payments-click}]]]])]
|
||||||
|
|
||||||
[:div {:class (stl/css :modal-footer)}
|
[:div {:class (stl/css :modal-footer)}
|
||||||
[:div {:class (stl/css :action-buttons)}
|
[:div {:class (stl/css :action-buttons)}
|
||||||
|
|||||||
Reference in New Issue
Block a user