This commit is contained in:
Bryce Covert
2017-12-09 22:15:26 -08:00
parent e368b719ec
commit 87b89b3528
2 changed files with 43 additions and 33 deletions

View File

@@ -29,6 +29,14 @@
:on-success [::received-invoices :pending]
}}))
(re-frame/reg-event-fx
::view-pending-invoices
(fn [cofx []]
{:db (assoc-in (:db cofx) [:status :loading] true)
:http {:method :get
:uri "/api/invoices/pending"
:on-success [::received-invoices :pending]}}))
(re-frame/reg-event-fx
::view-unpaid-invoices
(fn [cofx []]

View File

@@ -88,48 +88,50 @@
(defmethod active-page :import-invoices []
[(with-meta
(fn []
(let [invoices (re-frame/subscribe [::subs/pending-invoices])]
(let [invoices (re-frame/subscribe [::subs/pending-invoices])
status (re-frame/subscribe [::subs/status])]
[:div {:class "inbox-messages"}
[:h1.title "Upload invoices"]
[dropzone]
[:div {:class "section"}]
[:div {:class "card found-invoices", :style {:display (if (seq @invoices) "block" "none")}}
[:div {:class "card found-invoices",}
[:div {:class "card-header"}
[:span {:class "card-header-title"} "Found Invoices"]]
[:div {:class "card-content"}
[:table {:class "table", :style {:width "100%"}}
[:thead
[:tr
[:th "Customer"]
[:th "Invoice #"]
[:th "Date"]
[:th "Amount"]]]
[:tbody (for [{:keys [customer-identifier invoice-number date total id] :as i} @invoices]
^{:key (str customer-identifier "-" invoice-number "-" date "-" total "-" id)}
[:tr
[:td customer-identifier]
[:td invoice-number]
[:td date]
[:td total]])]]]
[:div.card-footer
[:a.card-footer-item
{:on-click (fn [e]
(.preventDefault e)
(re-frame/dispatch [::events/approve-invoices]))}
"Approve all"]
[:a.card-footer-item
{:on-click (fn [e]
(.preventDefault e)
(re-frame/dispatch [::events/reject-invoices]))}
"Reject all"]
]]]))
(if (:loading @status)
[:h1.title
[:i.fa.fa-spin.fa-spinner]]
(if (seq @invoices)
[:table {:class "table", :style {:width "100%"}}
[:thead
[:tr
[:th "Customer"]
[:th "Invoice #"]
[:th "Date"]
[:th "Amount"]]]
[:tbody (for [{:keys [customer-identifier invoice-number date total id] :as i} @invoices]
^{:key (str customer-identifier "-" invoice-number "-" date "-" total "-" id)}
[:tr
[:td customer-identifier]
[:td invoice-number]
[:td date]
[:td total]])]]
[:span "No pending invoices"]))]
(if (and (seq @invoices) (not (:loading @status)))
[:div.card-footer
[:a.card-footer-item
{:on-click (fn [e]
(.preventDefault e)
(re-frame/dispatch [::events/approve-invoices]))}
"Accept all"]
[:a.card-footer-item
{:on-click (fn [e]
(.preventDefault e)
(re-frame/dispatch [::events/reject-invoices]))}
"Reject all"]])]]))
{:component-will-mount (fn []
(go
(->> (<! (http/get "/api/invoices/pending"))
:body
(conj [::events/received-invoices :pending])
(re-frame/dispatch))))})])
(re-frame/dispatch [::events/view-pending-invoices]))})])
(defn main-panel []
(let [name (re-frame/subscribe [::subs/name])