lots of progress
This commit is contained in:
@@ -29,6 +29,7 @@
|
||||
field-validation-error
|
||||
form-validation-error
|
||||
html-response
|
||||
main-transformer
|
||||
many-entity
|
||||
money
|
||||
percentage
|
||||
@@ -66,8 +67,9 @@
|
||||
:url (bidi/path-for ssr-routes/only-routes
|
||||
:vendor-search)
|
||||
:id (str "vendor-search")
|
||||
:value [(:db/id (:vendor (:parsed-query-params request)))
|
||||
(:vendor/name (:vendor (:parsed-query-params request)))]}))
|
||||
:value (:vendor (:parsed-query-params request))
|
||||
:value-fn :db/id
|
||||
:content-fn :vendor/name}))
|
||||
(com/field {:label "Note"}
|
||||
(com/text-input {:name "note"
|
||||
:id "note"
|
||||
@@ -330,12 +332,11 @@
|
||||
:id name
|
||||
:x-model x-model
|
||||
:value value
|
||||
:value-fn (some-fn :db/id identity)
|
||||
:content-fn (fn [value]
|
||||
(:account/name (d-accounts/clientize (cond->> value
|
||||
(nat-int? value) (dc/pull (dc/db conn) d-accounts/default-read))
|
||||
(:account/name (d-accounts/clientize (dc/pull (dc/db conn) d-accounts/default-read value)
|
||||
client-id)))})])
|
||||
|
||||
;; TODO something is making the accountId not change the location for only existing ones?
|
||||
(defn- transaction-rule-account-row*
|
||||
[transaction-rule account]
|
||||
(com/data-grid-row (-> {:x-data (hx/json {:accountId (or (:db/id (fc/field-value (:transaction-rule-account/account account)))
|
||||
@@ -363,8 +364,7 @@
|
||||
(account-typeahead* {:value (fc/field-value)
|
||||
:client-id (:db/id (:transaction-rule/client transaction-rule))
|
||||
:name (fc/field-name)
|
||||
:x-model "accountId"
|
||||
}))))
|
||||
:x-model "accountId"}))))
|
||||
(fc/with-field :transaction-rule-account/location
|
||||
(com/data-grid-cell
|
||||
{}
|
||||
@@ -396,22 +396,21 @@
|
||||
(com/data-grid-cell {:class "align-top"}
|
||||
(com/a-icon-button {"@click.prevent.stop" "show=false; setTimeout(() => $refs.p.remove(), 500)"} svg/x))))
|
||||
|
||||
;; TODO dialog is no longer closeable
|
||||
;; TODO might not need #edit-form id
|
||||
;; TODO background jobs and company 1099
|
||||
(defn dialog* [{:keys [entity form-params form-errors]}]
|
||||
(fc/start-form form-params form-errors
|
||||
(com/modal
|
||||
{:modal-class "max-w-2xl"
|
||||
:hx-target "this"}
|
||||
|
||||
[:form#edit-form {:hx-ext "response-targets"
|
||||
:hx-swap "outerHTML swap:300ms"
|
||||
:hx-target-400 "#form-errors .error-content"
|
||||
:x-trap "true"
|
||||
:class "group/form"
|
||||
(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"
|
||||
:x-trap "true"
|
||||
:class "group/form"
|
||||
(if (:db/id entity)
|
||||
:hx-put
|
||||
:hx-post) (str (bidi/path-for ssr-routes/only-routes :admin-transaction-rule-edit-save))}
|
||||
(com/modal-card
|
||||
{}
|
||||
[:div.flex [:div.p-2 "Transaction Rule"]]
|
||||
@@ -465,10 +464,7 @@
|
||||
:url (bidi/path-for ssr-routes/only-routes :company-search)
|
||||
:x-model "clientId"
|
||||
:value (fc/field-value)
|
||||
:value-fn (some-fn :db/id identity)
|
||||
:content-fn (fn [c] (cond->> c
|
||||
(nat-int? c) (dc/pull (dc/db conn) '[:client/name])
|
||||
true :client/name))})]))
|
||||
:content-fn (fn [c] (pull-attr (dc/db conn) :client/name c))})]))
|
||||
|
||||
(fc/with-field :transaction-rule/bank-account
|
||||
(com/validated-field
|
||||
@@ -536,11 +532,9 @@
|
||||
(com/typeahead-2 {:name (fc/field-name)
|
||||
:placeholder "Search..."
|
||||
:url (bidi/path-for ssr-routes/only-routes :vendor-search)
|
||||
:id (str "form-vendor-search")
|
||||
:class "w-96"
|
||||
:value (fc/field-value)
|
||||
:value-fn (some-fn :db/id identity)
|
||||
:content-fn (some-fn :vendor/name #(pull-attr (dc/db conn) :vendor/name %))})]))
|
||||
:content-fn #(pull-attr (dc/db conn) :vendor/name %)})]))
|
||||
|
||||
(fc/with-field :transaction-rule/accounts
|
||||
(com/validated-field
|
||||
@@ -573,11 +567,6 @@
|
||||
(com/validated-save-button {:errors (:errors form-errors)} "Save rule")])])))
|
||||
|
||||
|
||||
;; TODO Should forms have some kind of helper to render an individual field? saving
|
||||
;; could generate the entire form and swap if there are errors
|
||||
;; but also when you tab out it could call the same function, and just
|
||||
;; pull out the single field to swap
|
||||
|
||||
(defn new-account [{{:keys [client-id index]} :query-params}]
|
||||
(html-response
|
||||
(fc/start-form-with-prefix
|
||||
@@ -598,16 +587,14 @@
|
||||
|
||||
;; TODO check to see if it should be called "Shared" or "shared" for the value
|
||||
;; TODO hydrate nested types more easily. make it easy to hydrate so you don't do weird sometimes pulls
|
||||
;; TODO is it possible to make it easy to get a virtual cursor in the case of adding a new row? setting up
|
||||
;; fake data doesn't feel right - maybe have a "prelude" that's dynamic
|
||||
|
||||
(defn location-select [{{:keys [name account-id client-id value] :as qp} :query-params}]
|
||||
(html-response (location-select* {:name name
|
||||
:value value
|
||||
:account-location (some->> account-id
|
||||
(pull-attr (dc/db conn) :account/location))
|
||||
(pull-attr (dc/db conn) :account/location))
|
||||
:client-locations (some->> client-id
|
||||
(pull-attr (dc/db conn) :client/locations))})))
|
||||
(pull-attr (dc/db conn) :client/locations))})))
|
||||
|
||||
(defn account-typeahead [{{:keys [name value client-id] :as qp} :query-params}]
|
||||
(let [account (some->> value (dc/pull (dc/db conn) [:account/name :db/id
|
||||
@@ -619,34 +606,37 @@
|
||||
:value account
|
||||
:client-id client-id}))))
|
||||
|
||||
(def form-schema (mc/schema
|
||||
[:map
|
||||
[:db/id {:optional true} [:maybe entity-id]]
|
||||
[:transaction-rule/client {:optional true} [:maybe entity-id]]
|
||||
[:transaction-rule/description [:and regex
|
||||
[:string {:min 3}]]]
|
||||
[:transaction-rule/bank-account [:maybe entity-id]]
|
||||
[:transaction-rule/amount-gte {:optional true} [:maybe money]]
|
||||
[:transaction-rule/amount-lte {:optional true} [:maybe money]]
|
||||
[:transaction-rule/dom-gte {:optional true} [:maybe :int]]
|
||||
[:transaction-rule/dom-lte {:optional true} [:maybe :int]]
|
||||
[:transaction-rule/vendor {:optional true} [:maybe entity-id]]
|
||||
[:transaction-rule/transaction-approval-status (ref->enum-schema "transaction-approval-status")]
|
||||
[:transaction-rule/accounts
|
||||
(many-entity {:min 1}
|
||||
[:db/id [:or entity-id temp-id]]
|
||||
[:transaction-rule-account/account entity-id]
|
||||
[:transaction-rule-account/location [:string {:min 1 :error/message "required"}]]
|
||||
[:transaction-rule-account/percentage percentage])]]))
|
||||
|
||||
(defn transaction-dialog [{:keys [entity form-params form-errors]}]
|
||||
(html-response (dialog* {:entity entity
|
||||
:form-params (or (when (seq form-params)
|
||||
form-params)
|
||||
entity ;; TODO coerce into form params
|
||||
(when entity
|
||||
(mc/decode form-schema entity main-transformer)) ;; TODO coerce into form params
|
||||
{})
|
||||
:form-errors form-errors})
|
||||
:headers {"hx-trigger" "modalopen"}))
|
||||
|
||||
(def transaction-rule-schema (mc/schema
|
||||
[:map
|
||||
[:db/id {:optional true} [:maybe entity-id]]
|
||||
[:transaction-rule/client {:optional true} [:maybe entity-id]]
|
||||
[:transaction-rule/description [:and regex
|
||||
[:string {:min 3}]]]
|
||||
[:transaction-rule/bank-account [:maybe entity-id]]
|
||||
[:transaction-rule/amount-gte {:optional true} [:maybe money]]
|
||||
[:transaction-rule/amount-lte {:optional true} [:maybe money]]
|
||||
[:transaction-rule/dom-gte {:optional true} [:maybe :int]]
|
||||
[:transaction-rule/dom-lte {:optional true} [:maybe :int]]
|
||||
[:transaction-rule/vendor {:optional true} [:maybe entity-id]]
|
||||
[:transaction-rule/transaction-approval-status (ref->enum-schema "transaction-approval-status")]
|
||||
[:transaction-rule/accounts
|
||||
(many-entity {:min 1}
|
||||
[:db/id [:or entity-id temp-id]]
|
||||
[:transaction-rule-account/account entity-id]
|
||||
[:transaction-rule-account/location [:string {:min 1 :error/message "required"}]]
|
||||
[:transaction-rule-account/percentage percentage])]]))
|
||||
|
||||
|
||||
(def key->handler
|
||||
(apply-middleware-to-all-handlers
|
||||
@@ -676,10 +666,10 @@
|
||||
[:maybe entity-id]]]))
|
||||
:admin-transaction-rule-save (-> transaction-rule-save
|
||||
(wrap-entity [:form-params :db/id] default-read)
|
||||
(wrap-schema-decode :form-schema transaction-rule-schema)
|
||||
(wrap-nested-form-params)
|
||||
(wrap-form-4xx-2 (-> transaction-dialog
|
||||
(wrap-entity [:form-params :db/id] default-read))))
|
||||
(wrap-schema-decode :form-schema form-schema)
|
||||
(wrap-nested-form-params)
|
||||
(wrap-form-4xx-2 (-> transaction-dialog
|
||||
(wrap-entity [:form-params :db/id] default-read))))
|
||||
:admin-transaction-rule-edit-dialog (-> transaction-dialog
|
||||
(wrap-entity [:route-params :db/id] default-read)
|
||||
(wrap-schema-decode :route-schema [:map [:db/id entity-id]]))
|
||||
|
||||
Reference in New Issue
Block a user