progress on invoices.

This commit is contained in:
2024-03-14 07:16:59 -07:00
parent 3b49a0804a
commit 5b9c4b7aef
17 changed files with 519 additions and 110 deletions

View File

@@ -4,7 +4,7 @@
[auto-ap.ssr.nested-form-params :refer [wrap-nested-form-params]]
[auto-ap.ssr.utils
:refer [ html-response
:refer [html-response
assert-schema
main-transformer
modal-response
@@ -31,7 +31,7 @@
:hx-trigger "submit"
:hx-target "this"
"x-trap" "true"
:class "h-full w-full" })
:class "h-full w-full"})
(defprotocol ModalWizardStep
(step-key [this])
@@ -57,7 +57,7 @@
(hydrate-from-request [this request])
(get-current-step [this])
(navigate [this step-key])
(form-schema [this])
(steps [this])
(get-step [this step-key])
@@ -197,9 +197,15 @@
(defn wrap-ensure-step [handler]
(->
(fn [{:keys [wizard multi-form-state] :as request}]
(println "ENSURE STEP")
(clojure.pprint/pprint (:step-params (:multi-form-state request)))
(assert-schema (step-schema (get-current-step wizard)) (:step-params multi-form-state))
(handler request))
(wrap-form-4xx-2 (fn [{:keys [wizard] :as request}] ;; THIS MAY BE BETTER TO JUST MAKE THE LINEAR WIZARD POPULATE FROM THE REQUEST
(println "FINAL")
(clojure.pprint/pprint (:step-params (:multi-form-state request)))
(html-response
(render-wizard wizard request)
:headers {"x-transition-type" "none"
@@ -223,25 +229,25 @@
(def next-handler
(-> (fn [{:keys [wizard] :as request}]
(let [current-step (get-current-step wizard)
to-step (:to (:query-params request))
wizard (navigate wizard to-step)
new-step (get-current-step wizard)
transition-type (get-transition-type wizard (step-key current-step) to-step)]
(html-response
(render-wizard wizard
(-> request
(assoc :multi-form-state (-> (:multi-form-state request)
(merge-multi-form-state)
(select-state
(edit-path new-step request)
(init-step-params- new-step request))))))
:headers {"HX-reswap" (when transition-type "outerHTML swap:0.15s")
"x-transition-type" (or transition-type "none")})))
(wrap-ensure-step)
(wrap-schema-enforce :query-schema
[:map
[:to step-key-schema]])))
(let [current-step (get-current-step wizard)
to-step (:to (:query-params request))
wizard (navigate wizard to-step)
new-step (get-current-step wizard)
transition-type (get-transition-type wizard (step-key current-step) to-step)]
(html-response
(render-wizard wizard
(-> request
(assoc :multi-form-state (-> (:multi-form-state request)
(merge-multi-form-state)
(select-state
(edit-path new-step request)
(init-step-params- new-step request))))))
:headers {"HX-reswap" (when transition-type "outerHTML swap:0.15s")
"x-transition-type" (or transition-type "none")})))
(wrap-ensure-step)
(wrap-schema-enforce :query-schema
[:map
[:to step-key-schema]])))
(def discard-handler
(->
@@ -263,7 +269,7 @@
(def submit-handler
(-> (fn [{:keys [wizard multi-form-state] :as request}]
(submit wizard (-> request
(assoc :multi-form-state (merge-multi-form-state multi-form-state)))))
(assoc :multi-form-state (merge-multi-form-state multi-form-state)))))
(wrap-ensure-step)))
(defn default-render-wizard [linear-wizard {:keys [multi-form-state form-errors snapshot current-step] :as request} & {:keys [form-params]}]
@@ -313,12 +319,8 @@
(defn open-wizard-handler [{:keys [wizard current-step] :as request}]
(modal-response
[:div {:x-data (hx/json {"transitionType" "none"
}
)
"@htmx:after-request" "if(event.detail.xhr.getResponseHeader('x-transition-type')) { $data.transitionType = event.detail.xhr.getResponseHeader('x-transition-type');}"
}
[:div {:x-data (hx/json {"transitionType" "none"})
"@htmx:after-request" "if(event.detail.xhr.getResponseHeader('x-transition-type')) { $data.transitionType = event.detail.xhr.getResponseHeader('x-transition-type');}"}
(render-wizard wizard request)]))
@@ -333,6 +335,24 @@
(wrap-init-multi-form-state
handler
(fn parse-multi-form-state [request]
(println "HERE WE ARE FULL")
(clojure.pprint/pprint (:step-params (:form-params request)))
(println "OK NOW")
(clojure.pprint/pprint (:step-params (map->MultiStepFormState (mc/decode [:map
[:snapshot {:optional true
:decode/arbitrary
#(clojure.edn/read-string {:readers clj-time.coerce/data-readers
:eof nil}
%)}
[:maybe :any]]
[:edit-path {:optional true :decode/arbitrary (fn [z]
(clojure.edn/read-string z))} [:maybe [:sequential {:min 0} any?]]]
[:step-params {:optional true}
[:maybe
:any]]]
(:form-params request)
main-transformer))))
(map->MultiStepFormState (mc/decode [:map
[:snapshot {:optional true
:decode/arbitrary
@@ -346,4 +366,20 @@
[:maybe
:any]]]
(:form-params request)
main-transformer)))))
main-transformer)))))
(comment
(def f {"snapshot"
"{:invoices [{:invoice_id 17592297837035, :amount 23.0, :invoice {:db/id 17592297837035, :invoice/vendor {:db/id 17592186045722, :vendor/name \"Sysco\"}, :invoice/client {:db/id 17592232555238}, :invoice/outstanding-balance 23.0, :invoice/invoice-number \"702,34\"}} {:invoice_id 17592297837049, :amount 23.0, :invoice {:db/id 17592297837049, :invoice/vendor {:db/id 17592186045722, :vendor/name \"Sysco\"}, :invoice/client {:db/id 17592232555238}, :invoice/outstanding-balance 23.0, :invoice/invoice-number \"80[234234\"}}], :client 17592232555238}",
"edit-path" "[]",
"current-step" ":payment-details",
"mode" "advanced",
"step-params"
{"invoices"
{"0" {"invoice_id" "17592297837035", "amount" "1"},
"1" {"invoice_id" "17592297837049", "amount" "23.00"}}}})
(mc/decode [:map [:step-params {:optional true} [:maybe :any]]]
f
main-transformer)
)