adding new invoices.
This commit is contained in:
@@ -12,7 +12,7 @@
|
|||||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.6.0/css/bulma.min.css" integrity="sha256-HEtF7HLJZSC3Le1HcsWbz1hDYFPZCqDhZa9QsCgVUdw=" crossorigin="anonymous" />
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.6.0/css/bulma.min.css" integrity="sha256-HEtF7HLJZSC3Le1HcsWbz1hDYFPZCqDhZa9QsCgVUdw=" crossorigin="anonymous" />
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
form { border: 2px dashed lightgray;}
|
form.dz { border: 2px dashed lightgray;}
|
||||||
|
|
||||||
html,body {
|
html,body {
|
||||||
font-family: 'Open Sans', serif;
|
font-family: 'Open Sans', serif;
|
||||||
|
|||||||
@@ -5,4 +5,5 @@
|
|||||||
:invoices {:pending #{}
|
:invoices {:pending #{}
|
||||||
:unpaid #{}}
|
:unpaid #{}}
|
||||||
:status {:loading false}
|
:status {:loading false}
|
||||||
|
:new-invoice {}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -14,9 +14,11 @@
|
|||||||
|
|
||||||
(re-frame/reg-fx
|
(re-frame/reg-fx
|
||||||
:http
|
:http
|
||||||
(fn [{:keys [method uri on-success]}]
|
(fn [{:keys [method uri on-success body headers]}]
|
||||||
(go
|
(go
|
||||||
(->> (http/request {:method method
|
(->> (http/request {:method method
|
||||||
|
:body body
|
||||||
|
:headers headers
|
||||||
:url uri})
|
:url uri})
|
||||||
(<! )
|
(<! )
|
||||||
:body
|
:body
|
||||||
|
|||||||
@@ -52,6 +52,21 @@
|
|||||||
:uri "/api/invoices/reject"
|
:uri "/api/invoices/reject"
|
||||||
:on-success [::received-invoices :pending]
|
:on-success [::received-invoices :pending]
|
||||||
}}))
|
}}))
|
||||||
|
(re-frame/reg-event-db
|
||||||
|
::submitted-new-invoice
|
||||||
|
(fn [db [_ invoice]]
|
||||||
|
(assoc db :new-invoice {})))
|
||||||
|
|
||||||
|
(re-frame/reg-event-fx
|
||||||
|
::submit-new-invoice
|
||||||
|
(fn [{:keys [db]} [_ invoice]]
|
||||||
|
|
||||||
|
{:http {:method :post
|
||||||
|
:uri "/api/invoices"
|
||||||
|
:body (pr-str {:rows [(assoc invoice :imported true)]})
|
||||||
|
:headers {"Content-Type" "application/edn"}
|
||||||
|
:on-success [::submitted-new-invoice]}
|
||||||
|
:db (assoc-in db [:new-invoice :loading?] true)}))
|
||||||
|
|
||||||
(re-frame/reg-event-db
|
(re-frame/reg-event-db
|
||||||
::received-invoices
|
::received-invoices
|
||||||
@@ -60,3 +75,8 @@
|
|||||||
(assoc-in [:invoices type] new-invoices)
|
(assoc-in [:invoices type] new-invoices)
|
||||||
(assoc-in [:status :loading] false)
|
(assoc-in [:status :loading] false)
|
||||||
)))
|
)))
|
||||||
|
|
||||||
|
(re-frame/reg-event-db
|
||||||
|
::change-form-state
|
||||||
|
(fn [db [_ target value]]
|
||||||
|
(assoc-in db target value)))
|
||||||
|
|||||||
@@ -5,4 +5,5 @@
|
|||||||
"invoices/" {"" :invoices
|
"invoices/" {"" :invoices
|
||||||
"import" :import-invoices
|
"import" :import-invoices
|
||||||
"unpaid" :unpaid-invoices
|
"unpaid" :unpaid-invoices
|
||||||
"paid" :paid-invoices}}])
|
"paid" :paid-invoices
|
||||||
|
"new" :new-invoice}}])
|
||||||
|
|||||||
@@ -25,3 +25,8 @@
|
|||||||
::status
|
::status
|
||||||
(fn [db]
|
(fn [db]
|
||||||
(:status db)))
|
(:status db)))
|
||||||
|
|
||||||
|
(re-frame/reg-sub
|
||||||
|
::new-invoice-form
|
||||||
|
(fn [db]
|
||||||
|
(:new-invoice db)))
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
(def dropzone
|
(def dropzone
|
||||||
(with-meta
|
(with-meta
|
||||||
(fn []
|
(fn []
|
||||||
[:form {:action "/pdf-upload"}
|
[:form.dz {:action "/pdf-upload"}
|
||||||
[:div.tile.notification
|
[:div.tile.notification
|
||||||
[:div.has-text-centered {:style {:padding "80px 0px" :width "100%"}}
|
[:div.has-text-centered {:style {:padding "80px 0px" :width "100%"}}
|
||||||
[:span
|
[:span
|
||||||
@@ -133,6 +133,66 @@
|
|||||||
{:component-will-mount (fn []
|
{:component-will-mount (fn []
|
||||||
(re-frame/dispatch [::events/view-pending-invoices]))})])
|
(re-frame/dispatch [::events/view-pending-invoices]))})])
|
||||||
|
|
||||||
|
|
||||||
|
(defmethod active-page :new-invoice []
|
||||||
|
(let [form-data (re-frame/subscribe [::subs/new-invoice-form])]
|
||||||
|
[:div {:class "inbox-messages"}
|
||||||
|
[:form
|
||||||
|
[:h1.title "New Invoice"]
|
||||||
|
[:div.field
|
||||||
|
[:label.label "Customer"]
|
||||||
|
[:div.control
|
||||||
|
[:input.input {:type "text"
|
||||||
|
:placeholder "Campbell's Brewery"
|
||||||
|
:value (:customer-identifier @form-data)
|
||||||
|
:on-change (fn [e]
|
||||||
|
(re-frame/dispatch [::events/change-form-state
|
||||||
|
[:new-invoice :customer-identifier]
|
||||||
|
(.. e -target -value)]))}]]]
|
||||||
|
[:div.field
|
||||||
|
[:label.label "Invoice #"]
|
||||||
|
[:div.control
|
||||||
|
[:input.input {:type "text"
|
||||||
|
:placeholder "12345"
|
||||||
|
:value (:invoice-number @form-data)
|
||||||
|
:on-change (fn [e]
|
||||||
|
(re-frame/dispatch [::events/change-form-state
|
||||||
|
[:new-invoice :invoice-number]
|
||||||
|
(.. e -target -value)]))}]]]
|
||||||
|
[:div.field
|
||||||
|
[:label.label "Date"]
|
||||||
|
[:div.control
|
||||||
|
[:input.input {:type "text"
|
||||||
|
:placeholder "11/11/2011"
|
||||||
|
:value (:date @form-data)
|
||||||
|
:on-change (fn [e]
|
||||||
|
(re-frame/dispatch [::events/change-form-state
|
||||||
|
[:new-invoice :date]
|
||||||
|
(.. e -target -value)]))}]]]
|
||||||
|
[:div.field
|
||||||
|
[:label.label "Total"]
|
||||||
|
[:div.control
|
||||||
|
[:input.input {:type "text"
|
||||||
|
:placeholder "$14.50"
|
||||||
|
:value (:total @form-data)
|
||||||
|
:on-change (fn [e]
|
||||||
|
(re-frame/dispatch [::events/change-form-state
|
||||||
|
[:new-invoice :total]
|
||||||
|
(.. e -target -value)]))}]]]
|
||||||
|
[:div.control
|
||||||
|
[:submit.button.is-large.is-primary {
|
||||||
|
:disabled (if (and (:total @form-data) (:date @form-data) (:customer-identifier @form-data) (:invoice-number @form-data))
|
||||||
|
""
|
||||||
|
"disabled")
|
||||||
|
:on-click
|
||||||
|
(fn [x]
|
||||||
|
(.preventDefault x)
|
||||||
|
(re-frame/dispatch [::events/submit-new-invoice @form-data]))}
|
||||||
|
[:span
|
||||||
|
(when (:loading? @form-data)
|
||||||
|
[:i.fa.fa-spin.fa-spinner])
|
||||||
|
"Save"]]]]]))
|
||||||
|
|
||||||
(defn main-panel []
|
(defn main-panel []
|
||||||
(let [name (re-frame/subscribe [::subs/name])
|
(let [name (re-frame/subscribe [::subs/name])
|
||||||
ap (re-frame/subscribe [::subs/active-page])]
|
ap (re-frame/subscribe [::subs/active-page])]
|
||||||
@@ -190,7 +250,7 @@
|
|||||||
|
|
||||||
[:div.left-nav
|
[:div.left-nav
|
||||||
[:div {:class "compose has-text-centered"}
|
[:div {:class "compose has-text-centered"}
|
||||||
[:a {:class "button is-danger is-block is-bold"}
|
[:a {:class "button is-danger is-block is-bold" :href (bidi/path-for routes/routes :new-invoice)}
|
||||||
[:span {:class "compose"} "New Invoice"]]]]]
|
[:span {:class "compose"} "New Invoice"]]]]]
|
||||||
[:div {:class "column messages hero is-fullheight", :id "message-feed"}
|
[:div {:class "column messages hero is-fullheight", :id "message-feed"}
|
||||||
[active-page @ap]]]
|
[active-page @ap]]]
|
||||||
|
|||||||
Reference in New Issue
Block a user