added ability to remove a transaction rule.

This commit is contained in:
Bryce Covert
2020-08-03 16:54:12 -07:00
parent a22eb01008
commit d989279058
10 changed files with 185 additions and 51 deletions

View File

@@ -8,10 +8,13 @@
[auto-ap.views.components.sorter :refer [sorted-column toggle-sort-by sort-icon]]
[auto-ap.views.components.buttons :as buttons]
[auto-ap.views.components.grid :as grid]
[auto-ap.views.components.modal :refer [simple-modal]]
[auto-ap.events :as events]
[auto-ap.status :as status]
[re-frame.core :as re-frame]
[reagent.core :as reagent]
[reagent.core :as r]))
[reagent.core :as r]
[auto-ap.views.components.modal :as modal]))
(re-frame/reg-event-fx
::run-clicked
@@ -63,6 +66,39 @@
{:db (merge table-params params)}))
(re-frame/reg-event-fx
::deleted-transaction-rule
(fn []
{:dispatch [::modal/modal-closed]}))
(re-frame/reg-event-fx
::delete-transaction-rule
[with-user]
(fn [{:keys [db user]} [_ id]]
{:graphql
{:token user
:owns-state {:single ::delete-transaction-rule}
:query-obj {:venia/operation {:operation/type :mutation
:operation/name "DeleteTransactionRule"}
:venia/queries [{:query/data [:delete-transaction-rule
{:transaction-rule-id id}]}]}
:on-success [::deleted-transaction-rule]}}))
;; TODO count how many transactions
(re-frame/reg-event-fx
::request-delete
(fn [_ [_ which]]
{:dispatch [::modal/modal-requested {:title "Confirmation"
:body [:div "Are you sure you want to delete transaction rule '" (:description which) "'? Any previously transactions will remain updated, but the rule association will be lost."]
:cancel? true
:confirm {:value "Delete Transaction Rule"
:status-from [::status/single ::delete-transaction-rule]
:on-click (dispatch-event [::delete-transaction-rule (:id which)] )}
:close-event [::status/completed ::delete-transaction-rule]}]}))
(defn table* [{:keys [id rule-page on-params-change params status]}]
(let [{:keys [sort asc]} @params
{:keys [transaction-rules start end count total]} @rule-page
@@ -70,33 +106,34 @@
opc (fn [p]
(re-frame/dispatch [::params-changed p]))
states @(re-frame/subscribe [::status/multi ::run])]
[grid/grid {:on-params-change opc
:params @(re-frame/subscribe [::table-params])
:status status
:column-count 6}
[grid/controls {:start start :end end :count count :total total}]
[grid/table {:fullwidth true }
[:div
[grid/grid {:on-params-change opc
:params @(re-frame/subscribe [::table-params])
:status status
:column-count 6}
[grid/controls {:start start :end end :count count :total total}]
[grid/table {:fullwidth true }
[grid/header
[grid/row {}
[grid/sortable-header-cell {:sort-key "client"
:sort-name "Client"}
:sort-name "Client"}
"Client"]
[grid/sortable-header-cell {:sort-key "bank-account"
:sort-name "Bank Account"}
:sort-name "Bank Account"}
"Bank Account"]
[grid/sortable-header-cell {:sort-key "description"
:sort-name "Description"}
:sort-name "Description"}
"Description"]
[grid/header-cell {:style {:width "12em"}} "Amount"]
[grid/sortable-header-cell {:sort-key "note"
:sort-name "Note"}
:sort-name "Note"}
"Note"]
[grid/header-cell {:style {:width (str (inc (* 2 44)) "px")}}]]]
[grid/header-cell {:style {:width (str (inc (* 3 44)) "px")}}]]]
[grid/body
(for [{:keys [client bank-account description amount-lte amount-gte note id] :as r} transaction-rules]
^{:key id}
@@ -120,7 +157,8 @@
[grid/cell {}
[:div.buttons
[buttons/fa-icon {:event [::run-clicked r] :icon :fa-play :class (status/class-for (get states (:id r)))}]
[buttons/fa-icon {:event [::form/editing r] :icon :fa-pencil}]]]])]]]))
[buttons/sl-icon {:event [::request-delete r] :icon :icon-bin-2}]
[buttons/fa-icon {:event [::form/editing r] :icon :fa-pencil}]]]])]]]]))
(defn table [params]
(r/create-class {:component-will-unmount (dispatch-event [::unmounted])