Created
August 26, 2015 06:47
-
-
Save Deraen/2409137ef726ebd13124 to your computer and use it in GitHub Desktop.
Hiding stuff on Reagent based on Users role
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns frontend.access | |
(:require [reagent.ratom :refer-macros [reaction]] | |
[frontend.app :refer [app]] | |
[common.domain :as domain])) | |
(def admin #{:domain/admin}) | |
(def user #{:domain/user}) | |
(defn role [] | |
(reaction app [:session :user :role])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns frontend.view.profile | |
(:require ... | |
[frontend.access :as access])) | |
(defn profile-view [{:keys [save k edit-role]}] | |
(let [... | |
role (access/role)] | |
(fn [] | |
... | |
(if (edit-role @role) | |
[:div.btn-toolbar | |
[f/form-status form] | |
[f/cancel-btn form] | |
[f/save-btn form :on-click save]]) | |
... | |
))) | |
(defmethod r/render-view :profile [_] | |
[profile-view {:save save-current, :k :profile, :edit-role access/admin}]) | |
(defmethod r/render-view :user [_] | |
[profile-view {:save save, :k :user, :edit-role access/user}]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment