Prevents errors from multiple dialogs open

This commit is contained in:
Bryce
2024-03-29 11:14:30 -07:00
parent d34e125b6f
commit a8e1a15393
3 changed files with 22 additions and 28 deletions

View File

@@ -41,8 +41,9 @@
[:input (merge {:id "checkbox-all", :type "checkbox", :class inputs/default-checkbox-classes :name (:name params) :value (:value params)} params)]
[:label {:for "checkbox-all", :class "sr-only"} "checkbox"]]])
(defn data-grid- [{:keys [headers thead-params id]} & rest]
[:table {:class "w-full text-sm text-left text-gray-500 dark:text-gray-400" :id id}
(defn data-grid- [{:keys [headers thead-params id] :as params} & rest]
[:table (merge {:class "w-full text-sm text-left text-gray-500 dark:text-gray-400"}
(dissoc params :headers :thead-params))
[:thead (assoc thead-params :class "text-xs text-gray-800 uppercase bg-gray-50 dark:bg-gray-700 dark:text-gray-400")
(into
[:tr]

View File

@@ -596,8 +596,6 @@
})
[:headers "hx-trigger"] "invalidated")))))
(def new-wizard (->NewWizard2 nil nil))

View File

@@ -39,7 +39,7 @@
dissoc-nil-transformer entity-id html-response
main-transformer modal-response money ref->enum-schema
round-money strip wrap-entity wrap-implied-route-param
wrap-merge-prior-hx wrap-schema-enforce]]
wrap-merge-prior-hx wrap-schema-enforce form-validation-error assert-schema]]
[auto-ap.time :as atime]
[auto-ap.utils :refer [by dollars=]]
[bidi.bidi :as bidi]
@@ -642,8 +642,9 @@
(and (< outstanding-balance 0)
(< amount outstanding-balance))
(and (< outstanding-balance 0)
(>= amount 0)))))
(>= amount 0))
(and (= outstanding-balance 0.0)
(not= amount 0.0)))))
(def payment-form-schema
(mc/schema
@@ -663,6 +664,7 @@
(map :invoice-id invoices))
(into {}))]
(every? (fn [%]
(println "TEST" (:amount %) (outstanding-balances (:invoice-id %)))
(not (does-amount-exceed-outstanding? (:amount %) (outstanding-balances (:invoice-id %)))))
invoices)))]]]
[:has-warning? :boolean]
@@ -838,7 +840,7 @@
[])
(step-schema [_]
(mut/select-keys (mm/form-schema linear-wizard) #{:invoices :check-number :handwritten-date}))
(mut/select-keys (mm/form-schema linear-wizard) #{:invoices :check-number :handwritten-date :mode}))
(render-step [this request]
(mm/default-render-step
@@ -877,15 +879,16 @@
(format "Pay in full ($%,.2f)" total)))}
{:value "advanced"
:content "Customize payments"}]})
[:div.space-y-4 (hx/alpine-appear {:x-show "mode==\"advanced\""})
[:div.space-y-4
(fc/with-field :invoices
(com/validated-field
{:errors (fc/field-errors)}
(com/data-grid
{:headers [(com/data-grid-header {} "Vendor")
(com/data-grid-header {} "Invoice Number")
(com/data-grid-header {:class "text-right"} "Total")
(com/data-grid-header {:class "text-right"} "Pay")]}
(hx/alpine-appear {:headers [(com/data-grid-header {} "Vendor")
(com/data-grid-header {} "Invoice Number")
(com/data-grid-header {:class "text-right"} "Total")
(com/data-grid-header {:class "text-right"} "Pay")]
:x-show "mode==\"advanced\""})
(fc/cursor-map
(fn [i]
(com/data-grid-row
@@ -945,16 +948,6 @@
(doseq [[_ i] (:tempids result)]
(solr/touch-with-ledger i)))))
;; TODO Payment validations
;; 1. ensure that filtering for selected ids happens again
;; at the end of the modal to prevent race conditions
;; add validation to prevent overpaying
;; Paying a completed invoice is allowed presently
;; Thought is to put it into the pay function itself
;; balance should only go to negative if total was negative
;; balance should stay positive if total was positive
;; NOTE: payable-ids function could be used.
;; TODO support crediting from balance
(defrecord PayWizard [form-params current-step invoice-by-id]
mm/LinearModalWizard
@@ -1029,14 +1022,16 @@
payment-form-schema
(:snapshot multi-form-state)
mt/strip-extra-keys-transformer)
_ (assert-schema payment-form-schema snapshot)
_ (exception->4xx
#(if (= :handwrite-check (:method snapshot))
(when (or (not (some? (:check-number snapshot)))
(= "" (:check-number snapshot)))
(throw (Exception. "Check number is required")))
true))
;; TODO just confirm that the outstanding balances haven't been surpassed
;; and that the invoices are still pending
result (exception->4xx
#(if (= :handwrite-check (:method snapshot))
(add-handwritten-check request this snapshot)
@@ -1131,7 +1126,7 @@
(def key->handler
(apply-middleware-to-all-handlers
(->
(->
{::route/all-page (-> (helper/page-route grid-page)
(wrap-implied-route-param :status nil))
::route/paid-page (-> (helper/page-route grid-page)
@@ -1154,7 +1149,7 @@
(mm/wrap-wizard pay-wizard)
(mm/wrap-init-multi-form-state initial-pay-wizard-state))
::route/pay-submit (-> mm/submit-handler
(mm/wrap-wizard pay-wizard)
@@ -1165,7 +1160,7 @@
(mm/wrap-decode-multi-form-state))
::route/table (helper/table-route grid-page)}
(merge new-invoice-wizard/key->handler))
(merge new-invoice-wizard/key->handler))
(fn [h]
(-> h
(wrap-status-from-source)