Supports vendors not loading
This commit is contained in:
@@ -13,20 +13,6 @@
|
||||
(defn jwt->data [token]
|
||||
(js->clj (.parse js/JSON (b64/decodeString (second (str/split token #"\." ))))))
|
||||
|
||||
(def vendor-query
|
||||
[:id :name :hidden :terms [:default-account [:name :id :location]]
|
||||
[:account-overrides [[:client [:id :name]] :id [:account [:id :numeric-code :name]]]]
|
||||
[:automatically-paid-when-due [:id :name]]
|
||||
[:terms-overrides [[:client [:id :name]] :id :terms]]
|
||||
[:schedule-payment-dom [[:client [:id :name]] :id :dom]]
|
||||
[:usage [:client-id :count]]
|
||||
[:primary-contact [:name :phone :email :id]]
|
||||
[:secondary-contact [:id :name :phone :email]]
|
||||
:print-as :invoice-reminder-schedule :code
|
||||
:legal-entity-first-name :legal-entity-middle-name :legal-entity-last-name
|
||||
:legal-entity-tin :legal-entity-tin-type
|
||||
:legal-entity-1099-type
|
||||
[:address [:street1 :street2 :city :state :zip]]])
|
||||
|
||||
(defn client-query [token]
|
||||
(cond-> [:id :name :signature-file :code :email :matches :week-a-debits :week-a-credits :week-b-debits :week-b-credits :locations :locked-until :square-auth-token
|
||||
@@ -45,7 +31,7 @@
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::initialize-db
|
||||
(fn [{:keys [db]} [_ token]]
|
||||
(fn [{:keys [_]} [_ token]]
|
||||
(let [handler (:handler (bidi/match-route routes/routes (.. js/window -location -pathname)))]
|
||||
(cond
|
||||
(= :login handler)
|
||||
@@ -79,8 +65,7 @@
|
||||
:query-obj {:venia/queries [[:client
|
||||
|
||||
(client-query token)]
|
||||
[:vendor
|
||||
vendor-query]
|
||||
|
||||
[:accounts [:numeric-code :location :name :type :account_set :applicability :id [:client-overrides [:name :id [:client [:name :id]]]]]]]}
|
||||
:on-success [::received-initial]
|
||||
:on-error [::failed-initial]}}))))
|
||||
@@ -97,8 +82,7 @@
|
||||
{:graphql {:token token
|
||||
:query-obj {:venia/queries [[:client
|
||||
(client-query token)]
|
||||
[:vendor
|
||||
vendor-query]
|
||||
|
||||
[:accounts [:numeric-code :name :location :type :account_set :applicability :id [:client-overrides [:name [:client [:name :id]]]]]]]}
|
||||
|
||||
:on-success [::received-initial]
|
||||
@@ -109,11 +93,10 @@
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::received-initial
|
||||
(fn [{:keys [db]} [_ {accounts :accounts clients :client vendors :vendor :as x}]]
|
||||
(fn [{:keys [db]} [_ {accounts :accounts clients :client}]]
|
||||
|
||||
{:db (-> db
|
||||
(assoc :clients (by :id clients) )
|
||||
(assoc :vendors (by :id vendors) )
|
||||
(assoc :is-initial-loading? false)
|
||||
(assoc :accounts accounts )
|
||||
(assoc :client (or (when (= 1 (count clients)) (->> clients first :id ))
|
||||
@@ -178,36 +161,6 @@
|
||||
:auto-ap.forms/forms nil)
|
||||
(auto-ap.views.pages.data-page/dispose-all))})))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::imported-invoices
|
||||
(fn [db [_ new-invoices]]
|
||||
(assoc-in db [:invoices :pending] new-invoices)))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::view-pending-invoices
|
||||
(fn [cofx []]
|
||||
{:db (assoc-in (:db cofx) [:status :loading] true)
|
||||
:graphql {:token (-> cofx :db :user)
|
||||
:query-obj {:venia/queries [[:invoice
|
||||
{:imported false :client_id (:id @(re-frame/subscribe [::subs/client]))}
|
||||
[:id :total :invoice-number :date [:vendor [:name :id]] [:client [:name :id]]]]]}
|
||||
|
||||
:on-success [::received-invoices :pending]}}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::view-unpaid-invoices
|
||||
(fn [cofx []]
|
||||
{:db (assoc-in (:db cofx) [:status :loading] true)
|
||||
:graphql {:token (-> cofx :db :user)
|
||||
:query-obj {:venia/queries [[:invoice
|
||||
{:imported true :client_id (:id @(re-frame/subscribe [::subs/client]))}
|
||||
[:id :total :invoice-number :date [:vendor [:name :id]] [:client [:name :id]]]]]}
|
||||
:on-success [::received-invoices :unpaid]}}))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::submitted-new-invoice
|
||||
(fn [db [_ invoice]]
|
||||
(assoc db :new-invoice {})))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::logout
|
||||
@@ -218,48 +171,6 @@
|
||||
:redirect (bidi/path-for routes/routes :login)
|
||||
:set-local-storage ["jwt" nil]}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::submit-new-invoice
|
||||
(fn [{:keys [db]} [_ invoice]]
|
||||
{:http {:method :post
|
||||
:token (-> db :user)
|
||||
:uri "/api/invoices"
|
||||
:body (pr-str {:rows [(assoc invoice :imported true)]})
|
||||
:headers {"Content-Type" "application/edn"}
|
||||
:on-success [::submitted-new-invoice]}
|
||||
:db (assoc-in db [:new-invoice :loading?] true)}))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::received-invoices
|
||||
(fn [db [_ type result]]
|
||||
(let [new-invoices (if (:invoice result)
|
||||
(:invoice result)
|
||||
result)]
|
||||
(-> db
|
||||
(assoc-in [:invoices type] new-invoices)
|
||||
(assoc-in [:status :loading] false)))))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::change-form-state
|
||||
(fn [db [_ target value]]
|
||||
(assoc-in db target value)))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::change-nested-form-state
|
||||
(fn [db [_ form more value]]
|
||||
(update-in db form
|
||||
(fn [x]
|
||||
(assoc-in x more value)))))
|
||||
|
||||
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::page-failed
|
||||
(fn [db [_ result]]
|
||||
(println "Page failure" result)
|
||||
(assoc db :page-failure result
|
||||
:status nil)))
|
||||
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::yodlee-merchants-received
|
||||
|
||||
Reference in New Issue
Block a user