From d6345832dc2d2821f612bf547f60b2435c673c5c Mon Sep 17 00:00:00 2001 From: BC Date: Thu, 12 Jul 2018 23:31:39 -0700 Subject: [PATCH] some visual feedback that it worked --- src/clj/auto_ap/routes/invoices.clj | 9 +-- .../auto_ap/views/pages/transactions.cljs | 56 ++++++++++++++----- 2 files changed, 45 insertions(+), 20 deletions(-) diff --git a/src/clj/auto_ap/routes/invoices.clj b/src/clj/auto_ap/routes/invoices.clj index 604a457f..48611926 100644 --- a/src/clj/auto_ap/routes/invoices.clj +++ b/src/clj/auto_ap/routes/invoices.clj @@ -89,14 +89,10 @@ (map #(str/split % #"\t")) (map #(into {} (filter identity (map (fn [c k] [k c] ) % columns)))) - - - - - (map (parse-or-error :amount parse-amount)) (map (parse-or-error :account-id parse-account-id)) (map (parse-or-error :date parse-date))) + error-rows (filter :errors rows) raw-transactions (vec (->> rows (filter #(not (seq (:errors %))) ) @@ -110,7 +106,8 @@ (manual-import raw-transactions company-id 1) {:status 200 - :body (pr-str {:status "success"}) + :body (pr-str {:imported (count raw-transactions) + :errors (map #(dissoc % :date) error-rows)}) :headers {"Content-Type" "application/edn"}})) ) (context "/invoices" [] diff --git a/src/cljs/auto_ap/views/pages/transactions.cljs b/src/cljs/auto_ap/views/pages/transactions.cljs index 97a90000..bc0e360f 100644 --- a/src/cljs/auto_ap/views/pages/transactions.cljs +++ b/src/cljs/auto_ap/views/pages/transactions.cljs @@ -150,8 +150,12 @@ (re-frame/reg-event-fx ::manual-yodlee-import-completed - (fn [{:keys [db]} _] - {:dispatch [::events/modal-completed ::manual-yodlee-import]})) + (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 @@ -182,27 +186,51 @@ :event change-event :subscription data}]]]]])) +(re-frame/reg-sub + ::notification + (fn [db] + (-> db ::notification))) + (def transactions-page (with-meta (fn [] - (let [current-company @(re-frame/subscribe [::subs/company]) + (let [notification (re-frame/subscribe [::notification]) + current-company @(re-frame/subscribe [::subs/company]) user @(re-frame/subscribe [::subs/user])] + [:div [:h1.title "Transactions"] (when (= "admin" (:role user)) - [:div.is-pulled-right - [:button.button.is-danger {:disabled (if current-company - "" - "disabled") - :on-click (dispatch-event [::manual-yodlee-import])} - "Manual Yodlee Import"]]) + (list + (when (:message @notification) + + (list + [:div.notification + (:message @notification) + ] + (when (seq (:errors @notification)) + [:div.notification.is-danger + [:h3 (count (:errors @notification)) " errors:"] + + [:ul + (for [transaction (:errors @notification) + error (:errors transaction)] + [:li (:description-original transaction) "-" (:details error)]) + ]]))) + + [:div.is-pulled-right + [:button.button.is-danger {:disabled (if current-company + "" + "disabled") + :on-click (dispatch-event [::manual-yodlee-import])} + "Manual Yodlee Import"]])) [transaction-table {:id :transactions - :params (re-frame/subscribe [::params]) - :transaction-page (re-frame/subscribe [::transaction-page]) - :status (re-frame/subscribe [::subs/status]) - :on-params-change (fn [params] - (re-frame/dispatch [::params-change params]))}] + :params (re-frame/subscribe [::params]) + :transaction-page (re-frame/subscribe [::transaction-page]) + :status (re-frame/subscribe [::subs/status]) + :on-params-change (fn [params] + (re-frame/dispatch [::params-change params]))}] [manual-yodlee-import-modal]])) {:component-will-mount #(re-frame/dispatch-sync [::params-change {}]) }))