can set up multiple locations
This commit is contained in:
@@ -68,7 +68,7 @@
|
|||||||
:plugins [[lein-figwheel "0.5.13"]
|
:plugins [[lein-figwheel "0.5.13"]
|
||||||
[lein-pdo "0.1.1"]
|
[lein-pdo "0.1.1"]
|
||||||
[cider/cider-nrepl "0.16.0"]]
|
[cider/cider-nrepl "0.16.0"]]
|
||||||
:jvm-opts ["-Dconfig=config/dev.edn" "--add-modules" "java.xml.bind"]}
|
:jvm-opts ["-Dconfig=config/dev.edn" #_#_"--add-modules" "java.xml.bind"]}
|
||||||
:uberjar {:prep-tasks [["cljsbuild" "once" "min"] "compile"]}
|
:uberjar {:prep-tasks [["cljsbuild" "once" "min"] "compile"]}
|
||||||
:provided {:dependencies [[org.clojure/clojurescript "1.10.238"]
|
:provided {:dependencies [[org.clojure/clojurescript "1.10.238"]
|
||||||
[reagent "0.7.0"]
|
[reagent "0.7.0"]
|
||||||
|
|||||||
@@ -19,7 +19,9 @@
|
|||||||
(-> x
|
(-> x
|
||||||
(assoc-in [:data :bank-accounts] (:bank-accounts x))
|
(assoc-in [:data :bank-accounts] (:bank-accounts x))
|
||||||
(assoc-in [:data :address] (:address x))
|
(assoc-in [:data :address] (:address x))
|
||||||
|
(assoc-in [:data :locations] (:locations x))
|
||||||
(dissoc :bank-accounts)
|
(dissoc :bank-accounts)
|
||||||
|
(dissoc :locations)
|
||||||
(dissoc :address)))
|
(dissoc :address)))
|
||||||
|
|
||||||
(defn get-all []
|
(defn get-all []
|
||||||
|
|||||||
@@ -34,6 +34,7 @@
|
|||||||
{:fields {:id {:type 'Int}
|
{:fields {:id {:type 'Int}
|
||||||
:name {:type 'String}
|
:name {:type 'String}
|
||||||
:email {:type 'String}
|
:email {:type 'String}
|
||||||
|
:locations {:type '(list String)}
|
||||||
:bank_accounts {:type '(list :bank_account)}}}
|
:bank_accounts {:type '(list :bank_account)}}}
|
||||||
|
|
||||||
:bank_account
|
:bank_account
|
||||||
|
|||||||
@@ -10,6 +10,9 @@
|
|||||||
(s/def ::name ::shared/required-identifier)
|
(s/def ::name ::shared/required-identifier)
|
||||||
(s/def ::address ::address/address)
|
(s/def ::address ::address/address)
|
||||||
|
|
||||||
|
(s/def ::location string?)
|
||||||
|
(s/def ::locations (s/coll-of ::location))
|
||||||
|
|
||||||
(s/def ::email (s/nilable (s/and string? (s/or :is-email #(re-matches email-regex %)
|
(s/def ::email (s/nilable (s/and string? (s/or :is-email #(re-matches email-regex %)
|
||||||
:is-empty #(= % "")))))
|
:is-empty #(= % "")))))
|
||||||
|
|
||||||
@@ -17,6 +20,7 @@
|
|||||||
(s/def ::company (s/keys :req-un [::name]
|
(s/def ::company (s/keys :req-un [::name]
|
||||||
:opt-un [::email
|
:opt-un [::email
|
||||||
::address
|
::address
|
||||||
|
::locations
|
||||||
::id]))
|
::id]))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -36,7 +36,8 @@
|
|||||||
:user token)
|
:user token)
|
||||||
:graphql {:token token
|
:graphql {:token token
|
||||||
:query-obj {:venia/queries [[:company
|
:query-obj {:venia/queries [[:company
|
||||||
[:id :name [:bank-accounts [:id :number :check-number :name]]]]
|
|
||||||
|
[:id :name :locations [:bank-accounts [:id :number :check-number :name] ]]]
|
||||||
[:vendor
|
[:vendor
|
||||||
[:id :name :default-expense-account]]]}
|
[:id :name :default-expense-account]]]}
|
||||||
|
|
||||||
|
|||||||
@@ -1,21 +1,25 @@
|
|||||||
(ns auto-ap.events.admin.companies
|
(ns auto-ap.events.admin.companies
|
||||||
(:require [re-frame.core :as re-frame]
|
(:require [re-frame.core :as re-frame]
|
||||||
[auto-ap.db :as db]
|
[auto-ap.db :as db]
|
||||||
|
[auto-ap.events :as events]
|
||||||
[auto-ap.routes :as routes]
|
[auto-ap.routes :as routes]
|
||||||
[auto-ap.effects :as effects]
|
[auto-ap.effects :as effects]
|
||||||
[auto-ap.entities.companies :as entity]
|
[auto-ap.entities.companies :as entity]
|
||||||
[bidi.bidi :as bidi]))
|
[bidi.bidi :as bidi]))
|
||||||
|
|
||||||
(re-frame/reg-event-db
|
(re-frame/reg-event-fx
|
||||||
::edit
|
::edit
|
||||||
(fn [db [_ company-id]]
|
(fn [{:keys [db]} [_ company-id]]
|
||||||
(assoc-in db [:admin :company]
|
{:dispatch [::events/modal-status :auto-ap.views.pages.admin.companies/edit {:visible? true}]
|
||||||
(get (:companies db) company-id))))
|
:db (assoc-in db [:admin :company]
|
||||||
|
(get (:companies db) company-id))}))
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::save
|
::save
|
||||||
(fn [{:keys [db]} _]
|
(fn [{:keys [db]} _]
|
||||||
(let [edited-company (get-in db [:admin :company])]
|
(let [edited-company (-> (get-in db [:admin :company])
|
||||||
|
(dissoc :location))]
|
||||||
|
|
||||||
{:db (assoc-in db [:admin :company :saving?] true)
|
{:db (assoc-in db [:admin :company :saving?] true)
|
||||||
:http {:method :put
|
:http {:method :put
|
||||||
:token (:user db)
|
:token (:user db)
|
||||||
@@ -25,13 +29,14 @@
|
|||||||
:on-success [::save-complete]
|
:on-success [::save-complete]
|
||||||
:on-error [::save-error]}})))
|
:on-error [::save-error]}})))
|
||||||
|
|
||||||
(re-frame/reg-event-db
|
(re-frame/reg-event-fx
|
||||||
::save-complete
|
::save-complete
|
||||||
(fn [db [_ company]]
|
(fn [{:keys [db]} [_ company]]
|
||||||
(-> db
|
{:dispatch [::events/modal-completed :auto-ap.views.pages.admin.companies/edit]
|
||||||
|
:db (-> db
|
||||||
(assoc-in [:admin :company] nil)
|
|
||||||
(assoc-in [:companies (:id company)] company))))
|
(assoc-in [:admin :company] nil)
|
||||||
|
(assoc-in [:companies (:id company)] company))}))
|
||||||
|
|
||||||
(re-frame/reg-event-db
|
(re-frame/reg-event-db
|
||||||
::save-error
|
::save-error
|
||||||
|
|||||||
@@ -6,11 +6,20 @@
|
|||||||
[auto-ap.events.admin.companies :as events]
|
[auto-ap.events.admin.companies :as events]
|
||||||
[auto-ap.entities.companies :as entity]
|
[auto-ap.entities.companies :as entity]
|
||||||
[auto-ap.views.components.address :refer [address-field]]
|
[auto-ap.views.components.address :refer [address-field]]
|
||||||
[auto-ap.views.utils :refer [login-url dispatch-value-change bind-field horizontal-field]]
|
[auto-ap.views.utils :refer [login-url dispatch-event dispatch-value-change bind-field horizontal-field]]
|
||||||
[auto-ap.views.components.modal :refer [modal]]
|
[auto-ap.views.components.modal :refer [action-modal]]
|
||||||
[cljs.reader :as edn]
|
[cljs.reader :as edn]
|
||||||
[auto-ap.routes :as routes]
|
[auto-ap.routes :as routes]
|
||||||
[bidi.bidi :as bidi]))
|
[bidi.bidi :as bidi]))
|
||||||
|
|
||||||
|
(re-frame/reg-event-fx
|
||||||
|
::add-location
|
||||||
|
(fn [{:keys [db]} _]
|
||||||
|
(let [company (:company @(re-frame/subscribe [::subs/admin]))]
|
||||||
|
{:db (-> db
|
||||||
|
(update-in [:admin :company :locations] conj (:location company))
|
||||||
|
(update-in [:admin :company] dissoc :location))})))
|
||||||
|
|
||||||
(defn companies-table []
|
(defn companies-table []
|
||||||
(let [companies (re-frame/subscribe [::subs/companies])
|
(let [companies (re-frame/subscribe [::subs/companies])
|
||||||
editing-company (:company @(re-frame/subscribe [::subs/admin]))]
|
editing-company (:company @(re-frame/subscribe [::subs/admin]))]
|
||||||
@@ -35,46 +44,57 @@
|
|||||||
[:h1.title "Companies"]
|
[:h1.title "Companies"]
|
||||||
[companies-table]
|
[companies-table]
|
||||||
|
|
||||||
(when editing-company
|
[action-modal {:id ::edit
|
||||||
[modal {:title (str "Edit " (:name editing-company))
|
:title (str "Edit " (:name editing-company))
|
||||||
:foot [:a.button.is-primary {:on-click (fn [] (re-frame/dispatch [::events/save]))}
|
:action-text "Save"
|
||||||
[:span "Save"]
|
:save-event [::events/save]}
|
||||||
(when (:saving? editing-company)
|
[horizontal-field
|
||||||
[:span.icon
|
[:label.label "Name"]
|
||||||
[:i.fa.fa-spin.fa-spinner]])]
|
[:div.control
|
||||||
:hide-event [::events/edit nil]}
|
[bind-field
|
||||||
[horizontal-field
|
[:input.input {:type "text"
|
||||||
[:label.label "Name"]
|
:field :name
|
||||||
[:div.control
|
:spec ::entity/name
|
||||||
|
:event ::events/change
|
||||||
|
:subscription editing-company}]]]]
|
||||||
|
|
||||||
|
[horizontal-field
|
||||||
|
[:label.label "Email"]
|
||||||
|
[:div.control
|
||||||
|
[bind-field
|
||||||
|
[:input.input {:type "email"
|
||||||
|
:field :email
|
||||||
|
:spec ::entity/name
|
||||||
|
:event ::events/change
|
||||||
|
:subscription editing-company}]]]]
|
||||||
|
|
||||||
|
[:h2.subtitle "Address"]
|
||||||
|
|
||||||
|
[address-field {:field [:address]
|
||||||
|
:event ::events/change
|
||||||
|
:subscription editing-company}]
|
||||||
|
|
||||||
|
[horizontal-field
|
||||||
|
[:label.label "Bank Accounts"]
|
||||||
|
[:div.control
|
||||||
|
[:ul
|
||||||
|
(for [{:keys [number check-number id]} (:bank-accounts editing-company)]
|
||||||
|
^{:key id} [:li number " - " check-number])]]]
|
||||||
|
|
||||||
|
[horizontal-field
|
||||||
|
[:label.label "Locations"]
|
||||||
|
[:div.control
|
||||||
|
[:div.field.has-addons
|
||||||
|
[:p.control
|
||||||
[bind-field
|
[bind-field
|
||||||
[:input.input {:type "text"
|
[:input.input {:type "text"
|
||||||
:field :name
|
:field :location
|
||||||
:spec ::entity/name
|
|
||||||
:event ::events/change
|
:event ::events/change
|
||||||
:subscription editing-company}]]]]
|
:subscription editing-company}]]]
|
||||||
|
[:p.control [:button.button.is-primary {:on-click (dispatch-event [::add-location])} "Add"]]]
|
||||||
[horizontal-field
|
[:ul
|
||||||
[:label.label "Email"]
|
(for [location (:locations editing-company)]
|
||||||
[:div.control
|
^{:key location} [:li location ])]]]
|
||||||
[bind-field
|
|
||||||
[:input.input {:type "email"
|
|
||||||
:field :email
|
(when (:saving? editing-company) [:div.is-overlay {:style {"backgroundColor" "rgba(150,150,150, 0.5)"}}])]])])
|
||||||
:spec ::entity/name
|
|
||||||
:event ::events/change
|
|
||||||
:subscription editing-company}]]]]
|
|
||||||
|
|
||||||
[:h2.subtitle "Address"]
|
|
||||||
|
|
||||||
[address-field {:field [:address]
|
|
||||||
:event ::events/change
|
|
||||||
:subscription editing-company}]
|
|
||||||
|
|
||||||
[horizontal-field
|
|
||||||
[:label.label "Bank Accounts"]
|
|
||||||
[:div.control
|
|
||||||
[:ul
|
|
||||||
(for [{:keys [number check-number id]} (:bank-accounts editing-company)]
|
|
||||||
^{:key id} [:li number " - " check-number])]]]
|
|
||||||
|
|
||||||
|
|
||||||
(when (:saving? editing-company) [:div.is-overlay {:style {"backgroundColor" "rgba(150,150,150, 0.5)"}}])])])])
|
|
||||||
|
|||||||
Reference in New Issue
Block a user