Accounts don't need to be loaded

This commit is contained in:
2022-04-19 13:27:47 -07:00
parent f73b406abd
commit f51f3450d6
22 changed files with 398 additions and 420 deletions

View File

@@ -32,78 +32,6 @@
(fn [db]
(by :id (:accounts db))))
(defn clientize-account [account client]
(let [override (->>
(:client-overrides account)
(filter (fn [co]
(= (:id (:client co)) (:id client))))
first)]
(condp = (:applicability account)
nil
(assoc account :name (or (:name override) (:name account)))
:global
(assoc account :name (or (:name override) (:name account)))
:optional
(when override
(assoc account :name (or (:name override) (:name account))))
:customized
(when override
(assoc account :name (or (:name override) (:name account)))))))
(re-frame/reg-sub
::accounts
:<- [::all-accounts]
:<- [::client]
(fn [[accounts client] [_ client-override]]
(transduce
(comp
(map
#(clientize-account % (or client-override client)))
(filter identity))
conj
[]
accounts)))
(re-frame/reg-sub
::accounts-index
:<- [::accounts]
(fn [accounts]
(doto (MiniSearch. #js {:fields #js ["numeric-code" "name" "content"]
:storeFields #js ["id" "numeric-code" "name" "content"]})
(.addAll (clj->js (map (fn [v] {:id (:id v)
:name (:name v)
:numeric-code (:numeric-code v)
:content (str (:numeric-code v) " " (:name v))})
accounts))))))
(re-frame/reg-sub
::account
(fn [[_ client]]
[(re-frame/subscribe [::accounts-by-id client])])
(fn [[as] [_ _ i]]
(as i)))
(defn accounts-by-id [accounts client]
(by :id
(map
#(clientize-account % client)
accounts)))
(re-frame/reg-sub
::accounts-by-id
(fn [[_ client-override]]
[(re-frame/subscribe [::accounts client-override])
(re-frame/subscribe [::client])])
(fn [[accounts client] ]
(accounts-by-id accounts client)))
(re-frame/reg-sub
::bank-accounts
:<- [::clients]
@@ -181,15 +109,6 @@
(fn [db]
(::intuit-bank-accounts db)))
(re-frame/reg-sub
::modal-state
(fn [db [_ id status-from]]
(if status-from
(assoc (get (:modal-state db) id)
:error-message (get-in db [:auto-ap.forms/forms status-from :error])
:saving? (= (get-in db [:auto-ap.forms/forms status-from :status]) :loading))
(get (:modal-state db) id))))
(re-frame/reg-sub
::token
(fn [db]
@@ -224,22 +143,6 @@
(fn [db]
(:active-page db)))
(re-frame/reg-sub
::pending-invoices
(fn [db]
(:pending (:invoices db))))
(re-frame/reg-sub
::status
(fn [db]
(:status db)))
(re-frame/reg-sub
::new-invoice-form
(fn [db]
(:new-invoice db)))
(re-frame/reg-sub
::query-params
(fn [db]