-
-
Notifications
You must be signed in to change notification settings - Fork 406
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ui): Add user requests page (#936)
* feat(ui): add user requests page * fix: return error if user attempts to fetch another user's requests without adequate perms * fix(ui): make user name on request page link back to user profile * feat(ui): link user request count to their filtered request list view * fix(frontend): only display user requests on profiles if current user has adequate perms * fix: use 'all' filter for user-filtered request list * fix(frontend): pass userId to router.push() * fix: do not pass userId in query for non-user-filtered requests page * fix(frontend): also allow REQUEST_VIEW perm through route guard * fix(frontend): only link request count to user request list if current user has required perms
- Loading branch information
1 parent
49782c0
commit a9461f7
Showing
8 changed files
with
176 additions
and
44 deletions.
There are no files selected for viewing
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,19 @@ | ||
import { Permission, useUser } from './useUser'; | ||
import { useRouter } from 'next/router'; | ||
import { useEffect } from 'react'; | ||
import { Permission, PermissionCheckOptions, useUser } from './useUser'; | ||
|
||
const useRouteGuard = (permission: Permission | Permission[]): void => { | ||
const useRouteGuard = ( | ||
permission: Permission | Permission[], | ||
options?: PermissionCheckOptions | ||
): void => { | ||
const router = useRouter(); | ||
const { user, hasPermission } = useUser(); | ||
|
||
useEffect(() => { | ||
if (user && !hasPermission(permission)) { | ||
if (user && !hasPermission(permission, options)) { | ||
router.push('/'); | ||
} | ||
}, [user, permission, router, hasPermission]); | ||
}, [user, permission, router, hasPermission, options]); | ||
}; | ||
|
||
export default useRouteGuard; |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { NextPage } from 'next'; | ||
import React from 'react'; | ||
import RequestList from '../../../components/RequestList'; | ||
import useRouteGuard from '../../../hooks/useRouteGuard'; | ||
import { Permission } from '../../../hooks/useUser'; | ||
|
||
const UserRequestsPage: NextPage = () => { | ||
useRouteGuard([Permission.MANAGE_REQUESTS, Permission.REQUEST_VIEW], { | ||
type: 'or', | ||
}); | ||
return <RequestList />; | ||
}; | ||
|
||
export default UserRequestsPage; |