(ns auto-ap.views (:require-macros [cljs.core.async.macros :refer [go]]) (:require [re-frame.core :as re-frame] [reagent.core :as reagent] [auto-ap.subs :as subs] [auto-ap.events :as events] [cljs.reader :as edn] [cljsjs.dropzone :as dz] [auto-ap.routes :as routes] [bidi.bidi :as bidi] [cljs-http.client :as http] [cljs.core.async :refer [js {:init (fn [] (.on (js-this) "success" (fn [_ files] (re-frame/dispatch [::events/received-invoices :pending (edn/read-string files)])))) :paramName "file" :url "/pdf-upload" :previewsContainer "#dz-hidden" :previewTemplate "
"})))})) (defmulti active-page identity) (defmethod active-page :index [] [:div {:class "inbox-messages"} [:div.hero [:div.hero-body [:div.container [:h1.title "Dashboard"] [:h2.subtitle "To get started, " [:a {:href (bidi/path-for routes/routes :import-invoices)} "Import some invoices"]]]]]]) (defmethod active-page :unpaid-invoices [] [(with-meta (fn [] (let [invoices (re-frame/subscribe [::subs/unpaid-invoices]) status (re-frame/subscribe [::subs/status])] [:div {:class "inbox-messages"} [:h1.title "Unpaid invoices"] (if (:loading @status) [:div {:class "inbox-messages"} [:h1.title [:i.fa.fa-spin.fa-spinner]]] [: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]])]])])) {:component-will-mount #(re-frame/dispatch-sync [::events/view-unpaid-invoices]) })]) (defmethod active-page :paid-invoices [] [:div {:class "inbox-messages"} [:h1.title "Paid invoices"]]) (defmethod active-page :invoices [] [(with-meta (fn [] [:div {:class "inbox-messages"} [:h1.title "All invoices"]]) {:component-did-mount (fn [] (go (re-frame/dispatch [::events/received-invoices (:body (> (