diff --git a/src/clj/auto_ap/cursor.clj b/src/clj/auto_ap/cursor.clj index 6a7f25cc..4247b9f5 100644 --- a/src/clj/auto_ap/cursor.clj +++ b/src/clj/auto_ap/cursor.clj @@ -1,7 +1,6 @@ (ns auto-ap.cursor (:import (clojure.lang IDeref Atom ILookup Counted IFn AFn Indexed ISeq Seqable))) -; TODO not sure if these methods are needed at all; ICursor is used solely as a marker right now (defprotocol ICursor (path [cursor]) (state [cursor])) diff --git a/src/clj/auto_ap/ssr/admin/accounts.clj b/src/clj/auto_ap/ssr/admin/accounts.clj index 5c913a68..53061b12 100644 --- a/src/clj/auto_ap/ssr/admin/accounts.clj +++ b/src/clj/auto_ap/ssr/admin/accounts.clj @@ -232,7 +232,6 @@ "hx-reswap" "afterbegin") (= :put request-method) (assoc "hx-retarget" (format "#entity-table tr[data-id=\"%d\"]" (:db/id updated-account))))))) -;; TODO decide when cursors are used. other cases it's not, some are (defn client-override* [override] (com/data-grid-row (-> {:x-ref "p" :data-key "show" @@ -245,7 +244,7 @@ (fc/with-field :account-client-override/client (com/data-grid-cell {} (com/validated-field {:errors (fc/field-errors)} - (com/typeahead-2 {:name (fc/field-name) + (com/typeahead {:name (fc/field-name) :placeholder "Search..." :class "w-96" :url (bidi/path-for ssr-routes/only-routes @@ -262,20 +261,6 @@ (com/data-grid-cell {:class "align-top"} (com/a-icon-button {"@click.prevent.stop" "show=false; setTimeout(() => $refs.p.remove(), 500)"} svg/x)))) -;; TODO each form: -;; elimante typeahead1 -;; work with new dialog -;; use cursor -;; ensure all dialogs are opened the same way -;; form level validation -;; form level validation -;; componentize -;; ensure all dependency oriented stuff works the same way -;; make sure that "new row index" stuff works ok -;; TODO figure out when hx-targets are decided -;; ensure that adding a new one results in a new row - - (defn dialog* [{:keys [entity form-params form-errors]}] (fc/start-form form-params form-errors [:div {:x-data (hx/json {"accountName" (or (:account/name form-params) (:account/numeric-code entity)) @@ -383,8 +368,6 @@ (com/validated-save-button {:errors (seq form-errors)} "Save account")])]])])) -;; TODO saving new row should att it to the tbody - (defn new-client-override [{ {:keys [index]} :query-params}] (html-response (fc/start-form-with-prefix diff --git a/src/clj/auto_ap/ssr/admin/background_jobs.clj b/src/clj/auto_ap/ssr/admin/background_jobs.clj index ec1ecdfc..f09879bd 100644 --- a/src/clj/auto_ap/ssr/admin/background_jobs.clj +++ b/src/clj/auto_ap/ssr/admin/background_jobs.clj @@ -182,7 +182,7 @@ (fc/with-field :client (com/validated-field {:label "Client" :errors (fc/field-errors)} - (com/typeahead-2 {:name (fc/field-name) + (com/typeahead {:name (fc/field-name) :value (fc/field-value) :placeholder "Search..." :url (bidi/path-for ssr-routes/only-routes diff --git a/src/clj/auto_ap/ssr/admin/transaction_rules.clj b/src/clj/auto_ap/ssr/admin/transaction_rules.clj index 87e02b7f..734a3aac 100644 --- a/src/clj/auto_ap/ssr/admin/transaction_rules.clj +++ b/src/clj/auto_ap/ssr/admin/transaction_rules.clj @@ -56,7 +56,7 @@ [:fieldset.space-y-6 (com/field {:label "Vendor"} - (com/typeahead-2 {:name "vendor" + (com/typeahead {:name "vendor" :placeholder "Search..." :url (bidi/path-for ssr-routes/only-routes :vendor-search) @@ -318,7 +318,7 @@ (defn- account-typeahead* [{:keys [name value client-id x-model]}] [:div.flex.flex-col - (com/typeahead-2 {:name name + (com/typeahead {:name name :placeholder "Search..." :url (str (bidi/path-for ssr-routes/only-routes :account-search) "?client-id=" client-id) :id name @@ -389,7 +389,6 @@ (com/data-grid-cell {:class "align-top"} (com/a-icon-button {"@click.prevent.stop" "show=false; setTimeout(() => $refs.p.remove(), 500)"} svg/x)))) -;; TODO background jobs and company 1099 (defn dialog* [{:keys [entity form-params form-errors]}] (fc/start-form form-params form-errors (com/modal @@ -448,7 +447,7 @@ :x-show "clientFilter"} (hx/alpine-appear)) [:div.w-96 - (com/typeahead-2 {:name (fc/field-name) + (com/typeahead {:name (fc/field-name) :error? (fc/error?) :class "w-96" :placeholder "Search..." @@ -520,7 +519,7 @@ (com/validated-field {:label "Assign Vendor" :errors (fc/field-errors)} [:div.w-96 - (com/typeahead-2 {:name (fc/field-name) + (com/typeahead {:name (fc/field-name) :placeholder "Search..." :url (bidi/path-for ssr-routes/only-routes :vendor-search) :class "w-96" @@ -572,7 +571,6 @@ (some->> client-id (pull-attr (dc/db conn) :client/locations) client-id))))) -;; TODO check to see if it should be called "Shared" or "shared" for the value (defn location-select [{{:keys [name account-id client-id value] :as qp} :query-params}] (html-response (location-select* {:name name diff --git a/src/clj/auto_ap/ssr/company.clj b/src/clj/auto_ap/ssr/company.clj index 075bae63..aa1a19d2 100644 --- a/src/clj/auto_ap/ssr/company.clj +++ b/src/clj/auto_ap/ssr/company.clj @@ -108,7 +108,7 @@ (defn bank-account-typeahead* [{:keys [client-id name value]}] (if client-id - (com/typeahead-2 {:name name + (com/typeahead {:name name :class "w-96" :placeholder "Search..." :url (bidi/path-for ssr-routes/only-routes :bank-account-search diff --git a/src/clj/auto_ap/ssr/company/company_1099.clj b/src/clj/auto_ap/ssr/company/company_1099.clj index fdbb27bb..ecf21bf2 100644 --- a/src/clj/auto_ap/ssr/company/company_1099.clj +++ b/src/clj/auto_ap/ssr/company/company_1099.clj @@ -176,8 +176,20 @@ {:keys [vendor-id]} :route-params {:keys [client-id]} :query-params}] + (assert-can-see-client identity client-id) - @(dc/transact conn [[:upsert-entity (assoc form-params :db/id (:vendor-id route-params))]]) + + @(dc/transact conn [[:upsert-entity (-> form-params + (assoc :db/id (:vendor-id route-params)) + (update :vendor/address (fn [a] + (if (or (:address/street1 a) + (:address/street2 a) + (:address/city a) + (:address/state a) + (:address/zip a) + (:db/id a)) + a + nil)) ))]]) (html-response (row* identity [(dc/pull (dc/db conn) [:db/id :client/code] client-id) @@ -192,7 +204,7 @@ (def form-schema (mc/schema [:map - [:vendor/address {:default {} } + [:vendor/address {:default {}} [:maybe [:map [:db/id {:optional true} [:maybe entity-id]] @@ -234,7 +246,8 @@ [:div.flex [:div.p-2 "Vendor 1099 Info"] [:p.ml-2.rounded.bg-gray-200.p-2.dark:bg-gray-600 (:vendor/name entity)]] [:div.grid.grid-cols-6.gap-x-4.gap-y-2 - (fc/with-field :vendor/address ;; TODO support default + (fc/with-field-default :vendor/address {} + (println "ADDRESS" fc/*current*) (list [:h4.text-xl.border-b.col-span-6 "Address"] [:div.col-span-6 (fc/with-field :db/id @@ -335,11 +348,11 @@ :errors (fc/field-errors)} (com/select {:name (fc/field-name) :allow-blank? true - :value (some-> (fc/field-value) name) ;; TODO use ref stuff + :value (some-> (fc/field-value) name) :options (ref->select-options "legal-entity-1099-type")})))]] [:div (com/form-errors {:errors (:errors fc/*form-errors*)}) - (com/validated-save-button {:errors form-errors} "Save rule")])]])))) + (com/validated-save-button {:errors form-errors} "Save vendor")])]])))) (def vendor-table (helper/table-route grid-page)) (def page (helper/page-route grid-page)) diff --git a/src/clj/auto_ap/ssr/company/yodlee.clj b/src/clj/auto_ap/ssr/company/yodlee.clj index 699c40fa..7bae6fa2 100644 --- a/src/clj/auto_ap/ssr/company/yodlee.clj +++ b/src/clj/auto_ap/ssr/company/yodlee.clj @@ -208,7 +208,6 @@ fastlink.open({fastLinkURL: '%s', (def page (helper/page-route grid-page)) (def table (helper/table-route grid-page)) -;; TODO delete-after-settle (defn refresh-provider-account [{:keys [form-params identity]}] (let [provider-account (dc/pull (dc/db conn) default-read (some-> (get form-params "id") not-empty Long/parseLong))] (yodlee/refresh-provider-account (:client/code (:yodlee-provider-account/client provider-account)) diff --git a/src/clj/auto_ap/ssr/components.clj b/src/clj/auto_ap/ssr/components.clj index 305afc49..8187030d 100644 --- a/src/clj/auto_ap/ssr/components.clj +++ b/src/clj/auto_ap/ssr/components.clj @@ -31,8 +31,7 @@ (def date-input inputs/date-input-) (def hidden inputs/hidden-) (def select inputs/select-) -(def typeahead inputs/typeahead-) -(def typeahead-2 inputs/typeahead-2-) +(def typeahead inputs/tytypeahead- (def field-errors inputs/field-errors-) (def field inputs/field-) (def validated-field inputs/validated-field-) diff --git a/src/clj/auto_ap/ssr/components/inputs.clj b/src/clj/auto_ap/ssr/components/inputs.clj index acc46704..8bfb07db 100644 --- a/src/clj/auto_ap/ssr/components/inputs.clj +++ b/src/clj/auto_ap/ssr/components/inputs.clj @@ -32,45 +32,8 @@ (:allow-blank? params) (conj [:option {:value "" :selected (not (:value params))} ""]))] children)) + (defn typeahead- [params] - [:select (-> params - (dissoc :url) - (dissoc :value) - (dissoc :value-fn) - (dissoc :content-fn)) - (for [value (if (:multiple params) - (:value params) - [(:value params)]) - :when ((:value-fn params first) value)] - [:option {:value ((:value-fn params first) value) :selected true} ((:content-fn params second) value)]) - - [:script {:lang "javascript"} - (hiccup/raw (format " -(function () { -var element = document.getElementById('%s'); -var c = new Choices(element, {removeItems: true, removeItemButton:true, searchFloor: 3, searchPlaceholderValue: '%s'}); -let baseUrl = '%s'; - -element.addEventListener('search', function (e) { - let fullUrl = baseUrl + (baseUrl.includes(\"?\") ? \"&\" : \"?\") + \"q=\" + e.detail.value; - let data = fetch(fullUrl) - .then(res => res.json()) - .then(data => { - c.setChoices(data, 'value', 'label', true) - }); -}); -element.addEventListener('choice', function (e) { -c.clearChoices(); - }) -})(); - -" - (:id params) - (:placeholder params) - (:url params) - ))]]) - -(defn typeahead-2- [params] [:div {:x-data (hx/json {:open false :baseUrl (if (str/includes? (:url params) "?") (str (:url params) "&q=") @@ -152,7 +115,6 @@ c.clearChoices(); ]]) -;; TODO fix search modal (defn use-size [size] (if (= :small size) (str " " "text-xs p-2") diff --git a/src/clj/auto_ap/ssr/form_cursor.clj b/src/clj/auto_ap/ssr/form_cursor.clj index 00921e5e..b1617452 100644 --- a/src/clj/auto_ap/ssr/form_cursor.clj +++ b/src/clj/auto_ap/ssr/form_cursor.clj @@ -31,12 +31,8 @@ ~@rest)) (defmacro with-field-default [field default & rest] - `(let [next-cursor# (get *current* ~field ) - next-cursor# (if (nil? @next-cursor#) - (cursor/update! next-cursor# default) - next-cursor#)] - (with-cursor next-cursor# - ~@rest))) + `(with-cursor (get *current* ~field ~default) + ~@rest)) (defn field-name diff --git a/src/clj/auto_ap/ssr/pos/refunds.clj b/src/clj/auto_ap/ssr/pos/refunds.clj index 49f741b1..2651307e 100644 --- a/src/clj/auto_ap/ssr/pos/refunds.clj +++ b/src/clj/auto_ap/ssr/pos/refunds.clj @@ -8,25 +8,15 @@ merge-query pull-many query2]] - [auto-ap.graphql.utils :refer [extract-client-ids]] - [auto-ap.routes.utils - :refer [wrap-client-redirect-unauthenticated wrap-secure]] - [auto-ap.ssr.pos.common :refer [date-range-field* processor-field* total-field*]] + [auto-ap.query-params :as query-params] [auto-ap.ssr-routes :as ssr-routes] [auto-ap.ssr.components :as com] [auto-ap.ssr.grid-page-helper :as helper] - [auto-ap.ssr.svg :as svg] + [auto-ap.ssr.pos.common :refer [date-range-field* total-field*]] [auto-ap.time :as atime] [bidi.bidi :as bidi] [clj-time.coerce :as c] - [datomic.api :as dc] - [clojure.set :as set] - [auto-ap.query-params :as query-params] - [malli.core :as m])) - -;; TODO refunds -;; always should be fast -;; make params parsing composable + [datomic.api :as dc])) (defn filters [request] [:form {"hx-trigger" "change delay:500ms, keyup changed from:.hot-filter delay:1000ms" diff --git a/src/clj/auto_ap/ssr/users.clj b/src/clj/auto_ap/ssr/users.clj index 7861f1d2..7d481140 100644 --- a/src/clj/auto_ap/ssr/users.clj +++ b/src/clj/auto_ap/ssr/users.clj @@ -80,7 +80,7 @@ {:value "none" :content "None"}]})) (com/field {:label "Client"} - (com/typeahead-2 {:name "client" + (com/typeahead {:name "client" :placeholder "Search..." :url (bidi/path-for ssr-routes/only-routes :company-search) @@ -273,7 +273,7 @@ hx/alpine-mount-then-appear) (com/data-grid-cell {} (com/validated-field {:errors (fc/field-errors (:db/id fc/*current*))} - (com/typeahead-2 {:name (fc/field-name (:db/id fc/*current*)) + (com/typeahead {:name (fc/field-name (:db/id fc/*current*)) :class "w-full" :url (bidi/path-for ssr-routes/only-routes :company-search) diff --git a/src/clj/auto_ap/ssr/utils.clj b/src/clj/auto_ap/ssr/utils.clj index 080fd2cc..80479333 100644 --- a/src/clj/auto_ap/ssr/utils.clj +++ b/src/clj/auto_ap/ssr/utils.clj @@ -102,7 +102,8 @@ (defn parse-empty-as-nil [] (mt2/transformer {:decoders - {:double empty->nil + {:string empty->nil + :double empty->nil :int empty->nil :long empty->nil 'nat-int? empty->nil}})) @@ -160,10 +161,7 @@ (subs (str k) 1)) -;; TODO need to remove or at least remove usages as the form is not included -(defn validation-error [m & {:as data}] - (throw+ (ex-info m (merge data {:type :validation})))) - +;; TODO make this bubble the form data automatically (defn field-validation-error [m path & {:as data}] (throw+ (ex-info m (merge data {:type :field-validation :form-errors (assoc-in {} path [m])}))))