mirror of
https://github.com/vale981/Vulcan
synced 2025-03-05 09:31:43 -05:00
create AdminLayout in vulcan:admin
This commit is contained in:
parent
be42d6740f
commit
1da5d5d4f2
3 changed files with 46 additions and 1 deletions
44
packages/vulcan-admin/lib/components/AdminLayout.jsx
Normal file
44
packages/vulcan-admin/lib/components/AdminLayout.jsx
Normal file
|
@ -0,0 +1,44 @@
|
|||
/**
|
||||
* @Author: Apollinaire Lecocq <apollinaire>
|
||||
* @Date: 08-01-19
|
||||
* @Last modified by: apollinaire
|
||||
* @Last modified time: 08-01-19
|
||||
*/
|
||||
import React from 'react';
|
||||
import {
|
||||
registerComponent,
|
||||
Components,
|
||||
withCurrentUser,
|
||||
} from 'meteor/vulcan:core';
|
||||
|
||||
/**
|
||||
* A simple component that renders the existing layout and checks wether the currentUser is an admin or not.
|
||||
*/
|
||||
|
||||
class AdminLayout extends React.PureComponent {
|
||||
renderWithRestrictedAccess(children, currentUser) {
|
||||
// while the currentUser is loading, don't render anything.
|
||||
if (currentUser && currentUser.loading) {
|
||||
return null;
|
||||
} //if the currentUser is an admin, then render the children
|
||||
else if (currentUser && currentUser.isAdmin) {
|
||||
return children;
|
||||
} // for every other case (just a member or not logged), render the 404 message
|
||||
return <Components.Error404 />;
|
||||
}
|
||||
|
||||
render() {
|
||||
const {currentUser, children} = this.props;
|
||||
return (
|
||||
<Components.Layout>
|
||||
{this.renderWithRestrictedAccess(children, currentUser)}
|
||||
</Components.Layout>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
registerComponent({
|
||||
name: 'AdminLayout',
|
||||
component: AdminLayout,
|
||||
hocs: [withCurrentUser],
|
||||
});
|
|
@ -1,3 +1,4 @@
|
|||
import './fragments.js';
|
||||
import './routes.js';
|
||||
import './i18n.js';
|
||||
import '../components/AdminLayout';
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { addRoute, getDynamicComponent } from 'meteor/vulcan:core';
|
||||
import React from 'react';
|
||||
|
||||
addRoute({ name: 'admin', path: '/admin', component: () => getDynamicComponent(import('../components/AdminHome.jsx'))});
|
||||
addRoute({ name: 'admin', path: '/admin', component: () => getDynamicComponent(import('../components/AdminHome.jsx')), layoutName: 'AdminLayout'});
|
||||
addRoute({ name: 'admin2', path: '/admin/users', component: () => getDynamicComponent(import('../components/AdminHome.jsx'))});
|
||||
|
|
Loading…
Add table
Reference in a new issue