Streamlining invoices

This commit is contained in:
Bryce Covert
2020-08-10 14:13:19 -07:00
parent 9dede12b61
commit 5bc0e957ef
13 changed files with 185 additions and 67 deletions

View File

@@ -15,7 +15,9 @@
[cljsjs.dropzone :as dropzone]
[cljs.reader :as edn]
[clojure.string :as str]
[vimsical.re-frame.cofx.inject :as inject]))
[vimsical.re-frame.cofx.inject :as inject]
[auto-ap.status :as status]
[vimsical.re-frame.fx.track :as track]))
(defn dropzone []
(let [client (re-frame/subscribe [::subs/client])
token (re-frame/subscribe [::subs/token])
@@ -23,7 +25,6 @@
(reagent/create-class
{:display-name "dropzone"
:component-did-mount (fn [this]
(println "HERE?")
(js/Dropzone. (rdom/dom-node this)
(clj->js {:init (fn []
(.on (js-this) "success" (fn [_ files]
@@ -87,6 +88,19 @@
(fn [cofx [_ params]]
{:dispatch [::params-change @(re-frame/subscribe [::params])]}))
(re-frame/reg-event-fx
::mounted
(fn [cofx [_ params]]
{::track/register {:id ::params
:subscription [::params]
:event-fn (fn [params]
[::params-change params])}}))
(re-frame/reg-event-fx
::unmounted
(fn [cofx [_ params]]
{::track/dispose {:id ::params}}))
(re-frame/reg-event-fx
::completed
(fn [cofx [_ params]]
@@ -95,35 +109,24 @@
:db (-> (:db cofx)
(update ::batch inc))}))
(re-frame/reg-sub
::last-params
(fn [db]
(-> db ::last-params)))
(re-frame/reg-sub
::params
:<- [::last-params]
:<- [::subs/client]
:<- [::invoice-table/table-params]
(fn [[last-params client table-params]]
(println "RE-EVALUATING")
(let [params (cond-> {:import-status "pending"}
client (assoc :client-id (:id client))
(seq table-params) (merge table-params))]
(when (not= params last-params)
(re-frame/dispatch [::params-change]))
params)))
(fn [[client table-params]]
(cond-> {:import-status "pending"}
client (assoc :client-id (:id client))
(seq table-params) (merge table-params))))
(re-frame/reg-event-fx
::params-change
[with-user (re-frame/inject-cofx ::inject/sub [::params])]
(fn [{:keys [db user] ::keys [params]} [_]]
{:db (-> db
(dissoc ::error)
(assoc-in [:status :loading] true)
(assoc-in [::last-params] params))
(dissoc ::error))
:graphql {:token user
:owns-state {:single ::page}
:query-obj (invoice-table/query params)
:on-success [::received]}}))
@@ -147,6 +150,7 @@
(fn [{:keys [db]} [_ invoices on-success]]
{:graphql
{:token (-> db :user)
:owns-state {:single ::reject}
:query-obj {:venia/operation {:operation/type :mutation
:operation/name "RejectInvoices"}
@@ -161,6 +165,7 @@
(fn [{:keys [db]} [_ invoices on-success]]
{:graphql
{:token (-> db :user)
:owns-state {:single ::approve}
:query-obj {:venia/operation {:operation/type :mutation
:operation/name "ApproveInvoices"}
@@ -195,6 +200,7 @@
[:div.is-pulled-right
[:button.button.is-success {:on-click (dispatch-event [::approve-invoices-clicked checked])
:class (status/class-for @(re-frame/subscribe [::status/single ::approve]))
:disabled (if (seq checked)
""
"disabled")}
@@ -207,6 +213,7 @@
[:span " "]]
[:button.button.is-danger {:on-click (dispatch-event [::reject-invoices-clicked checked])
:class (status/class-for @(re-frame/subscribe [::status/single ::reject]))
:disabled (if (seq checked)
""
"disabled")}
@@ -247,7 +254,7 @@
[approve-reject-button (:checked @invoice-page)]
(if (seq (:invoices @invoice-page))
[invoice-table {:id :approved
:invoice-page invoice-page
:invoice-page @invoice-page
:overrides {:client (fn [row]
[:p (:name (:client row))
[:p [:i.is-size-7 (:client-identifier row)]]])}
@@ -255,10 +262,12 @@
:checked (:checked @invoice-page)
:on-check-changed (fn [which invoice]
(re-frame/dispatch [::toggle-check which invoice]))
:status (re-frame/subscribe [::subs/status])}]
:status @(re-frame/subscribe [::status/single ::page])}]
[:span "No pending invoices"])]]]))
{:component-will-mount (fn []
(re-frame/dispatch-sync [::invalidated]))}))
{:component-did-mount (fn []
(re-frame/dispatch-sync [::mounted]))
:component-will-unmount (fn []
(re-frame/dispatch-sync [::unmounted]))}))
(defn import-invoices-page []
[side-bar-layout {:side-bar [invoices-side-bar {}]

View File

@@ -605,7 +605,7 @@
(when (= status :unpaid)
[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])
:invoice-page @(re-frame/subscribe [::invoice-page])
:status @(re-frame/subscribe [::status/single ::page])
:check-boxes (= status :unpaid)