import React, { useState, useEffect } from 'react'; import { ToastContainer, toast } from 'react-toastify' import ResponsiveNavLink from '@/Components/ResponsiveNavLink'; import NavItem from '@/Components/NavItem'; import NavDropdown from '@/Components/NavDropdown'; import { ArrowDownIcon } from '@/Components/Icons'; import { hasPermission } from '@/utils'; const rs = [ {name: "Dashboard", route: "dashboard", show: true}, {name: "Dokumen", show: true, items: [ {name: "Dokumen", route: 'docs.index', show: true, permission: 'view-document'}, {name: "Ketegori", route: 'categories.index', show: true, permission: 'view-category'}, {name: "Klasifikasi", route: 'classifications.index', show: true, permission: 'view-classification'}, {name: "Jenis", route: 'types.index', show: true, permission: 'view-type'}, ]}, {name: "Perusahaan", show: true, items: [ {name:"Group", route: "groups.index", show: true, permission: 'view-group'}, {name:"Region", route: "regions.index", show: true, permission: 'view-region'}, {name:"Perusahaan", route: "companies.index", show: true, permission: 'view-company'}, ]}, {name: "User", show: true, items: [ {name:"User", route: "users.index", show: true, permission: 'view-user'}, {name:"Role", route: "roles.index", show: true, permission: 'view-role'}, ]}, {name: "Setting", route: "setting.index", show: true, permission: 'view-setting'}, ] export default function Authenticated({ auth, children, flash, notify }) { const [showingNavigationDropdown, setShowingNavigationDropdown] = useState(false); const routes = rs.map(r => { if ('permission' in r ) { r.show = hasPermission(r.permission, auth.user) } if('items' in r) { r.items = r.items.map(ri => { ri.show = hasPermission(ri.permission, auth.user) return ri }) if (r.items.filter(r => r.show).length <= 0) { r.show = false } else { r.show = true } } return r }) useEffect(() => { if (flash.message !== null) { toast(flash.message.message, {type: flash.message.type}) } }, [flash]) return (
{children}
); }