Yodlee is manually refreshable

This commit is contained in:
Bryce Covert
2020-12-22 13:59:50 -08:00
parent 6930a8c7c2
commit bbdb9602aa
6 changed files with 114 additions and 92 deletions

View File

@@ -210,18 +210,7 @@
{:db (assoc-in db [::provider-accounts] result)
:dispatch [::forms/form-closing [::refresh-provider-account i]]}))
(re-frame/reg-event-fx
::refresh-provider-account
[with-user ]
(fn [{:keys [user db]} [_ provider-account-id ]]
{:db (forms/loading db [::refresh-provider-account provider-account-id])
:http {:token user
:method :post
:headers {"Content-Type" "application/edn"}
:uri (str "/api/yodlee2/provider-accounts/refresh/" provider-account-id )
:body {}
:on-success [::provider-account-refreshed provider-account-id]
:on-error [::forms/save-error [::refresh-provider-account provider-account-id] ]}}))
(re-frame/reg-event-fx
::provider-account-deleted
@@ -410,25 +399,30 @@
:data (grid/virtual-paginate (:start params) (:per-page params) (:yodlee-provider-accounts all-yodlee-provider-accounts)))))
(re-frame/reg-event-fx
::mounted
::data-requested
(fn [{:keys [db]} _]
{:graphql {:token (:user db)
:owns-state {:single ::page}
:query-obj {:venia/queries [[:yodlee-provider-account-page {:client-id (:id @(re-frame/subscribe [::subs/client]))}
[[:yodlee-provider-accounts [:id :last-updated :status :detailed-status
[:accounts [:id :name :number :available-balance]]]]
:count]]]}
:on-success [::received]}
#_#_::forward/register {:id ::edited-yodlee-provider-account
#_#_:events #{::form/saved}
#_#_:event-fn (fn [[_ query-result]]
[::saved query-result])}
[:accounts [:id :name :number :available-balance]]]]
:count]]]}
:on-success [::received]}}))
(re-frame/reg-event-fx
::mounted
(fn [{:keys [db]} _]
{:dispatch [::data-requested]
::forward/register {:id ::yodlee-account-refreshed
:events #{::table/refreshed}
:event-fn (fn [[_ query-result]]
[::data-requested])}
:db (dissoc db ::authentication)}))
(re-frame/reg-event-fx
::unmounted
(fn [{:keys [db]} _]
#_{::forward/dispose {:id ::edited-yodlee-provider-account}}))
{::forward/dispose {:id ::yodlee-account-refreshed}}))
(re-frame/reg-event-fx

View File

@@ -1,11 +1,32 @@
(ns auto-ap.views.pages.admin.yodlee2.table
(:require
[clojure.string :as str]
[re-frame.core :as re-frame]
[auto-ap.views.utils :refer [action-cell-width date->str]]
[auto-ap.views.pages.admin.users.form :as form]
[auto-ap.views.components.buttons :as buttons]
[auto-ap.views.components.grid :as grid]))
(:require [auto-ap.status :as status]
[auto-ap.subs :as subs]
[auto-ap.views.components.buttons :as buttons]
[auto-ap.views.components.grid :as grid]
[auto-ap.views.pages.admin.users.form :as form]
[auto-ap.views.utils :refer [action-cell-width date->str with-user ->$]]
[re-frame.core :as re-frame]))
(re-frame/reg-event-fx
::refreshed
[with-user ]
(fn [{:keys [user db]} [_ provider-account ]]
;; this is tracked in yodlee main, for refreshing
{}))
(re-frame/reg-event-fx
::request-refresh
[with-user ]
(fn [{:keys [user db]} [_ provider-account ]]
{:http {:token user
:method :post
:headers {"Content-Type" "application/edn"}
:uri (str "/api/yodlee2/provider-accounts/refresh/")
:owns-state {:multi ::refresh
:which provider-account}
:body {:client-id (:id @(re-frame/subscribe [::subs/client]))
:provider-account-id provider-account}
:on-success [::refreshed provider-account]}}))
(re-frame/reg-event-fx
::params-changed
@@ -18,7 +39,8 @@
(-> db ::params)))
(defn table [{:keys [status page]}]
(let [params @(re-frame/subscribe [::params])]
(let [params @(re-frame/subscribe [::params])
statuses @(re-frame/subscribe [::status/multi ::refresh])]
[grid/grid {:status status
:on-params-change (fn [p]
(re-frame/dispatch [::params-changed p]))
@@ -28,12 +50,12 @@
[grid/table {:fullwidth true}
[grid/header
[grid/row {}
[grid/header-cell {} "Provider Account"]
[grid/header-cell {} "Status"]
[grid/header-cell {} "Detailed Status"]
[grid/header-cell {} "Last Updated"]
[grid/header-cell {:style {:width "18em"}} "Provider Account"]
[grid/header-cell {:style {:width "20em"}} "Status"]
[grid/header-cell {:style {:width "20em"}} "Detailed Status"]
[grid/header-cell {:style {:width "12em"}} "Last Updated"]
[grid/header-cell {} "Accounts"]
[grid/header-cell {:style {:width (action-cell-width 1)}} ]]]
[grid/header-cell {:style {:width (action-cell-width 3)}} ]]]
[grid/body
(for [{:keys [id name accounts status detailed-status last-updated clients] :as c} (:data page)]
^{:key (str name "-" id )}
@@ -46,7 +68,11 @@
[:ul
(for [a accounts]
^{:key (:id a)}
[:li (:name a) " - " (:number a)])]]
[:li (:name a) " - " (:number a) [:div.tag (->$ (:available-balance a))]])]]
[grid/cell {}
[buttons/fa-icon {:event [::form/editing c]
:icon "fa-pencil"}]]])]]]))
[:div.buttons
[buttons/fa-icon {:event [::form/editing c]
:icon "fa-pencil"}]
[buttons/fa-icon {:event [::request-refresh (:id c)]
:class (status/class-for (get statuses (:id c)))
:icon "fa-refresh"}]]]])]]]))