improvements
This commit is contained in:
@@ -21,8 +21,8 @@
|
||||
[auto-ap.ssr.utils
|
||||
:refer [apply-middleware-to-all-handlers
|
||||
entity-id
|
||||
forced-vector
|
||||
html-response
|
||||
many-entity
|
||||
map->db-id-decoder
|
||||
ref->enum-schema
|
||||
ref->select-options
|
||||
@@ -135,16 +135,16 @@
|
||||
:action-buttons (fn [request]
|
||||
[(com/button {:hx-get (str (bidi/path-for ssr-routes/only-routes
|
||||
:admin-account-new-dialog))
|
||||
:hx-target "#modal-holder"
|
||||
:hx-swap "outerHTML"
|
||||
:hx-target "#modal-content"
|
||||
:hx-swap "innerHTML"
|
||||
:color :primary}
|
||||
"New Account")])
|
||||
:row-buttons (fn [request entity]
|
||||
[(com/icon-button {:hx-get (str (bidi/path-for ssr-routes/only-routes
|
||||
:admin-account-edit-dialog
|
||||
:db/id (:db/id entity)))
|
||||
:hx-target "#modal-holder"
|
||||
:hx-swap "outerHTML"}
|
||||
:hx-target "#modal-content"
|
||||
:hx-swap "innerHTML"}
|
||||
svg/pencil)])
|
||||
:breadcrumbs [[:a {:href (bidi/path-for ssr-routes/only-routes
|
||||
:admin)}
|
||||
@@ -207,22 +207,26 @@
|
||||
"account_client_override_id" (:db/id o)})))
|
||||
(html-response
|
||||
(row* identity updated-account {:flash? true})
|
||||
:headers {"hx-trigger" "closeModal"
|
||||
:headers {"hx-trigger" "modalclose"
|
||||
"hx-retarget" (format "#account-table tr[data-id=\"%d\"]" (:db/id updated-account))})))
|
||||
|
||||
;; TODO use cursor
|
||||
;; TODO index based list not dbid
|
||||
|
||||
(defn client-override* [override]
|
||||
(defn client-override* [override index]
|
||||
[:div.flex.gap-2.mb-2.client-override
|
||||
[:div.w-96
|
||||
(com/typeahead {:name (format "account/client-overrides[%s][account-client-override/client]" (:db/id override))
|
||||
:placeholder "Search..."
|
||||
:url (bidi/path-for ssr-routes/only-routes
|
||||
:company-search)
|
||||
:id (str "account-client-override-" (:db/id override))
|
||||
:value [(:db/id (:account-client-override/client override))
|
||||
(:client/name (:account-client-override/client override))]})]
|
||||
(com/hidden {:name (format "account/client-overrides[%s][db/id]" index)
|
||||
:value (:db/id override)})
|
||||
(com/typeahead-2 {:name (format "account/client-overrides[%s][account-client-override/client]" index)
|
||||
:placeholder "Search..."
|
||||
:url (bidi/path-for ssr-routes/only-routes
|
||||
:company-search)
|
||||
:id (str "account-client-override-" (:db/id override))
|
||||
:value [(:db/id (:account-client-override/client override))
|
||||
(:client/name (:account-client-override/client override))]})]
|
||||
[:div.w-96
|
||||
(com/text-input {:name (format "account/client-overrides[%s][account-client-override/name]" (:db/id override))
|
||||
(com/text-input {:name (format "account/client-overrides[%s][account-client-override/name]" index)
|
||||
:class "w-full"
|
||||
:value (:account-client-override/name override)})]
|
||||
[:div (com/a-icon-button {"_" (hiccup/raw "on click halt the event then transition the closest <.client-override />'s opacity to 0 then remove closest <.client-override />") } svg/x)]])
|
||||
@@ -230,7 +234,7 @@
|
||||
|
||||
(defn dialog* [& {:keys [ account form-params]}]
|
||||
(com/modal
|
||||
{:modal-class "max-w-4xl"}
|
||||
{}
|
||||
[:form#edit-form (merge {:hx-ext "response-targets"
|
||||
:hx-swap "outerHTML swap:300ms"
|
||||
:hx-target-400 "#form-errors .error-content"}
|
||||
@@ -282,33 +286,37 @@
|
||||
:options (ref->select-options "account-applicability")}))
|
||||
|
||||
(com/field {:label "Client Overrides" :id "client-overrides"}
|
||||
(for [override (:account/client-overrides account)]
|
||||
(client-override* override)))
|
||||
(for [[override index] (map vector (:account/client-overrides account) (range))]
|
||||
(client-override* override index)))
|
||||
(com/a-button {:hx-get (bidi/path-for ssr-routes/only-routes
|
||||
:admin-account-client-override-new)
|
||||
:hx-target "#client-overrides"
|
||||
:hx-swap "beforeend"}
|
||||
:admin-account-client-override-new)
|
||||
:hx-vals (hiccup/raw "js:{index: document.getElementById('client-overrides').children.length - 1}")
|
||||
:hx-target "#client-overrides"
|
||||
:hx-swap "beforeend"}
|
||||
"New override")
|
||||
[:div#form-errors [:span.error-content]]
|
||||
(com/button {:color :primary :form "edit-form" :type "submit"}
|
||||
"Save")]
|
||||
[:div])]]))
|
||||
]
|
||||
(com/validated-save-button {:errors []}
|
||||
"Save account"))]]))
|
||||
|
||||
(defn new-client-override [_]
|
||||
(defn new-client-override [{ {:keys [index]} :query-params}]
|
||||
(html-response
|
||||
(client-override* {:db/id (str (java.util.UUID/randomUUID))})))
|
||||
(client-override* {:db/id (str (java.util.UUID/randomUUID))}
|
||||
index)))
|
||||
|
||||
(defn account-edit-dialog [request]
|
||||
(let [account (some-> request :route-params :db/id (#(dc/pull (dc/db conn) default-read %)))]
|
||||
(html-response (dialog* :account account
|
||||
:form-params {:hx-put (str (bidi/path-for ssr-routes/only-routes
|
||||
:admin-account-edit-save))}))))
|
||||
:admin-account-edit-save))})
|
||||
:headers {"hx-trigger" "modalopen"})))
|
||||
|
||||
|
||||
(defn account-new-dialog [_]
|
||||
(html-response (dialog* :account nil
|
||||
:form-params {:hx-post (str (bidi/path-for ssr-routes/only-routes
|
||||
:admin-account-new-save))})))
|
||||
:admin-account-new-save))})
|
||||
:headers {"hx-trigger" "modalopen"}))
|
||||
|
||||
(def account-schema (mc/schema
|
||||
[:map
|
||||
@@ -320,20 +328,23 @@
|
||||
[:account/applicability (ref->enum-schema "account-applicability")]
|
||||
[:account/invoice-allowance (ref->enum-schema "allowance")]
|
||||
[:account/vendor-allowance (ref->enum-schema "allowance")]
|
||||
[:account/client-overrides {:decode/json map->db-id-decoder
|
||||
:optional true}
|
||||
[:account/client-overrides {:optional true}
|
||||
[:maybe
|
||||
(forced-vector [:map
|
||||
[:db/id [:or entity-id temp-id]]
|
||||
[:account-client-override/client [:or entity-id :string]]
|
||||
[:account-client-override/name :string]])]]]))
|
||||
(many-entity {}
|
||||
[:db/id [:or entity-id temp-id]]
|
||||
[:account-client-override/client [:or entity-id :string]]
|
||||
[:account-client-override/name :string])]]]))
|
||||
|
||||
(def key->handler
|
||||
(apply-middleware-to-all-handlers
|
||||
(->>
|
||||
{:admin-accounts (helper/page-route grid-page)
|
||||
:admin-account-table (helper/table-route grid-page)
|
||||
:admin-account-client-override-new (-> new-client-override wrap-admin wrap-client-redirect-unauthenticated)
|
||||
:admin-account-client-override-new (-> new-client-override
|
||||
(wrap-schema-decode :query-schema [:map
|
||||
[:index {:optional true
|
||||
:default 0} [nat-int? {:default 0}]]])
|
||||
wrap-admin wrap-client-redirect-unauthenticated)
|
||||
:admin-account-save (-> account-save
|
||||
(wrap-schema-decode :form-schema account-schema)
|
||||
(wrap-nested-form-params)
|
||||
|
||||
@@ -193,7 +193,7 @@
|
||||
[(com/button {:hx-get (str (bidi/path-for ssr-routes/only-routes
|
||||
:admin-transaction-rule-new-dialog))
|
||||
:hx-target "#modal-content"
|
||||
:hx-swap "outerHTML"
|
||||
:hx-swap "innerHTML"
|
||||
:color :primary}
|
||||
"New Transaction Rule")])
|
||||
:row-buttons (fn [request entity]
|
||||
@@ -201,7 +201,7 @@
|
||||
:admin-transaction-rule-edit-dialog
|
||||
:db/id (:db/id entity)))
|
||||
:hx-target "#modal-content"
|
||||
:hx-swap "outerHTML"}
|
||||
:hx-swap "innerHTML"}
|
||||
svg/pencil)])
|
||||
:breadcrumbs [[:a {:href (bidi/path-for ssr-routes/only-routes
|
||||
:admin)}
|
||||
@@ -581,10 +581,7 @@
|
||||
[:div#form-errors (when (:errors fc/*form-errors*)
|
||||
[:span.error-content
|
||||
(com/errors {:errors (:errors fc/*form-errors*)})])]])]
|
||||
[:div (com/button {:color :primary :form "edit-form" :type "submit" :class (cond-> "w-32"
|
||||
(seq form-errors) (->
|
||||
(hh/add-class "animate-shake")))}
|
||||
"Save")])]))
|
||||
(com/validated-save-button {:errors form-errors} "Save rule"))]))
|
||||
|
||||
|
||||
;; TODO Should forms have some kind of helper to render an individual field? saving
|
||||
|
||||
Reference in New Issue
Block a user