Undoes old way of doing forms in favor of context version. Much easier
This commit is contained in:
@@ -4,16 +4,16 @@
|
||||
[auto-ap.subs :as subs]
|
||||
[auto-ap.views.components.layouts :refer [side-bar]]
|
||||
[auto-ap.views.components.typeahead :refer [typeahead-v3]]
|
||||
[auto-ap.views.utils :refer [dispatch-event multi-field]]
|
||||
[auto-ap.views.utils :refer [dispatch-event multi-field with-user]]
|
||||
[clojure.spec.alpha :as s]
|
||||
[clojure.string :as str]
|
||||
[re-frame.core :as re-frame]))
|
||||
[re-frame.core :as re-frame]
|
||||
[auto-ap.forms.builder :as form-builder]
|
||||
[vimsical.re-frame.cofx.inject :as inject]))
|
||||
|
||||
(def types [:dividend :expense :asset :liability :equity :revenue])
|
||||
(def applicabilities [:global :optional :customized])
|
||||
|
||||
|
||||
|
||||
(re-frame/reg-sub
|
||||
::request
|
||||
:<- [::forms/form ::form]
|
||||
@@ -51,103 +51,99 @@
|
||||
(re-frame/reg-event-fx
|
||||
::edited
|
||||
[(forms/triggers-saved ::form :upsert-account)]
|
||||
(fn [{:keys [db]} [_ {:keys [upsert-account]}]]))
|
||||
(fn [_ [_ _]]))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::add-client-override
|
||||
[(forms/in-form ::form)]
|
||||
(fn [form]
|
||||
(update form :data (fn [data]
|
||||
(-> data
|
||||
(update :client-overrides conj (:new-client-override data))
|
||||
(dissoc :new-client-override))))))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::saving
|
||||
(fn [{:keys [db]} _]
|
||||
[with-user (re-frame/inject-cofx ::inject/sub [::request]) ]
|
||||
(fn [{:keys [user] ::keys [request]} _]
|
||||
(when @(re-frame/subscribe [::can-submit])
|
||||
(let [{{:keys [id type name numeric-code account-set]} :data :as data} @(re-frame/subscribe [::forms/form ::form])]
|
||||
{:db (forms/loading db ::form )
|
||||
:graphql
|
||||
{:token (-> db :user)
|
||||
(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 @(re-frame/subscribe [::request])}
|
||||
{: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-form (forms/vertical-form {:can-submit [::can-submit]
|
||||
:change-event [::forms/change ::form]
|
||||
:submit-event [::saving]
|
||||
:id ::form}))
|
||||
|
||||
(defn form [_]
|
||||
(let [{error :error account :data } @(re-frame/subscribe [::forms/form ::form])
|
||||
{:keys [form-inline field field-holder raw-field error-notification submit-button]} account-form]
|
||||
|
||||
^{:key (:id account)}
|
||||
(let [{account :data } @(re-frame/subscribe [::forms/form ::form])]
|
||||
[side-bar {:on-close (dispatch-event [::forms/form-closing ::form])}
|
||||
(form-inline {:title (if (:id account)
|
||||
"Edit account"
|
||||
"Add account")}
|
||||
[:<>
|
||||
[form-builder/builder {:can-submit [::can-submit]
|
||||
:change-event [::forms/change ::form]
|
||||
:submit-event [::saving]
|
||||
:id ::form}
|
||||
[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}]]
|
||||
|
||||
(field "Account Set"
|
||||
[:input.input {:type "text"
|
||||
:field :account-set
|
||||
:disabled (boolean (:id account))
|
||||
:spec ::entity/account-set}])
|
||||
[form-builder/field
|
||||
"Code"
|
||||
[:input.input {:type "text"
|
||||
:field :numeric-code
|
||||
:disabled (boolean (:id account))
|
||||
:spec ::entity/numeric-code}]]
|
||||
|
||||
(field "Code"
|
||||
[:input.input {:type "text"
|
||||
:field :numeric-code
|
||||
:disabled (boolean (:id account))
|
||||
:spec ::entity/numeric-code}])
|
||||
[form-builder/field
|
||||
"Name"
|
||||
[:input.input {:type "text"
|
||||
:field :name
|
||||
:spec ::entity/name}]]
|
||||
|
||||
(field "Name"
|
||||
[:input.input {:type "text"
|
||||
:field :name
|
||||
:spec ::entity/name}])
|
||||
|
||||
(field-holder "Account Type"
|
||||
[:div.select
|
||||
(raw-field
|
||||
[:select {:type "select"
|
||||
:field :type
|
||||
:spec (set types)}
|
||||
(map (fn [l]
|
||||
[:option {:value (name l)} (str/capitalize (name l))]) types)])])
|
||||
[form-builder/vertical-control
|
||||
"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)]]]]
|
||||
|
||||
|
||||
(field "Location"
|
||||
[:input.input.known-field.location {:type "text"
|
||||
:field :location
|
||||
:spec ::entity/location}])
|
||||
[form-builder/field
|
||||
"Location"
|
||||
[:input.input.known-field.location {:type "text"
|
||||
:field :location
|
||||
:spec ::entity/location}]]
|
||||
|
||||
[:h2.subtitle "Client"]
|
||||
(field-holder "Applicability"
|
||||
[:div.select
|
||||
(raw-field
|
||||
[:select {:type "select"
|
||||
:field :applicability
|
||||
:spec (set applicabilities)}
|
||||
(map (fn [l]
|
||||
[:option {:value (name l)} (str/capitalize (name l))]) applicabilities)])])
|
||||
(field "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]}]
|
||||
]}])
|
||||
(error-notification)
|
||||
[form-builder/section {:title "Client"}
|
||||
[:h2.subtitle "Client"]
|
||||
[form-builder/vertical-control
|
||||
"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
|
||||
"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]}]
|
||||
]}]]]
|
||||
[form-builder/error-notification]
|
||||
|
||||
(submit-button "Save")])]))
|
||||
[form-builder/submit-button "Save"]]]]))
|
||||
|
||||
Reference in New Issue
Block a user