avoids duplicate invoices atomic, prevents query that causes warnings.
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
[auto-ap.views.pages.transactions.form :as edit]
|
||||
[auto-ap.views.utils
|
||||
:refer
|
||||
[action-cell-width date->str dispatch-event dispatch-event-with-propagation nf pretty]]
|
||||
[action-cell-width date->str dispatch-event dispatch-event-with-propagation nf pretty with-role]]
|
||||
[goog.string :as gstring]
|
||||
[re-frame.core :as re-frame]
|
||||
[auto-ap.views.components.buttons :as buttons]
|
||||
@@ -32,24 +32,29 @@
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::intend-to-edit
|
||||
(fn [{:keys [db]} [_ which]]
|
||||
[with-role]
|
||||
(fn [{:keys [db role]} [_ which]]
|
||||
{:graphql
|
||||
{:token (-> db :user)
|
||||
:owns-state {:multi ::edits
|
||||
:which (:id which)}
|
||||
:query-obj {:venia/queries (into [{:query/data [:potential-payment-matches
|
||||
{:transaction_id (:id which)}
|
||||
[:id :memo :check-number [:vendor [:name]]]]}
|
||||
{:query/data [:potential-autopay-invoices-matches
|
||||
{:transaction_id (:id which)}
|
||||
[:id :invoice-number :total :date :scheduled-payment [:vendor [:name]]]]}
|
||||
{:query/data [:potential-unpaid-invoices-matches
|
||||
{:transaction_id (:id which)}
|
||||
[:id :invoice-number :total :date :scheduled-payment [:vendor [:name]]]]}]
|
||||
(when @(re-frame/subscribe [::subs/is-admin?])
|
||||
[{:query/data [:potential-transaction-rule-matches
|
||||
{:transaction_id (:id which)}
|
||||
[:id :note]]}]))}
|
||||
:query-obj {:venia/queries
|
||||
(cond-> [{:query/data [:potential-payment-matches
|
||||
{:transaction_id (:id which)}
|
||||
[:id :memo :check-number [:vendor [:name]]]]}]
|
||||
(or (= "admin" role)
|
||||
(= "power-user" role))
|
||||
|
||||
(into [{:query/data [:potential-autopay-invoices-matches
|
||||
{:transaction_id (:id which)}
|
||||
[:id :invoice-number :total :date :scheduled-payment [:vendor [:name]]]]}
|
||||
{:query/data [:potential-unpaid-invoices-matches
|
||||
{:transaction_id (:id which)}
|
||||
[:id :invoice-number :total :date :scheduled-payment [:vendor [:name]]]]}])
|
||||
(= "admin" role)
|
||||
(into [{:query/data [:potential-transaction-rule-matches
|
||||
{:transaction_id (:id which)}
|
||||
[:id :note]]}]))}
|
||||
:on-success [::editing-matches-found which]
|
||||
:on-error [::editing-matches-failed which]}}))
|
||||
|
||||
|
||||
@@ -466,6 +466,19 @@
|
||||
(-> context
|
||||
(assoc-in [:coeffects :user] (get-in context [:coeffects :db :user]))))))
|
||||
|
||||
(def with-role
|
||||
(re-frame/->interceptor
|
||||
:id :with-role
|
||||
:before (fn [context]
|
||||
(-> context
|
||||
(assoc-in [:coeffects :role] (-> (get-in context [:coeffects :db :user])
|
||||
(str/split #"\.")
|
||||
second
|
||||
(base64/decodeString )
|
||||
(#(.parse js/JSON % ))
|
||||
(js->clj :keywordize-keys true)
|
||||
:user/role))))))
|
||||
|
||||
(def with-is-admin?
|
||||
(re-frame/->interceptor
|
||||
:id :with-is-admin?
|
||||
|
||||
Reference in New Issue
Block a user