lots of QOL improvements.

This commit is contained in:
Bryce Covert
2020-07-31 18:26:57 -07:00
parent 98f0d40313
commit be9c789003
15 changed files with 302 additions and 282 deletions

View File

@@ -7,14 +7,15 @@
[auto-ap.entities.clients :as client]
[auto-ap.views.components.layouts :refer [side-bar-layout]]
[auto-ap.views.components.invoices.side-bar :refer [invoices-side-bar]]
[auto-ap.views.utils :refer [dispatch-event bind-field]]
[auto-ap.views.utils :refer [dispatch-event bind-field with-user]]
[auto-ap.utils :refer [by]]
[auto-ap.entities.vendors :as vendor]
[auto-ap.views.components.typeahead :refer [typeahead-entity]]
[auto-ap.views.components.invoice-table :refer [invoice-table] :as invoice-table]
[cljsjs.dropzone :as dropzone]
[cljs.reader :as edn]
[clojure.string :as str]))
[clojure.string :as str]
[vimsical.re-frame.cofx.inject :as inject]))
(defn dropzone []
(let [client (re-frame/subscribe [::subs/client])
token (re-frame/subscribe [::subs/token])
@@ -75,10 +76,6 @@
(fn [db]
(-> db ::error)))
(re-frame/reg-sub
::params
(fn [db]
(-> db (::params {}))))
(re-frame/reg-sub
::batch
@@ -98,16 +95,36 @@
: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)))
(re-frame/reg-event-fx
::params-change
(fn [cofx [_ params]]
[with-user (re-frame/inject-cofx ::inject/sub [::params])]
(fn [{:keys [db user] ::keys [params]} [_]]
{:db (-> (:db cofx)
{:db (-> db
(dissoc ::error)
(assoc-in [:status :loading] true)
(assoc-in [::params] params))
:graphql {:token (-> cofx :db :user)
:query-obj (invoice-table/query (assoc params :import-status "pending"))
(assoc-in [::last-params] params))
:graphql {:token user
:query-obj (invoice-table/query params)
:on-success [::received]}}))
(re-frame/reg-event-db
@@ -210,6 +227,7 @@
status (re-frame/subscribe [::subs/status])
error (re-frame/subscribe [::error])
batch (re-frame/subscribe [::batch])
params @(re-frame/subscribe [::params])
client (:id @(re-frame/subscribe [::subs/client]))]
^{:key (str client "-" @batch)}
[:div
@@ -227,24 +245,18 @@
[:span {:class "card-header-title"} "Found Invoices"]]
[:div {:class "card-content"}
[approve-reject-button (:checked @invoice-page)]
(if (:loading @status)
[:h1.title
[:i.fa.fa-spin.fa-spinner]]
(if (seq (:invoices @invoice-page))
[invoice-table {:id :approved
:invoice-page invoice-page
:overrides {:client (fn [row]
[:p (:name (:client row))
[:p [:i.is-size-7 (:client-identifier row)]]])}
:check-boxes true
:checked (:checked @invoice-page)
:on-check-changed (fn [which invoice]
(re-frame/dispatch [::toggle-check which invoice]))
:status (re-frame/subscribe [::subs/status])
:params (re-frame/subscribe [::params])
:on-params-change (fn [params]
(re-frame/dispatch [::params-change params])) }]
[:span "No pending invoices"]))]]]))
(if (seq (:invoices @invoice-page))
[invoice-table {:id :approved
:invoice-page invoice-page
:overrides {:client (fn [row]
[:p (:name (:client row))
[:p [:i.is-size-7 (:client-identifier row)]]])}
:check-boxes true
:checked (:checked @invoice-page)
:on-check-changed (fn [which invoice]
(re-frame/dispatch [::toggle-check which invoice]))
:status (re-frame/subscribe [::subs/status])}]
[:span "No pending invoices"])]]]))
{:component-will-mount (fn []
(re-frame/dispatch-sync [::invalidated]))}))