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

@@ -55,7 +55,8 @@
(defn navbar [ap]
(let [client (re-frame/subscribe [::subs/client])
(let [user (re-frame/subscribe [::subs/user])
client (re-frame/subscribe [::subs/client])
clients (re-frame/subscribe [::subs/clients])
menu (re-frame/subscribe [::subs/menu])]
[:nav {:class "navbar has-shadow is-fixed-top"}
@@ -74,12 +75,15 @@
[:a.navbar-item {:class [(active-when ap = :payments)]
:href (bidi/path-for routes/routes :payments)}
"Payments" ]
[:a.navbar-item {:class [(active-when ap = :transactions)]
:href (bidi/path-for routes/routes :transactions)}
"Transactions" ]
[:a.navbar-item {:class [(active-when ap = :ledger)]
:href (bidi/path-for routes/routes :ledger)}
"Ledger" ]]
(when (not= "manager" (:user/role @user))
[:a.navbar-item {:class [(active-when ap = :transactions)]
:href (bidi/path-for routes/routes :transactions)}
"Transactions" ])
(when (not= "manager" (:user/role @user))
[:a.navbar-item {:class [(active-when ap = :ledger)]
:href (bidi/path-for routes/routes :ledger)}
"Ledger" ])]
[:div {:class "navbar-burger burger", :data-target "navMenu"}
[:span]
[:span]

View File

@@ -24,7 +24,6 @@
(defn action-modal [{:keys [title class warning action-text id save-event can-submit? status-from] :or {can-submit? true}} & rest]
(let [{:keys [visible? saving? error-message]} @(re-frame/subscribe [::subs/modal-state id status-from])]
(println id visible?)
(when visible?
[:form {:id id
:on-submit (fn [e]

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