Makes an okay experience of editing vendors through a wizard
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -1,5 +1,6 @@
|
||||
normal
|
||||
6/16/17 Acme Bread DEMO-CB 3/26/56 12:00 AM $54.00 Naschmarkt X 7/31/17 8:26 AM 8/1/17 3:57 PM 116
|
||||
6/16/2017 Acme Bread DEMO-CB 3/26/56 12:00 AM $54.00 Naschmarkt X 7/31/17 8:26 AM 8/1/17 3:57 PM 116
|
||||
6/16/2017 GirlzWurk SGMF-SG 2 cases honey $54.00 Saratoga Meat & Fish X 7/31/17 8:26 AM 8/1/17 3:57 PM 116
|
||||
|
||||
normal
|
||||
6/16/17 Acme Bread DEMO-CB 3/26/56 12:00 AM $54.00 Naschmarkt X 7/31/17 8:26 AM 8/1/17 3:57 PM 4500
|
||||
|
||||
|
@@ -19,3 +19,11 @@
|
||||
|
||||
(defmacro error [x & kvs]
|
||||
`(mu/log ~x :status "ERROR" ~@kvs ))
|
||||
|
||||
(defn peek
|
||||
([x]
|
||||
(info ::peek :entity x)
|
||||
x)
|
||||
([y x]
|
||||
(info y :entity x)
|
||||
x))
|
||||
|
||||
621
src/clj/auto_ap/ssr/admin/vendors.clj
Normal file
621
src/clj/auto_ap/ssr/admin/vendors.clj
Normal file
@@ -0,0 +1,621 @@
|
||||
(ns auto-ap.ssr.admin.vendors
|
||||
(:require
|
||||
[auto-ap.datomic
|
||||
:refer [add-sorter-fields
|
||||
apply-pagination
|
||||
apply-sort-3
|
||||
audit-transact
|
||||
conn
|
||||
merge-query
|
||||
pull-attr
|
||||
pull-many
|
||||
query2]]
|
||||
[auto-ap.routes.admin.vendors :as route]
|
||||
[auto-ap.query-params :as query-params]
|
||||
[auto-ap.routes.utils
|
||||
:refer [wrap-admin wrap-client-redirect-unauthenticated]]
|
||||
[auto-ap.solr :as solr]
|
||||
[auto-ap.ssr-routes :as ssr-routes]
|
||||
[auto-ap.ssr.components :as com]
|
||||
[auto-ap.ssr.form-cursor :as fc]
|
||||
[auto-ap.ssr.grid-page-helper :as helper]
|
||||
[auto-ap.ssr.hx :as hx]
|
||||
[auto-ap.ssr.nested-form-params :refer [wrap-nested-form-params]]
|
||||
[auto-ap.ssr.svg :as svg]
|
||||
[auto-ap.ssr.utils
|
||||
:refer [apply-middleware-to-all-handlers
|
||||
entity-id
|
||||
field-validation-error
|
||||
form-validation-error
|
||||
html-response
|
||||
main-transformer
|
||||
many-entity
|
||||
modal-response
|
||||
ref->enum-schema
|
||||
ref->select-options
|
||||
strip
|
||||
temp-id
|
||||
wrap-entity
|
||||
wrap-form-4xx-2
|
||||
wrap-schema-decode]]
|
||||
[bidi.bidi :as bidi]
|
||||
[clojure.string :as str]
|
||||
[datomic.api :as dc]
|
||||
[malli.core :as mc]
|
||||
[auto-ap.ssr.hiccup-helper :as hh]
|
||||
[auto-ap.logging :as alog]
|
||||
[auto-ap.cursor :as cursor]))
|
||||
|
||||
(defn filters [request]
|
||||
[:form {"hx-trigger" "change delay:500ms, keyup changed from:.hot-filter delay:1000ms"
|
||||
"hx-get" (bidi/path-for ssr-routes/only-routes
|
||||
::route/table)
|
||||
"hx-target" "#entity-table"
|
||||
"hx-indicator" "#entity-table"}
|
||||
|
||||
[:fieldset.space-y-6
|
||||
(com/field {:label "Name"}
|
||||
(com/text-input {:name "name"
|
||||
:id "name"
|
||||
:class "hot-filter"
|
||||
:value (:name (:parsed-query-params request))
|
||||
:placeholder "Cash"
|
||||
:size :small}))
|
||||
(com/field {:label "Type"}
|
||||
(com/radio {:size :small
|
||||
:name "type"
|
||||
:value (:type (:parsed-query-params request))
|
||||
:options [{:value ""
|
||||
:content "All"}
|
||||
{:value "only-hidden"
|
||||
:content "Only hidden"}
|
||||
{:value "only-global"
|
||||
:content "Only global"}
|
||||
#_{:value "potential-duplicates"
|
||||
:content "Potential duplicates"}]}))]])
|
||||
|
||||
(def default-read '[:db/id
|
||||
:vendor/name
|
||||
:vendor/print-as
|
||||
:vendor/hidden
|
||||
:vendor/terms
|
||||
:vendor/legal-entity-tin
|
||||
:vendor/legal-entity-name
|
||||
:vendor/legal-entity-first-name
|
||||
:vendor/legal-entity-middle-name
|
||||
:vendor/legal-entity-last-name
|
||||
{:vendor/primary-contact [:contact/email :contact/first-name :contact/middle-name :contact/last-name]
|
||||
:vendor/address [:address/street1 :address/street2 :address/city :address/state :address/zip]
|
||||
:vendor/terms-overrides [:vendor-terms-override/terms {:vendor-terms-override/client [:client/name :db/id]}]
|
||||
:vendor/account-overrides [{:vendor-terms-override/account [:account/name :db/id]
|
||||
:vendor-terms-override/client [:client/name :db/id]}]
|
||||
:vendor/default-account [:account/name :account/numeric-code :db/id]
|
||||
[:vendor-usage/_vendor :as :vendor/usage] [:vendor-usage/client :vendor-usage/count]
|
||||
[:vendor/legal-entity-1099-type :xform iol-ion.query/ident] [:db/ident]
|
||||
[:vendor/legal-entity-tin-type :xform iol-ion.query/ident] [:db/ident]}])
|
||||
|
||||
(defn fetch-ids [db request]
|
||||
(let [query-params (:parsed-query-params request)
|
||||
query (cond-> {:query {:find []
|
||||
:in '[$ ]
|
||||
:where '[]}
|
||||
:args [db ]}
|
||||
(:sort query-params) (add-sorter-fields {"name" ['[?e :vendor/name ?n]
|
||||
'[(clojure.string/upper-case ?n) ?sort-name]]}
|
||||
query-params)
|
||||
(some->> query-params :name not-empty)
|
||||
(merge-query {:query {:find []
|
||||
:in ['?ns]
|
||||
:where ['[?e :vendor/name ?an]
|
||||
'[(clojure.string/upper-case ?an) ?upper-an]
|
||||
'[(clojure.string/includes? ?upper-an ?ns)]]}
|
||||
:args [(str/upper-case (:name query-params))]})
|
||||
|
||||
(some->> query-params :type not-empty (= "only-hidden"))
|
||||
(merge-query {:query {:find []
|
||||
:in []
|
||||
:where ['[?e :vendor/hidden true]
|
||||
]}
|
||||
:args []})
|
||||
(some->> query-params :type not-empty (= "only-global"))
|
||||
(merge-query {:query {:find []
|
||||
:in []
|
||||
:where ['[?e :vendor/hidden false]]}
|
||||
:args []})
|
||||
|
||||
true
|
||||
(merge-query {:query {:find ['?sort-default '?e]
|
||||
:where ['[?e :vendor/name ?un]
|
||||
'[(clojure.string/upper-case ?un) ?sort-default]]}}))]
|
||||
(cond->> (query2 query)
|
||||
true (apply-sort-3 query-params)
|
||||
true (apply-pagination query-params))))
|
||||
|
||||
(defn hydrate-results [ids db _]
|
||||
(let [results (->> (pull-many db default-read ids)
|
||||
(group-by :db/id))
|
||||
refunds (->> ids
|
||||
(map results)
|
||||
(map first))]
|
||||
refunds))
|
||||
|
||||
(defn fetch-page [request]
|
||||
(let [db (dc/db conn)
|
||||
{ids-to-retrieve :ids matching-count :count} (fetch-ids db request)]
|
||||
|
||||
[(->> (hydrate-results ids-to-retrieve db request))
|
||||
matching-count]))
|
||||
|
||||
(def grid-page
|
||||
(helper/build {:id "entity-table"
|
||||
:nav (com/admin-aside-nav)
|
||||
:page-specific-nav filters
|
||||
:fetch-page fetch-page
|
||||
:parse-query-params (comp
|
||||
(query-params/parse-key :code query-params/parse-long)
|
||||
(helper/default-parse-query-params grid-page))
|
||||
:action-buttons (fn [_]
|
||||
[(com/button {:hx-get (str (bidi/path-for ssr-routes/only-routes
|
||||
::route/new))
|
||||
:color :primary}
|
||||
"New Vendor")])
|
||||
:row-buttons (fn [_ entity]
|
||||
[(com/icon-button {:hx-get (str (bidi/path-for ssr-routes/only-routes
|
||||
::route/edit
|
||||
:db/id (:db/id entity)))}
|
||||
svg/pencil)])
|
||||
:breadcrumbs [[:a {:href (bidi/path-for ssr-routes/only-routes
|
||||
:admin)}
|
||||
"Admin"]
|
||||
|
||||
[:a {:href (bidi/path-for ssr-routes/only-routes
|
||||
::route/page)}
|
||||
"Vendors"]]
|
||||
:title "Vendors"
|
||||
:entity-name "Vendor"
|
||||
:route ::route/table
|
||||
:headers [{:key "name"
|
||||
:name "Name"
|
||||
:sort-key "name"
|
||||
:render (fn [entity]
|
||||
(let [client-usage (count (:vendor/usage entity))
|
||||
total-usage (reduce + 0 (map :vendor-usage/count (:vendor/usage entity)))]
|
||||
[:div.flex.gap-x-2.flex-wrap
|
||||
[:div (:vendor/name entity)]
|
||||
[:div (if (= client-usage 0)
|
||||
(com/pill {:color :red}
|
||||
"Unused")
|
||||
|
||||
(com/pill {:color :primary}
|
||||
(format "Used by %d clients" client-usage)))]
|
||||
(when (> client-usage 0)
|
||||
[:div (com/pill {:color :secondary}
|
||||
(format "Used %d times" total-usage))])]))}
|
||||
|
||||
{:key "email"
|
||||
:name "Email"
|
||||
:sort-key "email"
|
||||
:render #(some-> % :vendor/primary-contact :contact/email)}
|
||||
{:key "default-account"
|
||||
:name "Default Account"
|
||||
:sort-key "default-account"
|
||||
:render #(some-> % :vendor/default-account :account/name)}]}))
|
||||
|
||||
(def row* (partial helper/row* grid-page))
|
||||
(def table* (partial helper/table* grid-page))
|
||||
|
||||
(defn save [{:keys [form-params request-method] :as request}]
|
||||
(let [entity (alog/peek (cond-> form-params
|
||||
(= :post request-method) (assoc :db/id "new")))
|
||||
|
||||
|
||||
{:keys [tempids]} (audit-transact [[:upsert-entity entity]]
|
||||
(:identity request))
|
||||
updated-vendor (dc/pull (dc/db conn)
|
||||
default-read
|
||||
(or (get tempids (:db/id entity)) (:db/id entity)))]
|
||||
#_(solr/index-documents-raw solr/impl
|
||||
"accounts"
|
||||
(into [{"id" (:db/id updated-account)
|
||||
"account_id" (:db/id updated-account)
|
||||
"name" (:account/name updated-account)
|
||||
"numeric_code" (:account/numeric-code updated-account)
|
||||
"location" (:account/location updated-account)
|
||||
"applicability" (some-> updated-account :account/applicability clojure.core/name)}]
|
||||
(for [o (:account/client-overrides updated-account)]
|
||||
{"id" (:db/id o)
|
||||
"account_id" (:db/id updated-account)
|
||||
"name" (:account-client-override/name o)
|
||||
"numeric_code" (:account/numeric-code updated-account)
|
||||
"location" (:account/location updated-account)
|
||||
"applicability" (clojure.core/name (:account/applicability updated-account))
|
||||
"client_id" (:db/id (:account-client-override/client o))
|
||||
"account_client_override_id" (:db/id o)})))
|
||||
(html-response
|
||||
(row* identity updated-vendor {:flash? true})
|
||||
:headers (cond-> {"hx-trigger" "modalclose"}
|
||||
(= :post request-method) (assoc "hx-retarget" "#entity-table tbody"
|
||||
"hx-reswap" "afterbegin")
|
||||
(= :put request-method) (assoc "hx-retarget" (format "#entity-table tr[data-id=\"%d\"]" (:db/id updated-vendor)))))))
|
||||
|
||||
#_(defn client-override* [override]
|
||||
(com/data-grid-row (-> {:x-ref "p"
|
||||
:data-key "show"
|
||||
:x-data (hx/json {:show (boolean (doto (not (fc/field-value (:new? override)))
|
||||
println))})}
|
||||
hx/alpine-mount-then-appear)
|
||||
(fc/with-field :db/id
|
||||
(com/hidden {:name (fc/field-name)
|
||||
:value (fc/field-value)}))
|
||||
(fc/with-field :account-client-override/client
|
||||
(com/data-grid-cell {}
|
||||
(com/validated-field {:errors (fc/field-errors)}
|
||||
(com/typeahead {:name (fc/field-name)
|
||||
:placeholder "Search..."
|
||||
:class "w-96"
|
||||
:url (bidi/path-for ssr-routes/only-routes
|
||||
:company-search)
|
||||
:value (fc/field-value)
|
||||
:content-fn #(pull-attr (dc/db conn) :client/name %)}))))
|
||||
(fc/with-field :account-client-override/name
|
||||
(com/data-grid-cell
|
||||
{}
|
||||
(com/validated-field {:errors (fc/field-errors)}
|
||||
(com/text-input {:name (fc/field-name)
|
||||
:class "w-96"
|
||||
:value (fc/field-value)}))))
|
||||
(com/data-grid-cell {:class "align-top"}
|
||||
(com/a-icon-button {"@click.prevent.stop" "show=false; setTimeout(() => $refs.p.remove(), 500)"} svg/x))))
|
||||
|
||||
(defn back-button []
|
||||
[:a {"@click" "$dispatch('modalprevious')"
|
||||
"class" "text-sm font-medium text-gray-700 cursor-pointer"}
|
||||
"Back"])
|
||||
|
||||
(defn dialog* [{:keys [entity form-params form-errors]}]
|
||||
(alog/peek ::dialog-entity form-params)
|
||||
(fc/start-form form-params form-errors
|
||||
[:div {:x-data (hx/json {"vendorName" (or (:vendor/name form-params) (:vendor/name entity))
|
||||
"showPrintAs" (boolean (not-empty (:vendor/print-as form-params)))
|
||||
"printAs" (or (:vendor/print-as form-params) (:vendor/print-as entity))})
|
||||
:class "w-full h-full"}
|
||||
[:form#my-form (-> {:hx-ext "response-targets"
|
||||
:hx-swap "outerHTML swap:300ms"
|
||||
:hx-target-400 "#form-errors .error-content"
|
||||
:hx-trigger "submit"
|
||||
:class "h-full w-full"}
|
||||
(assoc (if (:db/id entity)
|
||||
:hx-put
|
||||
:hx-post)
|
||||
(str (bidi/path-for ssr-routes/only-routes ::route/save))))
|
||||
(com/modal
|
||||
{}
|
||||
(com/stacked-modal-card
|
||||
0
|
||||
{"@keydown.enter.prevent.stop" "$refs.next.click()"}
|
||||
[:div.flex [:div.p-2 "Basic Info"] [:p.ml-2.rounded.bg-gray-200.p-2.dark:bg-gray-600
|
||||
[:span {:x-text "vendorName"}]]]
|
||||
[:div.space-y-1
|
||||
(when-let [id (:db/id entity)]
|
||||
(com/hidden {:name "db/id"
|
||||
:value id}))
|
||||
|
||||
(fc/with-field :vendor/name
|
||||
(com/validated-field {:label "Name"
|
||||
:errors (fc/field-errors)
|
||||
}
|
||||
[:div.flex.items-baseline.space-x-2
|
||||
(com/text-input {:name (fc/field-name)
|
||||
:value (fc/field-value)
|
||||
:x-model "vendorName"
|
||||
:autofocus true
|
||||
:class "w-64"})
|
||||
(com/checkbox {:x-model "showPrintAs" "@change" "if (!showPrintAs) { printAs = ''; } "} "Use different name for checks")]))
|
||||
|
||||
(fc/with-field :vendor/print-as
|
||||
(com/validated-field (-> {:label "Print as"
|
||||
:errors (fc/field-errors)
|
||||
:x-show "showPrintAs"}
|
||||
hx/alpine-appear
|
||||
hx/alpine-disappear)
|
||||
(com/text-input {:name (fc/field-name)
|
||||
:x-model "printAs"
|
||||
:value (fc/field-value)
|
||||
:class "w-64"})))
|
||||
|
||||
(fc/with-field :vendor/hidden
|
||||
(alog/peek (cursor/path fc/*current*))
|
||||
(com/checkbox {:name (fc/field-name)
|
||||
:value (boolean (fc/field-value))
|
||||
:checked (alog/peek :checked (fc/field-value))}
|
||||
"Hidden"))]
|
||||
[:div.flex.justify-end
|
||||
(com/form-errors {:errors (:errors fc/*form-errors*)})
|
||||
[:div.flex.items-baseline.gap-x-4
|
||||
|
||||
(com/validated-save-button {:errors (seq form-errors)
|
||||
:x-ref "next"
|
||||
:class "w-48"
|
||||
"@click.prevent" "$dispatch('modalnext'); console.log($el)"}
|
||||
|
||||
"Terms"
|
||||
[:div.w-5.h-5 svg/arrow-right])]])
|
||||
|
||||
(com/stacked-modal-card
|
||||
1
|
||||
{"@keydown.enter.prevent.stop" "$refs.next.click()"}
|
||||
[:div.flex
|
||||
[:div.p-2 "Vendor Terms"]
|
||||
[:p.ml-2.rounded.bg-gray-200.p-2.dark:bg-gray-600
|
||||
[:span {:x-text "vendorName"}]]]
|
||||
[:div
|
||||
[:div.space-y-1
|
||||
(fc/with-field :vendor/terms
|
||||
(com/validated-field {:label "Terms"
|
||||
:errors (fc/field-errors)}
|
||||
(com/int-input {:name (fc/field-name)
|
||||
:value (fc/field-value)
|
||||
:autofocus true
|
||||
:class "w-24"})))]]
|
||||
[:div.flex.justify-end
|
||||
(com/form-errors {:errors (:errors fc/*form-errors*)})
|
||||
[:div.flex.items-baseline.gap-x-4
|
||||
(back-button)
|
||||
(com/validated-save-button {:errors (seq form-errors)
|
||||
:x-ref "next"
|
||||
:class "w-48"
|
||||
"@click.prevent" "$dispatch('modalnext'); console.log($el)"}
|
||||
|
||||
"Account assignments"
|
||||
[:div.w-5.h-5 svg/arrow-right])]])
|
||||
|
||||
(com/stacked-modal-card
|
||||
2
|
||||
{"@keydown.enter.prevent.stop" "$refs.next.click()"}
|
||||
[:div.flex
|
||||
[:div.p-2 "Vendor Account"]
|
||||
[:p.ml-2.rounded.bg-gray-200.p-2.dark:bg-gray-600
|
||||
[:span {:x-text "vendorName"}]]]
|
||||
[:div
|
||||
[:div.space-y-1
|
||||
(fc/with-field :vendor/default-account
|
||||
(alog/info ::acount-check :a (fc/field-value))
|
||||
(com/validated-field {:label "Default Account"
|
||||
:errors (fc/field-errors)}
|
||||
(com/typeahead {:name (fc/field-name)
|
||||
:error? (fc/error?)
|
||||
:class "w-96"
|
||||
:placeholder "Search..."
|
||||
:url (bidi/path-for ssr-routes/only-routes :account-search)
|
||||
:value (fc/field-value)
|
||||
:content-fn (fn [c] (pull-attr (dc/db conn) :account/name c))})))]]
|
||||
[:div.flex.justify-end
|
||||
(com/form-errors {:errors (:errors fc/*form-errors*)})
|
||||
[:div.flex.items-baseline.gap-x-4
|
||||
(back-button)
|
||||
(com/validated-save-button {:errors (seq form-errors)
|
||||
:x-ref "next"
|
||||
"@click.prevent" "$dispatch('modalnext'); console.log($el)"}
|
||||
|
||||
"Address"
|
||||
[:div.w-5.h-5 svg/arrow-right])]])
|
||||
(com/stacked-modal-card
|
||||
3
|
||||
{"@keydown.enter.prevent.stop" "$refs.next.click()"}
|
||||
[:div.flex ;; TODO standardize how these headers are built
|
||||
[:div.p-2 "Address"]
|
||||
[:p.ml-2.rounded.bg-gray-200.p-2.dark:bg-gray-600
|
||||
[:span {:x-text "vendorName"}]]]
|
||||
[:div.mt-2
|
||||
[:div.space-y-1
|
||||
(fc/with-field :vendor/address
|
||||
[:div.flex.flex-col.w-full
|
||||
(fc/with-field :address/street1
|
||||
(com/validated-field {:label "Street"
|
||||
:errors (fc/field-errors)}
|
||||
(com/text-input {:name (fc/field-name)
|
||||
:error? (fc/error?)
|
||||
:autofocus true
|
||||
:class "w-full"
|
||||
:placeholder "1200 Pennsylvania Avenue"
|
||||
:value (fc/field-value)})))
|
||||
(fc/with-field :address/street2
|
||||
(com/validated-field {:errors (fc/field-errors)}
|
||||
(com/text-input {:name (fc/field-name)
|
||||
:error? (fc/error?)
|
||||
:class "w-full"
|
||||
:placeholder "Suite 300"
|
||||
:value (fc/field-value)})))
|
||||
[:div.flex.w-full.space-x-4
|
||||
(fc/with-field :address/city
|
||||
(com/validated-field {:errors (fc/field-errors)
|
||||
:class "w-full grow shrink"}
|
||||
(com/text-input {:name (fc/field-name)
|
||||
:error? (fc/error?)
|
||||
:class "w-full"
|
||||
:placeholder "Suite 300"
|
||||
:value (fc/field-value)})))
|
||||
(fc/with-field :address/state
|
||||
(com/validated-field {:errors (fc/field-errors)
|
||||
:class "w-16 shrink-0"}
|
||||
(com/text-input {:name (fc/field-name)
|
||||
:error? (fc/error?)
|
||||
:class "w-full"
|
||||
:placeholder "Suite 300"
|
||||
:value (fc/field-value)})))
|
||||
(fc/with-field :address/zip
|
||||
(com/validated-field {:errors (fc/field-errors)
|
||||
:class "w-24 shrink-0"}
|
||||
(com/text-input {:name (fc/field-name)
|
||||
:error? (fc/error?)
|
||||
:placeholder "Suite 300"
|
||||
:class "w-full"
|
||||
:value (fc/field-value)})))]])]]
|
||||
[:div.flex.justify-end
|
||||
(com/form-errors {:errors (:errors fc/*form-errors*)})
|
||||
[:div.flex.items-baseline.gap-x-4
|
||||
(back-button)
|
||||
(com/validated-save-button {:errors (seq form-errors)
|
||||
:x-ref "next"
|
||||
"@click.prevent" "$dispatch('modalnext'); console.log($el)"}
|
||||
|
||||
"Legal Entity"
|
||||
[:div.w-5.h-5 svg/arrow-right])]])
|
||||
(com/stacked-modal-card
|
||||
4
|
||||
{"@keydown.enter.prevent.stop" "$refs.next.click()"}
|
||||
[:div.flex
|
||||
[:div.p-2 "Legal Entity Info"]
|
||||
[:p.ml-2.rounded.bg-gray-200.p-2.dark:bg-gray-600
|
||||
[:span {:x-text "vendorName"}]]]
|
||||
[:div
|
||||
[:div.grid.grid-cols-6.gap-x-4.gap-y-2
|
||||
[:div.col-span-6
|
||||
(fc/with-field :vendor/legal-entity-name
|
||||
(com/validated-field {:label "Legal Entity Name"
|
||||
:errors (fc/field-errors)}
|
||||
(com/text-input {:name (fc/field-name)
|
||||
:class "w-full"
|
||||
:value (fc/field-value)
|
||||
:placeholder "Good Restaurant LLC"})))]
|
||||
[:div.col-span-6.text-center " - OR -"]
|
||||
[:div.col-span-2
|
||||
(fc/with-field :vendor/legal-entity-first-name
|
||||
(com/validated-field {:label "First Name"
|
||||
:errors (fc/field-errors)}
|
||||
(com/text-input {:name (fc/field-name)
|
||||
:value (fc/field-value)
|
||||
:placeholder "John"})))]
|
||||
[:div.col-span-2
|
||||
(fc/with-field :vendor/legal-entity-middle-name
|
||||
(com/validated-field {:label "Middle Name"
|
||||
:errors (fc/field-errors)}
|
||||
(com/text-input {:name (fc/field-name)
|
||||
:value (fc/field-value)
|
||||
:placeholder "C."})))]
|
||||
[:div.col-span-2
|
||||
(fc/with-field :vendor/legal-entity-last-name
|
||||
(com/validated-field {:label "Last Name"
|
||||
:errors (fc/field-errors)}
|
||||
(com/text-input {:name (fc/field-name)
|
||||
:value (fc/field-value)
|
||||
:placeholder "Riley"})))]
|
||||
[:div.col-span-2
|
||||
(fc/with-field :vendor/legal-entity-tin
|
||||
(com/validated-field {:label "TIN"
|
||||
:errors (fc/field-errors)}
|
||||
(com/text-input {:name (fc/field-name)
|
||||
:value (fc/field-value)
|
||||
:placeholder "John"})))]
|
||||
[:div.col-span-2
|
||||
(fc/with-field :vendor/legal-entity-tin-type
|
||||
(com/validated-field {:label "TIN Type"
|
||||
:errors (fc/field-errors)}
|
||||
(com/select {:name (fc/field-name)
|
||||
:allow-blank? true
|
||||
:value (some-> (fc/field-value) name)
|
||||
:options [["ein" "EIN"]
|
||||
["ssn" "SSN"]]})))]
|
||||
[:div.col-span-2
|
||||
(fc/with-field :vendor/legal-entity-1099-type
|
||||
(com/validated-field {:label "1099 Type"
|
||||
:errors (fc/field-errors)}
|
||||
(com/select {:name (fc/field-name)
|
||||
:allow-blank? true
|
||||
:value (some-> (fc/field-value) name)
|
||||
:options (ref->select-options "legal-entity-1099-type")})))]]]
|
||||
[:div.flex.justify-end
|
||||
(com/form-errors {:errors (:errors fc/*form-errors*)})
|
||||
[:div.flex.items-baseline.gap-x-4
|
||||
(back-button)
|
||||
(com/validated-save-button {:errors (seq form-errors)
|
||||
:x-ref "next"}
|
||||
"Save vendor")]]))]]))
|
||||
|
||||
#_(defn new-client-override [{ {:keys [index]} :query-params}]
|
||||
(html-response
|
||||
(fc/start-form-with-prefix
|
||||
[:account/client-overrides (or index 0)]
|
||||
{:db/id (str (java.util.UUID/randomUUID))
|
||||
:new? true}
|
||||
[]
|
||||
(client-override* fc/*current*))))
|
||||
|
||||
(def form-schema (mc/schema
|
||||
[:map
|
||||
[:db/id {:optional true} [:maybe entity-id]]
|
||||
[:vendor/name [:string {:min 3 :decode/string strip}]]
|
||||
[:vendor/print-as {:optional true} [:maybe [:string {:min 3 :decode/string strip}]]]
|
||||
[:vendor/default-account entity-id]
|
||||
[:vendor/terms {:optional true} [:maybe :int]]
|
||||
[:vendor/hidden {:optional true :default false}
|
||||
[:boolean {:decode/string {:enter #(if (= % "on") true (boolean %))}}]] ;; TODO cant turn off
|
||||
[:vendor/address {:optional true}
|
||||
[:maybe [:map
|
||||
[:address/street1 {:optional true} [:maybe [:string {:min 3 :decode/string strip}]] ]
|
||||
[:address/street2 {:optional true} [:maybe [:string {:min 3 :decode/string strip}]] ]
|
||||
[:address/city {:optional true} [:maybe [:string {:min 2 :decode/string strip}]] ]
|
||||
[:address/state {:optional true} [:maybe [:string {:min 2 :max 2 :decode/string strip}]] ]
|
||||
[:address/zip {:optional true} [:maybe [:string {:min 5 :max 5 :decode/string strip}]] ]]]]
|
||||
[:vendor/legal-entity-tin {:optional true} [:maybe [:string {:min 3 :decode/string strip}]]]
|
||||
[:vendor/legal-entity-name {:optional true} [:maybe [:string {:min 3 :decode/string strip}]]]
|
||||
[:vendor/legal-entity-first-name {:optional true} [:maybe [:string {:min 3 :decode/string strip}]]]
|
||||
[:vendor/legal-entity-middle-name {:optional true} [:maybe [:string {:min 3 :decode/string strip}]]]
|
||||
[:vendor/legal-entity-last-name {:optional true} [:maybe [:string {:min 3 :decode/string strip}]]]
|
||||
[:vendor/legal-entity-tin-type {:optional true} [:maybe (ref->enum-schema "legal-entity-tin-type")]]
|
||||
[:vendor/legal-entity-1099-type {:optional true} [:maybe (ref->enum-schema "legal-entity-1099-type")]]]))
|
||||
|
||||
(defn dialog [{:keys [entity form-params form-errors]}]
|
||||
(alog/info ::here :fp entity)
|
||||
(modal-response (dialog* {:entity entity
|
||||
:form-params (or (when (seq form-params)
|
||||
form-params)
|
||||
(when entity
|
||||
(mc/decode form-schema entity main-transformer))
|
||||
{})
|
||||
:form-errors form-errors})))
|
||||
|
||||
(defn terms-dialog [{:keys [entity form-params form-errors]}]
|
||||
(let [form-params (merge {}
|
||||
(when entity
|
||||
(mc/decode form-schema entity main-transformer))
|
||||
(when (seq form-params)
|
||||
form-params))]
|
||||
(html-response
|
||||
|
||||
:headers (-> {}
|
||||
(assoc "hx-trigger-after-settle" "modalnext")
|
||||
(assoc "hx-retarget" ".modal-stack")
|
||||
(assoc "hx-reswap" "beforeend")))))
|
||||
|
||||
|
||||
|
||||
(def key->handler
|
||||
(apply-middleware-to-all-handlers
|
||||
(->>
|
||||
{::route/page (helper/page-route grid-page)
|
||||
::route/table (helper/table-route grid-page)
|
||||
::route/new nil #_ (-> new-client-override
|
||||
(wrap-schema-decode :query-schema [:map
|
||||
[:index {:optional true
|
||||
:default 0} [nat-int? {:default 0}]]])
|
||||
wrap-admin wrap-client-redirect-unauthenticated)
|
||||
::route/save (-> save
|
||||
(wrap-entity [:form-params :db/id] default-read)
|
||||
(wrap-schema-decode :form-schema form-schema)
|
||||
(wrap-nested-form-params)
|
||||
(wrap-form-4xx-2 (wrap-entity dialog [:form-params :db/id] default-read)))
|
||||
::route/edit (-> dialog
|
||||
(wrap-entity [:route-params :db/id] default-read)
|
||||
(wrap-schema-decode :route-schema [:map [:db/id entity-id]]))
|
||||
::route/edit-terms (-> terms-dialog
|
||||
(wrap-entity [:form-params :db/id] default-read)
|
||||
(wrap-schema-decode :form-schema form-schema)
|
||||
(wrap-nested-form-params)
|
||||
(wrap-form-4xx-2 (-> dialog
|
||||
(wrap-entity [:form-params :db/id] default-read))))
|
||||
#_#_:admin-account-new-dialog account-dialog})
|
||||
(fn [h]
|
||||
(-> h
|
||||
(wrap-admin)
|
||||
(wrap-client-redirect-unauthenticated)))))
|
||||
@@ -8,7 +8,8 @@
|
||||
[auto-ap.routes.admin.transaction-rules :as transaction-rules]
|
||||
[auto-ap.ssr.hiccup-helper :as hh]
|
||||
[auto-ap.routes.admin.import-batch :as ib-routes]
|
||||
[auto-ap.routes.admin.excel-invoices :as ei-routes]))
|
||||
[auto-ap.routes.admin.excel-invoices :as ei-routes]
|
||||
[auto-ap.routes.admin.vendors :as v-routes]))
|
||||
|
||||
(defn menu-button- [params & children]
|
||||
[:div
|
||||
@@ -203,9 +204,8 @@
|
||||
"Clients")]
|
||||
[:li
|
||||
(menu-button- {:icon svg/vendors
|
||||
:href (bidi/path-for client-routes/routes
|
||||
:admin-vendors)
|
||||
:target "_new"}
|
||||
:href (bidi/path-for ssr-routes/only-routes
|
||||
::v-routes/page)}
|
||||
"Vendors")]
|
||||
[:li
|
||||
(menu-button- {:icon svg/user
|
||||
|
||||
@@ -6,28 +6,31 @@
|
||||
(defn modal- [params & children]
|
||||
[:div (-> params
|
||||
(assoc "@click.outside" "open=false"
|
||||
:x-data (hx/json {:index 0 :hidingIndex -1 :unexpectedError false})
|
||||
:x-data (hx/json {:index 0 :hidingIndex -1 :unexpectedError false :transitioning false})
|
||||
"x-on:htmx:response-error" "unexpectedError=true"
|
||||
"x-on:htmx:before-request" "unexpectedError=false"
|
||||
:x-ref "modalStack"
|
||||
"@modalnext"
|
||||
"$refs.modalStack.children[index].setAttribute('x-transition:leave-end', '-translate-x-full scale-0 opacity-0' );
|
||||
"@modalnext.window"
|
||||
" $refs.modalStack.children[index].setAttribute('x-transition:leave-end', '-translate-x-full scale-0 opacity-0' );
|
||||
$refs.modalStack.children[index + 1].setAttribute('x-transition:enter-start', 'translate-x-full scale-0 opacity-0' );
|
||||
hidingIndex = index;
|
||||
setTimeout(() => {index ++; hidingIndex = -1 }, 150)"
|
||||
setTimeout(() => {index ++; transitioning=true; hidingIndex = -1; }, 150);
|
||||
setTimeout(() => transitioning=false, 320)"
|
||||
|
||||
"@modalprevious"
|
||||
"$refs.modalStack.children[index].setAttribute('x-transition:leave-end', 'translate-x-full scale-0 opacity-0' );
|
||||
"@modalprevious.window"
|
||||
" $refs.modalStack.children[index].setAttribute('x-transition:leave-end', 'translate-x-full scale-0 opacity-0' );
|
||||
$refs.modalStack.children[index - 1].setAttribute('x-transition:enter-start', '-translate-x-full scale-0 opacity-0' );
|
||||
hidingIndex = index;
|
||||
setTimeout(() => { index --; hidingIndex = -1; }, 150)"
|
||||
setTimeout(() => { index --; hidingIndex = -1; transitioning=true; }, 150);
|
||||
setTimeout(() => transitioning=false, 320)"
|
||||
|
||||
"@modalpop"
|
||||
"$refs.modalStack.children[index].setAttribute('x-transition:leave-end', 'translate-x-full scale-0 opacity-0' );
|
||||
"@modalpop.window"
|
||||
" $refs.modalStack.children[index].setAttribute('x-transition:leave-end', 'translate-x-full scale-0 opacity-0' );
|
||||
$refs.modalStack.children[index - 1].setAttribute('x-transition:enter-start', '-translate-x-full scale-0 opacity-0' );
|
||||
hidingIndex = index;
|
||||
setTimeout(() => index --, 150)
|
||||
setTimeout(() => { $refs.modalStack.removeChild($refs.modalStack.children[index+1]); hidingIndex=-1; }, 300)
|
||||
setTimeout(() => {index --; transitioning=true;}, 150);
|
||||
setTimeout(() => { $refs.modalStack.removeChild($refs.modalStack.children[index+1]); hidingIndex=-1; }, 300);
|
||||
setTimeout(() => transitioning=false, 320)
|
||||
"
|
||||
)
|
||||
(update :class (fnil hh/add-class "") "w-full h-full modal-stack"))
|
||||
@@ -58,6 +61,7 @@
|
||||
{:class "bg-white rounded-lg shadow dark:bg-gray-700 dark:text-white modal-content flex flex-col h-full"
|
||||
:x-data (hx/json {:i index})
|
||||
:x-show "index == i && hidingIndex != i"
|
||||
"x-trap" "index == i && hidingIndex == -1 && !transitioning"
|
||||
"x-transition:enter" "transition duration-150",
|
||||
"x-transition:enter-end" "translate-x-0 scale-100 opacity-100",
|
||||
"x-transition:leave" "transition duration-150",
|
||||
|
||||
@@ -55,7 +55,6 @@
|
||||
[:a {:class (-> (hh/add-class (or (:class params) "") default-input-classes)
|
||||
(hh/add-class "cursor-pointer"))
|
||||
"@click.prevent" "open = !open; popper.update()"
|
||||
"@keydown.enter.prevent.stop" "open = !open; popper.update()"
|
||||
"@keydown.down.prevent.stop" "open = true; popper.update()"
|
||||
"@keydown.backspace" "value = {value: '', label: '' }"
|
||||
:tabindex 0
|
||||
@@ -101,7 +100,7 @@
|
||||
"placeholder" (:placeholder params)
|
||||
"@keydown.down.prevent" "active ++; active = active >= elements.length - 1 ? elements.length - 1 : active"
|
||||
"@keydown.up.prevent" "active --; active = active < 0 ? 0 : active"
|
||||
"@keydown.enter.prevent" "open = false; value = elements.length > 0 ? $data.elements[active] : {'value': '', label: ''};"
|
||||
"@keydown.enter.prevent.stop" "open = false; value = elements.length > 0 ? $data.elements[active] : {'value': '', label: ''};"
|
||||
"x-init" "$watch('search', s => { if($el.value.length > 2) {fetch(baseUrl + s).then(data=>data.json()).then(data => {elements = data; active=-1}) }})"}]
|
||||
[:div.dropdown-options {:class "rounded-b-lg overflow-hidden"}
|
||||
[:template {:x-for "(element, index) in elements"}
|
||||
@@ -131,7 +130,9 @@
|
||||
(dissoc :error?)
|
||||
(assoc :type "text")
|
||||
(update
|
||||
:class (fnil hh/add-class "") default-input-classes)
|
||||
:class #(-> ""
|
||||
(hh/add-class default-input-classes)
|
||||
(hh/add-class %)))
|
||||
(update :class #(str % (use-size size))))])
|
||||
|
||||
(defn money-input- [{:keys [size] :as params}]
|
||||
@@ -204,5 +205,10 @@
|
||||
[:input {:type "hidden" :value value :name name}])
|
||||
|
||||
(defn checkbox- [params & rest]
|
||||
[:input (merge params {:type "checkbox" :class (hh/add-class default-checkbox-classes (:class params ""))})
|
||||
rest])
|
||||
(if (seq rest)
|
||||
[:label {:class "text-sm text-gray-800 dark:text-gray-300"}
|
||||
[:input (merge params {:type "checkbox" :class (hh/add-class default-checkbox-classes (:class params ""))})]
|
||||
[:span.ml-2
|
||||
rest]]
|
||||
[:input (merge params {:type "checkbox" :class (hh/add-class default-checkbox-classes (:class params ""))})
|
||||
]))
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
[auto-ap.ssr.admin.history :as history]
|
||||
[auto-ap.ssr.admin.import-batch :as import-batch]
|
||||
[auto-ap.ssr.admin.transaction-rules :as admin-rules]
|
||||
[auto-ap.ssr.admin.vendors :as admin-vendors]
|
||||
[auto-ap.ssr.auth :as auth]
|
||||
[auto-ap.ssr.company :as company]
|
||||
[auto-ap.ssr.company-dropdown :as company-dropdown]
|
||||
@@ -87,5 +88,6 @@
|
||||
(into admin-excel-invoices/key->handler)
|
||||
(into admin/key->handler)
|
||||
(into admin-jobs/key->handler)
|
||||
(into admin-vendors/key->handler)
|
||||
(into admin-rules/key->handler)))
|
||||
|
||||
|
||||
@@ -425,6 +425,12 @@
|
||||
[:line {:x1 "12", :y1 "6", :x2 "12", :y2 "0.5", :fill "none", :stroke "currentColor", :stroke-linecap "round", :stroke-linejoin "round"}]
|
||||
[:line {:x1 "1.034", :y1 "6", :x2 "22.966", :y2 "6", :fill "none", :stroke "currentColor", :stroke-linecap "round", :stroke-linejoin "round"}]])
|
||||
|
||||
(def arrow-right
|
||||
[:svg {:id "Regular", :xmlns "http://www.w3.org/2000/svg", :viewbox "-0.75 -0.75 24 24"}
|
||||
[:defs]
|
||||
[:title "arrow-button-right"]
|
||||
[:path {:d "M5.007187500000001 4.53 11.5415625 11.25l-6.534375 6.72a0.7368750000000001 0.7368750000000001 0 0 0 0 1.021875l2.5209375 2.593125a0.69 0.69 0 0 0 0.9946875 0L18.075000000000003 11.7609375a0.7368750000000001 0.7368750000000001 0 0 0 0 -1.021875L8.522812499999999 0.915a0.69 0.69 0 0 0 -0.9946875 0L5.007187500000001 3.508125a0.7368750000000001 0.7368750000000001 0 0 0 0 1.021875Z", :fill "none", :stroke "currentColor", :stroke-linecap "round", :stroke-linejoin "round", :fill-rule "evenodd", :stroke-width "1.5"}]])
|
||||
|
||||
(def thumbs-up
|
||||
[:svg {:xmlns "http://www.w3.org/2000/svg", :viewbox "0 0 24 24"}
|
||||
[:defs]
|
||||
|
||||
@@ -77,7 +77,7 @@ input[type=number] {
|
||||
|
||||
|
||||
[:div#modal-holder
|
||||
{:tabindex "-1", :class "fixed top-0 left-0 z-[99] flex items-center justify-center w-screen h-screen"
|
||||
{ :class "fixed top-0 left-0 z-[99] flex items-center justify-center w-screen h-screen"
|
||||
"x-show" "open"
|
||||
":aria-hidden" "!open"
|
||||
"x-data" (hx/json {"open" false})
|
||||
|
||||
10
src/cljc/auto_ap/routes/admin/vendors.cljc
Normal file
10
src/cljc/auto_ap/routes/admin/vendors.cljc
Normal file
@@ -0,0 +1,10 @@
|
||||
(ns auto-ap.routes.admin.vendors)
|
||||
|
||||
(def routes {"" {:get ::page
|
||||
:put ::save
|
||||
:post ::save}
|
||||
"/table" ::table
|
||||
"/terms" ::edit-terms
|
||||
"/new" {:get ::new}
|
||||
["/" [#"\d+" :db/id] "/edit"] {:get ::edit
|
||||
}})
|
||||
@@ -2,6 +2,7 @@
|
||||
(:require
|
||||
[auto-ap.routes.admin.excel-invoices :as ei-routes]
|
||||
[auto-ap.routes.admin.import-batch :as ib-routes]
|
||||
[auto-ap.routes.admin.vendors :as v-routes]
|
||||
[auto-ap.routes.admin.transaction-rules :as tr-routes]))
|
||||
|
||||
(def routes {"impersonate" :impersonate
|
||||
@@ -37,6 +38,7 @@
|
||||
"/table" :admin-job-table
|
||||
"/new" {:get :admin-job-start-dialog}
|
||||
"/subform" :admin-job-subform}
|
||||
"/vendor" v-routes/routes
|
||||
"/ezcater-xls" :admin-ezcater-xls
|
||||
"/import-batch" ib-routes/routes
|
||||
"/transaction-rule" tr-routes/routes
|
||||
|
||||
Reference in New Issue
Block a user