side panel work.

This commit is contained in:
BC
2019-01-29 17:33:27 -08:00
parent 327e51658c
commit 684c5343ac
4 changed files with 35 additions and 19 deletions

View File

@@ -29,7 +29,7 @@
(def integreat-schema
{
:scalars {:id {
:parse (schema/as-conformer #(Long/parseLong %))
:parse (schema/as-conformer #(when % (Long/parseLong %)))
:serialize (schema/as-conformer #(.toString %))}
:ident {:parse (schema/as-conformer (fn [x] {:db/ident x}))
:serialize (schema/as-conformer #(or (:ident %) (:db/ident %) %))}}
@@ -53,6 +53,7 @@
{:fields {:id {:type :id }
:type {:type :bank_account_type}
:number {:type 'String}
:routing {:type 'String}
:code {:type 'String}
:check_number {:type 'Int}
:name {:type 'String}

View File

@@ -12,15 +12,9 @@
(defn edit-client [context {:keys [edit_client new_bank_accounts] :as args} value]
(assert-admin (:id context))
(let [client (d-clients/get-by-id (:id edit_client))
#_#_new-clients (set (map #(Long/parseLong %) (:clients edit_user)))
#_#_clients-to-remove (->> (:user/clients user)
(map :db/id)
(filter #(not (new-clients %)) ))]
@(d/transact (d/connect uri)
(doto (-> [(remove-nils {:db/id (:db/id client)
(let [client (when (:id edit_client) (d-clients/get-by-id (:id edit_client)))
id (or (:db/id client) "new-client")
transactions [(remove-nils {:db/id id
:client/code (if (str/blank? (:client/code client))
(:code edit_client)
(:client/code client))
@@ -51,12 +45,8 @@
) (:bank_accounts edit_client))
})]
#_(into (map (fn [c] [:db/retract (:db/id user) :user/clients c]) clients-to-remove)))
clojure.pprint/pprint))
(doto (->graphql
(d-clients/get-by-id (:id edit_client)))
println)))
result @(d/transact (d/connect uri) transactions)]
(-> result :tempids (get id) d-clients/get-by-id ->graphql)))
(defn get-client [context args value]

View File

@@ -30,7 +30,7 @@
:is-empty #(= % "")))))
(s/def ::client (s/keys :req-un [::name]
(s/def ::client (s/keys :req-un [::name ::code]
:opt-un [::email
::address
::locations

View File

@@ -43,7 +43,28 @@
{:edit-client
;; TODO - hard code fields we want
(-> edited-client
(update :bank-accounts #(into % (map (fn [ba] (dissoc ba :is-new?)) (:new-bank-accounts edited-client))))
(update :bank-accounts #(seq (into % (map (fn [ba] (dissoc ba :is-new?)) (:new-bank-accounts edited-client)))))
(dissoc :new-bank-accounts)
)}
[:id :name :code :email [:address [:street1 :street2 :city :state :zip]] [:bank-accounts [:id :number :check-number :name :code :bank-code :bank-name :routing]]]]}]}
:on-success [::save-complete]
:on-error [::save-error]}})))
(re-frame/reg-event-fx
::save-new-client
(fn [{:keys [db]} _]
(let [new-client (-> (:new-client @(re-frame/subscribe [::subs/admin]))
(dissoc :location))]
{:db (assoc-in db [:admin :client :saving?] true)
:graphql
{:token (-> db :user)
:query-obj {:venia/operation {:operation/type :mutation
:operation/name "EditClient"}
:venia/queries [{:query/data [:edit-client
{:edit-client
;; TODO - hard code fields we want
(-> new-client
(update :bank-accounts #(seq (into % (map (fn [ba] (dissoc ba :is-new?)) (:new-bank-accounts new-client)))))
(dissoc :new-bank-accounts))
}
[:id :name :code :email [:address [:street1 :street2 :city :state :zip]] [:bank-accounts [:id :number :check-number :name :code :bank-code :bank-name :routing]]]
@@ -480,7 +501,11 @@
(for [[index {:keys [name code number check-number]}] (map vector (range) (:new-bank-accounts new-client))]
^{:key index} [:li [:strong "* " code ": " name] [:button.button {:on-click (dispatch-event [::remove-new-bank-account index])} [:span.icon [:i.fa.fa-times]]]])]]]]
(when (:saving? new-client) [:div.is-overlay {:style {"backgroundColor" "rgba(150,150,150, 0.5)"}}])]]))
#_(when (:saving? new-client) [:div.is-overlay {:style {"backgroundColor" "rgba(150,150,150, 0.5)"}}])
[:submit.button.is-large.is-primary {:disabled (if (s/valid? ::entity/client new-client)
""
"disabled")
:on-click (dispatch-event [::save-new-client])} "Save"]]]))
(defn admin-clients-page []
(let [adding-client? @(re-frame/subscribe [::subs/admin])]