preserves values.

This commit is contained in:
2023-10-25 06:46:31 -07:00
parent f5fd532a31
commit b4ea51df84

View File

@@ -259,7 +259,6 @@
bank-account-id))
(defn transaction-rule-save [{:keys [form-params request-method identity] :as request}]
(clojure.pprint/pprint form-params)
(let [entity (cond-> form-params
(= :post request-method) (assoc :db/id "new")
true (assoc :transaction-rule/note (entity->note form-params)))
@@ -330,10 +329,11 @@
client-id)))})])
(defn- transaction-rule-account-row*
[transaction-rule account]
[account client-id client-locations]
(com/data-grid-row
(-> {:x-data (hx/json {:accountId (or (:db/id (fc/field-value (:transaction-rule-account/account account)))
(fc/field-value (:transaction-rule-account/account account)))
:location (fc/field-value (:transaction-rule-account/location account))
:show (boolean (not (fc/field-value (:new? account))))})
:data-key "show"
:x-ref "p"}
@@ -351,11 +351,11 @@
{:errors (fc/field-errors)}
[:div {:hx-trigger "changed"
:hx-target "next div"
:hx-vals (format "js:{name: '%s', 'client-id': event.detail.clientId}" account-name)
:hx-vals (format "js:{name: '%s', 'client-id': event.detail.clientId, value: event.detail.accountId}" account-name)
:hx-get (str (bidi/path-for ssr-routes/only-routes :admin-transaction-rule-account-typeahead))
:x-init "$watch('clientId', cid => $dispatch('changed', $data))"}]
:x-init "$watch('clientId', cid => $dispatch('changed', $data));"}]
(account-typeahead* {:value (fc/field-value)
:client-id (:db/id (:transaction-rule/client transaction-rule))
:client-id client-id
:name (fc/field-name)
:x-model "accountId"}))))
(fc/with-field :transaction-rule-account/location
@@ -366,24 +366,21 @@
:x-data (hx/json {:location (fc/field-value)})}
[:div {:hx-trigger "changed"
:hx-target "next *"
:hx-vals (format "js:{name: '%s', 'client-id': event.detail.clientId || '', 'account-id': event.detail.accountId || ''}" (fc/field-name) )
:hx-vals (format "js:{name: '%s', 'client-id': event.detail.clientId || '', 'account-id': event.detail.accountId || '', value: event.detail.location}" (fc/field-name) )
:hx-get (bidi/path-for ssr-routes/only-routes :admin-transaction-rule-location-select)
:x-init "$watch('clientId', cid => $dispatch('changed', $data)); $watch('accountId', cid => $dispatch('changed', $data) )"}]
(location-select* {:name (fc/field-name)
:account-location (:account/location (cond->> (:transaction-rule-account/account @account)
(nat-int? (:transaction-rule-account/account @account)) (dc/pull (dc/db conn)
'[:account/location])))
:client-locations (:client/locations (:transaction-rule/client transaction-rule))
:hx-model "location"
:client-locations client-locations
:x-model "location"
:value (fc/field-value)}))))
(fc/with-field :transaction-rule-account/percentage
(com/data-grid-cell
{}
(com/validated-field
{:errors (fc/field-errors)}
(println "FIELD VALUE IS" (fc/field-value) (some-> (fc/field-value)
(* 100 )
(long )))
(com/money-input {:name (fc/field-name)
:class "w-16"
:value (some-> (fc/field-value)
@@ -477,7 +474,7 @@
:hx-vals (format "js:{name: '%s', 'client-id': event.detail.clientId}" (fc/field-name))
:x-init "$watch('clientId', cid => $dispatch('changed', $data))"}]
(bank-account-typeahead* {:client-id ((some-fn :db/id identity) (:transaction-rule/client form-params))
(bank-account-typeahead* {:client-id (:transaction-rule/client form-params)
:name (fc/field-name)
:value (fc/field-value)})]))
@@ -534,17 +531,18 @@
(fc/with-field :transaction-rule/accounts
(com/validated-field
{:errors (fc/field-errors)}
(com/data-grid {:headers [(com/data-grid-header {} "Account")
(com/data-grid-header {:class "w-32"} "Location")
(com/data-grid-header {:class "w-16"} "%")
(com/data-grid-header {:class "w-16"})]}
(fc/cursor-map #(transaction-rule-account-row* form-params %))
(com/data-grid-new-row {:colspan 4
:hx-get (bidi/path-for ssr-routes/only-routes
:admin-transaction-rule-new-account)
:index (count (fc/field-value))
:tr-params (hx/bind-alpine-vals {} {:client-id "clientId"})}
"New account"))))
(let [client-locations (some->> form-params :transaction-rule/client (pull-attr (dc/db conn) :client/locations))]
(com/data-grid {:headers [(com/data-grid-header {} "Account")
(com/data-grid-header {:class "w-32"} "Location")
(com/data-grid-header {:class "w-16"} "%")
(com/data-grid-header {:class "w-16"})]}
(fc/cursor-map #(transaction-rule-account-row* % (:transaction-rule/client form-params) client-locations))
(com/data-grid-new-row {:colspan 4
:hx-get (bidi/path-for ssr-routes/only-routes
:admin-transaction-rule-new-account)
:index (count (fc/field-value))
:tr-params (hx/bind-alpine-vals {} {:client-id "clientId"})}
"New account")))))
(fc/with-field :transaction-rule/transaction-approval-status
(com/validated-field {:label "Approval status"
@@ -570,13 +568,9 @@
:new? true}
[]
(transaction-rule-account-row*
;; TODO store a pointer to the "head " cursor for errors instead of nesting them
;; makes it so you don't have to do this
{:transaction-rule/client (dc/pull (dc/db conn) '[:client/name :client/locations :db/id]
client-id)}
fc/*current*))))
fc/*current*
client-id
(some->> client-id (pull-attr (dc/db conn) :client/locations) client-id)))))
;; TODO check to see if it should be called "Shared" or "shared" for the value
@@ -591,15 +585,10 @@
(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
{:account/client-overrides [:db/id
:account-client-override/name
{:account-client-override/client [:db/id :client/name]}]}]))
client-id client-id]
(html-response (account-typeahead* {:name name
:value account
:client-id client-id
:x-model "accountId"}))))
(html-response (account-typeahead* {:name name
:value value
:client-id client-id
:x-model "accountId"})))
(def form-schema (mc/schema
[:map