lots of progress

This commit is contained in:
2023-10-24 11:52:55 -07:00
parent 91f7e79aed
commit a8cce0377d
9 changed files with 170 additions and 155 deletions

View File

@@ -27,6 +27,7 @@
field-validation-error
form-validation-error
html-response
main-transformer
many-entity
ref->enum-schema
ref->select-options
@@ -263,10 +264,7 @@
:url (bidi/path-for ssr-routes/only-routes
:company-search)
:value (fc/field-value)
:value-fn (some-fn :db/id identity) ;; TODO better hydration
:content-fn (fn [value]
(:client/name (cond->> value
(nat-int? value) (dc/pull (dc/db conn) [:client/name]))))}))))
:content-fn #(pull-attr (dc/db conn) :client/name %)}))))
(fc/with-field :account-client-override/name
(com/data-grid-cell
{}
@@ -298,14 +296,14 @@
:hx-target "this"}
(com/modal
{}
[:form#edit-form (-> {:hx-ext "response-targets"
:hx-swap "outerHTML swap:300ms"
:hx-target-400 "#form-errors .error-content"}
(assoc (if (:db/id entity)
:hx-put
:hx-post)
(str (bidi/path-for ssr-routes/only-routes
:admin-transaction-rule-edit-save))))
[:form (-> {:hx-ext "response-targets"
:hx-swap "outerHTML swap:300ms"
:hx-target-400 "#form-errors .error-content"}
(assoc (if (:db/id entity)
:hx-put
:hx-post)
(str (bidi/path-for ssr-routes/only-routes
:admin-transaction-rule-edit-save))))
[:fieldset {:class "hx-disable"}
(com/modal-card
{}
@@ -323,7 +321,7 @@
(com/validated-field {:label "Numeric code"
:errors (fc/field-errors)}
(com/text-input {:name (fc/field-name)
:value (fc/field-value)
:value (fc/field-value)
:x-model "accountCode"
:autofocus true
:class "w-32"}))
@@ -382,13 +380,13 @@
(com/data-grid {:headers [(com/data-grid-header {} "Client")
(com/data-grid-header {} "Account name")
(com/data-grid-header {})]
:id "client-override-table"}
:id "client-override-table"}
(fc/cursor-map
#(client-override* %))
(com/data-grid-new-row {:colspan 3
:index (count (fc/field-value))
:hx-get (bidi/path-for ssr-routes/only-routes
:index (count (fc/field-value))
:hx-get (bidi/path-for ssr-routes/only-routes
:admin-account-client-override-new)}
"New override"))))
@@ -407,17 +405,7 @@
[]
(client-override* fc/*current*))))
(defn account-dialog [{:keys [entity form-params form-errors]}]
(html-response (dialog* {:entity entity
:form-params (or (when (seq form-params)
form-params)
entity
{})
:form-errors form-errors})
:headers {"hx-trigger" "modalopen"}))
(def account-schema (mc/schema
(def form-schema (mc/schema
[:map
[:db/id {:optional true} [:maybe entity-id]]
[:account/numeric-code {:optional true} [:maybe :int]]
@@ -434,6 +422,19 @@
[:account-client-override/client entity-id]
[:account-client-override/name [:string {:min 2}]])]]]))
(defn account-dialog [{:keys [entity form-params form-errors]}]
(html-response (dialog* {:entity entity
:form-params (or (when (seq form-params)
form-params)
(when entity
(mc/decode form-schema entity main-transformer))
{})
:form-errors form-errors})
:headers {"hx-trigger" "modalopen"}))
(def key->handler
(apply-middleware-to-all-handlers
(->>
@@ -446,7 +447,7 @@
wrap-admin wrap-client-redirect-unauthenticated)
:admin-account-save (-> account-save
(wrap-entity [:form-params :db/id] default-read)
(wrap-schema-decode :form-schema account-schema)
(wrap-schema-decode :form-schema form-schema)
(wrap-nested-form-params)
(wrap-form-4xx-2 (wrap-entity account-dialog [:form-params :db/id] default-read)))
:admin-account-edit-dialog (-> account-dialog