Another improvement
This commit is contained in:
@@ -73,8 +73,7 @@
|
||||
[buttons/new-button {:name "Account"
|
||||
:class "is-primary"
|
||||
:event [::account-form/editing
|
||||
{:type :asset
|
||||
:account-set "default"}]}]]
|
||||
{:account-set "default"}]}]]
|
||||
[table/accounts-table {:data-page ::page}]])
|
||||
|
||||
(defn admin-accounts-page []
|
||||
|
||||
@@ -9,7 +9,10 @@
|
||||
[clojure.string :as str]
|
||||
[re-frame.core :as re-frame]
|
||||
[auto-ap.forms.builder :as form-builder]
|
||||
[vimsical.re-frame.cofx.inject :as inject]))
|
||||
[vimsical.re-frame.cofx.inject :as inject]
|
||||
[auto-ap.views.components :as com]
|
||||
[malli.core :as m]
|
||||
[auto-ap.schema :as schema]))
|
||||
|
||||
(def types [:dividend :expense :asset :liability :equity :revenue])
|
||||
(def applicabilities [:global :optional :customized])
|
||||
@@ -35,11 +38,7 @@
|
||||
(:name client-override))})
|
||||
client-overrides)}))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::can-submit
|
||||
:<- [::request]
|
||||
(fn [request]
|
||||
(s/valid? ::entity/account request)))
|
||||
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::editing
|
||||
@@ -58,92 +57,91 @@
|
||||
::saving
|
||||
[with-user (re-frame/inject-cofx ::inject/sub [::request]) ]
|
||||
(fn [{:keys [user] ::keys [request]} _]
|
||||
(when @(re-frame/subscribe [::can-submit])
|
||||
(let [_ @(re-frame/subscribe [::forms/form ::form])]
|
||||
{:graphql
|
||||
{:owns-state {:single ::form}
|
||||
:token user
|
||||
:query-obj {:venia/operation {:operation/type :mutation
|
||||
:operation/name "UpsertAccount"}
|
||||
:venia/queries [{:query/data [:upsert-account
|
||||
{:account request}
|
||||
[:id :type :name :account-set :numeric-code :location :applicability [:client-overrides [:name :id [:client [:id :name]]]]]]}]}
|
||||
:on-success [::edited]
|
||||
:on-error [::forms/save-error ::form]}}))))
|
||||
(let [_ @(re-frame/subscribe [::forms/form ::form])]
|
||||
{:graphql
|
||||
{:owns-state {:single ::form}
|
||||
:token user
|
||||
:query-obj {:venia/operation {:operation/type :mutation
|
||||
:operation/name "UpsertAccount"}
|
||||
:venia/queries [{:query/data [:upsert-account
|
||||
{:account request}
|
||||
[:id :type :name :account-set :numeric-code :location :applicability [:client-overrides [:name :id [:client [:id :name]]]]]]}]}
|
||||
:on-success [::edited]
|
||||
:on-error [::forms/save-error ::form]}})))
|
||||
|
||||
(def account-customization-schema
|
||||
(m/schema
|
||||
[:map [:client schema/reference]
|
||||
[:name schema/not-empty-string]]))
|
||||
|
||||
(def account-schema
|
||||
(m/schema
|
||||
[:map
|
||||
[:numeric-code schema/integer-code]
|
||||
[:name schema/not-empty-string]
|
||||
[:type [:enum :dividend :expense :asset :liability :equity :revenue]]
|
||||
[:location {:optional true} [:maybe :string]]
|
||||
[:applicability [:enum :global :optional :customized]]
|
||||
[:client-overrides {:optional true}
|
||||
[:maybe [:sequential account-customization-schema]]]]))
|
||||
|
||||
(defn form [_]
|
||||
(let [{account :data } @(re-frame/subscribe [::forms/form ::form])]
|
||||
[side-bar {:on-close (dispatch-event [::forms/form-closing ::form])}
|
||||
[form-builder/builder {:can-submit [::can-submit]
|
||||
:change-event [::forms/change ::form]
|
||||
[form-builder/builder {:change-event [::forms/change ::form]
|
||||
:submit-event [::saving]
|
||||
:id ::form}
|
||||
:id ::form
|
||||
:schema account-schema}
|
||||
[form-builder/section {:title (if (:id account)
|
||||
"Edit account"
|
||||
"Add account")}
|
||||
[form-builder/field
|
||||
"Account Set"
|
||||
[:input.input {:type "text"
|
||||
:field :account-set
|
||||
:disabled (boolean (:id account))
|
||||
:spec ::entity/account-set}]]
|
||||
|
||||
[form-builder/field
|
||||
[form-builder/field-v2 {:field :numeric-code}
|
||||
"Code"
|
||||
[:input.input {:type "text"
|
||||
:field :numeric-code
|
||||
:disabled (boolean (:id account))
|
||||
:spec ::entity/numeric-code}]]
|
||||
[com/number-input
|
||||
{:disabled (boolean (:id account))
|
||||
:auto-focus (not (boolean (:id account)))
|
||||
:style {:width "9em"}}]]
|
||||
|
||||
[form-builder/field
|
||||
[form-builder/field-v2 {:field :name}
|
||||
"Name"
|
||||
[:input.input {:type "text"
|
||||
:field :name
|
||||
:spec ::entity/name}]]
|
||||
:auto-focus (boolean (:id account))}]]
|
||||
|
||||
[form-builder/vertical-control
|
||||
[form-builder/field-v2 {:field :type}
|
||||
"Account Type"
|
||||
[:div.select
|
||||
[form-builder/raw-field
|
||||
[:select {:type "select"
|
||||
:field :type
|
||||
:spec (set types)}
|
||||
(map (fn [l]
|
||||
[:option {:value (name l)} (str/capitalize (name l))]) types)]]]]
|
||||
[com/select-field {:options (map (fn [l]
|
||||
[l (str/capitalize (name l))])
|
||||
types)
|
||||
:allow-nil? true
|
||||
:keywordize? true}]]
|
||||
|
||||
|
||||
[form-builder/field
|
||||
[form-builder/field-v2 {:field :location}
|
||||
"Location"
|
||||
[:input.input.known-field.location {:type "text"
|
||||
:field :location
|
||||
:spec ::entity/location}]]
|
||||
[:input.input.known-field.location {:type "text"}]]
|
||||
|
||||
[form-builder/section {:title "Client"}
|
||||
[:h2.subtitle "Client"]
|
||||
[form-builder/vertical-control
|
||||
[form-builder/field-v2 {:field :applicability}
|
||||
"Applicability"
|
||||
[:div.select
|
||||
[form-builder/raw-field
|
||||
[:select {:type "select"
|
||||
:field :applicability
|
||||
:spec (set applicabilities)}
|
||||
(map (fn [l]
|
||||
[:option {:value (name l)} (str/capitalize (name l))]) applicabilities)]]]]
|
||||
[form-builder/field
|
||||
[com/select-field {:options (map (fn [l]
|
||||
[l
|
||||
(str/capitalize (name l))])
|
||||
applicabilities)
|
||||
:allow-nil? true
|
||||
:keywordize? true}]]
|
||||
[form-builder/field-v2 {:field :client-overrides}
|
||||
"Customizations"
|
||||
[multi-field {:type "multi-field"
|
||||
:field [:client-overrides]
|
||||
:template [[typeahead-v3 {:entities @(re-frame/subscribe [::subs/clients])
|
||||
:style {:width "13em"}
|
||||
:entity->text :name
|
||||
:type "typeahead-v3"
|
||||
:field [:client]}]
|
||||
[:input.input {:type "text"
|
||||
:style {:width "15em"}
|
||||
:placeholder "Bubblegum"
|
||||
:field [:name]}]
|
||||
]}]]]
|
||||
[com/multi-field-v2 {:template [[form-builder/raw-field-v2 {:field :client}
|
||||
[typeahead-v3 {:entities @(re-frame/subscribe [::subs/clients])
|
||||
:style {:width "13em"}
|
||||
:entity->text :name}]]
|
||||
[form-builder/raw-field-v2 {:field :name}
|
||||
[:input.input {:type "text"
|
||||
:style {:width "15em"}
|
||||
:placeholder "Bubblegum"}]]]
|
||||
:key-fn :id
|
||||
:schema [:sequential account-customization-schema]}]]]
|
||||
[form-builder/error-notification]
|
||||
|
||||
[form-builder/submit-button "Save"]]]]))
|
||||
|
||||
Reference in New Issue
Block a user