feat: add edit-wizard-toggle-mode-handler
This commit is contained in:
@@ -1445,6 +1445,36 @@
|
|||||||
(fc/with-field :step-params
|
(fc/with-field :step-params
|
||||||
(manual-coding-section* :advanced render-request))))))
|
(manual-coding-section* :advanced render-request))))))
|
||||||
|
|
||||||
|
(defn edit-wizard-toggle-mode-handler [request]
|
||||||
|
(let [step-params (-> request :multi-form-state :step-params)
|
||||||
|
snapshot (-> request :multi-form-state :snapshot)
|
||||||
|
current-mode (keyword (or (:mode step-params) "simple"))
|
||||||
|
target-mode (if (= current-mode :simple) :advanced :simple)
|
||||||
|
;; When switching simple→advanced, promote simple-mode values into accounts
|
||||||
|
render-request
|
||||||
|
(if (and (= target-mode :advanced)
|
||||||
|
(= current-mode :simple))
|
||||||
|
;; carry the simple-mode single row into snapshot so the table shows it
|
||||||
|
(let [accounts (or (seq (:transaction/accounts step-params))
|
||||||
|
(seq (:transaction/accounts snapshot)))]
|
||||||
|
(-> request
|
||||||
|
(assoc-in [:multi-form-state :snapshot :transaction/accounts]
|
||||||
|
(vec accounts))
|
||||||
|
(assoc-in [:multi-form-state :step-params :transaction/accounts]
|
||||||
|
(vec accounts))))
|
||||||
|
;; advanced→simple: take first row only
|
||||||
|
(let [first-row (first (or (seq (:transaction/accounts step-params))
|
||||||
|
(seq (:transaction/accounts snapshot))))]
|
||||||
|
(-> request
|
||||||
|
(assoc-in [:multi-form-state :snapshot :transaction/accounts]
|
||||||
|
(if first-row [first-row] []))
|
||||||
|
(assoc-in [:multi-form-state :step-params :transaction/accounts]
|
||||||
|
(if first-row [first-row] [])))))]
|
||||||
|
(html-response
|
||||||
|
(fc/start-form (:multi-form-state render-request) nil
|
||||||
|
(fc/with-field :step-params
|
||||||
|
(manual-coding-section* target-mode render-request))))))
|
||||||
|
|
||||||
(def key->handler
|
(def key->handler
|
||||||
(apply-middleware-to-all-handlers
|
(apply-middleware-to-all-handlers
|
||||||
{::route/edit-wizard (-> mm/open-wizard-handler
|
{::route/edit-wizard (-> mm/open-wizard-handler
|
||||||
@@ -1486,6 +1516,10 @@
|
|||||||
(mm/wrap-wizard edit-wizard)
|
(mm/wrap-wizard edit-wizard)
|
||||||
(wrap-entity [:multi-form-state :snapshot :db/id] d-transactions/default-read)
|
(wrap-entity [:multi-form-state :snapshot :db/id] d-transactions/default-read)
|
||||||
(mm/wrap-decode-multi-form-state))
|
(mm/wrap-decode-multi-form-state))
|
||||||
|
::route/edit-wizard-toggle-mode (-> edit-wizard-toggle-mode-handler
|
||||||
|
(mm/wrap-wizard edit-wizard)
|
||||||
|
(wrap-entity [:multi-form-state :snapshot :db/id] d-transactions/default-read)
|
||||||
|
(mm/wrap-decode-multi-form-state))
|
||||||
::route/edit-wizard-new-account (->
|
::route/edit-wizard-new-account (->
|
||||||
(add-new-entity-handler [:step-params :transaction/accounts]
|
(add-new-entity-handler [:step-params :transaction/accounts]
|
||||||
(fn render [cursor request]
|
(fn render [cursor request]
|
||||||
|
|||||||
Reference in New Issue
Block a user