Undoes old way of doing forms in favor of context version. Much easier

This commit is contained in:
2022-07-17 17:32:47 -07:00
parent a17f587ff3
commit b6962c5bfa
17 changed files with 782 additions and 1393 deletions

View File

@@ -138,68 +138,3 @@
(assoc-in [::forms id :error] nil))) (assoc-in [::forms id :error] nil)))
(defn vertical-form [{:keys [can-submit id change-event submit-event fullwidth?] :or {fullwidth? true}}]
{:form
(fn [{:keys [title] :as params} & children]
(let [{:keys [data active? error]} @(re-frame/subscribe [::form id])
can-submit @(re-frame/subscribe can-submit)]
[:form { :on-submit (fn [e]
(when (.-stopPropagation e)
(.stopPropagation e)
(.preventDefault e))
(when can-submit
(re-frame/dispatch-sync (vec (conj submit-event params)))))}
[:h1.title.is-2 title]
[:<>
children]]))
:form-inline
(fn [{:keys [title] :as params} children]
(let [{:keys [data active? error]} @(re-frame/subscribe [::form id])
can-submit @(re-frame/subscribe can-submit)]
[:form { :on-submit (fn [e]
(when (.-stopPropagation e)
(.stopPropagation e)
(.preventDefault e))
(when can-submit
(re-frame/dispatch-sync (vec (conj submit-event params)))))}
(when title
[:h1.title.is-2 title])
children]))
:raw-field (fn [control]
(let [{:keys [data]} @(re-frame/subscribe [::form id])]
[bind-field (-> control
(assoc-in [1 :subscription] data)
(assoc-in [1 :event] change-event))]))
:field-holder (fn [label control]
[:div.field
(when label (if fullwidth? [:p.help label]
[:label.label label]))
[:div.control control]])
:field ^{:key "field"}
(fn [label control]
(let [{:keys [data]} @(re-frame/subscribe [::form id])]
[:div.field
(when label (if fullwidth? [:p.help label]
[:label.label label]))
[:div.control [bind-field (-> control
(assoc-in [1 :subscription] data)
(assoc-in [1 :event] change-event))]]]))
:error-notification
(fn []
(when-let [error (:error @(re-frame/subscribe [::form id]))]
^{:key error}
[:div.has-text-danger.animated.fadeInUp {} error]))
:submit-button (fn [child]
(let [error (:error @(re-frame/subscribe [::form id]))
status @(re-frame/subscribe [::status/single id])
can-submit @(re-frame/subscribe can-submit)]
[:button.button.is-medium.is-primary {:disabled (or (status/disabled-for status)
(not can-submit))
:class (cond-> (status/class-for status)
fullwidth? (conj "is-fullwidth")) }
child]))})

View File

