started work on simplifying invoice page
This commit is contained in:
@@ -21,7 +21,10 @@
|
||||
[goog.string :as gstring]
|
||||
[vimsical.re-frame.cofx.inject :as inject]
|
||||
[re-frame.core :as re-frame]
|
||||
[reagent.core :as r]))
|
||||
[reagent.core :as r]
|
||||
[auto-ap.status :as status]
|
||||
[vimsical.re-frame.fx.track :as track]
|
||||
[auto-ap.utils :refer [merge-by]]))
|
||||
|
||||
(defn does-amount-exceed-outstanding? [amount outstanding-balance]
|
||||
(let [amount (js/parseFloat amount)
|
||||
@@ -71,25 +74,16 @@
|
||||
(fn [db]
|
||||
(-> db ::check-results)))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::last-params
|
||||
(fn [db]
|
||||
(-> db ::last-params)))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::params
|
||||
:<- [::last-params]
|
||||
:<- [::subs/client]
|
||||
:<- [::side-bar/filter-params]
|
||||
:<- [::table/table-params]
|
||||
(fn [[last-params client filter-params table-params]]
|
||||
(let [params (cond-> {:import-status "imported"}
|
||||
client (assoc :client-id (:id client))
|
||||
(seq filter-params) (merge filter-params)
|
||||
(seq table-params) (merge table-params))]
|
||||
(when (not= params last-params)
|
||||
(re-frame/dispatch [::params-change]))
|
||||
params)))
|
||||
(fn [[client filter-params table-params]]
|
||||
(cond-> {:import-status "imported"}
|
||||
client (assoc :client-id (:id client))
|
||||
(seq filter-params) (merge filter-params)
|
||||
(seq table-params) (merge table-params))))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::invoice-updated
|
||||
@@ -101,12 +95,10 @@
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::params-change
|
||||
[with-user (re-frame/inject-cofx ::inject/sub [::params])]
|
||||
(fn [{::keys [params] :as cofx} _]
|
||||
{:db (-> (:db cofx)
|
||||
(assoc-in [:status :loading] true)
|
||||
(assoc-in [::last-params] params))
|
||||
:graphql {:token (-> cofx :db :user)
|
||||
[with-user]
|
||||
(fn [{:keys [user]} [_ params]]
|
||||
{:graphql {:token user
|
||||
:owns-state {:single ::page}
|
||||
:query-obj (table/query params )
|
||||
:on-success [::received]
|
||||
:on-error [::events/page-failed]}
|
||||
@@ -118,7 +110,20 @@
|
||||
(re-frame/reg-event-fx
|
||||
::unmounted
|
||||
(fn [{:keys [db]} _]
|
||||
{:db (dissoc db ::invoice-page ::table/table-params ::side-bar/filters ::side-bar/settled-filters ::last-params)}))
|
||||
{:db (dissoc db ::invoice-page ::table/table-params ::side-bar/filters ::side-bar/settled-filters ::last-params)
|
||||
:forward-events {:unregister ::updated}
|
||||
::track/dispose {:id ::params}}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::mounted
|
||||
(fn [{:keys [db]} _]
|
||||
{::track/register {:id ::params
|
||||
:subscription [::params]
|
||||
:event-fn (fn [params]
|
||||
[::params-change params])}
|
||||
:forward-events {:register ::updated
|
||||
:events #{::table/invoice-updated}
|
||||
:dispatch-to [::invoice-updated]}}))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::received
|
||||
@@ -310,32 +315,6 @@
|
||||
:location (first (:locations @(re-frame/subscribe [::subs/client])))}]}))
|
||||
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::unvoid-invoice
|
||||
(fn [{:keys [db]} [_ {id :id}]]
|
||||
{:graphql
|
||||
{:token (-> db :user)
|
||||
:query-obj {:venia/operation {:operation/type :mutation
|
||||
:operation/name "UnvoidInvoice"}
|
||||
|
||||
:venia/queries [{:query/data [:unvoid-invoice
|
||||
{:invoice-id id}
|
||||
invoice-read]}]}
|
||||
:on-success [::invoice-unvoided]}}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::void-invoice
|
||||
(fn [{:keys [db]} [_ {id :id}]]
|
||||
{:graphql
|
||||
{:token (-> db :user)
|
||||
:query-obj {:venia/operation {:operation/type :mutation
|
||||
:operation/name "VoidInvoice"}
|
||||
|
||||
:venia/queries [{:query/data [:void-invoice
|
||||
{:invoice-id id}
|
||||
invoice-read]}]}
|
||||
:on-success [::invoice-voided]}}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::handwrite-checks-save
|
||||
(fn [{:keys [db]} _]
|
||||
@@ -380,27 +359,12 @@
|
||||
(dissoc ::handwrite-checks))})))
|
||||
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::invoice-unvoided
|
||||
(fn [{:keys [db]} [_ {:keys [unvoid-invoice]}]]
|
||||
{:db (-> db
|
||||
(update-in [::invoice-page :invoices]
|
||||
(fn [is]
|
||||
(mapv (fn [i]
|
||||
(if (= (:id i) (:id unvoid-invoice))
|
||||
(assoc unvoid-invoice :class "live-removed")
|
||||
i)) is))))}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::invoice-voided
|
||||
(fn [{:keys [db]} [_ {:keys [void-invoice]}]]
|
||||
{:db (-> db
|
||||
(update-in [::invoice-page :invoices]
|
||||
(fn [is]
|
||||
(mapv (fn [i]
|
||||
(if (= (:id i) (:id void-invoice))
|
||||
(assoc void-invoice :class "live-removed")
|
||||
i)) is))))}))
|
||||
::invoice-updated
|
||||
[(re-frame/path [::invoice-page :invoices])]
|
||||
(fn [{:keys [db]} [_ [_ invoice]]]
|
||||
{:db (merge-by db :id invoice)}))
|
||||
|
||||
|
||||
|
||||
@@ -642,13 +606,8 @@
|
||||
[pay-button {:print-checks-shown? print-checks-shown? :checked-invoices checked :print-checks-loading? print-checks-loading?}])
|
||||
[table/invoice-table {:id :unpaid
|
||||
:invoice-page (re-frame/subscribe [::invoice-page])
|
||||
:status (re-frame/subscribe [::subs/status])
|
||||
:on-edit-invoice (fn [which]
|
||||
(re-frame/dispatch [::form/editing which]))
|
||||
:on-unvoid-invoice (fn [which]
|
||||
(re-frame/dispatch [::unvoid-invoice which]))
|
||||
:on-void-invoice (fn [which]
|
||||
(re-frame/dispatch [::void-invoice which]))
|
||||
:status @(re-frame/subscribe [::status/single ::page])
|
||||
|
||||
:check-boxes (= status :unpaid)
|
||||
:checked checked
|
||||
:on-check-changed (fn [which invoice]
|
||||
@@ -659,6 +618,7 @@
|
||||
(r/create-class
|
||||
{:display-name "invoices-page"
|
||||
:component-will-unmount #(re-frame/dispatch [::unmounted])
|
||||
:component-did-mount #(re-frame/dispatch [::mounted])
|
||||
:reagent-render
|
||||
(fn []
|
||||
(let [{invoice-bar-active? :active?} @(re-frame/subscribe [::forms/form ::form/form])
|
||||
|
||||
Reference in New Issue
Block a user