can set up multiple locations
This commit is contained in:
@@ -68,7 +68,7 @@
|
||||
:plugins [[lein-figwheel "0.5.13"]
|
||||
[lein-pdo "0.1.1"]
|
||||
[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"]}
|
||||
:provided {:dependencies [[org.clojure/clojurescript "1.10.238"]
|
||||
[reagent "0.7.0"]
|
||||
|
||||
@@ -19,7 +19,9 @@
|
||||
(-> x
|
||||
(assoc-in [:data :bank-accounts] (:bank-accounts x))
|
||||
(assoc-in [:data :address] (:address x))
|
||||
(assoc-in [:data :locations] (:locations x))
|
||||
(dissoc :bank-accounts)
|
||||
(dissoc :locations)
|
||||
(dissoc :address)))
|
||||
|
||||
(defn get-all []
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
{:fields {:id {:type 'Int}
|
||||
:name {:type 'String}
|
||||
:email {:type 'String}
|
||||
:locations {:type '(list String)}
|
||||
:bank_accounts {:type '(list :bank_account)}}}
|
||||
|
||||
:bank_account
|
||||
|
||||
@@ -10,6 +10,9 @@
|
||||
(s/def ::name ::shared/required-identifier)
|
||||
(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 %)
|
||||
:is-empty #(= % "")))))
|
||||
|
||||
@@ -17,6 +20,7 @@
|
||||
(s/def ::company (s/keys :req-un [::name]
|
||||
:opt-un [::email
|
||||
::address
|
||||
::locations
|
||||
::id]))
|
||||
|
||||
|
||||
|
||||
@@ -36,7 +36,8 @@
|
||||
:user token)
|
||||
:graphql {:token token
|
||||
: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
|
||||
[:id :name :default-expense-account]]]}
|
||||
|
||||
|
||||
@@ -1,21 +1,25 @@
|
||||
(ns auto-ap.events.admin.companies
|
||||
(:require [re-frame.core :as re-frame]
|
||||
[auto-ap.db :as db]
|
||||
[auto-ap.events :as events]
|
||||
[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
|
||||
(re-frame/reg-event-fx
|
||||
::edit
|
||||
(fn [db [_ company-id]]
|
||||
(assoc-in db [:admin :company]
|
||||
(get (:companies db) company-id))))
|
||||
(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))}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::save
|
||||
(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)
|
||||
:http {:method :put
|
||||
:token (:user db)
|
||||
@@ -25,13 +29,14 @@
|
||||
:on-success [::save-complete]
|
||||
:on-error [::save-error]}})))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
(re-frame/reg-event-fx
|
||||
::save-complete
|
||||
(fn [db [_ company]]
|
||||
(-> db
|
||||
|
||||
(assoc-in [:admin :company] nil)
|
||||
(assoc-in [:companies (:id company)] company))))
|
||||
(fn [{:keys [db]} [_ company]]
|
||||
{:dispatch [::events/modal-completed :auto-ap.views.pages.admin.companies/edit]
|
||||
:db (-> db
|
||||
|
||||
(assoc-in [:admin :company] nil)
|
||||
(assoc-in [:companies (:id company)] company))}))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::save-error
|
||||
|
||||
@@ -6,11 +6,20 @@
|
||||
[auto-ap.events.admin.companies :as events]
|
||||
[auto-ap.entities.companies :as entity]
|
||||
[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.components.modal :refer [modal]]
|
||||
[auto-ap.views.utils :refer [login-url dispatch-event dispatch-value-change bind-field horizontal-field]]
|
||||
[auto-ap.views.components.modal :refer [action-modal]]
|
||||
[cljs.reader :as edn]
|
||||
[auto-ap.routes :as routes]
|
||||
[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 []
|
||||
(let [companies (re-frame/subscribe [::subs/companies])
|
||||
editing-company (:company @(re-frame/subscribe [::subs/admin]))]
|
||||
@@ -35,46 +44,57 @@
|
||||
[:h1.title "Companies"]
|
||||
[companies-table]
|
||||
|
||||
(when editing-company
|
||||
[modal {:title (str "Edit " (:name editing-company))
|
||||
:foot [:a.button.is-primary {:on-click (fn [] (re-frame/dispatch [::events/save]))}
|
||||
[:span "Save"]
|
||||
(when (:saving? editing-company)
|
||||
[:span.icon
|
||||
[:i.fa.fa-spin.fa-spinner]])]
|
||||
:hide-event [::events/edit nil]}
|
||||
[horizontal-field
|
||||
[:label.label "Name"]
|
||||
[:div.control
|
||||
[action-modal {:id ::edit
|
||||
:title (str "Edit " (:name editing-company))
|
||||
:action-text "Save"
|
||||
:save-event [::events/save]}
|
||||
[horizontal-field
|
||||
[:label.label "Name"]
|
||||
[:div.control
|
||||
[bind-field
|
||||
[:input.input {:type "text"
|
||||
:field :name
|
||||
: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
|
||||
[:input.input {:type "text"
|
||||
:field :name
|
||||
:spec ::entity/name
|
||||
:field :location
|
||||
: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])]]]
|
||||
|
||||
|
||||
(when (:saving? editing-company) [:div.is-overlay {:style {"backgroundColor" "rgba(150,150,150, 0.5)"}}])])])])
|
||||
:subscription editing-company}]]]
|
||||
[:p.control [:button.button.is-primary {:on-click (dispatch-event [::add-location])} "Add"]]]
|
||||
[:ul
|
||||
(for [location (:locations editing-company)]
|
||||
^{:key location} [:li location ])]]]
|
||||
|
||||
|
||||
(when (:saving? editing-company) [:div.is-overlay {:style {"backgroundColor" "rgba(150,150,150, 0.5)"}}])]])])
|
||||
|
||||
Reference in New Issue
Block a user