From 31e56a387b4af16973fd89438361c1aa7deed84c Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Sat, 8 Aug 2020 11:54:34 -0700 Subject: [PATCH] moved payments to new table format. --- src/cljs/auto_ap/views/pages/payments.cljs | 45 +++++++------------ .../auto_ap/views/pages/payments/table.cljs | 34 +++++++++++--- 2 files changed, 45 insertions(+), 34 deletions(-) diff --git a/src/cljs/auto_ap/views/pages/payments.cljs b/src/cljs/auto_ap/views/pages/payments.cljs index 1179e34f..ef856ce1 100644 --- a/src/cljs/auto_ap/views/pages/payments.cljs +++ b/src/cljs/auto_ap/views/pages/payments.cljs @@ -60,30 +60,6 @@ :on-success [::received]} :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 ::received (fn [db [_ data]] @@ -95,14 +71,28 @@ ::unmounted (fn [{:keys [db]} _] {: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 ::mounted (fn [{:keys [db]} _] {::track/register {:id ::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 [] (let [params @(re-frame/subscribe [::params])] @@ -110,8 +100,7 @@ [:h1.title "Payments"] [table/table {:id :payments :payment-page @(re-frame/subscribe [::payment-page]) - :status @(re-frame/subscribe [::status/single ::page]) - :void-event [::void-check]}]])) + :status @(re-frame/subscribe [::status/single ::page])}]])) (defn payments-page [] (reagent/create-class diff --git a/src/cljs/auto_ap/views/pages/payments/table.cljs b/src/cljs/auto_ap/views/pages/payments/table.cljs index 931cd119..939c1661 100644 --- a/src/cljs/auto_ap/views/pages/payments/table.cljs +++ b/src/cljs/auto_ap/views/pages/payments/table.cljs @@ -13,7 +13,8 @@ [goog.string :as gstring] [re-frame.core :as re-frame] [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 ::specific-table-params @@ -33,9 +34,29 @@ (fn [{table-params :db} [_ params :as z]] {: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 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] [grid/row {:class (:class check)} @@ -77,11 +98,12 @@ (when (or (= :pending status) (and (#{":cash" :cash ":debit" :debit} type) (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]) - percentage-size (if selected-client "50%" "33%")] + states @(re-frame/subscribe [::status/multi ::void])] [grid/grid {:on-params-change (fn [e] (re-frame/dispatch [::params-changed e])) :params @(re-frame/subscribe [::table-params]) @@ -105,4 +127,4 @@ ^{:key (:id check)} [row {:check check :selected-client selected-client - :void-event void-event}])]]])) + :states states}])]]]))