maybe makes yodlee edit flow work.
This commit is contained in:
@@ -1,98 +1,36 @@
|
||||
(ns auto-ap.views.pages.admin.yodlee2.form
|
||||
(:require [auto-ap.views.components.modal :as modal]
|
||||
[auto-ap.status :as status]
|
||||
[auto-ap.forms :as forms]
|
||||
[re-frame.core :as re-frame]
|
||||
[auto-ap.views.utils :refer [->$ action-cell-width date->str with-user dispatch-event]]))
|
||||
(:require
|
||||
[auto-ap.views.components.modal :as modal]
|
||||
[re-frame.core :as re-frame]
|
||||
[reagent.core :as r]))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::can-submit
|
||||
(fn [db]
|
||||
true))
|
||||
(def form
|
||||
(r/create-class {
|
||||
:component-did-mount (fn [this]
|
||||
(let [{:keys [authentication provider-account-id]} (r/props this)]
|
||||
(try
|
||||
(.open (.-fastlink js/window)
|
||||
#js {"fastLinkURL" (:url authentication)
|
||||
"accessToken" (:token authentication)
|
||||
"params" #js { "configName" "Aggregation"
|
||||
"providerAccountId" (str provider-account-id)
|
||||
"flow" "edit"}}
|
||||
|
||||
"fa-modal-spot")
|
||||
(catch js/Error e
|
||||
(println e)))))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::saved
|
||||
(forms/triggers-stop ::form)
|
||||
(fn [{:keys [db]} [_ {:keys [edit-user]}]]
|
||||
{:dispatch [::modal/modal-closed]}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::saving
|
||||
[with-user (forms/in-form [::form])]
|
||||
(fn [{:keys [user db]} [_ ]]
|
||||
(let [provider-account-id (:id (:data db))]
|
||||
{:http {:token user
|
||||
:method :post
|
||||
:owns-state {:single ::form}
|
||||
:headers {"Content-Type" "application/edn"}
|
||||
:uri (str "/api/yodlee2/reauthenticate/" provider-account-id)
|
||||
:body {:client-id (:client-id (:data db))
|
||||
"loginForm"
|
||||
{"row"
|
||||
(->> db
|
||||
:data
|
||||
:login
|
||||
(sort-by (fn [[k v]] k))
|
||||
(map second)
|
||||
(map (fn [row]
|
||||
{"field"
|
||||
(mapv (fn [[k v]]
|
||||
{"id" k
|
||||
"value" v})
|
||||
row)})))}
|
||||
"field"
|
||||
(mapv (fn [[k v]]
|
||||
{"id" k
|
||||
"value" v})
|
||||
(-> db :data :mfa))}
|
||||
|
||||
:on-success [::saved]}})))
|
||||
|
||||
(def reauthenticate-form (forms/vertical-form {:submit-event [::saving]
|
||||
:change-event [::forms/change ::form]
|
||||
:can-submit [::can-submit]
|
||||
:id ::form}))
|
||||
(defn form [{:keys [provider-account]}]
|
||||
(let [{error :error account-data :data } @(re-frame/subscribe [::forms/form ::form])
|
||||
|
||||
{:keys [form-inline field error-notification submit-button]} reauthenticate-form
|
||||
]
|
||||
(form-inline {:title "Reauthenticate"}
|
||||
[:<>
|
||||
(error-notification)
|
||||
(doall
|
||||
(for [[row i] (map vector (-> account-data :provider-account :loginForm last :row) (range))
|
||||
f (:field row)
|
||||
:let [options (map :optionValue (:option f))]]
|
||||
^{:key (:id f)}
|
||||
[:div
|
||||
(field (:label row)
|
||||
[:input.input {:type "text" :field [:login i (:id f)]}])
|
||||
(if (seq options)
|
||||
[:ul
|
||||
(for [o options]
|
||||
^{:key o}
|
||||
[:li [:pre o]])])]))
|
||||
(doall
|
||||
(for [f (-> account-data :provider-account :field)]
|
||||
^{:key (:id f)}
|
||||
(field (:label f)
|
||||
[:input.input {:type "text" :mfa [:form (:id f)] :value (-> f :field first :value)}])))])))
|
||||
:reagent-render (fn [_]
|
||||
[:div#fa-modal-spot])}))
|
||||
|
||||
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::reauthenticate-start
|
||||
(fn [{:keys [db]} [_ client-id provider-account ]]
|
||||
{:db (-> db
|
||||
(forms/start-form ::form {:id (:id provider-account)
|
||||
:client-id client-id
|
||||
:provider-account provider-account}))
|
||||
:dispatch [::modal/modal-requested {:title (str "Reauthenticate " (:id provider-account))
|
||||
:body [form {:provider-account provider-account}]
|
||||
:cancel? false
|
||||
:confirm {:value "Reauthenticate"
|
||||
:status-from [::status/single ::form]
|
||||
:class "is-primary"
|
||||
:on-click (dispatch-event [::saving])
|
||||
:close-event [::status/completed ::form]}}]}))
|
||||
(fn [_ [_ _ provider-account-id authentication]]
|
||||
{:dispatch [::modal/modal-requested {:title (str "Reauthenticate " provider-account-id)
|
||||
:body [form {:provider-account-id provider-account-id
|
||||
:authentication authentication}]
|
||||
:cancel? false}]}))
|
||||
|
||||
|
||||
|
||||
@@ -42,12 +42,12 @@
|
||||
[with-user ]
|
||||
(fn [{:keys [user]} [_ provider-account client-id]]
|
||||
{:http {:token user
|
||||
:method :get
|
||||
:method :get
|
||||
:headers {"Content-Type" "application/edn"}
|
||||
:uri (str "/api/yodlee2/fastlink?client=" client-id)
|
||||
:owns-state {:multi ::request-login-form
|
||||
:which (:id provider-account)}
|
||||
:headers {"Content-Type" "application/edn"}
|
||||
:uri (str "/api/yodlee2/provider-accounts/" client-id "/" (:id provider-account) )
|
||||
:on-success [::form/reauthenticate-start client-id]}}))
|
||||
:on-success [::form/reauthenticate-start client-id provider-account]}}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::delete-provider-account
|
||||
@@ -123,7 +123,7 @@
|
||||
[grid/cell {}
|
||||
[:div.buttons
|
||||
[buttons/fa-icon {:event
|
||||
[::request-login-form c (:id (:client c))]
|
||||
[::request-login-form (:id c) (:id (:client c))]
|
||||
:class (status/class-for (get login-statuses (:id c)))
|
||||
:icon "fa-pencil"}]
|
||||
[buttons/fa-icon {:event [::request-refresh (:id c) (:id (:client c))]
|
||||
@@ -131,3 +131,31 @@
|
||||
:icon "fa-refresh"}]
|
||||
[buttons/fa-icon {:event [::delete-requested (:id c)]
|
||||
:icon "fa-times"}]]]])]]]))
|
||||
|
||||
#_(defn yodlee-link-button []
|
||||
[:div
|
||||
(let [authentication @(re-frame/subscribe [::authentication])
|
||||
status @(re-frame/subscribe [::status/single ::authenticating])
|
||||
client-code (:code @(re-frame/subscribe [::subs/client]))]
|
||||
(cond (and authentication client-code)
|
||||
[:div
|
||||
"Authentication successful!"
|
||||
[:div#fa-spot]
|
||||
[:button.button.is-primary {:on-click (fn []
|
||||
(.open (.-fastlink js/window)
|
||||
#js {"fastLinkURL" (:url authentication)
|
||||
"accessToken" (:token authentication)
|
||||
"params" #js { "configName" "Aggregation"}}
|
||||
|
||||
"fa-spot")
|
||||
)}
|
||||
[:span [:span.icon [:i.fa.fa-external-link]] " Go to yodlee"]]]
|
||||
|
||||
client-code
|
||||
[:button.button.is-primary {:disabled (status/disabled-for status)
|
||||
:class (status/class-for status)
|
||||
:on-click (dispatch-event [::authenticate-with-yodlee client-code])}
|
||||
"Authenticate with Yodlee (" client-code ")"]
|
||||
|
||||
:else
|
||||
nil))])
|
||||
|
||||
Reference in New Issue
Block a user