Vendors form progress

This commit is contained in:
2023-11-02 23:40:24 -07:00
parent 99e4f05769
commit eef1cfb919
16 changed files with 846 additions and 425 deletions

File diff suppressed because one or more lines are too long

View File

@@ -5,7 +5,7 @@
:refer [assert-can-see-client can-see-client? cleanse-query is-admin?]]
[auto-ap.solr :as solr]
[auto-ap.ssr.utils
:refer [entity-id ref->enum-schema wrap-schema-decode]]
:refer [entity-id ref->enum-schema wrap-schema-enforce]]
[com.brunobonacci.mulog :as mu]
[datomic.api :as dc]
[ring.middleware.json :refer [wrap-json-response]]))
@@ -91,7 +91,7 @@
xform))))
[]))}))
(def account-search (wrap-json-response (wrap-schema-decode account-search
(def account-search (wrap-json-response (wrap-schema-enforce account-search
:query-schema [:map
[:q :string]
[:client-id {:optional true

View File

@@ -36,7 +36,7 @@
temp-id
wrap-entity
wrap-form-4xx-2
wrap-schema-decode]]
wrap-schema-enforce]]
[bidi.bidi :as bidi]
[clojure.string :as str]
[datomic.api :as dc]
@@ -412,18 +412,18 @@
{:admin-accounts (helper/page-route grid-page)
:admin-account-table (helper/table-route grid-page)
:admin-account-client-override-new (-> new-client-override
(wrap-schema-decode :query-schema [:map
(wrap-schema-enforce :query-schema [:map
[:index {:optional true
:default 0} [nat-int? {:default 0}]]])
wrap-admin wrap-client-redirect-unauthenticated)
:admin-account-save (-> account-save
(wrap-entity [:form-params :db/id] default-read)
(wrap-schema-decode :form-schema form-schema)
(wrap-schema-enforce :form-schema form-schema)
(wrap-nested-form-params)
(wrap-form-4xx-2 (wrap-entity account-dialog [:form-params :db/id] default-read)))
:admin-account-edit-dialog (-> account-dialog
(wrap-entity [:route-params :db/id] default-read)
(wrap-schema-decode :route-schema [:map [:db/id entity-id]]))
(wrap-schema-enforce :route-schema [:map [:db/id entity-id]]))
:admin-account-new-dialog account-dialog})
(fn [h]
(-> h

View File

@@ -16,7 +16,7 @@
html-response
modal-response
wrap-form-4xx-2
wrap-schema-decode]]
wrap-schema-enforce]]
[auto-ap.time :as atime]
[bidi.bidi :as bidi]
[clj-time.coerce :as coerce]
@@ -256,9 +256,9 @@
(->>
{:admin-jobs (helper/page-route grid-page)
:admin-job-table (helper/table-route grid-page)
:admin-job-subform (-> subform (wrap-schema-decode :query-schema [:map [:name {:optional true} [:maybe :string]]]))
:admin-job-subform (-> subform (wrap-schema-enforce :query-schema [:map [:name {:optional true} [:maybe :string]]]))
:admin-job-start (-> job-start
(wrap-schema-decode :form-schema form-schema)
(wrap-schema-enforce :form-schema form-schema)
(wrap-nested-form-params)
(wrap-form-4xx-2 job-start-dialog))
:admin-job-start-dialog job-start-dialog})

View File

@@ -19,7 +19,7 @@
:refer [apply-middleware-to-all-handlers
html-response
wrap-form-4xx-2
wrap-schema-decode]]
wrap-schema-enforce]]
[auto-ap.utils :refer [by]]
[bidi.bidi :as bidi]
[clj-time.coerce :as coerce]
@@ -311,7 +311,7 @@
(->>
{::route/page page
::route/import (-> import
(wrap-schema-decode :form-schema [:map [:tsv :string]])
(wrap-schema-enforce :form-schema [:map [:tsv :string]])
(wrap-nested-form-params)
(wrap-form-4xx-2 form))
})

View File

