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 permspull/1290/head
parent
49782c0b73
commit
a9461f760d
@ -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;
|
||||
|
@ -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;
|
Loading…
Reference in new issue