separating out manual.

This commit is contained in:
Bryce Covert
2019-04-11 07:36:03 -07:00
parent 704481466b
commit 1aa5219659
2 changed files with 61 additions and 51 deletions

View File

@@ -0,0 +1,57 @@
(ns auto-ap.views.pages.transactions.manual
(:require [auto-ap.events :as events]
[auto-ap.subs :as subs]
[auto-ap.views.components.modal :refer [action-modal]]
[auto-ap.views.utils :refer [bind-field]]
[re-frame.core :as re-frame]))
(re-frame/reg-event-fx
::manual-yodlee-import
(fn [{:keys [db]} _]
{:dispatch [::events/modal-status ::manual-yodlee-import {:visible? true}]
:db (assoc-in db [::manual-yodlee-import] {:client-id (:id @(re-frame/subscribe [::subs/client]))
:data ""})}))
(re-frame/reg-sub
::manual-yodlee-import
(fn [db]
(-> db ::manual-yodlee-import)))
(re-frame/reg-event-fx
::manual-yodlee-import-completed
(fn [{:keys [db]} [_ {:keys [imported errors]}]]
(re-frame/dispatch [::params-change {}])
{:dispatch [::events/modal-completed ::manual-yodlee-import]
:db (-> db
(assoc-in [::notification :message] (str "Successfully imported " imported " transactions"))
(assoc-in [::notification :errors] errors))}))
(re-frame/reg-event-fx
::manual-yodlee-import-started
(fn [{:keys [db]} _]
(let [manual-yodlee-import (::manual-yodlee-import db)]
{:http {:token (:user db)
:method :post
:body (pr-str manual-yodlee-import)
:headers {"Content-Type" "application/edn"}
:uri (str "/api/transactions/batch-upload")
:on-success [::manual-yodlee-import-completed]
:on-error [::manual-yodlee-import-error]}})))
(defn manual-yodlee-import-modal []
(let [data @(re-frame/subscribe [::manual-yodlee-import])
change-event [::events/change-form [::manual-yodlee-import]]]
[action-modal {:id ::manual-yodlee-import
:title "Manual Yodlee Import"
:action-text "Import"
:save-event [::manual-yodlee-import-started]}
[:div.field
[:label.label
"Yodlee manual import table"]
[:div.control
[bind-field
[:textarea.textarea {:field [:data]
:event change-event
:subscription data}]]]]]))