@@ -45,7 +45,7 @@
temp-id
wrap-entity
wrap-form-4xx-2
wrap-schema-decode]]
wrap-schema-enforce]]
[auto-ap.time :as atime]
[auto-ap.utils :refer [dollars=]]
[bidi.bidi :as bidi]
@@ -832,6 +832,7 @@
{})
:form-errors form-errors})))
(defn check-badges [{query-params :query-params}]
(html-response
[:div (if (not-empty (:all query-params))
@@ -875,21 +876,21 @@
{::route/page (helper/page-route grid-page)
::route/table (helper/table-route grid-page)
::route/new-account (-> new-account
(wrap-schema-decode :query-schema [:map
(wrap-schema-enforce :query-schema [:map
[:client-id {:optional true}
[:maybe entity-id]]
[:index {:optional true
:default 0} [nat-int? {:default 0}]]])
wrap-admin wrap-client-redirect-unauthenticated)
::route/location-select (-> location-select
(wrap-schema-decode :query-schema [:map
(wrap-schema-enforce :query-schema [:map
[:name :string]
[:client-id {:optional true}
[:maybe entity-id]]
[:account-id {:optional true}
[:maybe entity-id]]]))
::route/account-typeahead (-> account-typeahead
(wrap-schema-decode :query-schema [:map
(wrap-schema-enforce :query-schema [:map
[:name :string]
[:client-id {:optional true}
[:maybe entity-id]]
@@ -897,7 +898,7 @@
[:maybe entity-id]]]))
::route/save (-> save
(wrap-entity [:form-params :db/id] default-read)
(wrap-schema-decode :form-schema form-schema)
(wrap-schema-enforce :form-schema form-schema)
(wrap-nested-form-params)
(wrap-form-4xx-2 (-> edit-dialog
(wrap-entity [:form-params :db/id] default-read))))
@@ -905,8 +906,8 @@
::route/execute (-> execute
(wrap-entity [:route-params :db/id] default-read)
(wrap-entity [:route-params :db/id] default-read)
(wrap-schema-decode :route-schema [:map [:db/id entity-id]])
(wrap-schema-decode :form-schema
(wrap-schema-enforce :route-schema [:map [:db/id entity-id]])
(wrap-schema-enforce :form-schema
[:map
[:transaction-id {:optional true}
[:maybe [:vector {:decode/arbitrary (fn [x] ;; TODO make this easier
@@ -920,13 +921,13 @@
::route/test (-> test
(wrap-entity [:form-params :db/id] default-read)
(wrap-schema-decode :form-schema form-schema)
(wrap-schema-enforce :form-schema form-schema)
(wrap-nested-form-params)
(wrap-form-4xx-2 (-> edit-dialog
(wrap-entity [:form-params :db/id] default-read))))
::route/check-badges (-> check-badges
(wrap-schema-decode :query-schema [:map
(wrap-schema-enforce :query-schema [:map
[:transaction-id {:optional true}
[:maybe [:vector {:decode/arbitrary (fn [x]
(if (sequential? x)
@@ -936,11 +937,11 @@
[:all {:optional true} [:maybe :string]]]))
::route/execute-dialog (-> execute-dialog
(wrap-entity [:route-params :db/id] default-read)
(wrap-schema-decode :route-schema [:map [:db/id entity-id]]))
(wrap-schema-enforce :route-schema [:map [:db/id entity-id]]))
::route/edit-dialog (-> edit-dialog
(wrap-entity [:route-params :db/id] default-read)
(wrap-schema-decode :route-schema [:map [:db/id entity-id]]))
(wrap-schema-enforce :route-schema [:map [:db/id entity-id]]))
::route/new-dialog edit-dialog})
(fn [h]
(-> h

File diff suppressed because it is too large Load Diff

View File

@@ -21,7 +21,7 @@
strip
wrap-entity
wrap-form-4xx-2
wrap-schema-decode]]
wrap-schema-enforce]]
[bidi.bidi :as bidi]
[clojure.string :as str]
[datomic.api :as dc]
@@ -365,18 +365,18 @@
:company-1099-vendor-table vendor-table
:company-1099-vendor-dialog (-> vendor-dialog
(wrap-entity [:route-params :vendor-id] default-vendor-read)
(wrap-schema-decode :route-schema [:map [:vendor-id entity-id]]
(wrap-schema-enforce :route-schema [:map [:vendor-id entity-id]]
:query-schema [:map [:client-id entity-id]]))
:company-1099-vendor-save (-> vendor-save
(wrap-entity [:form-params :db/id] default-vendor-read)
(wrap-schema-decode :form-schema form-schema
(wrap-schema-enforce :form-schema form-schema
:route-schema [:map [:vendor-id entity-id]]
:query-schema [:map [:client-id entity-id]])
(wrap-nested-form-params)
(wrap-form-4xx-2 (-> vendor-dialog
(wrap-entity [:form-params :db/id] default-vendor-read)
(wrap-entity [:route-params :vendor-id] default-vendor-read)
(wrap-schema-decode :route-schema [:map [:vendor-id entity-id]]
(wrap-schema-enforce :route-schema [:map [:vendor-id entity-id]]
:query-schema [:map [:client-id entity-id]]))))})
(fn [h]
(-> h

View File

@@ -25,6 +25,11 @@
(def modal dialog/modal-)
(def modal-card dialog/modal-card-)
(def stacked-modal-card dialog/stacked-modal-card-)
(def stacked-modal-card-2 dialog/stacked-modal-card-2-)
(def modal-header dialog/modal-header-)
(def modal-header-attachment dialog/modal-header-attachment-)
(def modal-body dialog/modal-body-)
(def modal-footer dialog/modal-footer-)
(def text-input inputs/text-input-)
(def checkbox inputs/checkbox-)

View File

@@ -58,7 +58,7 @@
(defn stacked-modal-card- [index params header content footer]
[:div (merge params
{:class "bg-white rounded-lg shadow dark:bg-gray-700 dark:text-white modal-content flex flex-col h-full"
{:class (hh/add-class "bg-white rounded-lg shadow dark:bg-gray-700 dark:text-white modal-content flex flex-col h-full" (:class params ""))
:x-data (hx/json {:i index})
:x-show "index == i && hidingIndex != i"
"x-trap" "index == i && hidingIndex == -1 && !transitioning"
@@ -67,12 +67,46 @@
"x-transition:leave" "transition duration-150",
"x-transition:leave-start" "translate-x-0 scale-100 opacity-100",
})
[:div {:class "flex items-start justify-between p-4 border-b rounded-t dark:border-gray-600 shrink-0"} header]
[:div {:class "flex items-start justify-between p-4 border-b rounded-t dark:border-gray-600 shrink-0"} header] ;; todo componentize these
[:div {:class "px-6 space-y-6 overflow-y-scroll w-full shrink"}
content]
content] ;; TODO componentize
(when footer [:div {:class "p-4"}
[:span.items-center.bg-red-100.text-red-800.text-xs.font-medium.mb-2.p-1.rounded-full.inline-flex (hx/alpine-appear {:x-show "unexpectedError" :class "dark:bg-red-900 dark:text-red-300"})
[:span {:class "w-2 h-2 bg-red-500 rounded-full"}]
[:span.px-2.py-0.5 "An unexpected error has occured. Integreat staff have been notified."]]
[:div {:class "shrink-0"}]footer])])
(defn modal-header- [params & children]
[:div {:class "flex items-start justify-between p-4 border-b rounded-t dark:border-gray-600 shrink-0"}
children])
(defn modal-header-attachment- [params & children]
[:div {:class "flex items-start justify-between p-4 border-b shrink-0"}
children])
(defn modal-body- [params & children]
[:div {:class "px-6 py-2 space-y-6 overflow-y-scroll w-full shrink"}
children])
(defn modal-footer- [params & children]
[:div {:class "p-4"}
[:span.items-center.bg-red-100.text-red-800.text-xs.font-medium.mb-2.p-1.rounded-full.inline-flex (hx/alpine-appear {:x-show "unexpectedError" :class "dark:bg-red-900 dark:text-red-300"})
[:span {:class "w-2 h-2 bg-red-500 rounded-full"}]
[:span.px-2.py-0.5 "An unexpected error has occured. Integreat staff have been notified."]]
[:div {:class "shrink-0"}]
children])
(defn stacked-modal-card-2- [index params & children]
[:div (merge params
{:class (hh/add-class "bg-white rounded-lg shadow dark:bg-gray-700 dark:text-white modal-content flex flex-col h-full" (:class params ""))
: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",
"x-transition:leave-start" "translate-x-0 scale-100 opacity-100",
})
children])

View File

@@ -128,7 +128,7 @@
[:input
(-> params
(dissoc :error?)
(assoc :type "text")
(assoc :type "text" :autocomplete "off")
(update
:class #(-> ""
(hh/add-class default-input-classes)

View File

@@ -0,0 +1,28 @@
(ns auto-ap.ssr.components.timeline
(:require [auto-ap.ssr.hiccup-helper :as hh]))
(defn timeline-step [{:keys [active? visited? last?]} & children]
(if active?
[:li {:class "flex items-center text-primary-600 font-medium dark:text-primary-500"}
[:span {:class "flex items-center justify-center w-5 h-5 mr-2 text-xs border-2 border-primary-600 rounded-full shrink-0 dark:border-primary-500"} ]
children
(when-not last?
[:svg {:class "w-3 h-3 ml-2 sm:ml-4", :aria-hidden "true", :xmlns "http://www.w3.org/2000/svg", :fill "none", :viewbox "0 0 12 10"}
[:path {:stroke "currentColor", :stroke-linecap "round", :stroke-linejoin "round", :stroke-width "2", :d "m7 9 4-4-4-4M1 9l4-4-4-4"}]])]
[:li {:class (cond-> "flex items-center"
(not visited?) (hh/add-class "text-gray-400"))}
[:span {:class "flex items-center justify-center w-5 h-5 mr-2 text-xs border border-gray-500 rounded-full shrink-0 dark:border-gray-400"}
(when visited?
[:svg {:class "w-3 h-3 text-primary-600 dark:text-primary-500", :aria-hidden "true", :xmlns "http://www.w3.org/2000/svg", :fill "none", :viewbox "0 0 16 12"}
[:path {:stroke "currentColor", :stroke-linecap "round", :stroke-linejoin "round", :stroke-width "2", :d "M1 5.917 5.724 10.5 15 1.5"}]])]
children
(when-not last?
[:svg {:class "w-3 h-3 ml-2 sm:ml-4", :aria-hidden "true", :xmlns "http://www.w3.org/2000/svg", :fill "none", :viewbox "0 0 12 10"}
[:path {:stroke "currentColor", :stroke-linecap "round", :stroke-linejoin "round", :stroke-width "2", :d "m7 9 4-4-4-4M1 9l4-4-4-4"}]])]))
(defn timeline [params & children]
[:ol {:class "flex items-center w-full space-x-2 text-xs text-center text-gray-500 bg-white dark:text-gray-400 sm:text-base dark:bg-gray-800 sm:space-x-4 px-2"}
children
#_[:li {:class "flex items-center"}
[:span {:class "flex items-center justify-center w-5 h-5 mr-2 text-xs border border-gray-500 rounded-full shrink-0 dark:border-gray-400"} ]]])

View File

@@ -31,7 +31,7 @@
ref->select-options
wrap-entity
wrap-form-4xx-2
wrap-schema-decode]]
wrap-schema-enforce]]
[auto-ap.time :as atime]
[bidi.bidi :as bidi]
[buddy.sign.jwt :as jwt]
@@ -375,20 +375,20 @@
:user-table (helper/table-route grid-page)
:user-edit-save (-> user-edit-save
(wrap-entity [:form-params :db/id] default-read)
(wrap-schema-decode :form-schema form-schema)
(wrap-schema-enforce :form-schema form-schema)
(wrap-nested-form-params)
(wrap-form-4xx-2 (wrap-entity user-dialog [:form-params :db/id] default-read)))
:user-client-new (-> new-client
(wrap-schema-decode :query-schema [:map
(wrap-schema-enforce :query-schema [:map
[:index {:optional true
:default 0} [nat-int? {:default 0}]]]))
:user-edit-dialog (-> user-dialog
(wrap-entity [:route-params :db/id] default-read)
(wrap-schema-decode
(wrap-schema-enforce
:route-schema (mc/schema [:map [:db/id entity-id]])))
:user-impersonate (-> impersonate
(wrap-entity [:params :db/id] default-read)
(wrap-schema-decode
(wrap-schema-enforce
:params-schema (mc/schema [:map [:db/id entity-id]])))}
(fn [h]
(-> h

View File

@@ -174,55 +174,102 @@
:else
s))
(defn schema-enforce-request [{:keys [form-params query-params params] :as request} & {:keys [form-schema query-schema route-schema params-schema]}]
(let [request (try
(cond-> request
(and (:params request) params-schema)
(assoc :params
(mc/coerce
params-schema
(:params request)
main-transformer))
(and (:route-params request) route-schema)
(assoc :route-params
(mc/coerce
route-schema
(:route-params request)
main-transformer))
(and form-schema form-params)
(assoc :form-params
(mc/coerce
form-schema
form-params
main-transformer))
(and query-schema query-params)
(assoc :query-params
(mc/coerce
query-schema
query-params
main-transformer)))
(catch Exception e
(alog/warn ::validation-error :error e)
(throw (ex-info (->> (-> e
(ex-data )
:data
:explain
(me/humanize {:errors (assoc me/default-errors
::mc/missing-key {:error/message {:en "required"}})}))
(map (fn [[k v]]
(str (if (keyword? k)
(name k)
k) ": " (str/join ", " v))))
(str/join ", "))
{:type :schema-validation
:decoded (:value (:data (ex-data e)))
:error (:data (ex-data e))}))))]
request))
(defn wrap-schema-enforce [handler & {:keys [form-schema query-schema route-schema params-schema]}]
(fn [request]
(handler (schema-enforce-request request
:form-schema form-schema
:query-schema query-schema
:route-schema route-schema
:params-schema params-schema))))
(defn schema-decode-request [{:keys [form-params query-params params] :as request} & {:keys [form-schema query-schema route-schema params-schema]}]
(let [request (cond-> request
(and (:params request) params-schema)
(assoc :params
(mc/decode
params-schema
(:params request)
main-transformer))
(and (:route-params request) route-schema)
(assoc :route-params
(mc/decode
route-schema
(:route-params request)
main-transformer))
(and form-schema form-params)
(assoc :form-params
(mc/decode
form-schema
form-params
main-transformer))
(and query-schema query-params)
(assoc :query-params
(mc/decode
query-schema
query-params
main-transformer)))]
request))
(defn wrap-schema-decode [handler & {:keys [form-schema query-schema route-schema params-schema]}]
(fn [{:keys [form-params query-params params] :as request}]
(let [request (try
(cond-> request
(and (:params request) params-schema)
(assoc :params
(mc/coerce
params-schema
(:params request)
main-transformer))
(and (:route-params request) route-schema)
(assoc :route-params
(mc/coerce
route-schema
(:route-params request)
main-transformer))
(and form-schema form-params)
(assoc :form-params
(mc/coerce
form-schema
form-params
main-transformer))
(and query-schema query-params)
(assoc :query-params
(mc/coerce
query-schema
query-params
main-transformer)))
(catch Exception e
(alog/warn ::validation-error :error e)
(throw (ex-info (->> (-> e
(ex-data )
:data
:explain
(me/humanize {:errors (assoc me/default-errors
::mc/missing-key {:error/message {:en "required"}})}))
(map (fn [[k v]]
(str (if (keyword? k)
(name k)
k) ": " (str/join ", " v))))
(str/join ", "))
{:type :schema-validation
:decoded (:value (:data (ex-data e)))
:error (:data (ex-data e))}))))]
(handler request))))
(fn [request]
(handler (schema-decode-request request
:form-schema form-schema
:query-schema query-schema
:route-schema route-schema
:params-schema params-schema))))
(defn ref->enum-schema [n]
(into [:enum {:decode/string #(if (keyword? %)

View File

@@ -38,7 +38,14 @@
"")
(:user-name item)
)
(puget/cprint (reduce
(println (reduce
(fn [acc [k v]]
(assoc acc k v))
{}
(dissoc
item
:user)))
#_(puget/cprint (reduce
(fn [acc [k v]]
(assoc acc k v))
{}

View File

@@ -4,7 +4,11 @@
:put ::save
:post ::save}
"/table" ::table
"/terms" ::edit-terms
"/terms/override" ::new-terms-override
"/automatic-payment" ::new-automatic-payment
"/account-override" ::new-account-override
"/account-typeahead" ::account-typeahead
"/validate" ::validate
"/new" {:get ::new}
["/" [#"\d+" :db/id] "/edit"] {:get ::edit
}})