more standardization

This commit is contained in:
Bryce Covert
2020-08-17 10:58:05 -07:00
parent 85a110d878
commit 8036d34a4e
12 changed files with 252 additions and 255 deletions

View File

@@ -6,11 +6,10 @@
[auto-ap.subs :as subs]
[auto-ap.utils :refer [by merge-by replace-if]]
[auto-ap.views.components.dropdown :refer [drop-down]]
[auto-ap.effects.forward :as forward]
[auto-ap.views.components.expense-accounts-dialog
:as
expense-accounts-dialog
:refer
[change-expense-accounts-modal]]
expense-accounts-dialog]
[auto-ap.views.components.invoice-table :as table]
[auto-ap.views.components.invoices.side-bar
:as
@@ -36,10 +35,8 @@
[reagent.core :as r]
[vimsical.re-frame.fx.track :as track]))
(re-frame/reg-sub
::change-expense-accounts
(fn [db]
(-> db ::change-expense-accounts)))
;; TODO: Sort out approaches for which buttons to show
;; TODO: make it so filters are basically free
(re-frame/reg-sub
::params
@@ -77,8 +74,8 @@
(fn [{:keys [db]} _]
{:db (dissoc db ::table/table-params ::side-bar/filters ::side-bar/settled-filters ::last-params)
:dispatch [::data-page/dispose :invoices]
:forward-events [{:unregister ::updated}
{:unregister ::checks-printed}]
::forward/dispose [{:id ::updated}
{:id ::checks-printed}]
::track/dispose [{:id ::params}]}))
(re-frame/reg-event-fx
@@ -88,12 +85,14 @@
:subscription [::params]
:event-fn (fn [params]
[::params-change params])}]
:forward-events [{:register ::updated
:events #{::table/invoice-updated ::form/updated}
:dispatch-to [::data-page/entity-updated :invoices]}
{:register ::checks-printed
:events #{::form/checks-printed ::advanced-print-checks/checks-printed ::handwritten-checks/succeeded}
:dispatch-to [::checks-printed]}]}))
::forward/register [{:id ::updated
:events #{::table/invoice-updated ::form/updated ::expense-accounts-dialog/updated}
:event-fn (fn [[_ invoice]]
[::data-page/updated-entity :invoices invoice])}
{:id ::checks-printed
:events #{::form/checks-printed ::advanced-print-checks/checks-printed ::handwritten-checks/succeeded}
:event-fn (fn [[_ invoices pdf-url]]
[::checks-printed invoices pdf-url])}]}))
(re-frame/reg-sub
@@ -104,7 +103,6 @@
(filter (comp #(get checked %) :id) (:data data))))
(defn print-checks-query [invoice-payments bank-account-id type client-id]
{:venia/operation {:operation/type :mutation
:operation/name "PrintChecks"}
@@ -132,18 +130,19 @@
(:client db))
:on-success (fn [result]
[::checks-printed
[nil
(:invoices (:print-checks result))
(:pdf-url (:print-checks result))]])}}))
(:invoices (:print-checks result))
(:pdf-url (:print-checks result))])}}))
(re-frame/reg-event-fx
::checks-printed
(fn [{:keys [db]} [_ [_ invoices pdf-url]]]
{:dispatch-n (cond->> (mapv
(fn [i]
[::data-page/entity-updated :invoices [nil (assoc i :class "live-added")]])
invoices)
(fn [{:keys [db]} [_ invoices pdf-url]]
{:dispatch-n (cond->> [[::data-page/reset-checked :invoices]]
true (into (mapv
(fn [i]
[::data-page/updated-entity :invoices i])
invoices))
pdf-url (into [[::modal/modal-requested {:title "Your checks are ready!"
:body [:div
[:div "Click " [:a {:href pdf-url :target "_new"} "here"] " to print them."]
@@ -158,15 +157,6 @@
#_#_:date (date->str (c/now) standard)
:location (first (:locations @(re-frame/subscribe [::subs/client])))}]}))
(re-frame/reg-event-fx
::expense-accounts-updated
(fn [{:keys [db]} [_ data]]
(let [updated (:edit-expense-accounts data)]
{:dispatch-n [[::events/modal-completed ::expense-accounts-dialog/change-expense-accounts]
[::data-page/entity-updated :invoices [nil updated]]]
:db (-> db
(dissoc ::change-expense-accounts))})))
(defn pay-button []
(let [current-client @(re-frame/subscribe [::subs/client])
@@ -232,7 +222,7 @@
:check-boxes (= status :unpaid)
:on-check-changed (fn [new]
(re-frame/dispatch [::data-page/toggle-check :invoices new ]))
:expense-event [::expense-accounts-dialog/change-expense-accounts]}]]))
:actions #{:edit :void :expense-accounts}}]]))
(defn unpaid-invoices-page [params]
(r/create-class
@@ -245,6 +235,4 @@
params @(re-frame/subscribe [::params])]
[side-bar-layout {:side-bar [invoices-side-bar {}]
:main [unpaid-invoices-content params]
:bottom [:div
[change-expense-accounts-modal {:updated-event [::expense-accounts-updated]}]]
:right-side-bar [appearing-side-bar {:visible? invoice-bar-active?} [form/form {}]]}]))}))