progress on making it possible to import from excel.

This commit is contained in:
Bryce Covert
2018-05-04 09:56:18 -07:00
parent a526d2da1b
commit df3755d099
3 changed files with 47 additions and 25 deletions

View File

@@ -38,18 +38,26 @@
:uri (str "/api/invoices/upload-integreat")
:on-success [::save-complete]
:on-error [::save-error]}
:db (assoc-in db [::excel-import :rows] nil)})))
:db (-> db
(assoc-in [::excel-import :rows] nil)
(assoc-in [::excel-import :saving?] true))})))
(re-frame/reg-event-fx
::save-complete
(fn [{:keys [db]} [_ rows]]
{:dispatch [::edit nil]
:db (assoc-in db [::excel-import :rows] rows)}))
:db
(-> db
(assoc-in [::excel-import :rows] rows)
(assoc-in [::excel-import :saving?] false))}))
(re-frame/reg-event-fx
::save-error
(fn [{:keys [db]}]
{:dispatch [::change [:error] true]}))
{:dispatch [::change [:error] true]
:db (-> db
(assoc-in [::excel-import :rows] nil)
(assoc-in [::excel-import :saving?] false))}))
(defn admin-excel-import-page []
[:div
@@ -63,12 +71,18 @@
:event ::change
:subscription excel-import-data}]]
[:button.button.is-large.is-pulled-right.is-primary {:on-click (dispatch-event [::save])} "Import"]
[:button.button.is-large.is-pulled-right.is-primary {:on-click (dispatch-event [::save])
:class (when (:saving? excel-import-data)
"is-loading")
:disabled (when (:saving? excel-import-data) "disabled")} "Import"]
[:div.is-clearfix
(when-let [imported (:imported (:rows excel-import-data))]
(str imported " rows imported."))
]
[:p
(when-let [imported (:imported (:rows excel-import-data))]
(str imported " rows imported."))]
[:p
(when-let [already-imported (:already-imported (:rows excel-import-data))]
(str already-imported " rows already imported."))]]
(when-let [errors (:errors (:rows excel-import-data))]
[:div