trimming more vendor usage.
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
(ns auto-ap.views.components.expense-accounts-field
|
||||
(:require [auto-ap.forms :as forms]
|
||||
[auto-ap.subs :as subs]
|
||||
(:require [auto-ap.subs :as subs]
|
||||
[auto-ap.views.components.typeahead :refer [typeahead-v3]]
|
||||
[auto-ap.views.components.money-field :refer [money-field]]
|
||||
[auto-ap.views.utils :refer [bind-field dispatch-event ->$]]
|
||||
[goog.string :as gstring]
|
||||
[re-frame.core :as re-frame]
|
||||
|
||||
@@ -1,19 +1,27 @@
|
||||
(ns auto-ap.views.pages.admin.rules.form
|
||||
(:require [auto-ap.entities.transaction-rule :as entity]
|
||||
[auto-ap.forms :as forms]
|
||||
[auto-ap.subs :as subs]
|
||||
[auto-ap.views.components.button-radio :refer [button-radio]]
|
||||
[auto-ap.views.components.expense-accounts-field :as expense-accounts-field :refer [expense-accounts-field]]
|
||||
[auto-ap.views.components.layouts :as layouts]
|
||||
[auto-ap.views.components.typeahead :refer [typeahead-v3]]
|
||||
[auto-ap.views.pages.admin.rules.common :refer [default-read]]
|
||||
[auto-ap.views.pages.admin.rules.results-modal :as results-modal]
|
||||
[auto-ap.views.utils :refer [dispatch-event with-user]]
|
||||
[clojure.spec.alpha :as s]
|
||||
[clojure.string :as str]
|
||||
[re-frame.core :as re-frame]
|
||||
[auto-ap.status :as status]
|
||||
[vimsical.re-frame.cofx.inject :as inject]))
|
||||
(:require
|
||||
[auto-ap.entities.transaction-rule :as entity]
|
||||
[auto-ap.events :as events]
|
||||
[auto-ap.forms :as forms]
|
||||
[auto-ap.status :as status]
|
||||
[auto-ap.subs :as subs]
|
||||
[auto-ap.views.components.button-radio :refer [button-radio]]
|
||||
[auto-ap.views.components.expense-accounts-field
|
||||
:as expense-accounts-field
|
||||
:refer [expense-accounts-field]]
|
||||
[auto-ap.views.components.layouts :as layouts]
|
||||
[auto-ap.views.components.typeahead :refer [typeahead-v3]]
|
||||
[auto-ap.views.components.typeahead.vendor
|
||||
:refer [search-backed-typeahead]]
|
||||
[auto-ap.views.pages.admin.rules.common :refer [default-read]]
|
||||
[auto-ap.views.pages.admin.rules.results-modal :as results-modal]
|
||||
[auto-ap.views.utils :refer [dispatch-event with-user]]
|
||||
[clojure.spec.alpha :as s]
|
||||
[clojure.string :as str]
|
||||
[re-frame.core :as re-frame]
|
||||
[reagent.core :as r]
|
||||
[vimsical.re-frame.cofx.inject :as inject]
|
||||
[vimsical.re-frame.fx.track :as track]))
|
||||
|
||||
;; SUBS
|
||||
|
||||
@@ -161,25 +169,35 @@
|
||||
xs)))))))))
|
||||
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::changed-vendor
|
||||
[(forms/in-form ::form)]
|
||||
(fn [{{{:keys [client]} :data} :db} [_ vendor]]
|
||||
(when (and (:id client) (:id vendor))
|
||||
{:dispatch [::events/vendor-preferences-requested {:client-id (:id client)
|
||||
:vendor-id (:id vendor)
|
||||
:on-success [::changed [:vendor-preferences]]}]})))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::changed-client
|
||||
[(forms/in-form ::form)]
|
||||
(fn [{{{:keys [vendor]} :data} :db} [_ client]]
|
||||
(when (and (:id client) (:id vendor))
|
||||
{:dispatch [::events/vendor-preferences-requested {:client-id (:id client)
|
||||
:vendor-id (:id vendor)
|
||||
:on-success [::changed [:vendor-preferences]]}]})))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::changed
|
||||
(forms/change-handler ::form
|
||||
(fn [data field value]
|
||||
(cond (and (= [:vendor] field)
|
||||
(cond (and (= [:vendor-preferences] field)
|
||||
value
|
||||
(expense-accounts-field/can-replace-with-default? (:accounts data)))
|
||||
[[:accounts] (expense-accounts-field/default-account (:accounts data)
|
||||
@(re-frame/subscribe [::subs/vendor-default-account (:id value) (:client data)])
|
||||
(:default-account value)
|
||||
(:total data)
|
||||
[])]
|
||||
|
||||
(= [:client] field)
|
||||
[[:accounts] (expense-accounts-field/default-account (:accounts data)
|
||||
@(re-frame/subscribe [::subs/vendor-default-account (:id (:vendor data)) value])
|
||||
(:total data)
|
||||
[])
|
||||
[:bank-account] nil]
|
||||
|
||||
:else
|
||||
[]))))
|
||||
|
||||
@@ -228,14 +246,30 @@
|
||||
:submit-event [::saving ]
|
||||
:id ::form}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::mounted
|
||||
(fn [_ _]
|
||||
{::track/register [{:id ::client
|
||||
:subscription [::forms/field ::form [:client]]
|
||||
:event-fn (fn [c]
|
||||
[::changed-client c])}
|
||||
{:id ::vendor-change
|
||||
:subscription [::forms/field ::form [:vendor]]
|
||||
:event-fn (fn [v]
|
||||
[::changed-vendor v])}]}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::unmounted
|
||||
(fn []
|
||||
{::track/dispose [{:id ::client}
|
||||
{:id ::vendor-change}]}))
|
||||
|
||||
(defn form [params]
|
||||
[layouts/side-bar {:on-close (dispatch-event [::forms/form-closing ::form ])}
|
||||
(let [{:keys [data id]} @(re-frame/subscribe [::forms/form ::form])
|
||||
(defn form-contents [params]
|
||||
[layouts/side-bar {:on-close (dispatch-event [::forms/form-closing ::form ])}
|
||||
(let [{:keys [data id]} @(re-frame/subscribe [::forms/form ::form])
|
||||
{:keys [form-inline field raw-field error-notification submit-button ]} rule-form
|
||||
default-note @(re-frame/subscribe [::default-note])
|
||||
test-state @(re-frame/subscribe [::status/single ::test])]
|
||||
default-note @(re-frame/subscribe [::default-note])
|
||||
test-state @(re-frame/subscribe [::status/single ::test])]
|
||||
^{:key id}
|
||||
(form-inline (assoc params :title "New Transaction Rule")
|
||||
[:<>
|
||||
@@ -314,12 +348,12 @@
|
||||
[:h2.title.is-4 "Outcomes"]
|
||||
|
||||
(field "Assign Vendor"
|
||||
[typeahead-v3 {:entities-by-id @(re-frame/subscribe [::subs/vendors-by-id])
|
||||
:entity-index @(re-frame/subscribe [::subs/all-vendors-index])
|
||||
:entity->text :name
|
||||
:type "typeahead-v3"
|
||||
:field [:vendor]
|
||||
:spec ::entity/vendor}])
|
||||
[search-backed-typeahead {:search-query (fn [i]
|
||||
[:search_vendor
|
||||
{:query i}
|
||||
[:name :id]])
|
||||
:type "typeahead-v3"
|
||||
:field [:vendor]}])
|
||||
|
||||
(with-meta
|
||||
(field nil
|
||||
@@ -330,7 +364,7 @@
|
||||
:locations (into ["Shared"] @(re-frame/subscribe [::subs/locations-for-client-or-bank-account (:id (:client data)) (:id (:bank-account data))]))
|
||||
:max 100
|
||||
:field [:accounts]}])
|
||||
{:key (some-> data :vendor :id str)})
|
||||
{:key (str (some-> data :vendor :id str) "-" (some-> data :client :id str))})
|
||||
|
||||
(field "Approval Status"
|
||||
[button-radio
|
||||
@@ -357,3 +391,11 @@
|
||||
"Test Rule"]]
|
||||
[:div.column
|
||||
(submit-button "Save")]]]))])
|
||||
|
||||
(defn form [_]
|
||||
(r/create-class
|
||||
{:display-name "rule-form"
|
||||
:component-did-mount #(re-frame/dispatch [::mounted])
|
||||
:component-will-unmount #(re-frame/dispatch [::unmounted])
|
||||
:reagent-render (fn [p]
|
||||
[form-contents p])}))
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
(ns auto-ap.views.pages.admin.vendors.merge-dialog
|
||||
(:require [auto-ap.forms :as forms]
|
||||
[auto-ap.status :as status]
|
||||
[auto-ap.subs :as subs]
|
||||
[auto-ap.views.components.modal :as modal]
|
||||
[auto-ap.views.components.typeahead :refer [typeahead-v3]]
|
||||
[auto-ap.views.utils :refer [dispatch-event]]
|
||||
[re-frame.core :as re-frame]))
|
||||
(:require
|
||||
[auto-ap.forms :as forms]
|
||||
[auto-ap.status :as status]
|
||||
[auto-ap.subs :as subs]
|
||||
[auto-ap.views.components.modal :as modal]
|
||||
[auto-ap.views.components.typeahead.vendor
|
||||
:refer [search-backed-typeahead]]
|
||||
[auto-ap.views.utils :refer [dispatch-event]]
|
||||
[re-frame.core :as re-frame]))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::can-submit
|
||||
@@ -21,29 +23,29 @@
|
||||
:id ::form}))
|
||||
|
||||
(defn form []
|
||||
(let [{:keys [data active? error id]} @(re-frame/subscribe [::forms/form ::form])
|
||||
{:keys [form-inline horizontal-field field raw-field error-notification submit-button]} merge-form]
|
||||
(let [_ @(re-frame/subscribe [::forms/form ::form])
|
||||
{:keys [form-inline field]} merge-form]
|
||||
|
||||
|
||||
(form-inline {}
|
||||
[:<>
|
||||
(field "Form Vendor (will be deleted)"
|
||||
[typeahead-v3 {:entities-by-id @(re-frame/subscribe [::subs/vendors-by-id])
|
||||
:entity-index @(re-frame/subscribe [::subs/all-vendors-index])
|
||||
:type "typeahead-v3"
|
||||
:auto-focus true
|
||||
:entity->text (fn [x]
|
||||
(str (:name x) " (" (reduce + 0 (map :count (:usage x))) " usages)") )
|
||||
:field [:from]}])
|
||||
[search-backed-typeahead {:search-query (fn [i]
|
||||
[:search_vendor
|
||||
{:query i}
|
||||
[:name :id]])
|
||||
:type "typeahead-v3"
|
||||
:auto-focus true
|
||||
:field [:from]}])
|
||||
|
||||
|
||||
(field "To Vendor"
|
||||
[typeahead-v3 {:entities-by-id @(re-frame/subscribe [::subs/vendors-by-id])
|
||||
:entity-index @(re-frame/subscribe [::subs/searchable-vendors-index])
|
||||
:type "typeahead-v3"
|
||||
:entity->text (fn [x]
|
||||
(str (:name x) " (" (reduce + 0 (map :count (:usage x))) " usages)") )
|
||||
:field [:to]}])])))
|
||||
[search-backed-typeahead {:search-query (fn [i]
|
||||
[:search_vendor
|
||||
{:query i}
|
||||
[:name :id]])
|
||||
:type "typeahead-v3"
|
||||
:field [:to]}])])))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::show
|
||||
@@ -68,7 +70,7 @@
|
||||
(re-frame/reg-event-fx
|
||||
::save
|
||||
[(forms/in-form ::form)]
|
||||
(fn [{{{:keys [from to]} :data :as merge-vendors-form} :db :as g} _]
|
||||
(fn [{{{:keys [from to]} :data} :db} _]
|
||||
(let [user @(re-frame/subscribe [::subs/token])]
|
||||
{:graphql
|
||||
{:token user
|
||||
|
||||
@@ -302,7 +302,6 @@
|
||||
{::track/register [{:id ::client
|
||||
:subscription [::subs/client]
|
||||
:event-fn (fn [c]
|
||||
(println "changing client?")
|
||||
[::maybe-change-client c])}
|
||||
{:id ::vendor-change
|
||||
:subscription [::forms/field ::form [:vendor]]
|
||||
|
||||
Reference in New Issue
Block a user