preventing submits.
This commit is contained in:
@@ -100,6 +100,35 @@
|
||||
.modal {
|
||||
animation: appear .7s ease both;
|
||||
}
|
||||
@keyframes grow-width {
|
||||
from {
|
||||
width: 0px;
|
||||
opacity: 0;
|
||||
}
|
||||
}
|
||||
@keyframes shrink-width {
|
||||
to {
|
||||
width: 0px;
|
||||
opacity: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.slide-in-right {
|
||||
animation: grow-width 0.5s ease both;
|
||||
}
|
||||
.slide-in-right div {
|
||||
width: 1000px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.slide-out-right {
|
||||
animation: shrink-width 0.5s ease both;
|
||||
}
|
||||
.slide-out-right div {
|
||||
width: 1000px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.inbox-messages {
|
||||
animation: scaleUp .3s ease both;
|
||||
}
|
||||
|
||||
@@ -84,6 +84,11 @@
|
||||
:invoice/client (:db/id (:invoice/client invoice))})
|
||||
println))
|
||||
(throw (ex-info (str "Invoice '" invoice_number "' already exists.") {:invoice-number invoice_number})))
|
||||
|
||||
expense-account-total (reduce + 0 (map (fn [x] (Double/parseDouble (:amount x))) expense_accounts))
|
||||
_ (when (not= total expense-account-total)
|
||||
(let [error (str "Expense account total (" expense-account-total ") does not equal invoice total (" total ")")]
|
||||
(throw (ex-info error {:validation-error error}))))
|
||||
paid-amount (- (:invoice/total invoice) (:invoice/outstanding-balance invoice))
|
||||
_ (assert-can-see-client (:id context) (:db/id (:invoice/client invoice)))
|
||||
updated-invoice (d-invoices/update {:db/id id
|
||||
|
||||
@@ -84,7 +84,7 @@
|
||||
(defn appearing-side-bar [{:keys [visible?]} & children ]
|
||||
(let [final-state (reagent/atom visible?)]
|
||||
(fn [{:keys [visible?]} & children]
|
||||
[css-transition-group {:in visible? :class-names {:exitDone "bounce animated" :exit "fadeOutRight animated" :enter "fadeInRight animated"} :timeout 300 :onEnter (fn [] (reset! final-state true )) :onExited (fn [] (reset! final-state false))}
|
||||
[css-transition-group {:in visible? :class-names {:exitDone "bounce animated" :exit "slide-out-right" :enter "slide-in-right"} :timeout 500 :onEnter (fn [] (reset! final-state true )) :onExited (fn [] (reset! final-state false))}
|
||||
(if (or @final-state visible?)
|
||||
[:aside {:class "column is-3 aside menu" :style {:height "calc(100vh - 46px)" :overflow "auto"}}
|
||||
[:div.sub-main {} children ]]
|
||||
|
||||
@@ -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