not using namespaced keys, due to graphql

This commit is contained in:
Bryce Covert
2018-04-10 10:51:21 -07:00
parent 4a0275f024
commit 53905c317b
19 changed files with 114 additions and 109 deletions

View File

@@ -4,7 +4,6 @@
[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
@@ -43,14 +42,14 @@
(fn [db [_ companies]]
(assoc db :companies (reduce (fn [companies company]
(assoc companies (::companies/id company) company))
(assoc companies (:id company) company))
{}
companies))))
(re-frame/reg-event-db
::swap-company
(fn [db [_ company]]
(assoc db :company (::companies/id company))))
(assoc db :company (:id company))))
(re-frame/reg-event-fx
::set-active-page
@@ -71,7 +70,7 @@
{:http {:method :post
:token (-> cofx :db :user)
:uri (str "/api/invoices/approve"
(when-let [company-id (::companies/id @(re-frame/subscribe [::subs/company]))]
(when-let [company-id (:id @(re-frame/subscribe [::subs/company]))]
(str "?company=" company-id)))
:on-success [::received-invoices :pending]
}}))
@@ -83,7 +82,7 @@
:http {:method :get
:token (-> cofx :db :user)
:uri (str "/api/invoices/pending"
(when-let [company-id (::companies/id @(re-frame/subscribe [::subs/company]))]
(when-let [company-id (:id @(re-frame/subscribe [::subs/company]))]
(str "?company=" company-id)))
:on-success [::received-invoices :pending]}}))
@@ -94,7 +93,7 @@
:http {:method :get
:token (-> cofx :db :user)
:uri (str "/api/invoices/unpaid"
(when-let [company-id (::companies/id @(re-frame/subscribe [::subs/company]))]
(when-let [company-id (:id @(re-frame/subscribe [::subs/company]))]
(str "?company=" company-id)))
:on-success [::received-invoices :unpaid]}}))
@@ -104,7 +103,7 @@
{:http {:method :post
:token (-> cofx :db :user)
:uri (str "/api/invoices/reject"
(when-let [company-id (::companies/id @(re-frame/subscribe [::subs/company]))]
(when-let [company-id (:id @(re-frame/subscribe [::subs/company]))]
(str "?company=" company-id)))
:on-success [::received-invoices :pending]
}}))

View File

@@ -21,7 +21,7 @@
:token (:user db)
:body (pr-str edited-company)
:headers {"Content-Type" "application/edn"}
:uri (str "/api/companies/" (::entity/id edited-company))
:uri (str "/api/companies/" (:id edited-company))
:on-success [::save-complete]
:on-error [::save-error]}})))
@@ -31,7 +31,7 @@
(-> db
(assoc-in [:admin :company] nil)
(assoc-in [:companies (::entity/id company)] company))))
(assoc-in [:companies (:id company)] company))))
(re-frame/reg-event-db
::save-error

View File

@@ -26,12 +26,12 @@
(let [edited-vendor (get-in db [:admin :vendor])
fx {:db (assoc-in db [:admin :vendor :saving?] true)}]
(when (s/valid? ::entity/vendor edited-vendor)
(if (::entity/id edited-vendor)
(if (:id edited-vendor)
(assoc fx :http {:method :put
:token (:user db)
:body (pr-str edited-vendor)
:headers {"Content-Type" "application/edn"}
:uri (str "/api/vendors/" (::entity/id edited-vendor))
:uri (str "/api/vendors/" (:id edited-vendor))
:on-success [::save-complete]
:on-error [::save-error]})
(assoc fx :http {:method :post
@@ -48,7 +48,7 @@
(-> db
(assoc-in [:admin :vendor] nil)
(assoc-in [:vendors (::entity/id vendor)] vendor))))
(assoc-in [:vendors (:id vendor)] vendor))))
(re-frame/reg-event-db
::save-error
@@ -76,6 +76,6 @@
(fn [db [_ vendors]]
(assoc db :vendors (reduce (fn [vendors vendor]
(assoc vendors (::entity/id vendor) vendor))
(assoc vendors (:id vendor) vendor))
{}
vendors))))

View File

@@ -17,13 +17,12 @@
[:tr
[:th "Name"]
[:th "Email"]]]
[:tbody (for [{:keys [::entity/id ::entity/name ::entity/email] :as c} @companies]
[:tbody (for [{:keys [id name 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 email]])]]))
(defn admin-companies-page []
[:div {:class "inbox-messages"}
@@ -55,7 +54,8 @@
[:div.control
[bind-field
[:input.input {:type "text"
:field ::entity/name
:field :name
:spec ::entity/name
:event ::events/change
:subscription editing-company}]]]]
@@ -64,7 +64,8 @@
[:div.control
[bind-field
[:input.input {:type "email"
:field ::entity/email
:field :email
:spec ::entity/name
:event ::events/change
:subscription editing-company}]]]]

