several fixes for invoices.

This commit is contained in:
Bryce Covert
2020-05-26 07:39:33 -07:00
parent 4429fa384a
commit f78133cbea
4 changed files with 101 additions and 57 deletions

View File

@@ -15,50 +15,52 @@
[cljsjs.dropzone :as dropzone]
[cljs.reader :as edn]
[clojure.string :as str]))
(def dropzone
(defn dropzone []
(let [client (re-frame/subscribe [::subs/client])
token (re-frame/subscribe [::subs/token])
vendor (reagent/atom nil)]
(with-meta
(fn []
[:form.dz {:action "/api/invoices/upload"}
[:div.field.has-addons
[:p.control
[:a.button.is-static "Force Location"]]
[:p.control
[:input.input {:name "location" :placeholder "SG" :size "4" :maxlength "2" :style {:display "inline"}}]]]
[:div.field.has-addons
[:p.control
[:a.button.is-static "Force vendor"]]
[typeahead-entity {:matches @(re-frame/subscribe [::subs/vendors])
:match->text :name
:name "vendor"
:type "typeahead"
:on-change (fn [v]
(reset! vendor v))
:value @vendor}]
]
[: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. (rdom/dom-node this)
(clj->js {:init (fn []
(.on (js-this) "success" (fn [_ files]
(re-frame/dispatch [::invalidated])))
(.on (js-this) "error" (fn [_ error]
(re-frame/dispatch [::errored error]))))
:paramName "file"
:headers {"Authorization" (str "Token " @token)}
:url (str "/api/invoices/upload"
(when-let [client-name (-> @client :id)]
(str "?client=" client-name)))
:previewsContainer "#dz-hidden"
:previewTemplate "<div class='dz-hidden-preview'></div>"})))})))
(reagent/create-class
{:display-name "dropzone"
:component-did-mount (fn [this]
(js/Dropzone. (rdom/dom-node this)
(clj->js {:init (fn []
(.on (js-this) "success" (fn [_ files]
(re-frame/dispatch [::invalidated])))
(.on (js-this) "error" (fn [_ error]
(re-frame/dispatch [::errored error]))))
:paramName "file"
:headers {"Authorization" (str "Token " @token)}
:url (str "/api/invoices/upload"
(when-let [client-name (-> @client :id)]
(str "?client=" client-name)))
:previewsContainer "#dz-hidden"
:previewTemplate "<div class='dz-hidden-preview'></div>"})))
:reagent-render (fn []
[:form.dz {:action "/api/invoices/upload"}
[:div.field.has-addons
[:p.control
[:a.button.is-static "Force Location"]]
[:p.control
[:input.input {:name "location" :placeholder "SG" :size "4" :maxlength "2" :style {:display "inline"}}]]]
[:div.field.has-addons
[:p.control
[:a.button.is-static "Force vendor"]]
[typeahead-entity {:matches @(re-frame/subscribe [::subs/vendors])
:match->text :name
:name "vendor"
:type "typeahead"
:on-change (fn [v]
(reset! vendor v))
:value @vendor}]
]
[: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"]]]])})
))
(re-frame/reg-sub
@@ -191,12 +193,13 @@
(fn []
(let [invoice-page (re-frame/subscribe [::invoice-page])
status (re-frame/subscribe [::subs/status])
error (re-frame/subscribe [::error])]
error (re-frame/subscribe [::error])
client (:id @(re-frame/subscribe [::subs/client]))]
^{:key client}
[:div
[:h1.title "Upload invoices"]
[dropzone]
[:div {:class "section"}
(when @error