renamed company to client.

This commit is contained in:
Bryce Covert
2019-01-18 07:44:12 -08:00
parent 583752d740
commit 775150131e
38 changed files with 250 additions and 306 deletions

View File

@@ -1,10 +1,10 @@
(ns auto-ap.views.pages.admin.companies
(ns auto-ap.views.pages.admin.clients
(:require-macros [cljs.core.async.macros :refer [go]])
(:require [re-frame.core :as re-frame]
[reagent.core :as reagent]
[auto-ap.subs :as subs]
[auto-ap.events :as events]
[auto-ap.entities.companies :as entity]
[auto-ap.entities.clients :as entity]
[auto-ap.views.components.address :refer [address-field]]
[auto-ap.views.utils :refer [login-url dispatch-event dispatch-value-change bind-field horizontal-field]]
[auto-ap.views.components.modal :refer [action-modal]]
@@ -14,105 +14,105 @@
(re-frame/reg-event-fx
::edit
(fn [{:keys [db]} [_ company-id]]
{:dispatch [::events/modal-status :auto-ap.views.pages.admin.companies/edit {:visible? true}]
:db (assoc-in db [:admin :company]
(get (:companies db) company-id))}))
(fn [{:keys [db]} [_ client-id]]
{:dispatch [::events/modal-status :auto-ap.views.pages.admin.clients/edit {:visible? true}]
:db (assoc-in db [:admin :client]
(get (:clients db) client-id))}))
(re-frame/reg-event-fx
::save
(fn [{:keys [db]} _]
(let [edited-company (-> (get-in db [:admin :company])
(let [edited-client (-> (get-in db [:admin :client])
(dissoc :location)
(dissoc :new-account))]
{:db (assoc-in db [:admin :company :saving?] true)
{:db (assoc-in db [:admin :client :saving?] true)
:http {:method :put
:token (:user db)
:body (pr-str edited-company)
:body (pr-str edited-client)
:headers {"Content-Type" "application/edn"}
:uri (str "/api/companies/" (:id edited-company))
:uri (str "/api/clients/" (:id edited-client))
:on-success [::save-complete]
:on-error [::save-error]}})))
(re-frame/reg-event-fx
::save-complete
(fn [{:keys [db]} [_ company]]
{:dispatch [::events/modal-completed :auto-ap.views.pages.admin.companies/edit]
(fn [{:keys [db]} [_ client]]
{:dispatch [::events/modal-completed :auto-ap.views.pages.admin.clients/edit]
:db (-> db
(assoc-in [:admin :company] nil)
(assoc-in [:companies (:id company)] company))}))
(assoc-in [:admin :client] nil)
(assoc-in [:clients (:id client)] client))}))
(re-frame/reg-event-db
::save-error
(fn [db [_ company]]
(fn [db [_ client]]
(-> db
(assoc-in [:admin :company :saving?] false)
(assoc-in [:admin :company :error] true))))
(assoc-in [:admin :client :saving?] false)
(assoc-in [:admin :client :error] true))))
(re-frame/reg-event-db
::change
(fn [db [_ path value]]
(assoc-in db (concat [:admin :company] path)
(assoc-in db (concat [:admin :client] path)
value)))
(re-frame/reg-event-fx
::add-location
(fn [{:keys [db]} _]
(let [company (:company @(re-frame/subscribe [::subs/admin]))]
(let [client (:client @(re-frame/subscribe [::subs/admin]))]
{:db (-> db
(update-in [:admin :company :locations] conj (:location company))
(update-in [:admin :company] dissoc :location))})))
(update-in [:admin :client :locations] conj (:location client))
(update-in [:admin :client] dissoc :location))})))
(re-frame/reg-event-fx
::add-new-bank-account
(fn [{:keys [db]} _]
(let [company (:company @(re-frame/subscribe [::subs/admin]))
new-bank-account (:new-account company)
(let [client (:client @(re-frame/subscribe [::subs/admin]))
new-bank-account (:new-account client)
new-bank-account (-> new-bank-account
(update :check-number #(if (seq %) (js/parseInt %) nil))
(update :yodlee-account-id #(if (seq %) (js/parseInt %) nil))
(assoc :is-new? true))]
{:db (-> db
(update-in [:admin :company :new-bank-accounts] (fn [bank-accounts]
(update-in [:admin :client :new-bank-accounts] (fn [bank-accounts]
(conj bank-accounts new-bank-account)))
(update-in [:admin :company] dissoc :new-account))})))
(update-in [:admin :client] dissoc :new-account))})))
(re-frame/reg-event-db
::remove-new-bank-account
(fn [db [_ index]]
(update-in db [:admin :company :new-bank-accounts]
(update-in db [:admin :client :new-bank-accounts]
(fn [bas]
(vec (concat (take index bas)
(drop (inc index) bas)))))))
(defn companies-table []
(let [companies (re-frame/subscribe [::subs/companies])
editing-company (:company @(re-frame/subscribe [::subs/admin]))]
(defn clients-table []
(let [clients (re-frame/subscribe [::subs/clients])
editing-client (:client @(re-frame/subscribe [::subs/admin]))]
[:table {:class "table", :style {:width "100%"}}
[:thead
[:tr
[:th "Name"]
[:th "Email"]]]
[:tbody (for [{:keys [id name email] :as c} @companies]
[:tbody (for [{:keys [id name email] :as c} @clients]
^{:key (str name "-" id )}
[:tr {:on-click (fn [] (re-frame/dispatch [::edit id]))
:style {"cursor" "pointer"}}
[:td name]
[:td email]])]]))
(defn admin-companies-page []
(defn admin-clients-page []
[:div
(let [companies (re-frame/subscribe [::subs/companies])
editing-company (:company @(re-frame/subscribe [::subs/admin]))]
(let [clients (re-frame/subscribe [::subs/clients])
editing-client (:client @(re-frame/subscribe [::subs/admin]))]
[:div
[:h1.title "Companies"]
[companies-table]
[:h1.title "Clients"]
[clients-table]
[action-modal {:id ::edit
:title (str "Edit " (:name editing-company))
:title (str "Edit " (:name editing-client))
:action-text "Save"
:save-event [::save]}
[horizontal-field
@@ -123,7 +123,7 @@
:field :name
:spec ::entity/name
:event ::change
:subscription editing-company}]]]]
:subscription editing-client}]]]]
[horizontal-field
[:label.label "Email"]
@@ -133,7 +133,7 @@
:field :email
:spec ::entity/name
:event ::change
:subscription editing-company}]]]]
:subscription editing-client}]]]]
[horizontal-field
[:label.label "Locations"]
@@ -144,16 +144,16 @@
[:input.input {:type "text"
:field :location
:event ::change
:subscription editing-company}]]]
:subscription editing-client}]]]
[:p.control [:button.button.is-primary {:on-click (dispatch-event [::add-location])} "Add"]]]
[:ul
(for [location (:locations editing-company)]
(for [location (:locations editing-client)]
^{:key location} [:li location ])]]]
[:h2.subtitle "Address"]
[address-field {:field [:address]
:event ::change
:subscription editing-company}]
:subscription editing-client}]
[:h2.subtitle "Add account"]
[horizontal-field
@@ -165,7 +165,7 @@
:type "text"
:field [:new-account :bank-name]
:event ::change
:subscription editing-company}]]]
:subscription editing-client}]]]
[:div.control
[bind-field
@@ -173,7 +173,7 @@
:type "text"
:field [:new-account :routing]
:event ::change
:subscription editing-company}]]]
:subscription editing-client}]]]
[:div.control
[bind-field
@@ -181,7 +181,7 @@
:type "text"
:field [:new-account :bank-code]
:event ::change
:subscription editing-company}]]]]
:subscription editing-client}]]]]
[horizontal-field
[:label.label "Account"]
[:div.control
@@ -190,21 +190,21 @@
:type "text"
:field [:new-account :name]
:event ::change
:subscription editing-company}]]]
:subscription editing-client}]]]
[:div.control
[bind-field
[:input.input {:placeholder "Acct #"
:type "text"
:field [:new-account :number]
:event ::change
:subscription editing-company}]]]
:subscription editing-client}]]]
[:div.control
[bind-field
[:input.input {:placeholder "Check #"
:type "text"
:field [:new-account :check-number]
:event ::change
:subscription editing-company}]]]]
:subscription editing-client}]]]]
[horizontal-field
[:label.label "Yodlee Account"]
[:div.control
@@ -213,7 +213,7 @@
:type "text"
:field [:new-account :yodlee-account-id]
:event ::change
:subscription editing-company}]]]
:subscription editing-client}]]]
[:div.control
[:button.button.is-primary.is-pulled-right {:on-click (dispatch-event [::add-new-bank-account])} "Add"]]]
@@ -225,9 +225,9 @@
[:div.control
[:ul
(for [{:keys [name number check-number id]} (:bank-accounts editing-company)]
(for [{:keys [name number check-number id]} (:bank-accounts editing-client)]
^{:key id} [:li name])
(for [[index {:keys [name number check-number]}] (map vector (range) (:new-bank-accounts editing-company))]
(for [[index {:keys [name number check-number]}] (map vector (range) (:new-bank-accounts editing-client))]
^{:key index} [:li [:strong "* " name] [:button.button {:on-click (dispatch-event [::remove-new-bank-account index])} [:span.icon [:i.fa.fa-times]]]])]]]
(when (:saving? editing-company) [:div.is-overlay {:style {"backgroundColor" "rgba(150,150,150, 0.5)"}}])]])])
(when (:saving? editing-client) [:div.is-overlay {:style {"backgroundColor" "rgba(150,150,150, 0.5)"}}])]])])

