moved payments to new table format.

This commit is contained in:
Bryce Covert
2020-08-08 11:54:34 -07:00
parent 32152ea924
commit 31e56a387b
2 changed files with 45 additions and 34 deletions

View File

@@ -60,30 +60,6 @@
:on-success [::received]} :on-success [::received]}
:set-uri-params (dissoc params :client-id)})) :set-uri-params (dissoc params :client-id)}))
(re-frame/reg-event-fx
::void-check
(fn [{:keys [db]} [_ payment]]
{:graphql
{:token (-> db :user)
:query-obj {:venia/operation {:operation/type :mutation
:operation/name "VoidPayment"}
:venia/queries [{:query/data [:void-payment
{:payment-id (:id payment)}
[:id :status [:bank-account [:name]] :amount :check_number :s3_url :date [:vendor [:name :id]] [:client [:name :id]]
[:invoices [:invoice-id]]]]}]}
:on-success [::payment-voided]}}))
(re-frame/reg-event-db
::payment-voided
(fn [db [_ {:keys [void-payment]}]]
(-> db
(update-in [::payment-page :payments] (fn [payments]
(mapv (fn [c]
(if (= (:id c) (:id void-payment))
(assoc void-payment :class "live-removed")
c))
payments))))))
(re-frame/reg-event-db (re-frame/reg-event-db
::received ::received
(fn [db [_ data]] (fn [db [_ data]]
@@ -95,14 +71,28 @@
::unmounted ::unmounted
(fn [{:keys [db]} _] (fn [{:keys [db]} _]
{:db (dissoc db ::last-params ::table/table-params ::side-bar/filters ::side-bar/settled-filters ::payment-page) {:db (dissoc db ::last-params ::table/table-params ::side-bar/filters ::side-bar/settled-filters ::payment-page)
::track/dispose {:id ::params} })) ::track/dispose {:id ::params}
:forward-events {:unregister ::page}}))
(re-frame/reg-event-fx (re-frame/reg-event-fx
::mounted ::mounted
(fn [{:keys [db]} _] (fn [{:keys [db]} _]
{::track/register {:id ::params {::track/register {:id ::params
:subscription [::params] :subscription [::params]
:event-fn (fn [params] [::params-change params])}})) :event-fn (fn [params] [::params-change params])}
:forward-events {:register ::page
:events #{::table/payment-voided}
:dispatch-to [::payment-voided]}}))
(re-frame/reg-event-db
::payment-voided
[(re-frame/path [::payment-page :payments])]
(fn [db [_ [_ {:keys [void-payment]}]]]
(mapv (fn [c]
(if (= (:id c) (:id void-payment))
(assoc void-payment :class "live-removed")
c))
db)))
(defn content [] (defn content []
(let [params @(re-frame/subscribe [::params])] (let [params @(re-frame/subscribe [::params])]
@@ -110,8 +100,7 @@
[:h1.title "Payments"] [:h1.title "Payments"]
[table/table {:id :payments [table/table {:id :payments
:payment-page @(re-frame/subscribe [::payment-page]) :payment-page @(re-frame/subscribe [::payment-page])
:status @(re-frame/subscribe [::status/single ::page]) :status @(re-frame/subscribe [::status/single ::page])}]]))
:void-event [::void-check]}]]))
(defn payments-page [] (defn payments-page []
(reagent/create-class (reagent/create-class

View File

@@ -13,7 +13,8 @@
[goog.string :as gstring] [goog.string :as gstring]
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[auto-ap.views.components.grid :as grid] [auto-ap.views.components.grid :as grid]
[auto-ap.views.components.buttons :as buttons])) [auto-ap.views.components.buttons :as buttons]
[auto-ap.status :as status]))
(re-frame/reg-sub (re-frame/reg-sub
::specific-table-params ::specific-table-params
@@ -33,9 +34,29 @@
(fn [{table-params :db} [_ params :as z]] (fn [{table-params :db} [_ params :as z]]
{:db (merge table-params params)})) {:db (merge table-params params)}))
(re-frame/reg-event-fx
::void-check
(fn [{:keys [db]} [_ payment]]
{:graphql
{:token (-> db :user)
:owns-state {:multi ::void
:which (:id payment)}
:query-obj {:venia/operation {:operation/type :mutation
:operation/name "VoidPayment"}
:venia/queries [{:query/data [:void-payment
{:payment-id (:id payment)}
[:id :status [:bank-account [:name]] :amount :check_number :s3_url :date [:vendor [:name :id]] [:client [:name :id]]
[:invoices [:invoice-id]]]]}]}
:on-success [::payment-voided]}}))
(re-frame/reg-event-db
::payment-voided
(fn [db [_ {:keys [void-payment]}]]
db))
(defn row [{check :check (defn row [{check :check
selected-client :selected-client selected-client :selected-client
void-event :void-event states :states
}] }]
(let [{:keys [client s3-url bank-account payments type check-number date amount id vendor status invoices] :as check} check] (let [{:keys [client s3-url bank-account payments type check-number date amount id vendor status invoices] :as check} check]
[grid/row {:class (:class check)} [grid/row {:class (:class check)}
@@ -77,11 +98,12 @@
(when (or (= :pending status) (when (or (= :pending status)
(and (#{":cash" :cash ":debit" :debit} type) (and (#{":cash" :cash ":debit" :debit} type)
(not= :voided status))) (not= :voided status)))
[buttons/sl-icon {:event (conj void-event check) :icon :icon-bin-2}])]]])) [buttons/sl-icon {:event [::void-check check] :icon :icon-bin-2
:class (status/class-for (get states (:id check)))}])]]]))
(defn table [{:keys [id payment-page status void-event]}] (defn table [{:keys [id payment-page status]}]
(let [selected-client @(re-frame/subscribe [::subs/client]) (let [selected-client @(re-frame/subscribe [::subs/client])
percentage-size (if selected-client "50%" "33%")] states @(re-frame/subscribe [::status/multi ::void])]
[grid/grid {:on-params-change (fn [e] [grid/grid {:on-params-change (fn [e]
(re-frame/dispatch [::params-changed e])) (re-frame/dispatch [::params-changed e]))
:params @(re-frame/subscribe [::table-params]) :params @(re-frame/subscribe [::table-params])
@@ -105,4 +127,4 @@
^{:key (:id check)} ^{:key (:id check)}
[row {:check check [row {:check check
:selected-client selected-client :selected-client selected-client
:void-event void-event}])]]])) :states states}])]]]))