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] :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 (re-frame/reg-event-fx
::view-unpaid-invoices ::view-unpaid-invoices
(fn [cofx []] (fn [cofx []]

View File

@@ -88,16 +88,21 @@
(defmethod active-page :import-invoices [] (defmethod active-page :import-invoices []
[(with-meta [(with-meta
(fn [] (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"} [:div {:class "inbox-messages"}
[:h1.title "Upload invoices"] [:h1.title "Upload invoices"]
[dropzone] [dropzone]
[:div {:class "section"}] [:div {:class "section"}]
[:div {:class "card found-invoices", :style {:display (if (seq @invoices) "block" "none")}} [:div {:class "card found-invoices",}
[:div {:class "card-header"} [:div {:class "card-header"}
[:span {:class "card-header-title"} "Found Invoices"]] [:span {:class "card-header-title"} "Found Invoices"]]
[:div {:class "card-content"} [:div {:class "card-content"}
(if (:loading @status)
[:h1.title
[:i.fa.fa-spin.fa-spinner]]
(if (seq @invoices)
[:table {:class "table", :style {:width "100%"}} [:table {:class "table", :style {:width "100%"}}
[:thead [:thead
[:tr [:tr
@@ -111,25 +116,22 @@
[:td customer-identifier] [:td customer-identifier]
[:td invoice-number] [:td invoice-number]
[:td date] [:td date]
[:td total]])]]] [:td total]])]]
[:span "No pending invoices"]))]
(if (and (seq @invoices) (not (:loading @status)))
[:div.card-footer [:div.card-footer
[:a.card-footer-item [:a.card-footer-item
{:on-click (fn [e] {:on-click (fn [e]
(.preventDefault e) (.preventDefault e)
(re-frame/dispatch [::events/approve-invoices]))} (re-frame/dispatch [::events/approve-invoices]))}
"Approve all"] "Accept all"]
[:a.card-footer-item [:a.card-footer-item
{:on-click (fn [e] {:on-click (fn [e]
(.preventDefault e) (.preventDefault e)
(re-frame/dispatch [::events/reject-invoices]))} (re-frame/dispatch [::events/reject-invoices]))}
"Reject all"] "Reject all"]])]]))
]]]))
{:component-will-mount (fn [] {:component-will-mount (fn []
(go (re-frame/dispatch [::events/view-pending-invoices]))})])
(->> (<! (http/get "/api/invoices/pending"))
:body
(conj [::events/received-invoices :pending])
(re-frame/dispatch))))})])
(defn main-panel [] (defn main-panel []
(let [name (re-frame/subscribe [::subs/name]) (let [name (re-frame/subscribe [::subs/name])