Adds manager type, blocks certain permissions

This commit is contained in:
Bryce Covert
2020-05-29 07:14:40 -07:00
parent e77e02137c
commit d9bf9867e4
19 changed files with 122 additions and 92 deletions

View File

@@ -1,6 +1,6 @@
(ns auto-ap.views.components.vendor-dialog
(:require [re-frame.core :as re-frame]
[auto-ap.views.utils :refer [dispatch-event horizontal-field bind-field with-user active-when]]
[auto-ap.views.utils :refer [dispatch-event horizontal-field bind-field with-user with-is-admin? active-when]]
[auto-ap.views.components.modal :refer [action-modal]]
[auto-ap.views.components.address :refer [address-field]]
[auto-ap.views.components.typeahead :refer [typeahead-entity]]
@@ -105,36 +105,37 @@
(re-frame/reg-event-fx
::save
[with-user (forms/triggers-loading ::vendor-form) (forms/in-form ::vendor-form)]
(fn [{:keys [user] {{:keys [name hidden print-as terms invoice-reminder-schedule primary-contact secondary-contact address default-account terms-overrides account-overrides id] :as data} :data} :db} _]
[with-user with-is-admin? (forms/triggers-loading ::vendor-form) (forms/in-form ::vendor-form)]
(fn [{:keys [user is-admin?] {{:keys [name hidden print-as terms invoice-reminder-schedule primary-contact secondary-contact address default-account terms-overrides account-overrides id] :as data} :data} :db} _]
(println user)
(when (s/valid? ::entity/vendor data)
{ :graphql
{:token user
:query-obj {:venia/operation {:operation/type :mutation
:operation/name "UpsertVendor"}
:venia/queries [{:query/data [:upsert-vendor
{:vendor {:id id
:name name
:hidden hidden
:print-as print-as
:terms terms
:terms-overrides (mapv
(fn [{:keys [client override id]}]
{:id id
:client-id (:id client)
:terms override})
terms-overrides)
:default-account-id (:id default-account)
:account-overrides (mapv
(fn [{:keys [client override id]}]
{:id id
:client-id (:id client)
:account-id (:id override)})
account-overrides)
:address address
:primary-contact primary-contact
:secondary-contact secondary-contact
:invoice-reminder-schedule invoice-reminder-schedule}}
{:vendor (cond-> {:id id
:name name
:print-as print-as
:terms terms
:terms-overrides (mapv
(fn [{:keys [client override id]}]
{:id id
:client-id (:id client)
:terms override})
terms-overrides)
:default-account-id (:id default-account)
:account-overrides (mapv
(fn [{:keys [client override id]}]
{:id id
:client-id (:id client)
:account-id (:id override)})
account-overrides)
:address address
:primary-contact primary-contact
:secondary-contact secondary-contact
:invoice-reminder-schedule invoice-reminder-schedule}
is-admin? (assoc :hidden hidden))}
events/vendor-query]}]}
:on-success [::save-complete]
:on-error [::forms/save-error ::vendor-form]}})))
@@ -171,7 +172,8 @@
(defn form-content [{:keys [data change-event]}]
(let [accounts @(re-frame/subscribe [::subs/accounts])
clients @(re-frame/subscribe [::subs/clients])]
clients @(re-frame/subscribe [::subs/clients])
is-admin? @(re-frame/subscribe [::subs/is-admin?])]
[:div
[horizontal-field
[:label.label "Name"]
@@ -194,15 +196,16 @@
:event change-event
:subscription data}]]]]
[horizontal-field
[:label.label "Hidden"]
[:div.control
[bind-field
[:input {:type "checkbox"
:field :hidden
:spec ::entity/hidden
:event change-event
:subscription data}]]]]
(when is-admin?
[horizontal-field
[:label.label "Hidden"]
[:div.control
[bind-field
[:input {:type "checkbox"
:field :hidden
:spec ::entity/hidden
:event change-event
:subscription data}]]]])
[:h2.subtitle "Terms"]
[default-with-overrides {:data data :change-event change-event
:default-key :terms