View File

@@ -26,12 +26,12 @@
[:th "Email"]
[:th "Invoice Reminders"]]]
[:tbody (for [v @vendors]
^{:key (str (::entity/id v))}
[:tr {:on-click (fn [] (re-frame/dispatch [::events/edit (::entity/id v)]))
^{:key (str (:id v))}
[:tr {:on-click (fn [] (re-frame/dispatch [::events/edit (:id v)]))
:style {"cursor" "pointer"}}
[:td (::entity/name v)]
[:td (::entity/primary-email v)]
[:td (::entity/invoice-reminder-schedule v)]])]]))
[:td (:name v)]
[:td (:primary-email v)]
[:td (:invoice-reminder-schedule v)]])]]))
(defn danger-for [[dom {:keys [field subscription class] :as keys} & rest]]
(let [keys (assoc keys :class (str class
@@ -50,9 +50,9 @@
[:div.modal-card
[:header.modal-card-head
[:p.modal-card-title
(if (::entity/id editing-vendor)
(str "Edit " (or (::entity/name editing-vendor) "<vendor>"))
(str "Add " (or (::entity/name editing-vendor) "<new vendor>")))]
(if (:id editing-vendor)
(str "Edit " (or (:name editing-vendor) "<vendor>"))
(str "Add " (or (:name editing-vendor) "<new vendor>")))]
(when (:error editing-vendor)
[:span.icon.has-text-danger
[:i.fa.fa-exclamation-triangle]])
@@ -63,7 +63,8 @@
[:div.control
[bind-field
[:input.input {:type "text"
:field ::entity/name
:field :name
:spec ::entity/name
:event ::events/change
:subscription editing-vendor}]]]]
@@ -73,7 +74,8 @@
[bind-field
[:input.input.is-expanded {:type "text"
:field ::entity/code
:field :code
:spec ::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"]]]
@@ -86,7 +88,8 @@
[bind-field
[:input.input.is-expanded {:type "text"
:placeholder "1700 Pennsylvania Ave"
:field ::entity/address1
:field :address1
:spec ::entity/address1
:event ::events/change
:subscription editing-vendor}]]]]
@@ -96,7 +99,8 @@
[bind-field
[:input.input.is-expanded {:type "text"
:placeholder "Suite 400"
:field ::entity/address2
:field :address2
:spec ::entity/address2
:event ::events/change
:subscription editing-vendor}]]]]
@@ -107,7 +111,8 @@
[bind-field
[:input.input.is-expanded {:type "text"
:placeholder "Cupertino"
:field ::entity/city
:field :city
:spec ::entity/city
:event ::events/change
:subscription editing-vendor}]]]
[:div.control
@@ -115,14 +120,16 @@
[bind-field
[:input.input {:type "text"
:placeholder "CA"
:field ::entity/state
:field :state
:spec ::entity/state
:event ::events/change
:subscription editing-vendor}]]]
[:div.control
[:p.help "Zip"]
[bind-field
[:input.input {:type "text"
:field ::entity/zip
:field :zip
:spec ::entity/zip
:event ::events/change
:subscription editing-vendor
:placeholder "95014"}]]]]
@@ -133,7 +140,8 @@
[:div.control.has-icons-left
[bind-field
[:input.input.is-expanded {:type "text"
:field ::entity/primary-contact
:field :primary-contact
:spec ::entity/primary-contact
:event ::events/change
:subscription editing-vendor}]]
[:span.icon.is-small.is-left
@@ -144,14 +152,16 @@
[:i.fa.fa-envelope]]
[bind-field
[:input.input {:type "email"
:field ::entity/primary-email
:field :primary-email
:spec ::entity/primary-email
:event ::events/change
:subscription editing-vendor}]]]
[:div.control.has-icons-left
[bind-field
[:input.input {:type "phone"
:field ::entity/primary-phone
:field :primary-phone
:spec ::entity/primary-phone
:event ::events/change
:subscription editing-vendor}]]
[:span.icon.is-small.is-left
@@ -162,7 +172,8 @@
[:div.control.has-icons-left
[bind-field
[:input.input.is-expanded {:type "text"
:field ::entity/secondary-contact
:field :secondary-contact
:spec ::entity/secondary-contact
:event ::events/change
:subscription editing-vendor}]]
[:span.icon.is-small.is-left
@@ -172,13 +183,15 @@
[:i.fa.fa-envelope]]
[bind-field
[:input.input {:type "email"
:field ::entity/secondary-email
:field :secondary-email
:spec ::entity/secondary-email
:event ::events/change
:subscription editing-vendor}]]]
[:div.control.has-icons-left
[bind-field
[:input.input {:type "phone"
:field ::entity/secondary-phone
:field :secondary-phone
:spec ::entity/secondary-phone
:event ::events/change
:subscription editing-vendor}]]
[:span.icon.is-small.is-left
@@ -192,7 +205,8 @@
[:input {:type "radio"
:name "schedule"
:value "Weekly"
:field ::entity/invoice-reminder-schedule
:field :invoice-reminder-schedule
:spec ::entity/invoice-reminder-schedule
:event ::events/change
:subscription editing-vendor}]]
" Send weekly"]
@@ -202,7 +216,8 @@
[:input {:type "radio"
:name "schedule"
:value "Never"
:field ::entity/invoice-reminder-schedule
:field :invoice-reminder-schedule
:spec ::entity/invoice-reminder-schedule
:event ::events/change
:subscription editing-vendor}]]
" Never"]]]