View File

@@ -4,8 +4,8 @@
[reagent.core :as reagent]
[auto-ap.subs :as subs]
[auto-ap.events :as all-events]
[auto-ap.events.admin.companies :as events]
[auto-ap.entities.companies :as entity]
[auto-ap.events.admin.clients :as events]
[auto-ap.entities.clients :as entity]
[auto-ap.views.components.typeahead :refer [typeahead]]
[auto-ap.views.utils :refer [login-url dispatch-value-change bind-field horizontal-field dispatch-event]]
@@ -182,17 +182,17 @@
[:thead
[:th "Date"]
[:th "Invoice #"]
[:th "Company"]
[:th "Client"]
[:th "Vendor"]
[:th "Amount"]
[:th "Errors"]]
(for [{:keys [raw-date invoice-number company vendor-name amount] row-errors :errors} (take 100 errors)]
^{:key (str raw-date invoice-number company vendor-name amount)}
(for [{:keys [raw-date invoice-number client vendor-name amount] row-errors :errors} (take 100 errors)]
^{:key (str raw-date invoice-number client vendor-name amount)}
[:tr
[:td raw-date]
[:td invoice-number]
[:td company]
[:td client]
[:td vendor-name]
[:td amount]
[:td (map (fn [{:keys [info]}] ^{:key info} [:p info]) row-errors)]])]])])])

