Repository: penpot/penpot
File: frontend/src/app/main/ui/settings/subscription.cljs (ClojureScript)

Code before:
(def ^:private schema:seats-form
  [:map {:title "SeatsForm"}
   [:min-members [::sm/number {:min 1 :max 9999}]]])

(mf/defc subscribe-management-dialog
  {::mf/register modal/components
   ::mf/register-as :management-dialog}
  [{:keys [subscription-name teams subscribe-to-trial]}]

  (let [formatted-subscription-name (if subscribe-to-trial
                                      (if (= subscription-name "unlimited")
                                        (tr "subscription.settings.unlimited-trial")
                                        (tr "subscription.settings.enterprise-trial"))
                                      (case subscription-name
                                        "professional" (tr "subscription.settings.professional")
                                        "unlimited" (tr "subscription.settings.unlimited")
                                        "enterprise" (tr "subscription.settings.enterprise")))
        initial                    (mf/with-memo []
                                     {:min-members (or (some->> teams (map :total-editors) (apply max)) 1)})
        form                       (fm/use-form :schema schema:seats-form
                                                :initial initial)
        subscribe-to-unlimited     (mf/use-fn
                                    (fn [form]
                                      (let [data (:clean-data @form)
                                            current-href (rt/get-current-href)
                                            returnUrl (js/encodeURIComponent current-href)
                                            href (dm/str "payments/subscriptions/create?type=unlimited&quantity=" (:min-members data) "&returnUrl=" returnUrl)]
                                        (st/emit! (ptk/event ::ev/event {::ev/name "create-trial-subscription"
                                                                         :type "unlimited"
                                                                         :quantity (:min-members data)})
                                                  (rt/nav-raw :href href)))))

        subscribe-to-enterprise   (mf/use-fn
                                   (fn []
                                     (st/emit! (ptk/event ::ev/event {::ev/name "create-trial-subscription"
                                                                      :type "enterprise"}))
                                     (let [current-href (rt/get-current-href)
                                           returnUrl (js/encodeURIComponent current-href)
                                           href (dm/str "payments/subscriptions/create?type=enterprise&returnUrl=" returnUrl)]
                                       (st/emit! (rt/nav-raw :href href)))))

        handle-accept-dialog       (mf/use-fn
                                    (fn []
                                      (st/emit! (ptk/event ::ev/event {::ev/name "open-subscription-management"
                                                                       ::ev/origin "profile"
                                                                       :section "subscription-management-modal"}))
                                      (let [current-href (rt/get-current-href)
                                            returnUrl (js/encodeURIComponent current-href)
                                            href (dm/str "payments/subscriptions/show?returnUrl=" returnUrl)]
                                        (st/emit! (rt/nav-raw :href href)))
                                      (modal/hide!)))

Review comment (suggestion):
should be `return-url` and this can be simplified with

```clojure
return-url (-> (rt/get-current-href) (rt/encode-url))
```

Code after:
(def ^:private schema:seats-form
  [:map {:title "SeatsForm"}
   [:min-members [::sm/number {:min 1 :max 9999}]]])

(mf/defc subscribe-management-dialog
  {::mf/register modal/components
   ::mf/register-as :management-dialog}
  [{:keys [subscription-type teams subscribe-to-trial]}]

  (let [subscription-name (if subscribe-to-trial
                            (if (= subscription-type "unlimited")
                              (tr "subscription.settings.unlimited-trial")
                              (tr "subscription.settings.enterprise-trial"))
                            (case subscription-type
                              "professional" (tr "subscription.settings.professional")
                              "unlimited" (tr "subscription.settings.unlimited")
                              "enterprise" (tr "subscription.settings.enterprise")))
        initial                    (mf/with-memo []
                                     {:min-members (or (some->> teams (map :total-editors) (apply max)) 1)})
        form                       (fm/use-form :schema schema:seats-form
                                                :initial initial)
        subscribe-to-unlimited     (mf/use-fn
                                    (fn [form]
                                      (let [data (:clean-data @form)
                                            return-url (-> (rt/get-current-href) (rt/encode-url))
                                            href (dm/str "payments/subscriptions/create?type=unlimited&quantity=" (:min-members data) "&returnUrl=" return-url)]
                                        (st/emit! (ptk/event ::ev/event {::ev/name "create-trial-subscription"
                                                                         :type "unlimited"
                                                                         :quantity (:min-members data)})
                                                  (rt/nav-raw :href href)))))

        subscribe-to-enterprise   (mf/use-fn
                                   (fn []
                                     (st/emit! (ptk/event ::ev/event {::ev/name "create-trial-subscription"
                                                                      :type "enterprise"}))
                                     (let [return-url (-> (rt/get-current-href) (rt/encode-url))
                                           href (dm/str "payments/subscriptions/create?type=enterprise&returnUrl=" return-url)]
                                       (st/emit! (rt/nav-raw :href href)))))

        handle-accept-dialog       (mf/use-fn
                                    (fn []
                                      (st/emit! (ptk/event ::ev/event {::ev/name "open-subscription-management"
                                                                       ::ev/origin "profile"
                                                                       :section "subscription-management-modal"}))
                                      (let [current-href (rt/get-current-href)
                                            returnUrl (js/encodeURIComponent current-href)
                                            href (dm/str "payments/subscriptions/show?returnUrl=" returnUrl)]
                                        (st/emit! (rt/nav-raw :href href)))
                                      (modal/hide!)))
        handle-close-dialog        (mf/use-fn
                                    (fn []