View File

@@ -27,7 +27,7 @@
:paramName "file"
:headers {"Authorization" (str "Token " @token)}
:url (str "/api/invoices/upload"
(when-let [company-name (-> @company ::company/id)]
(when-let [company-name (-> @company :id)]
(str "?company=" company-name)))
:previewsContainer "#dz-hidden"
:previewTemplate "<div class='dz-hidden-preview'></div>"})))})))
@@ -61,9 +61,9 @@
[:tbody (for [{:keys [vendor vendor-id potential-duplicate company-id customer-identifier invoice-number date total id] :as i} @invoices]
^{:key (str company-id "-" invoice-number "-" date "-" total "-" id)}
[:tr
[:td (::vendor/name (:vendor i))]
[:td (:name (:vendor i))]
(if company-id
[:td (::company/name (:company i))]
[:td (:name (:company i))]
[:td [:i.icon.fa.fa-warning {:title "potential duplicate"}]
(str "'" customer-identifier "' doesn't match any known company")])
[:td invoice-number]

View File

@@ -23,11 +23,11 @@
[:th "Invoice #"]
[:th "Date"]
[:th "Amount"]]]
[:tbody (for [{:keys [company invoice-number date total id vendor-id] :as i} @invoices]
^{:key (str company "-" invoice-number "-" date "-" total "-" id)}
[:tbody (for [{:keys [company vendor invoice-number date total id] :as i} @invoices]
^{:key (str (:id company) "-" invoice-number "-" date "-" total "-" id)}
[:tr
[:td vendor-id]
[:td company]
[:td (:name vendor)]
[:td (:name company)]
[:td invoice-number]
[:td date]
[:td total]])]])]))

View File

@@ -29,8 +29,8 @@
[:tbody (for [{:keys [company invoice-number date total id vendor] :as i} @invoices]
^{:key (str company "-" invoice-number "-" date "-" total "-" id)}
[:tr
[:td (::vendor/name vendor)]
[:td (::company/name company)]
[:td (:name vendor)]
[:td (:name company)]
[:td invoice-number]
[:td date]
[:td total]])]])]))

View File

@@ -36,25 +36,25 @@
type))
(defmethod do-bind "radio" [dom {:keys [field subscription event class value] :as keys} & rest]
(defmethod do-bind "radio" [dom {:keys [field subscription event class value spec] :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)))
(when (and spec (not (s/valid? spec (field subscription))))
" is-danger")))
keys (dissoc keys :field :subscription :event)]
keys (dissoc keys :field :subscription :event :spec)]
(vec (concat [dom keys] rest))))
(defmethod do-bind :default [dom {:keys [field event subscription class] :as keys} & rest]
(defmethod do-bind :default [dom {:keys [field event subscription class spec] :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)))
(when (and spec (not (s/valid? spec (field subscription))))
" is-danger")))
keys (dissoc keys :field :subscription :event)]
keys (dissoc keys :field :subscription :event :spec)]
(vec (concat [dom keys] rest))))
(defn bind-field [all]