View File

@@ -5,7 +5,7 @@
[clojure.string :as str]
[auto-ap.subs :as subs]
[auto-ap.events :as events]
[auto-ap.entities.companies :as entity]
[auto-ap.entities.clients :as entity]
[auto-ap.views.components.address :refer [address-field]]
[auto-ap.views.utils :refer [login-url dispatch-value-change bind-field horizontal-field dispatch-event]]
[auto-ap.views.components.modal :refer [modal action-modal]]
@@ -55,14 +55,14 @@
(dissoc db ::editing))))
(re-frame/reg-event-db
::add-company
::add-client
(fn [db [_ d]]
(let [company (get @(re-frame/subscribe [::subs/companies-by-id])
(get-in db [::editing :adding-company]))]
(update-in db [::editing :user :clients] conj company))))
(let [client (get @(re-frame/subscribe [::subs/clients-by-id])
(get-in db [::editing :adding-client]))]
(update-in db [::editing :user :clients] conj client))))
(re-frame/reg-event-db
::remove-company
::remove-client
(fn [db [_ d]]
(update-in db [::editing :user :clients] #(filter (fn [c] (not= (:id c) d)) %))))
@@ -116,7 +116,7 @@
(with-meta
(fn []
[:div
(let [companies (re-frame/subscribe [::users])
(let [clients (re-frame/subscribe [::users])
editing @(re-frame/subscribe [::editing])]
[:div
[:h1.title "Users"]
@@ -160,20 +160,20 @@
[:div.select
[bind-field
[:select {:type "select"
:field [:adding-company]
:field [:adding-client]
:event ::change
:subscription editing}
[:option]
(let [used-companies (set (map :id (:clients (:user editing))))]
(for [{:keys [id name]} @(re-frame/subscribe [::subs/companies])
:when (not (used-companies id))]
(let [used-clients (set (map :id (:clients (:user editing))))]
(for [{:keys [id name]} @(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-company])} "Add"]]]
[:button.button.is-primary {:on-click (dispatch-event [::add-client])} "Add"]]]
[:ul
(for [{:keys [id name]} (:clients (:user editing))]
^{:key id} [:li name [:a.icon {:on-click (dispatch-event [::remove-company id])} [:i.fa.fa-times ]]])]]])]])])
^{:key id} [:li name [:a.icon {:on-click (dispatch-event [::remove-client id])} [:i.fa.fa-times ]]])]]])]])])
{:component-will-mount #(re-frame/dispatch-sync [::users-mounted {}]) }))

View File

@@ -4,8 +4,8 @@
[reagent.core :as reagent]
[clojure.string :as str]
[auto-ap.subs :as subs]
[auto-ap.events.admin.companies :as events]
[auto-ap.entities.companies :as entity]
[auto-ap.events.admin.clients :as events]
[auto-ap.entities.clients :as entity]
[auto-ap.views.components.address :refer [address-field]]
[auto-ap.views.utils :refer [login-url dispatch-event dispatch-value-change bind-field horizontal-field]]
[auto-ap.views.components.modal :refer [action-modal]]