From 5596848cfc64c0201978704bde6839fd5a75f7d1 Mon Sep 17 00:00:00 2001 From: Bryce Date: Thu, 21 Mar 2024 22:33:05 -0700 Subject: [PATCH] modal --- src/clj/auto_ap/ssr/components/inputs.clj | 2 +- .../ssr/invoice/new_invoice_wizard.clj | 191 +++++++++--------- 2 files changed, 99 insertions(+), 94 deletions(-) diff --git a/src/clj/auto_ap/ssr/components/inputs.clj b/src/clj/auto_ap/ssr/components/inputs.clj index 10649310..b8e34c0d 100644 --- a/src/clj/auto_ap/ssr/components/inputs.clj +++ b/src/clj/auto_ap/ssr/components/inputs.clj @@ -157,7 +157,7 @@ (defn date-input- [{:keys [size] :as params}] [:div.shrink - [:input + [:input (-> params (update :class (fnil hh/add-class "") default-input-classes) (assoc :type "text") diff --git a/src/clj/auto_ap/ssr/invoice/new_invoice_wizard.clj b/src/clj/auto_ap/ssr/invoice/new_invoice_wizard.clj index 5fb92e74..b7bba26b 100644 --- a/src/clj/auto_ap/ssr/invoice/new_invoice_wizard.clj +++ b/src/clj/auto_ap/ssr/invoice/new_invoice_wizard.clj @@ -2,6 +2,7 @@ (:require [auto-ap.datomic :refer [conn pull-attr]] [auto-ap.datomic.accounts :as d-accounts] + [auto-ap.logging :as alog] [auto-ap.routes.invoice :as route] [auto-ap.routes.utils :refer [wrap-client-redirect-unauthenticated]] @@ -13,10 +14,11 @@ [auto-ap.ssr.hx :as hx] [auto-ap.ssr.svg :as svg] [auto-ap.ssr.utils - :refer [apply-middleware-to-all-handlers entity-id html-response - money wrap-schema-enforce]] + :refer [apply-middleware-to-all-handlers clj-date-schema + entity-id html-response money wrap-schema-enforce]] [auto-ap.time :as atime] [bidi.bidi :as bidi] + [clj-time.core :as time] [datomic.api :as dc] [malli.core :as mc] [malli.util :as mut])) @@ -24,8 +26,9 @@ (def new-form-schema [:map [:invoice/client entity-id] + [:invoice/date clj-date-schema] [:invoice/vendor entity-id] - [:invoice/expense-accounts + [:invoice/expense-accounts [:vector {:coerce? true} [:map [:invoice-expense-account/account entity-id] @@ -43,98 +46,99 @@ []) (step-schema [_] - (mut/select-keys (mm/form-schema linear-wizard) #{:invoice/client :invoice/vendor})) + (mut/select-keys (mm/form-schema linear-wizard) #{:invoice/client :invoice/vendor :invoice/date})) (render-step [this request] - (mm/default-render-step - linear-wizard this - :head [:div.p-2 "New invoice"] - :body (mm/default-step-body - {} - [:div {} - (fc/with-field :invoice/client - (if (:client request) - (com/hidden {:name (fc/field-name) - :value (:db/id (:client request))}) - (com/validated-field - {:label "Client" - :errors (fc/field-errors)} - [:div.w-96 - (com/typeahead {:name (fc/field-name) - :error? (fc/error?) - :class "w-96" - :placeholder "Search..." - :url (bidi/path-for ssr-routes/only-routes :company-search) - :value (fc/field-value) - :content-fn (fn [c] (pull-attr (dc/db conn) :client/name c))})]))) - (fc/with-field :invoice/vendor - (com/validated-field - {:label "Vendor" - :errors (fc/field-errors)} - [:div.w-96 - (com/typeahead {:name (fc/field-name) - :error? (fc/error?) - :class "w-96" - :placeholder "Search..." - :url (bidi/path-for ssr-routes/only-routes :vendor-search) - :value (fc/field-value) - :content-fn (fn [c] (pull-attr (dc/db conn) :vendor/name c))})])) - - [:div.flex.space-x-8 - (fc/with-field :invoice/date - (com/validated-field - {:label "Date" - :errors (fc/field-errors)} - [:div {:class "w-24"} - (com/date-input {:value (-> (fc/field-value) - (atime/unparse-local atime/normal-date)) - :name (fc/field-name) - :error? (fc/field-errors) - :placeholder "1/1/2024"})])) - (fc/with-field :invoice/due - (com/validated-field - {:label "Due (optional)" - :errors (fc/field-errors)} - [:div {:class "w-24"} - (com/date-input {:value (-> (fc/field-value) - (atime/unparse-local atime/normal-date)) - :name (fc/field-name) - :error? (fc/field-errors) - :placeholder "1/1/2024"})])) - (fc/with-field :invoice/scheduled-payment - (com/validated-field - {:label "Scheduled payment (optional)" - :errors (fc/field-errors)} - [:div {:class "w-24"} - (com/date-input {:value (-> (fc/field-value) - (atime/unparse-local atime/normal-date)) - :name (fc/field-name) - :error? (fc/field-errors) - :placeholder "1/1/2024"})]))] + (alog/peek ::check (:multi-form-state request)) + (mm/default-render-step + linear-wizard this + :head [:div.p-2 "New invoice"] + :body (mm/default-step-body + {} + [:div {} + (fc/with-field :invoice/client + (if (:client request) + (com/hidden {:name (fc/field-name) + :value (:db/id (:client request))}) + (com/validated-field + {:label "Client" + :errors (fc/field-errors)} + [:div.w-96 + (com/typeahead {:name (fc/field-name) + :error? (fc/error?) + :class "w-96" + :placeholder "Search..." + :url (bidi/path-for ssr-routes/only-routes :company-search) + :value (fc/field-value) + :content-fn (fn [c] (pull-attr (dc/db conn) :client/name c))})]))) + (fc/with-field :invoice/vendor + (com/validated-field + {:label "Vendor" + :errors (fc/field-errors)} + [:div.w-96 + (com/typeahead {:name (fc/field-name) + :error? (fc/error?) + :class "w-96" + :placeholder "Search..." + :url (bidi/path-for ssr-routes/only-routes :vendor-search) + :value (fc/field-value) + :content-fn (fn [c] (pull-attr (dc/db conn) :vendor/name c))})])) - (fc/with-field :invoice/invoice-number - (com/validated-field - {:label "Invoice Number" - :errors (fc/field-errors)} - [:div {:class "w-24"} - (com/text-input {:value (-> (fc/field-value)) - :name (fc/field-name) - :error? (fc/field-errors) - :placeholder "HA-123"})])) - (fc/with-field :invoice/total - (com/validated-field - {:label "Total" - :errors (fc/field-errors)} - [:div {:class "w-16"} - (com/money-input {:value (-> (fc/field-value)) - :name (fc/field-name) - :class "w-24" - :error? (fc/field-errors) - :placeholder "212.44"})]))]) + [:div.flex.space-x-8 + (fc/with-field :invoice/date + (com/validated-field + {:label "Date" + :errors (fc/field-errors)} + [:div {:class "w-24"} + (com/date-input {:value (some-> (fc/field-value) + (atime/unparse-local atime/normal-date)) + :name (fc/field-name) + :error? (fc/field-errors) + :placeholder "1/1/2024"})])) + (fc/with-field :invoice/due + (com/validated-field + {:label "Due (optional)" + :errors (fc/field-errors)} + [:div {:class "w-24"} + (com/date-input {:value (some-> (fc/field-value) + (atime/unparse-local atime/normal-date)) + :name (fc/field-name) + :error? (fc/field-errors) + :placeholder "1/1/2024"})])) + (fc/with-field :invoice/scheduled-payment + (com/validated-field + {:label "Scheduled payment (optional)" + :errors (fc/field-errors)} + [:div {:class "w-24"} + (com/date-input {:value (some-> (fc/field-value) + (atime/unparse-local atime/normal-date)) + :name (fc/field-name) + :error? (fc/field-errors) + :placeholder "1/1/2024"})]))] - :footer - (mm/default-step-footer linear-wizard this :validation-route ::route/new-wizard-navigate) - :validation-route ::route/new-wizard-navigate))) + (fc/with-field :invoice/invoice-number + (com/validated-field + {:label "Invoice Number" + :errors (fc/field-errors)} + [:div {:class "w-24"} + (com/text-input {:value (-> (fc/field-value)) + :name (fc/field-name) + :error? (fc/field-errors) + :placeholder "HA-123"})])) + (fc/with-field :invoice/total + (com/validated-field + {:label "Total" + :errors (fc/field-errors)} + [:div {:class "w-16"} + (com/money-input {:value (-> (fc/field-value)) + :name (fc/field-name) + :class "w-24" + :error? (fc/field-errors) + :placeholder "212.44"})]))]) + + :footer + (mm/default-step-footer linear-wizard this :validation-route ::route/new-wizard-navigate) + :validation-route ::route/new-wizard-navigate))) (defn- location-select* [{:keys [name account-location client-locations value]}] @@ -294,9 +298,10 @@ (defn initial-new-wizard-state [request] - (mm/->MultiStepFormState {:TODO nil} + (mm/->MultiStepFormState {:TODO nil + :invoice/date (time/plus (time/now) (time/days 12))} [] - {})) + {:invoice/date (time/plus (time/now) (time/days 12))})) (defn location-select [{{:keys [name account-id client-id value] :as qp} :query-params}] (html-response (location-select* {:name name