-
Notifications
You must be signed in to change notification settings - Fork 208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enhancing UserHasAccess component #472
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,13 +1,15 @@ | ||||||
/** @module @category API */ | ||||||
import { getCurrentUser, LoggedInUser, userHasAccess } from "@openmrs/esm-api"; | ||||||
import React, { useEffect, useState } from "react"; | ||||||
import { getCurrentUser, userHasAccess, LoggedInUser } from "@openmrs/esm-api"; | ||||||
|
||||||
export interface UserHasAccessProps { | ||||||
interface UserHasAccessProps { | ||||||
privilege: string; | ||||||
unauthorisedResponse?: React.ReactNode | undefined; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure @brandones , changes have been made accordingly. |
||||||
} | ||||||
|
||||||
export const UserHasAccess: React.FC<UserHasAccessProps> = ({ | ||||||
privilege, | ||||||
unauthorisedResponse, | ||||||
children, | ||||||
}) => { | ||||||
const [user, setUser] = useState<LoggedInUser | null>(null); | ||||||
|
@@ -21,7 +23,7 @@ export const UserHasAccess: React.FC<UserHasAccessProps> = ({ | |||||
|
||||||
if (user && userHasAccess(privilege, user)) { | ||||||
return <>{children}</>; | ||||||
} else { | ||||||
return unauthorisedResponse ? <>{unauthorisedResponse}</> : null; | ||||||
} | ||||||
|
||||||
return null; | ||||||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should still be exported