more standardization
This commit is contained in:
@@ -11,11 +11,11 @@
|
||||
[auto-ap.views.utils :refer [dispatch-event with-user]]
|
||||
[vimsical.re-frame.cofx.inject :as inject]
|
||||
[vimsical.re-frame.fx.track :as track]
|
||||
[day8.re-frame.forward-events-fx]
|
||||
[auto-ap.events :as events]
|
||||
[auto-ap.utils :refer [replace-by merge-by]]
|
||||
[re-frame.core :as re-frame]
|
||||
[auto-ap.status :as status]))
|
||||
[auto-ap.status :as status]
|
||||
[auto-ap.effects.forward :as forward]))
|
||||
|
||||
;; SUBS
|
||||
|
||||
@@ -91,16 +91,17 @@
|
||||
(re-frame/reg-event-db
|
||||
::deleted-transaction-rule
|
||||
[(re-frame/path [::page :transaction-rules])]
|
||||
(fn [transaction-rules [_ [_ {id :delete-transaction-rule}]]]
|
||||
(fn [transaction-rules [_ {id :delete-transaction-rule}]]
|
||||
(merge-by transaction-rules :id {:id id :class "live-removed"})))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::mounted
|
||||
(fn [{:keys [db]}]
|
||||
{:dispatch-n [[::events/yodlee-merchants-needed]]
|
||||
:forward-events {:register ::page
|
||||
:events #{::table/deleted-transaction-rule}
|
||||
:dispatch-to [::deleted-transaction-rule]}
|
||||
::forward/register {:id ::page
|
||||
:events #{::table/deleted-transaction-rule}
|
||||
:event-fn (fn [[_ result]]
|
||||
[::deleted-transaction-rule result])}
|
||||
::track/register {:id ::params
|
||||
:subscription [::params]
|
||||
:event-fn (fn [params] [::params-change params])}}))
|
||||
@@ -108,7 +109,7 @@
|
||||
(re-frame/reg-event-fx
|
||||
::unmounted
|
||||
(fn [{:keys [db]}]
|
||||
{:forward-events {:unregister ::page}
|
||||
{::forward/dispose {:id ::page}
|
||||
::track/dispose {:id ::params}}))
|
||||
|
||||
;; VIEWS
|
||||
|
||||
@@ -17,7 +17,8 @@
|
||||
[auto-ap.routes :as routes]
|
||||
[bidi.bidi :as bidi]
|
||||
[auto-ap.status :as status]
|
||||
[auto-ap.views.pages.admin.users.form :as form]))
|
||||
[auto-ap.views.pages.admin.users.form :as form]
|
||||
[auto-ap.effects.forward :as forward]))
|
||||
|
||||
|
||||
|
||||
@@ -56,19 +57,20 @@
|
||||
:role
|
||||
[:clients [:id :name]]]]]}
|
||||
:on-success [::received]}
|
||||
:forward-events {:register ::edited-user
|
||||
:events #{::form/saved}
|
||||
:dispatch-to [::saved]}}))
|
||||
::forward/register {:id ::edited-user
|
||||
:events #{::form/saved}
|
||||
:event-fn (fn [[_ query-result]]
|
||||
[::saved query-result])}}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::unmounted
|
||||
(fn [{:keys [db]} _]
|
||||
{:forward-events {:unregister ::edited-user}}))
|
||||
{::forward/dispose {:id ::edited-user}}))
|
||||
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::saved
|
||||
(fn [db [_ [_ query-result]]]
|
||||
(fn [db [_ query-result]]
|
||||
(-> db
|
||||
(update ::users
|
||||
replace-by
|
||||
|
||||
@@ -22,12 +22,18 @@
|
||||
(let [checked (or checked #{})]
|
||||
(disj checked to-remove))))))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::reset-checked
|
||||
(fn [db [_ id]]
|
||||
|
||||
(update db ::checked dissoc id)))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::updated-entity
|
||||
(fn [db [_ id entity]]
|
||||
(update-in db
|
||||
[::data id]
|
||||
replace-by :id (assoc entity :class "live-added"))))
|
||||
[::data id :data]
|
||||
replace-by :id (update entity :class #(or % "live-added")))))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::received
|
||||
@@ -62,13 +68,3 @@
|
||||
(defn in-page-entities [which]
|
||||
(re-frame/path [::data which :data ] ))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::entity-updated
|
||||
(fn [db [_ which [_ entity] :as g]]
|
||||
(println g)
|
||||
(update-in db [::data which :data]
|
||||
(fn [entities]
|
||||
(let [by-id (by :id entities )]
|
||||
(if (by-id (:id entity))
|
||||
(merge-by entities :id entity)
|
||||
(into [entity] entities)))))))
|
||||
|
||||
@@ -108,11 +108,13 @@
|
||||
(re-frame/reg-event-db
|
||||
::updated
|
||||
(fn [db [_ invoice command]]
|
||||
(-> db
|
||||
(forms/stop-form ::form )
|
||||
(forms/start-form ::form {:client @(re-frame/subscribe [::subs/client])
|
||||
:status :unpaid
|
||||
:date (date->str (c/now) standard)}))))
|
||||
(if (= :create command)
|
||||
(-> db
|
||||
(forms/stop-form ::form )
|
||||
(forms/start-form ::form {:client @(re-frame/subscribe [::subs/client])
|
||||
:status :unpaid
|
||||
:date (date->str (c/now) standard)}))
|
||||
db)))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::adding
|
||||
@@ -188,27 +190,28 @@
|
||||
::saving
|
||||
[with-user (forms/in-form ::form)]
|
||||
(fn [{:keys [user] {:keys [data]} :db} _]
|
||||
(let [command (if (:id data)
|
||||
:edit
|
||||
:create)]
|
||||
{:graphql
|
||||
{:token user
|
||||
:owns-state {:single ::form}
|
||||
:query-obj (if (:id data)
|
||||
@(re-frame/subscribe [::edit-query])
|
||||
@(re-frame/subscribe [::create-query]))
|
||||
:on-success (fn [result]
|
||||
[::updated (assoc (if (:id data)
|
||||
(:edit-invoice result)
|
||||
(:add-invoice result))
|
||||
:class "live-added")])
|
||||
:on-error [::forms/save-error ::form]}})))
|
||||
{:graphql
|
||||
{:token user
|
||||
:owns-state {:single ::form}
|
||||
:query-obj (if (:id data)
|
||||
@(re-frame/subscribe [::edit-query])
|
||||
@(re-frame/subscribe [::create-query]))
|
||||
:on-success (fn [result]
|
||||
[::updated
|
||||
(assoc (if (:id data)
|
||||
(:edit-invoice result)
|
||||
(:add-invoice result))
|
||||
:class "live-added")
|
||||
(if (:id data)
|
||||
:edit
|
||||
:create)])
|
||||
:on-error [::forms/save-error ::form]}}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::added-and-printed
|
||||
(fn [{:keys [db]} [_ result]]
|
||||
(let [invoice (first (:invoices (:add-and-print-invoice result)))]
|
||||
{:dispatch-n [[::updated (assoc invoice :class "live-added")]
|
||||
{:dispatch-n [[::updated (assoc invoice :class "live-added") :create]
|
||||
[::checks-printed [invoice] (:pdf-url (:add-and-print-invoice result))]]})))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
|
||||
@@ -20,7 +20,8 @@
|
||||
[auto-ap.views.pages.check :as check]
|
||||
[auto-ap.subs :as subs]
|
||||
[auto-ap.status :as status]
|
||||
[vimsical.re-frame.fx.track :as track]))
|
||||
[vimsical.re-frame.fx.track :as track]
|
||||
[auto-ap.effects.forward :as forward]))
|
||||
|
||||
|
||||
|
||||
@@ -72,7 +73,7 @@
|
||||
(fn [{:keys [db]} _]
|
||||
{:db (dissoc db ::last-params ::table/table-params ::side-bar/filters ::side-bar/settled-filters ::payment-page)
|
||||
::track/dispose {:id ::params}
|
||||
:forward-events {:unregister ::page}}))
|
||||
::forward/dispose {:id ::page}}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::mounted
|
||||
@@ -80,14 +81,15 @@
|
||||
{::track/register {:id ::params
|
||||
:subscription [::params]
|
||||
:event-fn (fn [params] [::params-change params])}
|
||||
:forward-events {:register ::page
|
||||
:events #{::table/payment-voided}
|
||||
:dispatch-to [::payment-voided]}}))
|
||||
::forward/register {:id ::page
|
||||
:events #{::table/payment-voided}
|
||||
:event-fn (fn [[_ result]]
|
||||
[::payment-voided result])}}))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::payment-voided
|
||||
[(re-frame/path [::payment-page :payments])]
|
||||
(fn [db [_ [_ {:keys [void-payment]}]]]
|
||||
(fn [db [_ {:keys [void-payment]}]]
|
||||
(mapv (fn [c]
|
||||
(if (= (:id c) (:id void-payment))
|
||||
(assoc void-payment :class "live-removed")
|
||||
|
||||
@@ -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 {}]]}]))}))
|
||||
|
||||
Reference in New Issue
Block a user