Files
payloadcms/src/admin/components/views/Dashboard/index.tsx
Dan Ribbens 4913441017 Free and open-source under MIT license (#565)
* feat: free and open-source under MIT license
2022-05-16 19:25:20 -04:00

51 lines
1.3 KiB
TypeScript

import React, { useState, useEffect } from 'react';
import { useConfig } from '../../utilities/Config';
import { useAuth } from '../../utilities/Auth';
import { useStepNav } from '../../elements/StepNav';
import RenderCustomComponent from '../../utilities/RenderCustomComponent';
import DefaultDashboard from './Default';
const Dashboard: React.FC = () => {
const { permissions } = useAuth();
const { setStepNav } = useStepNav();
const [filteredGlobals, setFilteredGlobals] = useState([]);
const {
collections,
globals,
admin: {
components: {
views: {
Dashboard: CustomDashboard,
} = {
Dashboard: undefined,
},
} = {},
} = {},
} = useConfig();
useEffect(() => {
setFilteredGlobals(
globals.filter((global) => permissions?.globals?.[global.slug]?.read?.permission),
);
}, [permissions, globals]);
useEffect(() => {
setStepNav([]);
}, [setStepNav]);
return (
<RenderCustomComponent
DefaultComponent={DefaultDashboard}
CustomComponent={CustomDashboard}
componentProps={{
globals: filteredGlobals,
collections: collections.filter((collection) => permissions?.collections?.[collection.slug]?.read?.permission),
permissions,
}}
/>
);
};
export default Dashboard;