preventing submits.
This commit is contained in:
@@ -285,43 +285,45 @@
|
||||
(re-frame/reg-event-fx
|
||||
::create-invoice
|
||||
(fn [{:keys [db]} _]
|
||||
(let [{:keys [data]} @(re-frame/subscribe [::forms/form ::new-invoice])]
|
||||
{:graphql
|
||||
{:token (-> db :user)
|
||||
:query-obj {:venia/operation {:operation/type :mutation
|
||||
:operation/name "AddInvoice"}
|
||||
|
||||
:venia/queries [{:query/data [:add-invoice
|
||||
{:invoice {:date (:date data)
|
||||
:vendor-id (:vendor-id data)
|
||||
:client-id (:client-id data)
|
||||
:invoice-number (:invoice-number data)
|
||||
:location (:location data)
|
||||
:total (:total data)
|
||||
}}
|
||||
invoice-read]}]}
|
||||
:on-success [::invoice-created]
|
||||
:on-error [::forms/save-error ::new-invoice]}})))
|
||||
(when @(re-frame/subscribe [::can-submit-edit-invoice])
|
||||
(let [{:keys [data]} @(re-frame/subscribe [::forms/form ::new-invoice])]
|
||||
{:graphql
|
||||
{:token (-> db :user)
|
||||
:query-obj {:venia/operation {:operation/type :mutation
|
||||
:operation/name "AddInvoice"}
|
||||
|
||||
:venia/queries [{:query/data [:add-invoice
|
||||
{:invoice {:date (:date data)
|
||||
:vendor-id (:vendor-id data)
|
||||
:client-id (:client-id data)
|
||||
:invoice-number (:invoice-number data)
|
||||
:location (:location data)
|
||||
:total (:total data)
|
||||
}}
|
||||
invoice-read]}]}
|
||||
:on-success [::invoice-created]
|
||||
:on-error [::forms/save-error ::new-invoice]}}))))
|
||||
|
||||
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::edit-invoice-saving
|
||||
(fn [{:keys [db]} _]
|
||||
(let [{{:keys [date total invoice-number id expense-accounts]} :data} @(re-frame/subscribe [::forms/form ::new-invoice])]
|
||||
{:graphql
|
||||
{:token (-> db :user)
|
||||
:query-obj {:venia/operation {:operation/type :mutation
|
||||
:operation/name "EditInvoice"}
|
||||
|
||||
:venia/queries [{:query/data [:edit-invoice
|
||||
{:invoice {:id id :invoice-number invoice-number :date date :total total :expense-accounts (map (fn [ea]
|
||||
{:id (:id ea)
|
||||
:amount (:amount ea)})
|
||||
expense-accounts)}}
|
||||
invoice-read]}]}
|
||||
:on-success [::invoice-edited]
|
||||
:on-error [::forms/save-error ::new-invoice]}})))
|
||||
(when @(re-frame/subscribe [::can-submit-edit-invoice])
|
||||
(let [{{:keys [date total invoice-number id expense-accounts]} :data} @(re-frame/subscribe [::forms/form ::new-invoice])]
|
||||
{:graphql
|
||||
{:token (-> db :user)
|
||||
:query-obj {:venia/operation {:operation/type :mutation
|
||||
:operation/name "EditInvoice"}
|
||||
|
||||
:venia/queries [{:query/data [:edit-invoice
|
||||
{:invoice {:id id :invoice-number invoice-number :date date :total total :expense-accounts (map (fn [ea]
|
||||
{:id (:id ea)
|
||||
:amount (:amount ea)})
|
||||
expense-accounts)}}
|
||||
invoice-read]}]}
|
||||
:on-success [::invoice-edited]
|
||||
:on-error [::forms/save-error ::new-invoice]}}))))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::unvoid-invoice
|
||||
@@ -499,6 +501,18 @@
|
||||
:max outstanding-balance
|
||||
:step "0.01"}]]]]]])]]])))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::can-submit-edit-invoice
|
||||
:<- [::forms/form ::new-invoice]
|
||||
(fn [{:keys [data]} _]
|
||||
(let [min-total (if (= (:total (:original data)) (:outstanding-balance (:original data)))
|
||||
nil
|
||||
(- (:total (:original data)) (:outstanding-balance (:original data))))]
|
||||
(and (s/valid? ::invoice/invoice data)
|
||||
(or (not min-total) (>= (:total data) min-total))
|
||||
(or (not (:id data))
|
||||
(< (.abs js/Math (- (js/parseFloat (:total data)) (reduce + 0 (map (fn [ea] (js/parseFloat (:amount ea))) (:expense-accounts data))))) 0.001))))))
|
||||
|
||||
(defn handwrite-checks-modal []
|
||||
(let [{:keys [checked]} @(re-frame/subscribe [::invoice-page])
|
||||
{:keys [invoice] :as handwrite-checks} @(re-frame/subscribe [::handwrite-checks])
|
||||
@@ -688,10 +702,7 @@
|
||||
|
||||
|
||||
|
||||
[:submit.button.is-large.is-primary {:disabled (if (and (s/valid? ::invoice/invoice data)
|
||||
(or (not min-total) (>= (:total data) min-total))
|
||||
(or (not exists?)
|
||||
(< (.abs js/Math (- (js/parseFloat (:total data)) (reduce + 0 (map (fn [ea] (js/parseFloat (:amount ea))) (:expense-accounts data))))) 0.001)))
|
||||
[:submit.button.is-large.is-primary {:disabled (if (doto @(re-frame/subscribe [::can-submit-edit-invoice]) println)
|
||||
""
|
||||
"disabled")
|
||||
:on-click (fn [e]
|
||||
|
||||
Reference in New Issue
Block a user