made it possible to change accounts.
This commit is contained in:
@@ -51,7 +51,7 @@
|
||||
[:id :name :hidden [:default-account [:name :id :location]] [:primary-contact [:name :phone :email :id]] [:secondary-contact [:id :name :phone :email]] :print-as :invoice-reminder-schedule :code
|
||||
[:account-overrides [[:client [:id :name]] :id [:account [:id :numeric-code :name]]]]
|
||||
[:terms-overrides [[:client [:id :name]] :id :terms]]]]
|
||||
[:accounts [:numeric-code :location :name :type :account_set :id]]]}
|
||||
[:accounts [:numeric-code :location :name :type :account_set :applicability :id [:client-overrides [:name [:client [:name :id]]]]]]]}
|
||||
:on-success [::received-initial]}}))))
|
||||
(def vendor-query
|
||||
[:id :name :hidden :terms [:default-account [:name :id :location]]
|
||||
@@ -75,7 +75,7 @@
|
||||
[:id :name :code :matches :locations [:location-matches [:location :match]] [:address [:street1 :street2 :city :state :zip]] [:bank-accounts [:id :code :number :bank-name :bank-code :check-number :name :routing :type :sort-order :visible :yodlee-account-id :locations] ]]]
|
||||
[:vendor
|
||||
[:id :name :hidden [:default-account [:name :id :location]] [:primary-contact [:name :phone :email :id]] [:secondary-contact [:id :name :phone :email]] :print-as :invoice-reminder-schedule :code]]
|
||||
[:accounts [:numeric-code :name :location :type :account_set :id]]]}
|
||||
[:accounts [:numeric-code :name :location :type :account_set :applicability :id [:client-overrides [:name [:client [:name :id]]]]]]]}
|
||||
|
||||
:on-success [::received-initial]}
|
||||
:db (assoc db :user (assoc user :token token))}))
|
||||
|
||||
@@ -24,17 +24,39 @@
|
||||
"is-loading"
|
||||
"")))
|
||||
|
||||
(defn start-form [db form data]
|
||||
(assoc-in db [::forms form] {:error nil
|
||||
:active? true
|
||||
:id (random-uuid)
|
||||
:status nil
|
||||
:data data}))
|
||||
(defn start-form
|
||||
([db form data]
|
||||
(start-form db form data nil))
|
||||
([db form data complete-listener]
|
||||
(assoc-in db [::forms form] {:error nil
|
||||
:active? true
|
||||
:id (random-uuid)
|
||||
:status nil
|
||||
:data data
|
||||
:complete-listener complete-listener})))
|
||||
|
||||
(defn saved-form [db form data]
|
||||
(defn ^:depracated saved-form [db form data]
|
||||
(update-in db [::forms form]
|
||||
assoc :error nil :status nil :data data))
|
||||
|
||||
(defn triggers-saved [form data-key]
|
||||
(i/->interceptor
|
||||
:id :triggers-saved
|
||||
:before (fn [context]
|
||||
context)
|
||||
:after (fn [context]
|
||||
(let [db (i/get-coeffect context :db)
|
||||
result (get-in (i/get-coeffect context :event) [1 data-key])]
|
||||
(println (get-in db [::forms form :complete-listener]))
|
||||
(cond-> context
|
||||
true
|
||||
(i/assoc-effect :db (update-in db
|
||||
[::forms form]
|
||||
assoc :error nil :status nil :data result))
|
||||
|
||||
(get-in db [::forms form :complete-listener])
|
||||
(i/assoc-effect :dispatch (conj (get-in db [::forms form :complete-listener ])
|
||||
result)))))))
|
||||
(defn stop-form [db form]
|
||||
(update db ::forms dissoc form))
|
||||
|
||||
@@ -48,8 +70,6 @@
|
||||
[form-name]
|
||||
(re-frame/path [::forms form-name]))
|
||||
|
||||
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::change
|
||||
(fn [db [_ form & path-pairs]]
|
||||
@@ -140,6 +160,10 @@
|
||||
[bind-field (-> control
|
||||
(assoc-in [1 :subscription] data)
|
||||
(assoc-in [1 :event] change-event))]))
|
||||
:field-holder (fn [label control]
|
||||
[:div.field
|
||||
(when label [:p.help label])
|
||||
[:div.control control]])
|
||||
:field (fn [label control]
|
||||
(let [{:keys [data]} @(re-frame/subscribe [::form id])]
|
||||
[:div.field
|
||||
|
||||
@@ -38,7 +38,9 @@
|
||||
[:td name]
|
||||
[:td type]
|
||||
[:td location]
|
||||
[:td [:a.button {:on-click (dispatch-event [::account-form/editing account])} [:span [:span.icon [:i.fa.fa-pencil]]]]]])]]])])
|
||||
[:td [:a.button {:on-click (dispatch-event [::account-form/editing
|
||||
account
|
||||
[::edit-completed]])} [:span [:span.icon [:i.fa.fa-pencil]]]]]])]]])])
|
||||
|
||||
(defn admin-accounts-content []
|
||||
[:div
|
||||
@@ -46,12 +48,14 @@
|
||||
[:div
|
||||
[:h1.title "Accounts"]
|
||||
[:div.is-pulled-right
|
||||
[:a.button.is-success {:on-click (dispatch-event [::account-form/editing {:type :asset
|
||||
:account-set "default"}])} "New Account"]]
|
||||
[:a.button.is-success {:on-click (dispatch-event [::account-form/editing
|
||||
{:type :asset
|
||||
:account-set "default"}
|
||||
[::edit-completed]])} "New Account"]]
|
||||
[accounts-table {:accounts accounts}]])])
|
||||
|
||||
(defn admin-accounts-page []
|
||||
(let [{:keys [active?]} @(re-frame/subscribe [::forms/form ::account-form/form])]
|
||||
[side-bar-layout {:side-bar [admin-side-bar {}]
|
||||
:main [admin-accounts-content]
|
||||
:right-side-bar [appearing-side-bar {:visible? active?} [account-form/form {:edit-completed [::edit-completed]}]]}]))
|
||||
:right-side-bar [appearing-side-bar {:visible? active?} [account-form/form ]]}]))
|
||||
|
||||
@@ -2,45 +2,66 @@
|
||||
(:require [auto-ap.forms :as forms]
|
||||
[clojure.string :as str]
|
||||
[clojure.spec.alpha :as s]
|
||||
[auto-ap.subs :as subs]
|
||||
[auto-ap.entities.account :as entity]
|
||||
[auto-ap.views.utils :refer [bind-field dispatch-event]]
|
||||
[auto-ap.views.components.typeahead :refer [typeahead-entity]]
|
||||
[re-frame.core :as re-frame]))
|
||||
|
||||
(def types [:dividend :expense :asset :liability :equity :revenue])
|
||||
(def applicabilities [:global :optional :customized])
|
||||
|
||||
|
||||
(re-frame/reg-sub
|
||||
::can-submit
|
||||
(fn [db]
|
||||
true))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::request
|
||||
:<- [::forms/form ::form]
|
||||
(fn [{{:keys [id location type numeric-code name account-set]} :data}]
|
||||
(fn [{{:keys [id location type client-overrides applicability numeric-code name account-set]} :data}]
|
||||
{:id id
|
||||
:type (keyword type)
|
||||
:applicability (keyword applicability)
|
||||
:location (if (clojure.string/blank? location)
|
||||
nil
|
||||
location)
|
||||
:numeric-code numeric-code
|
||||
:name name
|
||||
:account-set account-set}))
|
||||
:account-set account-set
|
||||
:client-overrides (map (fn [client-override]
|
||||
{:client-id (:id (:client client-override))
|
||||
:name (if (str/blank? (:name client-override))
|
||||
nil
|
||||
(: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
|
||||
(fn [db [_ which]]
|
||||
(fn [db [_ which complete-listener]]
|
||||
(-> db
|
||||
(forms/start-form ::form which))))
|
||||
(forms/start-form ::form which complete-listener))))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::edited
|
||||
(fn [{:keys [db]} [_ edit-completed {:keys [upsert-account]}]]
|
||||
{:db (-> db (forms/saved-form ::form upsert-account))
|
||||
:dispatch (conj edit-completed upsert-account)}))
|
||||
[(forms/triggers-saved ::form :upsert-account)]
|
||||
(fn [{:keys [db]} [_ {:keys [upsert-account]}]]))
|
||||
|
||||
(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]} [_ edit-completed]]
|
||||
(fn [{:keys [db]} _]
|
||||
(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 )
|
||||
@@ -50,88 +71,88 @@
|
||||
:operation/name "UpsertAccount"}
|
||||
:venia/queries [{:query/data [:upsert-account
|
||||
{:account @(re-frame/subscribe [::request])}
|
||||
[:id :type :name :account-set :numeric-code :location]]}]}
|
||||
:on-success [::edited edit-completed]
|
||||
[:id :type :name :account-set :numeric-code :location :applicability [:client-overrides [:name [:client [:id :name]]]]]]}]}
|
||||
:on-success [::edited]
|
||||
:on-error [::forms/save-error ::form]}}))))
|
||||
|
||||
(defn form [{:keys [edit-completed]}]
|
||||
(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])
|
||||
change-event [::forms/change ::form]]
|
||||
{:keys [form field field-holder raw-field error-notification submit-button]} account-form
|
||||
change-event [::forms/change ::form]]
|
||||
|
||||
[forms/side-bar-form {:form ::form}
|
||||
[:form
|
||||
[:h1.title.is-2 (if (:id account)
|
||||
"Edit account"
|
||||
"Add account")]
|
||||
^{:key (:id account)}
|
||||
[form {:title (if (:id account)
|
||||
"Edit account"
|
||||
"Add account")}
|
||||
|
||||
[:div.field
|
||||
[:p.help "Account Set"]
|
||||
[:div.control
|
||||
[bind-field
|
||||
[field "Account Set"
|
||||
[:input.input {:type "text"
|
||||
:field :account-set
|
||||
:disabled (boolean (:id account))
|
||||
:spec ::entity/account-set}]]
|
||||
|
||||
|
||||
[field "Code"
|
||||
[:input.input {:type "text"
|
||||
:field :numeric-code
|
||||
:disabled (boolean (:id account))
|
||||
:spec ::entity/numeric-code}]]
|
||||
|
||||
|
||||
[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)]]]]
|
||||
|
||||
|
||||
[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-holder "Customizations"
|
||||
[:div.field.has-addons
|
||||
[:p.control
|
||||
^{:key (count (:client-overrides account))} ;; resets after adding
|
||||
[raw-field
|
||||
[typeahead-entity {:matches @(re-frame/subscribe [::subs/clients])
|
||||
:match->text :name
|
||||
:type "typeahead"
|
||||
:field [:new-client-override :client]}]]]
|
||||
[:p.control
|
||||
[raw-field
|
||||
[:input.input {:type "text"
|
||||
:field :account-set
|
||||
:disabled (if (:id account)
|
||||
"disabled"
|
||||
"")
|
||||
:spec ::entity/account-set
|
||||
:event change-event
|
||||
:subscription account}]]]]
|
||||
:placeholder "Bubblegum"
|
||||
:field [:new-client-override :name]}]]]
|
||||
[:p.control [:button.button.is-primary {:on-click (dispatch-event [::add-client-override])} "Add"]]]]
|
||||
[:ul
|
||||
(for [client-override (:client-overrides account)]
|
||||
^{:key (:name client-override)}
|
||||
[:li (:name (:client client-override)) "-" (:name client-override)])]
|
||||
[error-notification]
|
||||
|
||||
[:div.field
|
||||
[:p.help "Code"]
|
||||
[:div.control
|
||||
[bind-field
|
||||
[:input.input {:type "text"
|
||||
:field :numeric-code
|
||||
:disabled (if (:id account)
|
||||
"disabled"
|
||||
"")
|
||||
:spec ::entity/numeric-code
|
||||
:event change-event
|
||||
:subscription account}]]]]
|
||||
|
||||
[:div.field
|
||||
[:p.help "Name"]
|
||||
[:div.control
|
||||
[bind-field
|
||||
[:input.input {:type "text"
|
||||
:field :name
|
||||
:spec ::entity/name
|
||||
:event change-event
|
||||
:subscription account}]]]]
|
||||
|
||||
|
||||
|
||||
[:div.field
|
||||
[:p.help "Account Type"]
|
||||
[:div.control
|
||||
[:div.select
|
||||
[bind-field
|
||||
[:select {:type "select"
|
||||
:field :type
|
||||
:spec (set types)
|
||||
:event change-event
|
||||
:subscription account}
|
||||
(map (fn [l]
|
||||
[:option {:value (name l)} (str/capitalize (name l))]) types)]]]]]
|
||||
|
||||
|
||||
[:div.field
|
||||
[:p.help "Location"]
|
||||
[:div.control
|
||||
[bind-field
|
||||
[:input.input.known-field.location {:type "text"
|
||||
:field :location
|
||||
:spec ::entity/location
|
||||
:event change-event
|
||||
:subscription account}]]]]
|
||||
|
||||
(when error
|
||||
[:div.notification.is-warning.animated.fadeInUp
|
||||
error])
|
||||
|
||||
[:button.button.is-large.is-primary {:disabled (if (s/valid? ::entity/account @(re-frame/subscribe [::request]))
|
||||
""
|
||||
"disabled")
|
||||
:on-click (dispatch-event [::saving edit-completed])
|
||||
:class (str @(re-frame/subscribe [::forms/loading-class ::form]) (when error " animated shake"))} "Save"]]]))
|
||||
[submit-button "Save"]]))
|
||||
|
||||
Reference in New Issue
Block a user