more specs.
This commit is contained in:
@@ -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"]]]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user