use children in routes instead of component prop
This commit is contained in:
parent
5f284dad1d
commit
0f9b3a5722
6 changed files with 80 additions and 88 deletions
25
resources/scripts/hoc/RequireServerPermission.tsx
Normal file
25
resources/scripts/hoc/RequireServerPermission.tsx
Normal file
|
@ -0,0 +1,25 @@
|
|||
import React from 'react';
|
||||
import Can from '@/components/elements/Can';
|
||||
import ScreenBlock from '@/components/screens/ScreenBlock';
|
||||
export interface RequireServerPermissionProps {
|
||||
permissions: string | string[]
|
||||
}
|
||||
|
||||
const RequireServerPermission: React.FC<RequireServerPermissionProps> = ({ children, permissions }) => {
|
||||
return (
|
||||
<Can
|
||||
action={permissions}
|
||||
renderOnError={
|
||||
<ScreenBlock
|
||||
image={'/assets/svgs/server_error.svg'}
|
||||
title={'Access Denied'}
|
||||
message={'You do not have permission to access this page.'}
|
||||
/>
|
||||
}
|
||||
>
|
||||
{children}
|
||||
</Can>
|
||||
);
|
||||
};
|
||||
|
||||
export default RequireServerPermission;
|
|
@ -1,31 +0,0 @@
|
|||
import React from 'react';
|
||||
import Can from '@/components/elements/Can';
|
||||
import ScreenBlock from '@/components/screens/ScreenBlock';
|
||||
import isEqual from 'react-fast-compare';
|
||||
|
||||
const requireServerPermission = (Component: React.ComponentType<any>, permissions: string | string[]) => {
|
||||
return class extends React.Component<any, any> {
|
||||
shouldComponentUpdate (nextProps: Readonly<any>) {
|
||||
return !isEqual(nextProps, this.props);
|
||||
}
|
||||
|
||||
render () {
|
||||
return (
|
||||
<Can
|
||||
action={permissions}
|
||||
renderOnError={
|
||||
<ScreenBlock
|
||||
image={'/assets/svgs/server_error.svg'}
|
||||
title={'Access Denied'}
|
||||
message={'You do not have permission to access this page.'}
|
||||
/>
|
||||
}
|
||||
>
|
||||
<Component {...this.props}/>
|
||||
</Can>
|
||||
);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
export default requireServerPermission;
|
Reference in a new issue