big updates for re-org.
This commit is contained in:
86
src/cljs/auto_ap/views/pages/import_invoices.cljs
Normal file
86
src/cljs/auto_ap/views/pages/import_invoices.cljs
Normal file
@@ -0,0 +1,86 @@
|
||||
(ns auto-ap.views.pages.import-invoices
|
||||
(:require [re-frame.core :as re-frame]
|
||||
[reagent.core :as reagent]
|
||||
[auto-ap.events :as events]
|
||||
[auto-ap.subs :as subs]
|
||||
[cljsjs.dropzone :as dropzone]
|
||||
[cljs.reader :as edn]))
|
||||
(def dropzone
|
||||
(let [company (re-frame/subscribe [::subs/company])
|
||||
token (re-frame/subscribe [::subs/token])]
|
||||
(with-meta
|
||||
(fn []
|
||||
[:form.dz {:action "/pdf-upload"}
|
||||
[:div.tile.notification
|
||||
[:div.has-text-centered {:style {:padding "80px 0px" :width "100%"}}
|
||||
[:span
|
||||
[:span {:class "icon"}
|
||||
[:i {:class "fa fa-cloud-download"}]]
|
||||
"Drop any invoices you want to process here"]]]])
|
||||
{:component-did-mount (fn [this]
|
||||
(js/Dropzone. (reagent/dom-node this)
|
||||
(clj->js {:init (fn []
|
||||
(.on (js-this) "success" (fn [_ files]
|
||||
(re-frame/dispatch [::events/received-invoices :pending (edn/read-string files)]))))
|
||||
:paramName "file"
|
||||
:headers {"Authorization" (str "Token " @token)}
|
||||
:url (str "/pdf-upload"
|
||||
(when-let [company-name (-> @company :name)]
|
||||
(str "?company=" company-name)))
|
||||
:previewsContainer "#dz-hidden"
|
||||
:previewTemplate "<div class='dz-hidden-preview'></div>"})))})))
|
||||
(def import-invoices-page
|
||||
(with-meta
|
||||
(fn []
|
||||
(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",}
|
||||
[:div {:class "card-header"}
|
||||
[:span {:class "card-header-title"} "Found Invoices"]]
|
||||
[:div {:class "card-content"}
|
||||
(if (:loading @status)
|
||||
[:h1.title
|
||||
[:i.fa.fa-spin.fa-spinner]]
|
||||
(if (seq @invoices)
|
||||
[:table {:class "table", :style {:width "100%"}}
|
||||
[:thead
|
||||
[:tr
|
||||
[:th "Vendor"]
|
||||
[:th "Customer"]
|
||||
[:th "Invoice #"]
|
||||
[:th "Date"]
|
||||
[:th "Amount"]
|
||||
[:th]]]
|
||||
[:tbody (for [{:keys [vendor potential-duplicate company customer-identifier invoice-number date total id] :as i} @invoices]
|
||||
^{:key (str company "-" invoice-number "-" date "-" total "-" id)}
|
||||
[:tr
|
||||
[:td vendor]
|
||||
(if company
|
||||
[:td company]
|
||||
[:td [:i.icon.fa.fa-warning {:title "potential duplicate"}]
|
||||
(str "'" customer-identifier "' doesn't match any known company")])
|
||||
[:td invoice-number]
|
||||
[:td date]
|
||||
[:td total]
|
||||
[:td (when potential-duplicate
|
||||
[:i.icon.fa.fa-warning {:title "potential duplicate"}])]])]]
|
||||
[: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 []
|
||||
(re-frame/dispatch [::events/view-pending-invoices]))}))
|
||||
Reference in New Issue
Block a user