diff --git a/src/cljs/auto_ap/events.cljs b/src/cljs/auto_ap/events.cljs index 9d88dfd3..7f26063d 100644 --- a/src/cljs/auto_ap/events.cljs +++ b/src/cljs/auto_ap/events.cljs @@ -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 []] diff --git a/src/cljs/auto_ap/views.cljs b/src/cljs/auto_ap/views.cljs index 1bca1553..c5891d2f 100644 --- a/src/cljs/auto_ap/views.cljs +++ b/src/cljs/auto_ap/views.cljs @@ -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 - (->> (