more specs.
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
[auto-ap.subs :as subs]
|
||||
[auto-ap.routes :as routes]
|
||||
[auto-ap.effects :as effects]
|
||||
[auto-ap.entities.companies :as companies]
|
||||
[bidi.bidi :as bidi]))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
@@ -42,14 +43,14 @@
|
||||
(fn [db [_ companies]]
|
||||
|
||||
(assoc db :companies (reduce (fn [companies company]
|
||||
(assoc companies (:id company) company))
|
||||
(assoc companies (::companies/id company) company))
|
||||
{}
|
||||
companies))))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::swap-company
|
||||
(fn [db [_ company]]
|
||||
(assoc db :company (:id company))))
|
||||
(assoc db :company (::companies/id company))))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::set-active-page
|
||||
@@ -70,7 +71,7 @@
|
||||
{:http {:method :post
|
||||
:token (-> cofx :db :user)
|
||||
:uri (str "/api/invoices/approve"
|
||||
(when-let [company-id (:id @(re-frame/subscribe [::subs/company]))]
|
||||
(when-let [company-id (::companies/id @(re-frame/subscribe [::subs/company]))]
|
||||
(str "?company=" company-id)))
|
||||
:on-success [::received-invoices :pending]
|
||||
}}))
|
||||
@@ -82,7 +83,7 @@
|
||||
:http {:method :get
|
||||
:token (-> cofx :db :user)
|
||||
:uri (str "/api/invoices/pending"
|
||||
(when-let [company-id (:id @(re-frame/subscribe [::subs/company]))]
|
||||
(when-let [company-id (::companies/id @(re-frame/subscribe [::subs/company]))]
|
||||
(str "?company=" company-id)))
|
||||
:on-success [::received-invoices :pending]}}))
|
||||
|
||||
@@ -93,7 +94,7 @@
|
||||
:http {:method :get
|
||||
:token (-> cofx :db :user)
|
||||
:uri (str "/api/invoices/unpaid"
|
||||
(when-let [company-id (:id @(re-frame/subscribe [::subs/company]))]
|
||||
(when-let [company-id (::companies/id @(re-frame/subscribe [::subs/company]))]
|
||||
(str "?company=" company-id)))
|
||||
:on-success [::received-invoices :unpaid]}}))
|
||||
|
||||
@@ -103,7 +104,7 @@
|
||||
{:http {:method :post
|
||||
:token (-> cofx :db :user)
|
||||
:uri (str "/api/invoices/reject"
|
||||
(when-let [company-id (:id @(re-frame/subscribe [::subs/company]))]
|
||||
(when-let [company-id (::companies/id @(re-frame/subscribe [::subs/company]))]
|
||||
(str "?company=" company-id)))
|
||||
:on-success [::received-invoices :pending]
|
||||
}}))
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
[auto-ap.db :as db]
|
||||
[auto-ap.routes :as routes]
|
||||
[auto-ap.effects :as effects]
|
||||
[auto-ap.entities.companies :as entity]
|
||||
[bidi.bidi :as bidi]))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
@@ -18,10 +19,11 @@
|
||||
{:db (assoc-in db [:admin :company :saving?] true)
|
||||
:http {:method :put
|
||||
:token (:user db)
|
||||
:body (pr-str (select-keys edited-company [:name :email :data :invoice-reminder-schedule]))
|
||||
:body (pr-str edited-company)
|
||||
:headers {"Content-Type" "application/edn"}
|
||||
:uri (str "/api/companies/" (:id edited-company))
|
||||
:on-success [::save-complete]}})))
|
||||
:uri (str "/api/companies/" (::entity/id edited-company))
|
||||
:on-success [::save-complete]
|
||||
:on-error [::save-error]}})))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::save-complete
|
||||
@@ -29,7 +31,14 @@
|
||||
(-> db
|
||||
|
||||
(assoc-in [:admin :company] nil)
|
||||
(assoc-in [:companies (:id company)] company))))
|
||||
(assoc-in [:companies (::entity/id company)] company))))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::save-error
|
||||
(fn [db [_ company]]
|
||||
(-> db
|
||||
(assoc-in [:admin :company :saving?] false)
|
||||
(assoc-in [:admin :company :error] true))))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::change
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
[auto-ap.subs :as subs]
|
||||
[auto-ap.events :as events]
|
||||
[auto-ap.views.utils :refer [active-when= login-url]]
|
||||
[auto-ap.entities.companies :as company]
|
||||
[auto-ap.views.pages :as pages]))
|
||||
|
||||
(defn page->layout [page]
|
||||
@@ -125,14 +126,14 @@
|
||||
:on-click (fn [] (re-frame/dispatch [::events/toggle-menu :company]))}
|
||||
[:div.navbar-start
|
||||
[:div { :class (str "navbar-item has-dropdown " (when (get-in @menu [:company :active?]) "is-active"))}
|
||||
[:a {:class "navbar-link login"} "Company: " (if @company (:name @company)
|
||||
[:a {:class "navbar-link login"} "Company: " (if @company (::company/name @company)
|
||||
"All")]
|
||||
[:div {:class "navbar-dropdown"}
|
||||
[:a {:class "navbar-item"
|
||||
:on-click (fn [] (re-frame/dispatch [::events/swap-company nil]))
|
||||
} "All"]
|
||||
[:hr {:class "navbar-divider"}]
|
||||
(for [{:keys [name] :as company} @companies]
|
||||
(for [{:keys [::company/name] :as company} @companies]
|
||||
^{:key name }
|
||||
[:a {:class "navbar-item"
|
||||
:on-click (fn [] (re-frame/dispatch [::events/swap-company company]))
|
||||
|
||||
@@ -4,7 +4,8 @@
|
||||
[reagent.core :as reagent]
|
||||
[auto-ap.subs :as subs]
|
||||
[auto-ap.events.admin.companies :as events]
|
||||
[auto-ap.views.utils :refer [login-url dispatch-value-change]]
|
||||
[auto-ap.entities.companies :as entity]
|
||||
[auto-ap.views.utils :refer [login-url dispatch-value-change bind-field horizontal-field]]
|
||||
[cljs.reader :as edn]
|
||||
[auto-ap.routes :as routes]
|
||||
[bidi.bidi :as bidi]))
|
||||
@@ -15,15 +16,14 @@
|
||||
[:thead
|
||||
[:tr
|
||||
[:th "Name"]
|
||||
[:th "Email"]
|
||||
[:th "Invoice Reminders"]]]
|
||||
[:tbody (for [{:keys [id name email data invoice-reminder-schedule] :as c} @companies]
|
||||
[:th "Email"]]]
|
||||
[:tbody (for [{:keys [::entity/id ::entity/name ::entity/email] :as c} @companies]
|
||||
^{:key (str name "-" id )}
|
||||
[:tr {:on-click (fn [] (re-frame/dispatch [::events/edit id]))
|
||||
:style {"cursor" "pointer"}}
|
||||
[:td name]
|
||||
[:td email]
|
||||
[:td invoice-reminder-schedule]])]]))
|
||||
])]]))
|
||||
|
||||
(defn admin-companies-page []
|
||||
[:div {:class "inbox-messages"}
|
||||
@@ -49,41 +49,25 @@
|
||||
(str "Edit " (:name editing-company))]
|
||||
[:button.delete {:on-click (fn [] (re-frame/dispatch [::events/edit nil]))}]]
|
||||
[:section.modal-card-body
|
||||
[:div.field
|
||||
|
||||
[horizontal-field
|
||||
[:label.label "Name"]
|
||||
[:div.control
|
||||
[:input.input {:type "text" :value (:name editing-company)
|
||||
:on-change (dispatch-value-change [::events/change [:name]])}]]]
|
||||
[bind-field
|
||||
[:input.input {:type "text"
|
||||
:field ::entity/name
|
||||
:event ::events/change
|
||||
:subscription editing-company}]]]]
|
||||
|
||||
[:div.field
|
||||
[horizontal-field
|
||||
[:label.label "Email"]
|
||||
[:div.control
|
||||
[:input.input {:type "email"
|
||||
:value (:email editing-company)
|
||||
:on-change (dispatch-value-change [::events/change [:email]])}]]]
|
||||
|
||||
[:div.field
|
||||
[:labal.label "Invoice Reminders"]
|
||||
[:div.control
|
||||
[:label.radio
|
||||
[:input {:type "radio"
|
||||
:name "schedule"
|
||||
:value "Weekly"
|
||||
:checked (if (= "Weekly" (:invoice-reminder-schedule editing-company))
|
||||
"checked"
|
||||
"")
|
||||
:on-change (dispatch-value-change [::events/change [:invoice-reminder-schedule]])}]
|
||||
" Send weekly"]]
|
||||
[:div.control
|
||||
[:label.radio
|
||||
[:input {:type "radio"
|
||||
:name "schedule"
|
||||
:value "Never"
|
||||
:checked (if (= "Never" (:invoice-reminder-schedule editing-company))
|
||||
"checked"
|
||||
"")
|
||||
:on-change (dispatch-value-change [::events/change [:invoice-reminder-schedule]])}]
|
||||
" Never"]]]
|
||||
[bind-field
|
||||
[:input.input {:type "email"
|
||||
:field ::entity/email
|
||||
:event ::events/change
|
||||
:subscription editing-company}]]]]
|
||||
|
||||
|
||||
(when (:saving? editing-company) [:div.is-overlay {:style {"backgroundColor" "rgba(150,150,150, 0.5)"}}])]
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
[auto-ap.events.admin.vendors :as events]
|
||||
[auto-ap.entities.vendors :as entity]
|
||||
[clojure.spec.alpha :as s]
|
||||
[auto-ap.views.utils :refer [login-url dispatch-value-change dispatch-event]]
|
||||
[auto-ap.views.utils :refer [login-url dispatch-value-change dispatch-event bind-field horizontal-field]]
|
||||
[cljs.reader :as edn]
|
||||
[auto-ap.routes :as routes]
|
||||
[bidi.bidi :as bidi]))
|
||||
@@ -33,10 +33,6 @@
|
||||
[:td (::entity/primary-email v)]
|
||||
[:td (::entity/invoice-reminder-schedule v)]])]]))
|
||||
|
||||
(defmulti do-bind (fn [_ {:keys [type]}]
|
||||
|
||||
type))
|
||||
|
||||
(defn danger-for [[dom {:keys [field subscription class] :as keys} & rest]]
|
||||
(let [keys (assoc keys :class (str class
|
||||
(when (not (s/valid? field (field subscription)))
|
||||
@@ -45,39 +41,6 @@
|
||||
(vec (concat [dom keys] rest))))
|
||||
|
||||
|
||||
(defmethod do-bind "radio" [dom {:keys [field subscription class value] :as keys} & rest]
|
||||
(let [keys (assoc keys
|
||||
:on-change (dispatch-value-change [::events/change [field]])
|
||||
:checked (= (field subscription) value)
|
||||
:class (str class
|
||||
(when (not (s/valid? field (field subscription)))
|
||||
" is-danger")))
|
||||
keys (dissoc keys :field :subscription)]
|
||||
(vec (concat [dom keys] rest))))
|
||||
|
||||
|
||||
(defmethod do-bind :default [dom {:keys [field subscription class] :as keys} & rest]
|
||||
(let [keys (assoc keys
|
||||
:on-change (dispatch-value-change [::events/change [field]])
|
||||
:value (field subscription)
|
||||
:class (str class
|
||||
(when (not (s/valid? field (field subscription)))
|
||||
" is-danger")))
|
||||
keys (dissoc keys :field :subscription)]
|
||||
(vec (concat [dom keys] rest))))
|
||||
|
||||
(defn bind-field [all]
|
||||
(apply do-bind all))
|
||||
|
||||
(defn horizontal-field [label & controls]
|
||||
[:div.field.is-horizontal
|
||||
[:div.field-label
|
||||
label
|
||||
]
|
||||
(into
|
||||
[:div.field-body
|
||||
]
|
||||
(map (fn [c] [:div.field c]) controls))])
|
||||
|
||||
(defn edit-dialog []
|
||||
(let [editing-vendor (:vendor @(re-frame/subscribe [::subs/admin]))]
|
||||
@@ -101,6 +64,7 @@
|
||||
[bind-field
|
||||
[:input.input {:type "text"
|
||||
:field ::entity/name
|
||||
:event ::events/change
|
||||
:subscription editing-vendor}]]]]
|
||||
|
||||
[horizontal-field
|
||||
@@ -110,6 +74,7 @@
|
||||
[bind-field
|
||||
[:input.input.is-expanded {:type "text"
|
||||
:field ::entity/code
|
||||
:event ::events/change
|
||||
:subscription editing-vendor}]]
|
||||
[:p.help "The vendor code is used for invoice parsing. Only one vendor at a time can use a code"]]]
|
||||
|
||||
@@ -122,6 +87,7 @@
|
||||
[:input.input.is-expanded {:type "text"
|
||||
:placeholder "1700 Pennsylvania Ave"
|
||||
:field ::entity/address1
|
||||
:event ::events/change
|
||||
:subscription editing-vendor}]]]]
|
||||
|
||||
[horizontal-field
|
||||
@@ -131,6 +97,7 @@
|
||||
[:input.input.is-expanded {:type "text"
|
||||
:placeholder "Suite 400"
|
||||
:field ::entity/address2
|
||||
:event ::events/change
|
||||
:subscription editing-vendor}]]]]
|
||||
|
||||
[horizontal-field
|
||||
@@ -141,6 +108,7 @@
|
||||
[:input.input.is-expanded {:type "text"
|
||||
:placeholder "Cupertino"
|
||||
:field ::entity/city
|
||||
:event ::events/change
|
||||
:subscription editing-vendor}]]]
|
||||
[:div.control
|
||||
[:p.help "State"]
|
||||
@@ -148,12 +116,14 @@
|
||||
[:input.input {:type "text"
|
||||
:placeholder "CA"
|
||||
:field ::entity/state
|
||||
:event ::events/change
|
||||
:subscription editing-vendor}]]]
|
||||
[:div.control
|
||||
[:p.help "Zip"]
|
||||
[bind-field
|
||||
[:input.input {:type "text"
|
||||
:field ::entity/zip
|
||||
:event ::events/change
|
||||
:subscription editing-vendor
|
||||
:placeholder "95014"}]]]]
|
||||
|
||||
@@ -164,6 +134,7 @@
|
||||
[bind-field
|
||||
[:input.input.is-expanded {:type "text"
|
||||
:field ::entity/primary-contact
|
||||
:event ::events/change
|
||||
:subscription editing-vendor}]]
|
||||
[:span.icon.is-small.is-left
|
||||
[:i.fa.fa-user]]]
|
||||
@@ -174,12 +145,14 @@
|
||||
[bind-field
|
||||
[:input.input {:type "email"
|
||||
:field ::entity/primary-email
|
||||
:event ::events/change
|
||||
:subscription editing-vendor}]]]
|
||||
|
||||
[:div.control.has-icons-left
|
||||
[bind-field
|
||||
[:input.input {:type "phone"
|
||||
:field ::entity/primary-phone
|
||||
:event ::events/change
|
||||
:subscription editing-vendor}]]
|
||||
[:span.icon.is-small.is-left
|
||||
[:i.fa.fa-phone]]]]
|
||||
@@ -190,6 +163,7 @@
|
||||
[bind-field
|
||||
[:input.input.is-expanded {:type "text"
|
||||
:field ::entity/secondary-contact
|
||||
:event ::events/change
|
||||
:subscription editing-vendor}]]
|
||||
[:span.icon.is-small.is-left
|
||||
[:i.fa.fa-user]]]
|
||||
@@ -199,11 +173,13 @@
|
||||
[bind-field
|
||||
[:input.input {:type "email"
|
||||
:field ::entity/secondary-email
|
||||
:event ::events/change
|
||||
:subscription editing-vendor}]]]
|
||||
[:div.control.has-icons-left
|
||||
[bind-field
|
||||
[:input.input {:type "phone"
|
||||
:field ::entity/secondary-phone
|
||||
:event ::events/change
|
||||
:subscription editing-vendor}]]
|
||||
[:span.icon.is-small.is-left
|
||||
[:i.fa.fa-phone]]]]
|
||||
@@ -217,6 +193,7 @@
|
||||
:name "schedule"
|
||||
:value "Weekly"
|
||||
:field ::entity/invoice-reminder-schedule
|
||||
:event ::events/change
|
||||
:subscription editing-vendor}]]
|
||||
" Send weekly"]
|
||||
|
||||
@@ -226,6 +203,7 @@
|
||||
:name "schedule"
|
||||
:value "Never"
|
||||
:field ::entity/invoice-reminder-schedule
|
||||
:event ::events/change
|
||||
:subscription editing-vendor}]]
|
||||
" Never"]]]
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
[reagent.core :as reagent]
|
||||
[auto-ap.events :as events]
|
||||
[auto-ap.subs :as subs]
|
||||
[auto-ap.entities.companies :as company]
|
||||
[cljsjs.dropzone :as dropzone]
|
||||
[cljs.reader :as edn]))
|
||||
(def dropzone
|
||||
@@ -25,7 +26,7 @@
|
||||
:paramName "file"
|
||||
:headers {"Authorization" (str "Token " @token)}
|
||||
:url (str "/api/invoices/upload"
|
||||
(when-let [company-name (-> @company :id)]
|
||||
(when-let [company-name (-> @company ::company/id)]
|
||||
(str "?company=" company-name)))
|
||||
:previewsContainer "#dz-hidden"
|
||||
:previewTemplate "<div class='dz-hidden-preview'></div>"})))})))
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
(ns auto-ap.views.utils
|
||||
(:require [re-frame.core :as re-frame]
|
||||
[clojure.spec.alpha :as s]
|
||||
[cljs-time.format :as format]))
|
||||
|
||||
(defn active-when= [active-page candidate]
|
||||
@@ -28,3 +29,42 @@
|
||||
|
||||
(defn date-time->str [d]
|
||||
(format/unparse pretty-long d))
|
||||
|
||||
|
||||
|
||||
(defmulti do-bind (fn [_ {:keys [type]}]
|
||||
type))
|
||||
|
||||
|
||||
(defmethod do-bind "radio" [dom {:keys [field subscription event class value] :as keys} & rest]
|
||||
(let [keys (assoc keys
|
||||
:on-change (dispatch-value-change [event [field]])
|
||||
:checked (= (field subscription) value)
|
||||
:class (str class
|
||||
(when (not (s/valid? field (field subscription)))
|
||||
" is-danger")))
|
||||
keys (dissoc keys :field :subscription :event)]
|
||||
(vec (concat [dom keys] rest))))
|
||||
|
||||
|
||||
(defmethod do-bind :default [dom {:keys [field event subscription class] :as keys} & rest]
|
||||
(let [keys (assoc keys
|
||||
:on-change (dispatch-value-change [event [field]])
|
||||
:value (field subscription)
|
||||
:class (str class
|
||||
(when (not (s/valid? field (field subscription)))
|
||||
" is-danger")))
|
||||
keys (dissoc keys :field :subscription :event)]
|
||||
(vec (concat [dom keys] rest))))
|
||||
|
||||
(defn bind-field [all]
|
||||
(apply do-bind all))
|
||||
|
||||
(defn horizontal-field [label & controls]
|
||||
[:div.field.is-horizontal
|
||||
[:div.field-label
|
||||
label
|
||||
]
|
||||
(into
|
||||
[:div.field-body]
|
||||
(map (fn [c] [:div.field c]) controls))])
|
||||
|
||||
Reference in New Issue
Block a user