switched to graphql to create a payment.

This commit is contained in:
Bryce Covert
2018-05-14 09:30:01 -07:00
parent fd2164e8ba
commit bbd9f00f30
5 changed files with 85 additions and 14 deletions

View File

@@ -9,6 +9,14 @@
[cljs-time.format :as format]
[goog.string :as gstring]))
;; TODO show busy
;; TODO only when one company selected
;; TODO partial payments
;; TODO invoice status = paid when complete
;; TODO performance
;; TODO check numbers
;; TODO psql transactions
;; TODO refactor graphql
@@ -97,4 +105,4 @@
[:td (gstring/format "$%.2f" total )]
[:td (for [check checks]
^{:key (:id check)}
[:a.tag {:href (:s3-url (:check check)) :target "_new"} (str "check " (:check-number (:check check)))])]]))]]]))))
[:a.tag {:href (:s3-url (:check check)) :target "_new"} [:i.fa.fa-money-check] (str " " (:check-number (:check check)) " (" (gstring/format "$%.2f" (:amount check) ) ")")])]]))]]]))))

View File

@@ -49,20 +49,36 @@
(re-frame/reg-event-fx
::print-checks
(fn [{:keys [db]} [_ data]]
{:db (assoc-in db [::invoice-page :checked] nil)
:http {:method :post
:token (:user db)
:body (pr-str {:invoice-ids (get-in db [::invoice-page :checked])})
:headers {"Content-Type" "application/edn"}
:uri (str "/api/checks/")
:on-success [::checks-created]
:on-error [::save-error]}}))
{:graphql
{:token (-> db :user)
:query-obj {:venia/operation {:operation/type :mutation
:operation/name "PrintChecks"}
:venia/queries [[:print-checks
{:invoice_ids (vec (get-in db [::invoice-page :checked]))}
[[:invoices [:id [:checks [:amount [:check [:amount :s3_url :check_number ]]]]]
]
:pdf_url]]]}
:on-success [::checks-created]}}))
(re-frame/reg-event-fx
::checks-created
(fn [{:keys [db]} [_ data]]
{:new-window (:url data)
}))
(let [{{:keys [pdf-url invoices]} :print-checks} data
invoices-by-id (reduce
(fn [x a]
(assoc x (:id a) a))
{}
invoices)]
{:new-window pdf-url
:db (-> db
(update-in [::invoice-page :invoices]
(fn [invoices]
(map (fn [i]
(merge i (invoices-by-id (:id i))))
invoices)))
(assoc-in [::invoice-page :checked] nil))})))
(re-frame/reg-event-fx
::invalidated