@@ -19,8 +19,10 @@
(let [data-sub (or data-sub [::forms/form id]) (let [data-sub (or data-sub [::forms/form id])
change-event (or change-event [::forms/change id]) change-event (or change-event [::forms/change id])
{:keys [data error] form-key :id} @(re-frame/subscribe data-sub) {:keys [data error] form-key :id} @(re-frame/subscribe data-sub)
status @(re-frame/subscribe [::status/single id])] status @(re-frame/subscribe [::status/single id])
(r/create-element Provider #js {:value #js {:can-submit @(re-frame/subscribe can-submit) can-submit (if can-submit @(re-frame/subscribe can-submit)
true)]
(r/create-element Provider #js {:value #js {:can-submit can-submit
:change-event change-event :change-event change-event
:submit-event submit-event :submit-event submit-event
:error error :error error

View File

@@ -2,7 +2,6 @@
(:require (:require
[auto-ap.forms :as forms] [auto-ap.forms :as forms]
[auto-ap.status :as status] [auto-ap.status :as status]
[auto-ap.subs :as subs]
[auto-ap.utils :refer [by]] [auto-ap.utils :refer [by]]
[auto-ap.views.components.modal :as modal] [auto-ap.views.components.modal :as modal]
[auto-ap.views.components.typeahead.vendor :refer [search-backed-typeahead]] [auto-ap.views.components.typeahead.vendor :refer [search-backed-typeahead]]
@@ -10,17 +9,13 @@
[auto-ap.views.utils :refer [dispatch-event with-user]] [auto-ap.views.utils :refer [dispatch-event with-user]]
[clojure.string :as str] [clojure.string :as str]
[goog.string :as gstring] [goog.string :as gstring]
[re-frame.core :as re-frame])) [re-frame.core :as re-frame]
[auto-ap.forms.builder :as form-builder]))
(re-frame/reg-sub
::can-submit
(fn [db]
true))
(re-frame/reg-event-fx (re-frame/reg-event-fx
::try-save ::try-save
[(forms/in-form ::form)] [(forms/in-form ::form)]
(fn [{:keys [db]} [_ id ]] (fn [{:keys [db]} _]
(let [{{:keys [ total]} :invoice (let [{{:keys [ total]} :invoice
:keys [expense-accounts]} (:data db) :keys [expense-accounts]} (:data db)
expense-accounts (vals expense-accounts) expense-accounts (vals expense-accounts)
@@ -44,7 +39,7 @@
(re-frame/reg-event-fx (re-frame/reg-event-fx
::save ::save
[with-user (forms/in-form ::form)] [with-user (forms/in-form ::form)]
(fn [{:keys [db user] } [_ id]] (fn [{:keys [db user] } _]
(let [{{:keys [id]} :invoice (let [{{:keys [id]} :invoice
:keys [expense-accounts]} (:data db) :keys [expense-accounts]} (:data db)
expense-accounts (vals expense-accounts)] expense-accounts (vals expense-accounts)]
@@ -85,16 +80,10 @@
(fn [db [_ x]] (fn [db [_ x]]
(update-in db [:data :expense-accounts] dissoc x))) (update-in db [:data :expense-accounts] dissoc x)))
(def change-expense-accounts-form (forms/vertical-form {:submit-event [::try-save]
:change-event [::forms/change ::form]
:can-submit [::can-submit]
:id ::form}))
(defn form [] (defn form []
(let [{:keys [data active? error id]} @(re-frame/subscribe [::forms/form ::form]) (let [{:keys [data]} @(re-frame/subscribe [::forms/form ::form])
expense-accounts (:expense-accounts data) expense-accounts (:expense-accounts data)
{:keys [total] :or {total 0} {:keys [locations] :as client} :client} (:invoice data) {:keys [total] :or {total 0} {:keys [locations] :as client} :client} (:invoice data)
{:keys [form-inline horizontal-field field raw-field error-notification submit-button]} change-expense-accounts-form
multi-location? (> (count locations) 1) multi-location? (> (count locations) 1)
expense-accounts-total (->> expense-accounts expense-accounts-total (->> expense-accounts
vals vals
@@ -108,7 +97,8 @@
[:div [:div
[:div [:div
[:a.button.is-outlined {:on-click (dispatch-event [::add-split])} "Add split"]] [:a.button.is-outlined {:on-click (dispatch-event [::add-split])} "Add split"]]
(form-inline {} [form-builder/builder {:submit-event [::try-save]
:id ::form}
[:table.table [:table.table
[:thead [:thead
[:tr [:tr
@@ -119,18 +109,18 @@
[:th {:style {:width "300px"}} "Amount"] [:th {:style {:width "300px"}} "Amount"]
[:th {:style {:width "5em"}}]]] [:th {:style {:width "5em"}}]]]
[:tbody [:tbody
(doall (for [[id expense-account] expense-accounts] (doall (for [[id _] expense-accounts]
^{:key id} ^{:key id}
[:tr [:tr
[:td.expandable [:div.control [:td.expandable [:div.control
(raw-field [form-builder/raw-field
[search-backed-typeahead {:search-query (fn [i] [search-backed-typeahead {:search-query (fn [i]
[:search_account [:search_account
{:query i {:query i
:client-id (:id client)} :client-id (:id client)}
[:name :id :location]]) [:name :id :location]])
:type "typeahead-v3" :type "typeahead-v3"
:field [:expense-accounts id :account]}])]] :field [:expense-accounts id :account]}]]]]
(when multi-location? (when multi-location?
[:td [:td
@@ -138,11 +128,12 @@
[:div.select [:div.select
[:select {:disabled "disabled" :value forced-location} [:option {:value forced-location} forced-location]]] [:select {:disabled "disabled" :value forced-location} [:option {:value forced-location} forced-location]]]
[:div.select [:div.select
(raw-field
[form-builder/raw-field
[:select {:type "select" [:select {:type "select"
:field [:expense-accounts id :location] :field [:expense-accounts id :location]
:spec (set locations)} :spec (set locations)}
(map (fn [l] ^{:key l} [:option {:value l} l]) locations)])])]) (map (fn [l] ^{:key l} [:option {:value l} l]) locations)]]])])
[:td [:td
(str "$" (get-in expense-accounts [id :amount]))] (str "$" (get-in expense-accounts [id :amount]))]
@@ -151,7 +142,7 @@
[:div.field.has-addons.is-extended [:div.field.has-addons.is-extended
[:p.control [:a.button.is-static "$"]] [:p.control [:a.button.is-static "$"]]
[:p.control [:p.control
(raw-field [form-builder/raw-field
[:input.input {:type "number" [:input.input {:type "number"
:field [:expense-accounts id :new-amount-temp] :field [:expense-accounts id :new-amount-temp]
:style {:text-align "right"} :style {:text-align "right"}
@@ -163,7 +154,7 @@
true) true)
false)) false))
:max (:total data) :max (:total data)
:step "0.01"}])]]]] :step "0.01"}]]]]]]
[:td [:a.button {:on-click (dispatch-event [::remove-expense-account-split id])} [:i.fa.fa-times]]]])) [:td [:a.button {:on-click (dispatch-event [::remove-expense-account-split id])} [:i.fa.fa-times]]]]))
[:tr [:tr
[:td.no-border { :col-span (if multi-location? "3" "2") :style { :text-align "right"} } "Invoice total: "] [:td.no-border { :col-span (if multi-location? "3" "2") :style { :text-align "right"} } "Invoice total: "]
@@ -173,7 +164,8 @@
[:td { :style { :text-align "right"} } (str (gstring/format "$%.2f" expense-accounts-total ) )]] [:td { :style { :text-align "right"} } (str (gstring/format "$%.2f" expense-accounts-total ) )]]
[:tr [:tr
[:td.no-border { :col-span (if multi-location? "3" "2") :style { :text-align "right"} } "Difference: "] [:td.no-border { :col-span (if multi-location? "3" "2") :style { :text-align "right"} } "Difference: "]
[:td.no-border { :style { :text-align "right"} } (str (gstring/format "$%.2f" (- total expense-accounts-total) ) )]]]])])) [:td.no-border { :style { :text-align "right"} } (str (gstring/format "$%.2f" (- total expense-accounts-total) ) )]]]]
[form-builder/hidden-submit-button]]]))
(re-frame/reg-event-fx (re-frame/reg-event-fx
::show ::show
@@ -184,7 +176,6 @@
:status-from [::status/single ::form] :status-from [::status/single ::form]
:class "is-primary" :class "is-primary"
:on-click (dispatch-event [::try-save]) :on-click (dispatch-event [::try-save])
:can-submit [::can-submit]
:close-event [::status/completed ::form]}}] :close-event [::status/completed ::form]}}]
:db (-> db :db (-> db
(forms/start-form ::form (forms/start-form ::form

View File

@@ -5,7 +5,7 @@
[react :as react])) [react :as react]))
(def good-$ #"^\-?[0-9]+(\.[0-9][0-9])?$") (def good-$ #"^\-?[0-9]+(\.[0-9][0-9])?$")
(defn -money-field [{:keys [min max disabled on-change value class style]}] (defn -money-field [{:keys [min max disabled on-change value class style placeholder]}]
(let [[ parsed-amount set-parsed-amount] (react/useState {:parsed value (let [[ parsed-amount set-parsed-amount] (react/useState {:parsed value
:raw (cond :raw (cond
(str/blank? value) (str/blank? value)
@@ -40,6 +40,7 @@
[:div.control.has-icons-left [:div.control.has-icons-left
[:input.input {:type "text" [:input.input {:type "text"
:disabled disabled :disabled disabled
:placeholder placeholder
:class class :class class
:on-change (fn [e] :on-change (fn [e]
(let [raw (.. e -target -value) (let [raw (.. e -target -value)

View File

@@ -119,7 +119,9 @@
[:div.level-item [:div.level-item
[:div.control [:div.control
[:div.tags.has-addons [:div.tags.has-addons
[:span.tag (:name selectedItem)] [:span.tag (if entity->text
(entity->text selectedItem)
(:name selectedItem))]
(when name (when name
[:input {:type "hidden" :name name :value (:id (js->clj selectedItem :keywordize-keys true))}]) [:input {:type "hidden" :name name :value (:id (js->clj selectedItem :keywordize-keys true))}])
(when-not disabled (when-not disabled

View File

@@ -4,16 +4,16 @@
[auto-ap.subs :as subs] [auto-ap.subs :as subs]
[auto-ap.views.components.layouts :refer [side-bar]] [auto-ap.views.components.layouts :refer [side-bar]]
[auto-ap.views.components.typeahead :refer [typeahead-v3]] [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.spec.alpha :as s]
[clojure.string :as str] [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 types [:dividend :expense :asset :liability :equity :revenue])
(def applicabilities [:global :optional :customized]) (def applicabilities [:global :optional :customized])
(re-frame/reg-sub (re-frame/reg-sub
::request ::request
:<- [::forms/form ::form] :<- [::forms/form ::form]
@@ -51,91 +51,87 @@
(re-frame/reg-event-fx (re-frame/reg-event-fx
::edited ::edited
[(forms/triggers-saved ::form :upsert-account)] [(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 (re-frame/reg-event-fx
::saving ::saving
(fn [{:keys [db]} _] [with-user (re-frame/inject-cofx ::inject/sub [::request]) ]
(fn [{:keys [user] ::keys [request]} _]
(when @(re-frame/subscribe [::can-submit]) (when @(re-frame/subscribe [::can-submit])
(let [{{:keys [id type name numeric-code account-set]} :data :as data} @(re-frame/subscribe [::forms/form ::form])] (let [_ @(re-frame/subscribe [::forms/form ::form])]
{:db (forms/loading db ::form ) {:graphql
:graphql {:owns-state {:single ::form}
{:token (-> db :user) :token user
:query-obj {:venia/operation {:operation/type :mutation :query-obj {:venia/operation {:operation/type :mutation
:operation/name "UpsertAccount"} :operation/name "UpsertAccount"}
:venia/queries [{:query/data [:upsert-account :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]]]]]]}]} [:id :type :name :account-set :numeric-code :location :applicability [:client-overrides [:name :id [:client [:id :name]]]]]]}]}
:on-success [::edited] :on-success [::edited]
:on-error [::forms/save-error ::form]}})))) :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 [_] (defn form [_]
(let [{error :error account :data } @(re-frame/subscribe [::forms/form ::form]) (let [{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)}
[side-bar {:on-close (dispatch-event [::forms/form-closing ::form])} [side-bar {:on-close (dispatch-event [::forms/form-closing ::form])}
(form-inline {:title (if (:id 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" "Edit account"
"Add account")} "Add account")}
[:<> [form-builder/field
"Account Set"
(field "Account Set"
[:input.input {:type "text" [:input.input {:type "text"
:field :account-set :field :account-set
:disabled (boolean (:id account)) :disabled (boolean (:id account))
:spec ::entity/account-set}]) :spec ::entity/account-set}]]
(field "Code" [form-builder/field
"Code"
[:input.input {:type "text" [:input.input {:type "text"
:field :numeric-code :field :numeric-code
:disabled (boolean (:id account)) :disabled (boolean (:id account))
:spec ::entity/numeric-code}]) :spec ::entity/numeric-code}]]
(field "Name" [form-builder/field
"Name"
[:input.input {:type "text" [:input.input {:type "text"
:field :name :field :name
:spec ::entity/name}]) :spec ::entity/name}]]
(field-holder "Account Type" [form-builder/vertical-control
"Account Type"
[:div.select [:div.select
(raw-field [form-builder/raw-field
[:select {:type "select" [:select {:type "select"
:field :type :field :type
:spec (set types)} :spec (set types)}
(map (fn [l] (map (fn [l]
[:option {:value (name l)} (str/capitalize (name l))]) types)])]) [:option {:value (name l)} (str/capitalize (name l))]) types)]]]]
(field "Location" [form-builder/field
"Location"
[:input.input.known-field.location {:type "text" [:input.input.known-field.location {:type "text"
:field :location :field :location
:spec ::entity/location}]) :spec ::entity/location}]]
[form-builder/section {:title "Client"}
[:h2.subtitle "Client"] [:h2.subtitle "Client"]
(field-holder "Applicability" [form-builder/vertical-control
"Applicability"
[:div.select [:div.select
(raw-field [form-builder/raw-field
[:select {:type "select" [:select {:type "select"
:field :applicability :field :applicability
:spec (set applicabilities)} :spec (set applicabilities)}
(map (fn [l] (map (fn [l]
[:option {:value (name l)} (str/capitalize (name l))]) applicabilities)])]) [:option {:value (name l)} (str/capitalize (name l))]) applicabilities)]]]]
(field "Customizations" [form-builder/field
"Customizations"
[multi-field {:type "multi-field" [multi-field {:type "multi-field"
:field [:client-overrides] :field [:client-overrides]
:template [[typeahead-v3 {:entities @(re-frame/subscribe [::subs/clients]) :template [[typeahead-v3 {:entities @(re-frame/subscribe [::subs/clients])
@@ -147,7 +143,7 @@
:style {:width "15em"} :style {:width "15em"}
:placeholder "Bubblegum" :placeholder "Bubblegum"
:field [:name]}] :field [:name]}]
]}]) ]}]]]
(error-notification) [form-builder/error-notification]
(submit-button "Save")])])) [form-builder/submit-button "Save"]]]]))

View File

@@ -3,13 +3,16 @@
[auto-ap.entities.transaction-rule :as entity] [auto-ap.entities.transaction-rule :as entity]
[auto-ap.events :as events] [auto-ap.events :as events]
[auto-ap.forms :as forms] [auto-ap.forms :as forms]
[auto-ap.forms.builder :as form-builder]
[auto-ap.status :as status] [auto-ap.status :as status]
[auto-ap.subs :as subs] [auto-ap.subs :as subs]
[auto-ap.views.components.level :refer [left-stack]]
[auto-ap.views.components.button-radio :refer [button-radio]] [auto-ap.views.components.button-radio :refer [button-radio]]
[auto-ap.views.components.expense-accounts-field [auto-ap.views.components.expense-accounts-field
:as expense-accounts-field :as expense-accounts-field
:refer [expense-accounts-field]] :refer [expense-accounts-field]]
[auto-ap.views.components.layouts :as layouts] [auto-ap.views.components.layouts :as layouts]
[auto-ap.views.components.money-field :refer [money-field]]
[auto-ap.views.components.typeahead :refer [typeahead-v3]] [auto-ap.views.components.typeahead :refer [typeahead-v3]]
[auto-ap.views.components.typeahead.vendor [auto-ap.views.components.typeahead.vendor
:refer [search-backed-typeahead]] :refer [search-backed-typeahead]]
@@ -29,7 +32,6 @@
::default-note ::default-note
:<- [::forms/form ::form] :<- [::forms/form ::form]
(fn [{{:keys [client description amount-lte amount-gte dom-lte dom-gte]} :data}] (fn [{{:keys [client description amount-lte amount-gte dom-lte dom-gte]} :data}]
(str/join " - " (filter (complement str/blank?) (str/join " - " (filter (complement str/blank?)
[(:code client) [(:code client)
description description
@@ -195,6 +197,9 @@
(:default-account value) (:default-account value)
(:total data) (:total data)
[])] [])]
(= [:client] field)
[[:bank-account] nil]
:else :else
[])))) []))))
@@ -223,9 +228,8 @@
(re-frame/reg-event-fx (re-frame/reg-event-fx
::updated ::updated
[(forms/triggers-stop ::form)] [(forms/triggers-stop ::form)]
(fn [{:keys [db]} [_ {:keys [rule-saved]} result]] (fn [{:keys [db]} [_ {:keys [rule-saved]} _]]
{:db (forms/start-form db ::form {:client @(re-frame/subscribe [::subs/client])}) {:db (forms/start-form db ::form {:client @(re-frame/subscribe [::subs/client])})}))
:dispatch (conj rule-saved (:upsert-transaction-rule result))}))
(re-frame/reg-event-fx (re-frame/reg-event-fx
::succeeded-test ::succeeded-test
@@ -238,10 +242,6 @@
;; VIEWS ;; VIEWS
(def rule-form (forms/vertical-form {:can-submit [::can-submit]
:change-event [::changed]
:submit-event [::saving ]
:id ::form}))
(re-frame/reg-event-fx (re-frame/reg-event-fx
::mounted ::mounted
@@ -264,122 +264,117 @@
(defn form-contents [params] (defn form-contents [params]
[layouts/side-bar {:on-close (dispatch-event [::forms/form-closing ::form ])} [layouts/side-bar {:on-close (dispatch-event [::forms/form-closing ::form ])}
(let [{:keys [data id]} @(re-frame/subscribe [::forms/form ::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]) default-note @(re-frame/subscribe [::default-note])
test-state @(re-frame/subscribe [::status/single ::test])] test-state @(re-frame/subscribe [::status/single ::test])]
^{:key id} [form-builder/builder {:can-submit [::can-submit]
(form-inline (assoc params :title "New Transaction Rule") :change-event [::changed]
[:<> :submit-event [::saving ]
:id ::form}
[form-builder/section {:title "Transaction Rule"}
(field "Client" [form-builder/field {:required? true}
"Client"
[typeahead-v3 {:entities @(re-frame/subscribe [::subs/clients]) [typeahead-v3 {:entities @(re-frame/subscribe [::subs/clients])
:auto-focus true :auto-focus true
:entity->text :name :entity->text :name
:type "typeahead-v3" :type "typeahead-v3"
:field [:client] :field [:client]
:spec ::entity/client}]) :spec ::entity/client}]]
(with-meta [form-builder/field
(field "Bank account" "Bank account"
[typeahead-v3 {:entities @(re-frame/subscribe [::subs/real-bank-accounts-for-client (:client data)]) [typeahead-v3 {:entities @(re-frame/subscribe [::subs/real-bank-accounts-for-client (:client data)])
:entity->text :name :entity->text :name
:type "typeahead-v3" :type "typeahead-v3"
:field [:bank-account] :field [:bank-account]
:spec ::entity/bank-account}]) :spec ::entity/bank-account}]]
;; TODO this forces unmounting when client changes, since it is an "uncontorlled" input
{:key (str "client-" (:id (:client data)))})
(field "Yodlee Merchant" #_[form-builder/field
"Yodlee Merchant"
[typeahead-v3 {:entities @(re-frame/subscribe [::subs/yodlee-merchants]) [typeahead-v3 {:entities @(re-frame/subscribe [::subs/yodlee-merchants])
:entity->text #(str (:name %) " - " (:yodlee-id %)) :entity->text #(str (:name %) " - " (:yodlee-id %))
:type "typeahead-v3" :type "typeahead-v3"
:field [:yodlee-merchant]}]) :field [:yodlee-merchant]}]]
(field [:span "Description (" [:a {:href "https://regex101.com" :target "_new"} "regex tester"] ")" ] [form-builder/field
[:span "Description (" [:a {:href "https://regex101.com" :target "_new"} "regex tester"] ")" ]
[:input.input {:type "text" [:input.input {:type "text"
:field [:description] :field [:description]
:spec ::entity/description}]) :spec ::entity/description}]]
[:div.field [:div.field
[:p.help "Amount"] [:p.help "Amount"]
[:div.control [left-stack
[:div.columns [form-builder/raw-field
[:div.column [money-field {:type "money"
(raw-field
[:input.input {:type "number"
:placeholder ">=" :placeholder ">="
:field [:amount-gte] :field [:amount-gte]
:spec ::entity/amount-gte :spec ::entity/amount-gte}]]
:step "0.01"}])] "-"
[:div.column [form-builder/raw-field
(raw-field [money-field {:type "money"
[:input.input {:type "number"
:placeholder "<=" :placeholder "<="
:field [:amount-lte] :field [:amount-lte]
:spec ::entity/amount-lte :spec ::entity/amount-lte}]]]]
:step "0.01"}])]]]]
[:div.field [:div.field
[:p.help "Day of Month"] [:p.help "Day of Month"]
[:div.control [:div.control
[:div.columns [:div.columns
[:div.column [:div.column
(raw-field [form-builder/raw-field
[:input.input {:type "number" [:input.input {:type "number"
:placeholder ">=" :placeholder ">="
:field [:dom-gte] :field [:dom-gte]
:spec ::entity/dom-gte :spec ::entity/dom-gte
:precision 0 :precision 0
:step "1"}])] :step "1"}]]]
[:div.column [:div.column
(raw-field [form-builder/raw-field
[:input.input {:type "number" [:input.input {:type "number"
:placeholder "<=" :placeholder "<="
:field [:dom-lte] :field [:dom-lte]
:spec ::entity/dom-lte :spec ::entity/dom-lte
:precision 0 :precision 0
:step "1"}])]]]] :step "1"}]]]]]]
[:h2.title.is-4 "Outcomes"] [:h2.title.is-4 "Outcomes"]
(field "Assign Vendor" [form-builder/field "Assign Vendor"
[search-backed-typeahead {:search-query (fn [i] [search-backed-typeahead {:search-query (fn [i]
[:search_vendor [:search_vendor
{:query i} {:query i}
[:name :id]]) [:name :id]])
:type "typeahead-v3" :type "typeahead-v3"
:field [:vendor]}]) :field [:vendor]}]]
(with-meta [form-builder/raw-field
(field nil
[expense-accounts-field {:type "expense-accounts" [expense-accounts-field {:type "expense-accounts"
:descriptor "account asssignment" :descriptor "account asssignment"
:percentage-only? true :percentage-only? true
:client (:client data) :client (:client data)
:locations (into ["Shared"] @(re-frame/subscribe [::subs/locations-for-client-or-bank-account (:id (:client data)) (:id (:bank-account data))])) :locations (into ["Shared"] @(re-frame/subscribe [::subs/locations-for-client-or-bank-account (:id (:client data)) (:id (:bank-account data))]))
:max 100 :max 100
:field [:accounts]}]) :field [:accounts]}]]
{:key (str (some-> data :vendor :id str) "-" (some-> data :client :id str))})
(field "Approval Status" [form-builder/field
"Approval Status"
[button-radio [button-radio
{:type "button-radio" {:type "button-radio"
:field [:transaction-approval-status] :field [:transaction-approval-status]
:options [[:unapproved "Unapproved"] :options [[:unapproved "Unapproved"]
[:requires-feedback "Client Review"] [:requires-feedback "Client Review"]
[:approved "Approved"] [:approved "Approved"]
[:excluded "Excluded from Ledger"]]}]) [:excluded "Excluded from Ledger"]]}]]
(field "Note" [form-builder/field "Note"
[:input.input {:type "text" [:input.input {:type "text"
:field [:note] :field [:note]
:placeholder default-note :placeholder default-note
:spec (s/nilable ::entity/note)}]) :spec (s/nilable ::entity/note)}]]
[:div.is-divider] [:div.is-divider]
(error-notification) [form-builder/error-notification]
[:div.columns [:div.columns
[:div.column [:div.column
[:a.button.is-medium.is-fullwidth.is-outlined {:on-click (dispatch-event [::test-clicked]) [:a.button.is-medium.is-fullwidth.is-outlined {:on-click (dispatch-event [::test-clicked])
@@ -387,7 +382,8 @@
:class (status/class-for test-state)} :class (status/class-for test-state)}
"Test Rule"]] "Test Rule"]]
[:div.column [:div.column
(submit-button "Save")]]]))]) [form-builder/submit-button {:class ["is-fullwidth"]}
"Save"]]]]])])
(defn form [_] (defn form [_]
(r/create-class (r/create-class

View File

@@ -1,49 +1,14 @@
(ns auto-ap.views.pages.admin.users.form (ns auto-ap.views.pages.admin.users.form
(:require [re-frame.core :as re-frame] (:require
[reagent.core :as reagent]
[clojure.string :as str]
[auto-ap.subs :as subs]
[auto-ap.events :as events]
[auto-ap.entities.clients :as entity] [auto-ap.entities.clients :as entity]
[auto-ap.views.components.address :refer [address-field]]
[auto-ap.views.components.admin.side-bar :refer [admin-side-bar]]
[auto-ap.views.components.layouts :refer [side-bar-layout]]
[auto-ap.views.utils :refer [login-url dispatch-value-change bind-field horizontal-field dispatch-event with-user]]
[auto-ap.views.components.grid :as grid]
[auto-ap.utils :refer [by replace-if]]
[cljs.reader :as edn]
[auto-ap.routes :as routes]
[bidi.bidi :as bidi]
[auto-ap.status :as status]
[auto-ap.forms :as forms] [auto-ap.forms :as forms]
[auto-ap.views.components.modal :as modal])) [auto-ap.forms.builder :as form-builder]
[auto-ap.status :as status]
(re-frame/reg-sub [auto-ap.subs :as subs]
::can-submit [auto-ap.views.components.modal :as modal]
(fn [db] [auto-ap.views.components.typeahead :refer [typeahead-v3]]
true)) [auto-ap.views.utils :refer [dispatch-event multi-field with-user]]
[re-frame.core :as re-frame]))
(re-frame/reg-event-db
::changed
(forms/change-handler ::form
(fn [data field value]
[])))
(re-frame/reg-event-db
::add-client
[(forms/in-form ::form)]
(fn [form [_ d]]
(let [client (get @(re-frame/subscribe [::subs/clients-by-id])
(get-in form [:data :adding-client]))]
(update-in form [:data :clients] conj client ))))
(re-frame/reg-event-db
::remove-client
[(forms/in-form ::form)]
(fn [form [_ d]]
(update-in form [:data :clients] #(filter (fn [c] (not= (:id c) d)) %))))
(re-frame/reg-event-fx (re-frame/reg-event-fx
::saving ::saving
@@ -56,7 +21,7 @@
:operation/name "EditUser"} :operation/name "EditUser"}
:venia/queries [{:query/data [:edit-user :venia/queries [{:query/data [:edit-user
{:edit-user (-> (:data db) {:edit-user (-> (:data db)
(update :clients #(map :id %)) (update :clients #(map (comp :id :client) %))
(select-keys #{:id :name :clients :role}))} (select-keys #{:id :name :clients :role}))}
[:id :name :role [:clients [:id :name]]]]}]} [:id :name :role [:clients [:id :name]]]]}]}
:on-success [::saved]}})) :on-success [::saved]}}))
@@ -64,28 +29,25 @@
(re-frame/reg-event-fx (re-frame/reg-event-fx
::saved ::saved
(forms/triggers-stop ::form) (forms/triggers-stop ::form)
(fn [{:keys [db]} [_ {:keys [edit-user]}]] (fn [_ _]
{:dispatch [::modal/modal-closed]})) {:dispatch [::modal/modal-closed]}))
(def user-form (forms/vertical-form {:submit-event [::saving]
:change-event [::changed]
:can-submit [::can-submit]
:id ::form}))
(defn form [] (defn form []
(let [{:keys [data active? error id]} @(re-frame/subscribe [::forms/form ::form]) (let [{:keys [data]} @(re-frame/subscribe [::forms/form ::form])
{:keys [form-inline field raw-field error-notification submit-button]} user-form] clients @(re-frame/subscribe [::subs/clients])]
(form-inline {} [form-builder/builder {:submit-event [::saving]
[:<> :id ::form}
(field "Name" [form-builder/field
"Name"
[:input.input {:type "text" [:input.input {:type "text"
:field [:name] :field [:name]
:spec ::entity/name}]) :spec ::entity/name}]]
[:div.field [:div.field
[:p.help "Role"] [:p.help "Role"]
[:div.control [:div.control
[:div.select [:div.select
[raw-field [form-builder/raw-field
[:select {:type "select" [:select {:type "select"
:field [:role]} :field [:role]}
[:option {:value ":none"} "None"] [:option {:value ":none"} "None"]
@@ -94,31 +56,22 @@
[:option {:value ":power_user"} "Power User"] [:option {:value ":power_user"} "Power User"]
[:option {:value ":admin"} "Admin"]]]]]] [:option {:value ":admin"} "Admin"]]]]]]
(when (#{":user" ":manager" ":power_user"} (:role data)) (when (#{":user" ":manager" ":power_user"} (:role data))
[:div.field [form-builder/field
[:p.help "Clients"] "Client"
[:div.control [multi-field {:type "multi-field"
[:div.field.has-addons :field [:clients]
[:div.control :template [[typeahead-v3 {:entities clients
[:div.select :entity->text :name
[raw-field :style {:width "13em"}
[:select {:type "select" :type "typeahead-v3"
:field [:adding-client]} :field [:client]}]]}]])
[:option] [form-builder/hidden-submit-button]]))
(let [used-clients (set (map :id (:clients data)))]
(for [{:keys [id name] :as client} @(re-frame/subscribe [::subs/clients])
:when (not (used-clients id))]
^{:key id} [:option {:value id} name]))]]]]
[:p.control
[:button.button.is-primary {:on-click (dispatch-event [::add-client])} "Add"]]]
[:ul
(for [{:keys [id name]} (:clients data)]
^{:key id} [:li name [:a.icon {:on-click (dispatch-event [::remove-client id])} [:i.fa.fa-times ]]])]]])])))
(re-frame/reg-event-fx (re-frame/reg-event-fx
::editing ::editing
(fn [{:keys [db]} [_ d]] (fn [{:keys [db]} [_ d]]
{:db (-> db {:db (-> db
(forms/start-form ::form d)) (forms/start-form ::form (update d :clients #(map (fn [x] {:client x}) %))))
:dispatch [::modal/modal-requested {:title (str "Edit user " (:name d)) :dispatch [::modal/modal-requested {:title (str "Edit user " (:name d))
:body [form] :body [form]
:cancel? false :cancel? false

View File

@@ -7,45 +7,38 @@
[auto-ap.views.components.typeahead.vendor [auto-ap.views.components.typeahead.vendor
:refer [search-backed-typeahead]] :refer [search-backed-typeahead]]
[auto-ap.views.utils :refer [dispatch-event]] [auto-ap.views.utils :refer [dispatch-event]]
[re-frame.core :as re-frame])) [re-frame.core :as re-frame]
[auto-ap.forms.builder :as form-builder]))
(re-frame/reg-sub (re-frame/reg-sub
::can-submit ::can-submit
:<- [::forms/form ::form] :<- [::forms/form ::form]
(fn [{:keys [data]}] (fn [{:keys [data]}]
(println data)
(and (:from data) (and (:from data)
(:to data)))) (:to data))))
(def merge-form (forms/vertical-form {:submit-event [::save]
:change-event [::forms/change ::form]
:can-submit [::can-submit]
:id ::form}))
(defn form [] (defn form []
(let [_ @(re-frame/subscribe [::forms/form ::form]) [form-builder/builder {:submit-event [::save]
{:keys [form-inline field]} merge-form] :can-submit [::can-submit]
:id ::form}
[form-builder/field "Form Vendor (will be deleted)"
(form-inline {}
[:<>
(field "Form Vendor (will be deleted)"
[search-backed-typeahead {:search-query (fn [i] [search-backed-typeahead {:search-query (fn [i]
[:search_vendor [:search_vendor
{:query i} {:query i}
[:name :id]]) [:name :id]])
:type "typeahead-v3" :type "typeahead-v3"
:auto-focus true :auto-focus true
:field [:from]}]) :field [:from]}]]
(field "To Vendor" [form-builder/field "To Vendor"
[search-backed-typeahead {:search-query (fn [i] [search-backed-typeahead {:search-query (fn [i]
[:search_vendor [:search_vendor
{:query i} {:query i}
[:name :id]]) [:name :id]])
:type "typeahead-v3" :type "typeahead-v3"
:field [:to]}])]))) :field [:to]}]]
[form-builder/hidden-submit-button]])
(re-frame/reg-event-fx (re-frame/reg-event-fx
::show ::show
@@ -58,8 +51,7 @@
:on-click (dispatch-event [::save]) :on-click (dispatch-event [::save])
:can-submit [::can-submit] :can-submit [::can-submit]
:close-event [::status/completed ::form]}}] :close-event [::status/completed ::form]}}]
:db (forms/start-form db ::form {})} :db (forms/start-form db ::form {})}))
))
(re-frame/reg-event-fx (re-frame/reg-event-fx
::complete ::complete

View File

@@ -1,415 +0,0 @@
(ns auto-ap.views.pages.admin.yodlee
(:require [re-frame.core :as re-frame]
[auto-ap.forms :as forms]
[reagent.core :as reagent]
[clojure.string :as str]
[cljs-time.format :as f]
[cljs-time.core :as time]
[auto-ap.subs :as subs]
[auto-ap.events :as events]
[auto-ap.entities.clients :as entity]
[auto-ap.views.components.layouts :refer [side-bar-layout]]
[auto-ap.views.components.admin.side-bar :refer [admin-side-bar]]
[auto-ap.views.components.address :refer [address-field]]
[auto-ap.views.utils :refer [login-url dispatch-event dispatch-value-change bind-field horizontal-field str->date date->str with-user]]
[auto-ap.views.components.modal :as modal]
[auto-ap.status :as status]
[cljs.reader :as edn]
[auto-ap.routes :as routes]
[bidi.bidi :as bidi]))
(re-frame/reg-sub
::authentication
(fn [db]
(-> db ::yodlee :authentication)))
(re-frame/reg-sub
::can-submit
(fn [db]
true))
(re-frame/reg-sub
::loading?
(fn [db]
(-> db ::yodlee :loading?)))
(re-frame/reg-sub
::accounts
(fn [db]
(-> db ::yodlee :accounts)))
(re-frame/reg-sub
::accounts-loading?
(fn [db]
(-> db ::yodlee :accounts-loading?)))
(re-frame/reg-sub
::provider-accounts-loading?
(fn [db]
(-> db ::provider-accounts-loading?)))
(re-frame/reg-sub
::provider-accounts
(fn [db]
(-> db ::provider-accounts)))
(re-frame/reg-event-fx
::authenticate-with-yodlee
(fn [{:keys [db]} _]
{:db (assoc-in db [::yodlee :loading?] true)
:http {:token (:user db)
:method :get
:headers {"Content-Type" "application/edn"}
:uri (str "/api/yodlee/fastlink")
:on-success [::authenticated]
:on-error [::save-error]}}))
(re-frame/reg-event-fx
::mounted
(fn [{:keys [db]} _]
{:db (-> db
(assoc ::yodlee {:provider-accounts-loading? true})
(assoc ::save-error nil)
(assoc ::provider-accounts [])
(assoc ::provider-accounts-loading? true))
:http {:token (:user db)
:method :get
:headers {"Content-Type" "application/edn"}
:uri (str "/api/yodlee/provider-accounts")
:on-success [::got-provider-accounts]
:on-error [::save-error]}}))
(re-frame/reg-event-fx
::kicked
(fn [{:keys [db]} [_ id state]]
{:dispatch [::mounted]}))
(re-frame/reg-event-fx
::kicked
(fn [{:keys [db]} [_ id state]]
{:dispatch [::mounted]}))
(re-frame/reg-event-fx
::kick
(fn [{:keys [db]} [_ id]]
{:http {:token (:user db)
:method :post
:headers {"Content-Type" "application/edn"}
:uri (str "/api/yodlee/provider-accounts/" id)
:on-success [::kicked id :kicked]
:on-error [::kicked id :errored]}}))
(re-frame/reg-event-fx
::got-accounts
(fn [{:keys [db]} [_ accounts]]
{:db (-> db
(assoc-in [::yodlee :accounts] accounts)
(assoc-in [::yodlee :accounts-loading?] false))}))
(re-frame/reg-event-fx
::got-provider-accounts
(fn [{:keys [db]} [_ accounts]]
{:db (-> db
(assoc-in [::provider-accounts] accounts)
(assoc-in [::provider-accounts-loading?] false))}))
(re-frame/reg-event-fx
::authenticated
(fn [{:keys [db]} [_ authentication]]
{:db (-> db
(assoc-in [::yodlee :authentication] authentication)
(assoc-in [::yodlee :loading?] false))}))
(re-frame/reg-event-fx
::authenticated-mfa
(fn [{:keys [db]} [_ provider-account-id authentication]]
{:db (-> db
(assoc-in [::yodlee :authentication] authentication)
(assoc-in [::yodlee :loading?] false)
(forms/stop-form [::mfa-form provider-account-id]))}))
(re-frame/reg-event-fx
::save-error
(fn [{:keys [db]} [_ authentication]]
{:db (assoc db ::load-error "error")}))
(defn yodlee-link-button []
[:div
(let [authentication @(re-frame/subscribe [::authentication])
loading? @(re-frame/subscribe [::loading?])]
(if authentication
[:div
"Authentication successful!"
[:form {:action (:url authentication) :method "POST"}
[:input {:type "hidden"
:name "rsession"
:value (:session authentication)}]
[:input {:type "hidden"
:name "token"
:value (:token authentication)}]
[:input {:type "hidden"
:name "app"
:value (:app authentication)}]
[:input {:type "hidden"
:name "redirectReq"
:value "true"}]
[:button.button.is-primary [:span [:span.icon [:i.fa.fa-external-link]] " Go to yodlee"]]]]
[:button.button.is-primary {:class (if loading? "is-loading" "") :on-click (dispatch-event [::authenticate-with-yodlee])} "Authenticate with Yodlee"]))])
(defn yodlee-date->date [d]
(try
(some-> d
(str->date (:date-time-no-ms f/formatters))
)
(catch js/Error e
nil)))
(defn yodlee-date->str [d]
(try
(or (some-> d
(str->date (:date-time-no-ms f/formatters))
date->str)
"N/A")
(catch js/Error e
"N/A")))
(defn yodlee-accounts-table [accounts]
(let [bank-accounts @(re-frame/subscribe [::bank-accounts-by-yodlee-account-id])]
[:div
[:table.table
[:thead
[:tr
[:th "Account Name"]
[:th "Account Number"]
[:th "Yodlee Account Number"]
[:th "Balance"]
[:th "Yodlee Status"]
[:th "Usage"]]]
[:tbody
(for [account accounts]
^{:key (:id account)} [:tr
[:td (:accountName account)]
[:td (:accountNumber account)]
[:td (:id account)]
[:td.has-text-right (:amount (:balance account))]
[:td (str/join ", " (map :additionalStatus (:dataset account)))]
[:td
(when-let [bank-accounts (get bank-accounts (:id account))]
[:div.tags
(for [bank-account bank-accounts]
^{:key (:id bank-account)}
[:div.tag (:name bank-account) " (" (:code bank-account) ")"])])]
])]]]))
(re-frame/reg-event-fx
::reauthenticate-mfa
[with-user ]
(fn [{:keys [user db]} [_ provider-account-id ]]
{:db (forms/loading db [::mfa-form provider-account-id])
:http {:token user
:method :post
:headers {"Content-Type" "application/edn"}
:uri (str "/api/yodlee/reauthenticate/" provider-account-id )
:body {"loginForm"
{"row"
(->> (get-in db [::forms/forms [::mfa-form provider-account-id]])
:data
:login
(sort-by (fn [[k v]] k))
(map second)
(map (fn [row]
{"field"
(mapv (fn [[k v]]
{"id" k
"value" v})
row)})))}
"field"
(mapv (fn [[k v]]
{"id" k
"value" v})
(:mfa (:data (get-in db [::forms/forms [::mfa-form provider-account-id]]))))}
:on-success [::authenticated-mfa provider-account-id]
:on-error [::forms/save-error [::mfa-form provider-account-id] ]}}))
(re-frame/reg-event-fx
::provider-account-refreshed
(fn [{:keys [db]} [_ i result]]
{:db (assoc-in db [::provider-accounts] result)
:dispatch [::forms/form-closing [::refresh-provider-account i]]}))
(re-frame/reg-event-fx
::refresh-provider-account
[with-user ]
(fn [{:keys [user db]} [_ provider-account-id ]]
{:db (forms/loading db [::refresh-provider-account provider-account-id])
:http {:token user
:method :post
:headers {"Content-Type" "application/edn"}
:uri (str "/api/yodlee/provider-accounts/refresh/" provider-account-id )
:body {}
:on-success [::provider-account-refreshed provider-account-id]
:on-error [::forms/save-error [::refresh-provider-account provider-account-id] ]}}))
(re-frame/reg-event-fx
::provider-account-deleted
(fn [{:keys [db]} [_ i result]]
{:db (assoc-in db [::provider-accounts] result)
:dispatch-n [[::forms/form-closing [::refresh-provider-account i]]
[::modal/modal-closed ]]}))
(re-frame/reg-event-fx
::delete-provider-account
[with-user ]
(fn [{:keys [user db]} [_ provider-account-id ]]
{:http {:token user
:method :post
:owns-state {:single ::delete-provider-account}
:headers {"Content-Type" "application/edn"}
:uri (str "/api/yodlee/provider-accounts/delete/" provider-account-id )
:body {}
:on-success [::provider-account-deleted provider-account-id]
:on-error [::forms/save-error [::delete-provider-account provider-account-id] ]}}))
(re-frame/reg-event-fx
::delete-requested
[with-user]
(fn [{:keys [user db]} [_ account-id]]
{:dispatch
[::modal/modal-requested {:title "Delete Provider account "
:body [:div "Are you sure you want to delete provider account " account-id "?"]
:confirm {:value "Delete provider account"
:status-from [::status/single ::delete-provider-account]
:class "is-danger"
:on-click (dispatch-event [::delete-provider-account account-id])
:close-event [::status/completed ::delete-provider-account]}
:cancel? true}]}))
(defn delete-button [account-id]
[:button.button
{:on-click (dispatch-event [::delete-requested account-id])}
[:span.icon [:i.fa.fa-times]]])
(re-frame/reg-sub
::bank-accounts-by-yodlee-account-id
:<- [::subs/bank-accounts]
(fn [bank-accounts]
(group-by :yodlee-account-id bank-accounts)))
(defn yodlee-provider-accounts-table []
(let [bank-accounts @(re-frame/subscribe [::bank-accounts-by-yodlee-account-id])]
(if @(re-frame/subscribe [::provider-accounts-loading?])
[:div "Loading..."]
[:div.columns
[:div.column.is-half
(doall
(for [account @(re-frame/subscribe [::provider-accounts])
:let [{:keys [error status] :as g} @(re-frame/subscribe [::forms/form [::refresh-provider-account (:id account)]])
total-usages (mapcat (comp bank-accounts :id) (:accounts account))]]
^{:key (:id account)}
[:div.card {:style {:margin-bottom "1em"}}
[:div.card-header
[:div.card-header-title "Provider account " (:id account)]
[:div.card-header-icon
(when (seq total-usages)
[:div.tags
[:div.tag.is-primary (count total-usages) " usages"]])]
[:div.card-header-icon
[delete-button (:id account)]]
[:div.card-header-icon
(cond
(= :loading status) [:button.button.is-disabled.is-loading [:i.fa.fa-refresh]]
error [:button.button.is-disabled [:span.icon [:i.fa.fa-exclamation-triangle]]]
:else
[:button.button
{:on-click (dispatch-event [::refresh-provider-account (:id account)])}
[:span.icon [:i.fa.fa-refresh]]])]]
[:div.card-content
(if (> (some-> (-> account :dataset first :lastUpdated)
(yodlee-date->date )
(time/interval (time/now))
(time/in-days ))
1)
[:div.notification.is-info.is-light
[:div.level
[:div.level-left
[:div.level-item
[:p
"This account was last updated on "
(yodlee-date->str (-> account :dataset first :lastUpdated))
", and last attempted "
(yodlee-date->str (-> account :dataset first :lastUpdateAttempt))
"."]]]
[:div.level-right [:button.button.is-success {:on-click (dispatch-event [::kick (:id account)] )} "Sync yodlee with bank" ]]]
])
[yodlee-accounts-table (:accounts account)]
(if (not= (-> account :dataset first :additionalStatus)
"AVAILABLE_DATA_RETRIEVED")
[:div
[:div.notification.is-info.is-warning
[:div.level
[:div.level-left
[:div.level-item
"This provider account's status is '"
(-> account :dataset first :additionalStatus)
"'. If this is in error, it might help to try reauthenticating by filling out the form below."]]]]
(let [{error :error account-data :data } @(re-frame/subscribe [::forms/form [::mfa-form (:id account)]])
change-event [::forms/change [::mfa-form (:id account)]]
{:keys [form-inline field field-holder raw-field error-notification submit-button]} (forms/vertical-form {:can-submit [::can-submit]
:change-event change-event
:submit-event [::reauthenticate-mfa (:id account)]
:id [::mfa-form (:id account)]} )]
(form-inline {:title "Reauthenticate"}
[:<>
(error-notification)
(doall
(for [[row i] (map vector (-> account :loginForm last :row) (range))
f (:field row)
:let [options (map :optionValue (:option f))]]
^{:key (:id f)}
[:div
(field (:label row)
[:input.input {:type "text" :field [:login i (:id f)]}])
(if (seq options)
[:ul
(for [o options]
^{:key o}
[:li [:pre o]])])]))
(doall
(for [f (-> account :field)]
^{:key (:id f)}
(field (:label f)
[:input.input {:type "text" :mfa [:form (:id f)] :value (-> f :field first :value)}])))
(submit-button "Reauthenticate")]))])]]))]])))
(defn admin-yodlee-content []
[(with-meta
(fn []
[:div
[:h1.title "Yodlee provider accounts"]
[yodlee-provider-accounts-table]
[yodlee-link-button]])
{:component-did-mount (fn []
(re-frame/dispatch [::mounted]))})])
#_(defn admin-yodlee-page []
[side-bar-layout {:side-bar [admin-side-bar {}]
:main [admin-yodlee-content]}])

View File

@@ -1,11 +1,13 @@
(ns auto-ap.views.pages.invoices.advanced-print-checks (ns auto-ap.views.pages.invoices.advanced-print-checks
(:require [auto-ap.forms :as forms] (:require
[auto-ap.forms :as forms]
[auto-ap.forms.builder :as form-builder]
[auto-ap.status :as status] [auto-ap.status :as status]
[auto-ap.subs :as subs] [auto-ap.subs :as subs]
[auto-ap.utils :refer [by]]
[auto-ap.views.components.modal :as modal] [auto-ap.views.components.modal :as modal]
[auto-ap.views.pages.invoices.common :refer [invoice-read does-amount-exceed-outstanding?]] [auto-ap.views.pages.invoices.common
[auto-ap.views.pages.invoices.form :as form] :refer [does-amount-exceed-outstanding? invoice-read]]
[auto-ap.views.components.money-field :refer [money-field]]
[auto-ap.views.utils :refer [dispatch-event horizontal-field with-user]] [auto-ap.views.utils :refer [dispatch-event horizontal-field with-user]]
[re-frame.core :as re-frame])) [re-frame.core :as re-frame]))
@@ -13,7 +15,15 @@
::can-submit ::can-submit
:<- [::forms/form ::form] :<- [::forms/form ::form]
(fn [{ {:keys [invoices invoice-amounts]} :data}] (fn [{ {:keys [invoices invoice-amounts]} :data}]
(cond (seq (filter (cond
(->> invoice-amounts
vals
(map :amount)
(filter nil?)
seq)
false
(seq (filter
(fn [{:keys [id outstanding-balance]}] (fn [{:keys [id outstanding-balance]}]
(does-amount-exceed-outstanding? (get-in invoice-amounts [id :amount]) outstanding-balance )) (does-amount-exceed-outstanding? (get-in invoice-amounts [id :amount]) outstanding-balance ))
invoices)) invoices))
@@ -22,27 +32,21 @@
:else :else
true))) true)))
(def advanced-print-checks-form (forms/vertical-form {:submit-event [::save]
:change-event [::forms/change ::form]
:can-submit [::can-submit]
:id ::form}))
(defn form [] (defn form []
(let [real-bank-accounts @(re-frame/subscribe [::subs/real-bank-accounts]) (let [real-bank-accounts @(re-frame/subscribe [::subs/real-bank-accounts])
{:keys [data active? error id]} @(re-frame/subscribe [::forms/form ::form]) {:keys [data]} @(re-frame/subscribe [::forms/form ::form])]
{:keys [form-inline horizontal-field field raw-field error-notification submit-button]} advanced-print-checks-form]
(form-inline {} [form-builder/builder {:submit-event [::save]
[:<> :can-submit [::can-submit]
:id ::form}
[:div.field [:div.field
[:label.label "Pay using"] [:label.label "Pay using"]
[:div.control [:div.control
[:span.select [:span.select
[raw-field [form-builder/raw-field
[:select {:type "select" [:select {:type "select"
:field :bank-account-id} :field :bank-account-id}
(for [{:keys [id number name]} real-bank-accounts] (for [{:keys [id name]} real-bank-accounts]
^{:key id} [:option {:value id} name])]]]]] ^{:key id} [:option {:value id} name])]]]]]
[:table.table.is-fullwidth [:table.table.is-fullwidth
@@ -53,19 +57,17 @@
[:th {:style {"width" "10em"}} "Payment"]]] [:th {:style {"width" "10em"}} "Payment"]]]
[:tbody [:tbody
(doall (doall
(for [{:keys [vendor payment outstanding-balance invoice-number id] :as i} (:invoices data)] (for [{:keys [vendor invoice-number id] :as i} (:invoices data)]
^{:key id} ^{:key id}
[:tr [:tr
[:td (:name vendor)] [:td (:name vendor)]
[:td invoice-number] [:td invoice-number]
[:td [:div.field.has-addons.is-extended [:td
[:p.control [:a.button.is-static "$"]] [form-builder/raw-field
[:p.control [money-field {:type "money"
(raw-field
[:input.input.has-text-right {:type "number"
:field [:invoice-amounts id :amount] :field [:invoice-amounts id :amount]
:step "0.01"}])]]]]))]]]))) :step "0.01"}]]]]))]]]))
(re-frame/reg-event-fx (re-frame/reg-event-fx
::show ::show

View File

@@ -23,7 +23,8 @@
[reagent.core :as reagent] [reagent.core :as reagent]
[vimsical.re-frame.fx.track :as track] [vimsical.re-frame.fx.track :as track]
[vimsical.re-frame.cofx.inject :as inject] [vimsical.re-frame.cofx.inject :as inject]
[auto-ap.views.pages.ledger.report-table :as rtable])) [auto-ap.views.pages.ledger.report-table :as rtable]
[auto-ap.forms.builder :as form-builder]))
(defn data-params->query-params [params] (defn data-params->query-params [params]
(when params (when params
@@ -36,11 +37,6 @@
:to-numeric-code (:to-numeric-code params) :to-numeric-code (:to-numeric-code params)
:date-range (:date-range params)})) :date-range (:date-range params)}))
(re-frame/reg-sub
::can-submit
(fn [_]
true))
(re-frame/reg-sub (re-frame/reg-sub
::ledger-list-active? ::ledger-list-active?
@@ -183,50 +179,43 @@ NOTE: Please review the transactions we may have question for you here: https://
:event-fn (fn [params] [::ledger-params-change params])}})) :event-fn (fn [params] [::ledger-params-change params])}}))
(def balance-sheet-form (forms/vertical-form {:can-submit [::can-submit]
:change-event [::change]
:submit-event [::report-requested]
:id ::form}))
(defn report-form [] (defn report-form []
(let [{:keys [form-inline raw-field]} balance-sheet-form (let [{:keys [data]} @(re-frame/subscribe [::forms/form ::form])]
{:keys [data]} @(re-frame/subscribe [::forms/form ::form])] [form-builder/builder {:change-event [::change]
(form-inline {} :submit-event [::report-requested]
:id ::form}
[:div [:div
[:div.report-controls [:div.report-controls
[:div.level [:div.level
[:div.level-left [:div.level-left
[:div.level-item [:div.level-item
[:div.control [:div.control
[:p.help "Date"] [form-builder/field
(raw-field "Date"
[date-picker {:output :cljs-date [date-picker {:output :cljs-date
:type "date" :type "date"
:field [:date]}])]] :field [:date]}]]]]
[:div.level-item [:div.level-item
[:div.control [form-builder/field
[:div.mt-3] [:div.mt-5]
[switch-field {:id "include-comparison" [switch-field {:id "include-comparison"
:checked (:include-comparison data) :field [:include-comparison]
:on-change (fn [e] :label "Include compariison"
(re-frame/dispatch [::change [:include-comparison] (.-checked (.-target e))]))
:label "Include comparison"
:type "checkbox"}]]] :type "checkbox"}]]]
[:div.level-item [:div.level-item
(when (boolean (:include-comparison data)) (when (boolean (:include-comparison data))
[:div.control [form-builder/field
[:p.help "Comparison Date"] "Comparison Date"
(raw-field
[date-picker {:output :cljs-date [date-picker {:output :cljs-date
:type "date" :type "date"
:field [:comparison-date]}])])]] :field [:comparison-date]}]])]]
[:div.level-right [:div.level-right
[:div.buttons [:div.buttons
(when @(re-frame/subscribe [::subs/is-admin?]) (when @(re-frame/subscribe [::subs/is-admin?])
[:button.button.is-secondary {:on-click (dispatch-event [::export-pdf])} "Export"]) [:button.button.is-secondary {:on-click (dispatch-event [::export-pdf])} "Export"])
[:button.button.is-primary "Run"]]]]]]))) [:button.button.is-primary "Run"]]]]]]]))
(defn balance-sheet-report [{:keys [args report-data]}] (defn balance-sheet-report [{:keys [args report-data]}]
(let [pnl-data (concat (->> (:balance-sheet-accounts report-data) (let [pnl-data (concat (->> (:balance-sheet-accounts report-data)

View File

@@ -31,7 +31,8 @@
[react-dom :as react-dom] [react-dom :as react-dom]
[reagent.core :as reagent] [reagent.core :as reagent]
[vimsical.re-frame.cofx.inject :as inject] [vimsical.re-frame.cofx.inject :as inject]
[vimsical.re-frame.fx.track :as track])) [vimsical.re-frame.fx.track :as track]
[auto-ap.forms.builder :as form-builder]))
@@ -223,14 +224,11 @@ NOTE: Please review the transactions we may have question for you here: https://
(fn [_] (fn [_]
true)) true))
(def pnl-form (forms/vertical-form {:can-submit [::can-submit]
:change-event [::change]
:submit-event [::report-requested]
:id ::form}))
(defn report-control-detail [{:keys [active box which]} children] (defn report-control-detail [{:keys [active box which]} children]
(when (and @box (when (and @box
(= which @active)) (= which @active))
(println @box)
(react-dom/createPortal (reagent/as-element (react-dom/createPortal (reagent/as-element
[:div.notification.is-light [:div.notification.is-light
[:a.delete {:on-click (fn [] (reset! active nil))}] [:a.delete {:on-click (fn [] (reset! active nil))}]
@@ -243,20 +241,26 @@ NOTE: Please review the transactions we may have question for you here: https://
[:div.control [:div.control
[:a.button [:a.button
{:class (when (= selected-preset title) "is-active") {:class (when (= selected-preset title) "is-active")
:on-click (dispatch-event :on-click (fn []
[::change (re-frame/dispatch-sync [::change
[:periods] [:periods]
periods periods
[:selected-preset] title])} [:selected-preset] title])
(re-frame/dispatch-sync [::change
[:show-advanced?]
false]))}
title]])) title]]))
(defn report-controls [_] (defn report-controls []
(let [!box (reagent/atom nil) (let [!box (atom nil)
active (reagent/atom nil)] active (reagent/atom nil)]
(fn [pnl-form] (fn []
(let [{:keys [raw-field]} pnl-form (let [{:keys [data]} @(re-frame/subscribe [::forms/form ::form])
{:keys [data]} @(re-frame/subscribe [::forms/form ::form])
{:keys [periods selected-preset include-deltas column-per-location]} data] {:keys [periods selected-preset include-deltas column-per-location]} data]
[form-builder/builder {:can-submit [::can-submit]
:change-event [::change]
:submit-event [::report-requested]
:id ::form}
[:div.report-controls [:div.report-controls
[:div.level.mb-2 [:div.level.mb-2
[:div.level-left [:div.level-left
@@ -268,13 +272,13 @@ NOTE: Please review the transactions we may have question for you here: https://
[report-control-detail {:active active :box !box :which :clients} [report-control-detail {:active active :box !box :which :clients}
[:div {:style {:width "20em"}} [:div {:style {:width "20em"}}
[:h4.subtitle "Companies"] [:h4.subtitle "Companies"]
[raw-field [form-builder/raw-field
[multi-field {:type "multi-field" [multi-field {:type "multi-field"
:field [:clients] :field [:clients]
:template [[typeahead-v3 {:entities @(re-frame/subscribe [::subs/clients]) :template [[typeahead-v3 {:entities @(re-frame/subscribe [::subs/clients])
:style {:width "18em"}
:entity->text :name :entity->text :name
:type "typeahead-v3"}]]}]] :type "typeahead-v3"}]]}]]]]]
]]]
[:div.level-item [:div.level-item
[buttons/dropdown {:on-click (fn [] (reset! active :range))} [buttons/dropdown {:on-click (fn [] (reset! active :range))}
[:span (str "Range" [:span (str "Range"
@@ -287,11 +291,11 @@ NOTE: Please review the transactions we may have question for you here: https://
[:div.control [:div.control
[:div.field.has-addons [:div.field.has-addons
[:div.control [:div.control
(raw-field [form-builder/raw-field
[date-picker {:placeholder "End date" [date-picker {:placeholder "End date"
:type "date" :type "date"
:output :cljs-date :output :cljs-date
:field [:thirteen-periods-end]}])] :field [:thirteen-periods-end]}]]]
[period-preset-button {:title "13 periods" [period-preset-button {:title "13 periods"
:periods (let [today (or (some-> (:thirteen-periods-end data)) :periods (let [today (or (some-> (:thirteen-periods-end data))
(local-today))] (local-today))]
@@ -308,11 +312,11 @@ NOTE: Please review the transactions we may have question for you here: https://
[:div.control [:div.control
[:div.field.has-addons [:div.field.has-addons
[:div.control [:div.control
(raw-field [form-builder/raw-field
[date-picker {:placeholder "End date" [date-picker {:placeholder "End date"
:output :cljs-date :output :cljs-date
:type "date" :type "date"
:field [:twelve-periods-end]}])] :field [:twelve-periods-end]}]]]
[period-preset-button {:title "12 months" [period-preset-button {:title "12 months"
:periods (let [end-date (or (some-> (:twelve-periods-end data)) :periods (let [end-date (or (some-> (:twelve-periods-end data))
(local-today)) (local-today))
@@ -376,28 +380,20 @@ NOTE: Please review the transactions we may have question for you here: https://
[:div [:div
[:div.field [:div.field
[:label.checkbox [:label.checkbox
(raw-field [form-builder/raw-field
[:input {:type "checkbox" [:input {:type "checkbox"
:field [:show-advanced?]}]) :field [:show-advanced?]}]]
" Show Advanced"]]] " Show Advanced"]]]
(when (:show-advanced? data) (when (:show-advanced? data)
(doall [form-builder/raw-field
(for [[_ i] (map vector periods (range))] [multi-field {:type "multi-field"
^{:key i} :field [:periods]
[:div.field.is-grouped :template [[date-picker {:type "date"
[:div.control :output :cljs-date
[:p.help "From"] :field [:start]}]
(raw-field
[date-picker {:type "date" [date-picker {:type "date"
:output :cljs-date :output :cljs-date
:field [:periods i :start]}])] :field [:end]}]]}]])]]]
[:div.control
[:p.help "To"]
(raw-field
[date-picker {:type "date"
:output :cljs-date
:field [:periods i :end]}])]])))]]]
[:div.level-item [:div.level-item
[:div [:div
@@ -426,8 +422,8 @@ NOTE: Please review the transactions we may have question for you here: https://
]] ]]
[:div.report-control-detail {:ref (fn [el] [:div.report-control-detail {:ref (fn [el]
(when-not @!box (when (not= @!box el)
(reset! !box el)))}]])))) (reset! !box el)))}]]]))))
@@ -466,13 +462,11 @@ NOTE: Please review the transactions we may have question for you here: https://
(defn profit-and-loss-content [] (defn profit-and-loss-content []
(let [status @(re-frame/subscribe [::status/single ::page]) (let [status @(re-frame/subscribe [::status/single ::page])
{:keys [data report]} @(re-frame/subscribe [::forms/form ::form]) {:keys [data report]} @(re-frame/subscribe [::forms/form ::form])]
{:keys [form-inline]} pnl-form]
[:div [:div
(form-inline {}
[:div [:div
[status/status-notification {:statuses [[::status/single ::page]]}] [status/status-notification {:statuses [[::status/single ::page]]}]
[report-controls pnl-form]]) [report-controls]]
[status/big-loader status] [status/big-loader status]
(when (and (not= :loading (:state status)) (when (and (not= :loading (:state status))
report) report)

View File

@@ -19,7 +19,8 @@
[reagent.core :as r] [reagent.core :as r]
[vimsical.re-frame.fx.track :as track] [vimsical.re-frame.fx.track :as track]
[auto-ap.events :as events] [auto-ap.events :as events]
[vimsical.re-frame.cofx.inject :as inject])) [vimsical.re-frame.cofx.inject :as inject]
[auto-ap.forms.builder :as form-builder]))
(re-frame/reg-sub (re-frame/reg-sub
::can-submit ::can-submit
@@ -105,45 +106,41 @@
(fn [] (fn []
{::track/dispose {:id ::vendor-change}})) {::track/dispose {:id ::vendor-change}}))
(def code-form (forms/vertical-form {:submit-event [::code-selected] (defn form-content [_]
(let [{:keys [data]} @(re-frame/subscribe [::forms/form ::form])]
[form-builder/builder {:submit-event [::code-selected]
:change-event [::changed] :change-event [::changed]
:can-submit [::can-submit] :can-submit [::can-submit]
:id ::form})) :id ::form}
(defn form-content [_]
(let [{:keys [data]} @(re-frame/subscribe [::forms/form ::form])
{:keys [form-inline field]} code-form]
(form-inline {}
[:<> [form-builder/field "Vendor"
(field "Vendor"
[search-backed-typeahead {:search-query (fn [i] [search-backed-typeahead {:search-query (fn [i]
[:search_vendor [:search_vendor
{:query i} {:query i}
[:name :id]]) [:name :id]])
:type "typeahead-v3" :type "typeahead-v3"
:auto-focus true :auto-focus true
:field [:vendor]}]) :field [:vendor]}]]
(field "Approval Status" [form-builder/field
"Approval Status"
[button-radio [button-radio
{:type "button-radio" {:type "button-radio"
:field [:transaction-approval-status] :field [:transaction-approval-status]
:options [[:unapproved "Unapproved"] :options [[:unapproved "Unapproved"]
[:requires-feedback "Client Review"] [:requires-feedback "Client Review"]
[:approved "Approved"] [:approved "Approved"]
[:excluded "Excluded from Ledger"]]}]) [:excluded "Excluded from Ledger"]]}]]
(with-meta [form-builder/raw-field
(field nil
[expense-accounts-field {:type "expense-accounts" [expense-accounts-field {:type "expense-accounts"
:descriptor "account asssignment" :descriptor "account asssignment"
:percentage-only? true :percentage-only? true
:client (:client data) :client (:client data)
:locations (into ["Shared"] @(re-frame/subscribe [::subs/locations-for-client (:id (:client data))])) :locations (into ["Shared"] @(re-frame/subscribe [::subs/locations-for-client (:id (:client data))]))
:max 100 :max 100
:field [:accounts]}]) :field [:accounts]}]]]))
{:key (some-> data :vendor :id str)})
])))
(defn form [_] (defn form [_]
(r/create-class (r/create-class
{:display-name "transaction-bulk-update-form" {:display-name "transaction-bulk-update-form"

View File

@@ -13,13 +13,14 @@
:refer [search-backed-typeahead]] :refer [search-backed-typeahead]]
[auto-ap.views.pages.transactions.common :refer [transaction-read]] [auto-ap.views.pages.transactions.common :refer [transaction-read]]
[auto-ap.views.utils [auto-ap.views.utils
:refer [->$ date->str dispatch-event pretty with-user]] :refer [->$ date->str date-picker dispatch-event pretty with-user]]
[clojure.string :as str] [clojure.string :as str]
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[react :as react] [react :as react]
[reagent.core :as r] [reagent.core :as r]
[vimsical.re-frame.fx.track :as track] [vimsical.re-frame.fx.track :as track]
[auto-ap.events :as events])) [auto-ap.events :as events]
[auto-ap.forms.builder :as form-builder]))
;; SUBS ;; SUBS
(re-frame/reg-sub (re-frame/reg-sub
@@ -211,10 +212,6 @@
;; VIEWS ;; VIEWS
(def transaction-form (forms/vertical-form {:can-submit [::can-submit]
:change-event [::changed]
:submit-event [::saving ]
:id ::form}))
(defn potential-transaction-rule-matches-box [{:keys [potential-transaction-rule-matches]}] (defn potential-transaction-rule-matches-box [{:keys [potential-transaction-rule-matches]}]
(let [states @(re-frame/subscribe [::status/multi ::matching])] (let [states @(re-frame/subscribe [::status/multi ::matching])]
@@ -340,45 +337,40 @@
[layouts/side-bar {:on-close (dispatch-event [::forms/form-closing ::form])} [layouts/side-bar {:on-close (dispatch-event [::forms/form-closing ::form])}
(let [{:keys [data] } @(re-frame/subscribe [::forms/form ::form]) (let [{:keys [data] } @(re-frame/subscribe [::forms/form ::form])
locations @(re-frame/subscribe [::subs/locations-for-client (:id (:client data))]) locations @(re-frame/subscribe [::subs/locations-for-client (:id (:client data))])
{:keys [form-inline field error-notification submit-button ]} transaction-form
is-admin? @(re-frame/subscribe [::subs/is-admin?]) is-admin? @(re-frame/subscribe [::subs/is-admin?])
is-power-user? @(re-frame/subscribe [::subs/is-power-user?]) is-power-user? @(re-frame/subscribe [::subs/is-power-user?])
should-disable-for-client? (and (not (or is-admin? is-power-user?)) should-disable-for-client? (and (not (or is-admin? is-power-user?))
(not= :requires-feedback (:original-status data))) (not= :requires-feedback (:original-status data)))
is-already-matched? (:payment data)] is-already-matched? (:payment data)]
(with-meta [form-builder/builder {:can-submit [::can-submit]
(form-inline {:title "Transaction"} :change-event [::changed]
:submit-event [::saving ]
:id ::form}
[form-builder/section {:title "Transaction"}
[:<> [:<>
(when (and @(re-frame/subscribe [::subs/is-admin?])
(get-in data [:yodlee-merchant]))
[:div.control
[:p.help "Merchant"]
[:input.input {:type "text"
:disabled true
:value (str (get-in data [:yodlee-merchant :name])
" - "
(get-in data [:yodlee-merchant :yodlee-id]))}]])
(when is-admin? (when is-admin?
(field "Matched Rule"
[form-builder/field
"Matched Rule"
[:input.input {:type "text" [:input.input {:type "text"
:field [:matched-rule :note] :field [:matched-rule :note]
:disabled "disabled"}])) :disabled "disabled"}]])
(field "Amount" [form-builder/field "Amount"
[:input.input {:type "text" [:input.input {:type "text"
:field [:amount] :field [:amount]
:disabled "disabled"}]) :disabled "disabled"}]]
(field "Description" [form-builder/field
"Description"
[:input.input {:type "text" [:input.input {:type "text"
:field [:description-original] :field [:description-original]
:disabled "disabled"}]) :disabled "disabled"}]]
(field "Date" [form-builder/field "Date"
[:input.input {:type "text" [date-picker {:type "date"
:field [:date] :field [:date]
:disabled "disabled"}]) :disabled "disabled"}]]
(when (and (:payment data) (when (and (:payment data)
@@ -415,7 +407,8 @@
[tab {:title "Details" :key :details} [tab {:title "Details" :key :details}
[:div [:div
(field "Vendor" [form-builder/field
"Vendor"
[search-backed-typeahead {:search-query (fn [i] [search-backed-typeahead {:search-query (fn [i]
[:search_vendor [:search_vendor
{:query i} {:query i}
@@ -424,10 +417,8 @@
:auto-focus true :auto-focus true
:field [:vendor] :field [:vendor]
:disabled (or (boolean (:payment data)) :disabled (or (boolean (:payment data))
should-disable-for-client?)}]) should-disable-for-client?)}]]
(with-meta [form-builder/raw-field [expense-accounts-field
(field nil
[expense-accounts-field
{:type "expense-accounts" {:type "expense-accounts"
:field [:accounts] :field [:accounts]
:max (Math/abs (js/parseFloat (:amount data))) :max (Math/abs (js/parseFloat (:amount data)))
@@ -435,9 +426,9 @@
:client (:client data) :client (:client data)
:disabled (or (boolean (:payment data)) :disabled (or (boolean (:payment data))
should-disable-for-client?) should-disable-for-client?)
:locations locations}]) :locations locations}]]
{:key (str (:id (:vendor data)))}) [form-builder/field
(field "Approval Status" "Approval Status"
[button-radio [button-radio
{:type "button-radio" {:type "button-radio"
:field [:approval-status] :field [:approval-status]
@@ -445,17 +436,17 @@
[:requires-feedback "Client Review"] [:requires-feedback "Client Review"]
[:approved "Approved"] [:approved "Approved"]
[:excluded "Excluded from Ledger"]] [:excluded "Excluded from Ledger"]]
:disabled should-disable-for-client?}]) :disabled should-disable-for-client?}]]
(field "Forecasted-transaction" [form-builder/field
"Forecasted-transaction"
[typeahead-v3 {:entities @(re-frame/subscribe [::subs/forecasted-transactions-for-client (:id (:client data))]) [typeahead-v3 {:entities @(re-frame/subscribe [::subs/forecasted-transactions-for-client (:id (:client data))])
:entity->text :identifier :entity->text :identifier
:type "typeahead-v3" :type "typeahead-v3"
:field [:forecast-match]}]) :field [:forecast-match]}]]
(error-notification) [form-builder/error-notification]
(when-not should-disable-for-client? (when-not should-disable-for-client?
(submit-button "Save"))]]]]) [form-builder/submit-button "Save"])]]]]]])])
{:key (:id data)}))])
(defn form [_] (defn form [_]
(r/create-class (r/create-class

View File

@@ -5,7 +5,8 @@
[auto-ap.subs :as subs] [auto-ap.subs :as subs]
[auto-ap.views.components.modal :as modal] [auto-ap.views.components.modal :as modal]
[auto-ap.views.utils :refer [dispatch-event with-user]] [auto-ap.views.utils :refer [dispatch-event with-user]]
[re-frame.core :as re-frame])) [re-frame.core :as re-frame]
[auto-ap.forms.builder :as form-builder]))
(re-frame/reg-sub (re-frame/reg-sub
::can-submit ::can-submit
@@ -13,22 +14,16 @@
(fn [{ {:keys [data]} :data}] (fn [{ {:keys [data]} :data}]
(not-empty data))) (not-empty data)))
(def import-form (forms/vertical-form {:submit-event [::save] (defn form []
:change-event [::forms/change ::form] [form-builder/builder {:submit-event [::save]
:can-submit [::can-submit] :can-submit [::can-submit]
:id ::form})) :id ::form}
(defn form [{import-completed-event :import-completed}] [form-builder/field {:required? true}
(let [{:keys [data active? error id]} @(re-frame/subscribe [::forms/form ::form]) "Yodlee manual import table"
{:keys [form-inline horizontal-field field raw-field error-notification submit-button]} import-form]
(form-inline {}
[:div.field
[:label.label
"Yodlee manual import table"]
[:div.control [:div.control
[raw-field [:textarea.textarea {:field [:data]}]]]
[:textarea.textarea {:field [:data]}]]]]))) [form-builder/hidden-submit-button]])
(re-frame/reg-event-fx (re-frame/reg-event-fx
::opening ::opening
@@ -46,11 +41,9 @@
{:client-id (:id @(re-frame/subscribe [::subs/client])) {:client-id (:id @(re-frame/subscribe [::subs/client]))
:data ""}))})) :data ""}))}))
(re-frame/reg-event-fx (re-frame/reg-event-fx
::import-completed ::import-completed
(fn [{:keys [db]} [_ {:keys [imported errors] :as result}]] (fn [_ _]
{:dispatch [::modal/modal-closed ]})) {:dispatch [::modal/modal-closed ]}))
(re-frame/reg-event-fx (re-frame/reg-event-fx

View File

@@ -211,7 +211,7 @@
e)] e)]
(if (map? this-value) (if (map? this-value)
(update this-value :key (fnil identity (random-uuid))) (update this-value :key (fnil identity (random-uuid)))
this-value)) )))) this-value))))))
(on-change (mapv (on-change (mapv
(fn [v] (fn [v]
(dissoc v :new? :key)) (dissoc v :new? :key))
@@ -251,7 +251,6 @@
options (if allow-nil? options (if allow-nil?
(with-keys (conj rest [:option {:value nil}])) (with-keys (conj rest [:option {:value nil}]))
(with-keys rest))] (with-keys rest))]
(println "KEYS" keys (dissoc keys :allow-nil?))
(into [dom (dissoc keys :allow-nil?)] options))) (into [dom (dissoc keys :allow-nil?)] options)))
@@ -281,21 +280,6 @@
keys (dissoc keys :field :subscription :event :spec)] keys (dissoc keys :field :subscription :event :spec)]
(into [dom keys] (with-keys rest)))) (into [dom keys] (with-keys rest))))
(defmethod do-bind "typeahead" [dom {:keys [field text-field event text-event subscription class spec] :as keys} & rest]
(let [field (if (keyword? field) [field] field)
event (if (keyword? event) [event] event)
keys (assoc keys
:on-change (fn [selected text-value]
(re-frame/dispatch (conj (conj event field) selected))
(when text-field
(re-frame/dispatch (conj (conj (or text-event event) text-field) text-value))))
:value (get-in subscription field)
:class (str class
(when (and spec (not (s/valid? spec (get-in subscription field))))
" is-danger")))
keys (dissoc keys :field :subscription :event :spec)]
(into [dom keys] (with-keys rest))))
(defmethod do-bind "multi-field" [dom {:keys [field event subscription class spec] :as keys} & rest] (defmethod do-bind "multi-field" [dom {:keys [field event subscription class spec] :as keys} & rest]
(let [field (if (keyword? field) [field] field) (let [field (if (keyword? field) [field] field)
event (if (keyword? event) [event] event) event (if (keyword? event) [event] event)
@@ -310,20 +294,6 @@
(into [dom keys] (with-keys rest)))) (into [dom keys] (with-keys rest))))
(defmethod do-bind "typeahead-entity" [dom {:keys [field event subscription class spec] :as keys} & rest]
(let [field (if (keyword? field) [field] field)
event (if (keyword? event) [event] event)
keys (assoc keys
:on-change (fn [selected]
(re-frame/dispatch (conj (conj event field) selected))
#_(when text-field
(re-frame/dispatch (conj (conj (or text-event event) text-field) text-value))))
:value (get-in subscription field)
:class (str class
(when (and spec (not (s/valid? spec (get-in subscription field))))
" is-danger")))
keys (dissoc keys :field :subscription :event :spec)]
(into [dom keys] (with-keys rest))))
(defmethod do-bind "typeahead-v3" [dom {:keys [field event subscription class spec] :as keys} & rest] (defmethod do-bind "typeahead-v3" [dom {:keys [field event subscription class spec] :as keys} & rest]
(let [field (if (keyword? field) [field] field) (let [field (if (keyword? field) [field] field)