misc_pterodactyl-panel/resources/scripts/hoc/requireServerPermission.tsx

32 lines
1 KiB
TypeScript
Raw Normal View History

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.'}
/>
}
>
2020-08-23 22:55:10 +00:00
<Component {...this.props}/>
</Can>
);
}
};
};
export default requireServerPermission;