67 lines
2.5 KiB
TypeScript
67 lines
2.5 KiB
TypeScript
import { Link, usePage } from '@inertiajs/react';
|
|
import type { ProfileAccess } from '@/types/profile-access';
|
|
|
|
export function profileLinks(access: ProfileAccess | null | undefined) {
|
|
if (!access) return [];
|
|
return [
|
|
...(access.mine
|
|
? [{ title: 'Minhas oportunidades', href: access.mine }]
|
|
: []),
|
|
...(access.create
|
|
? [{ title: 'Nova oportunidade', href: access.create }]
|
|
: []),
|
|
{
|
|
title: access.mine
|
|
? 'Autorizações de Promotor'
|
|
: 'Solicitar perfil de Promotor',
|
|
href: access.request,
|
|
},
|
|
...(!access.mine && access.review
|
|
? [{ title: 'Revisão de oportunidades', href: access.review }]
|
|
: []),
|
|
...(access.audit
|
|
? [{ title: 'Auditoria de acessos', href: access.audit }]
|
|
: []),
|
|
...(access.administration
|
|
? [{ title: 'Gestão de perfis', href: access.administration }]
|
|
: []),
|
|
...(access.administration
|
|
? [
|
|
{
|
|
title: 'Configuração dos perfis',
|
|
href: '/management/profile-install',
|
|
},
|
|
]
|
|
: []),
|
|
];
|
|
}
|
|
|
|
export default function ProfileNavigation() {
|
|
const { profileAccess } = usePage<{
|
|
profileAccess?: ProfileAccess | null;
|
|
}>().props;
|
|
if (!profileAccess) return null;
|
|
const links = profileLinks(profileAccess);
|
|
const workHrefs = [profileAccess.mine, profileAccess.create, profileAccess.review].filter(Boolean);
|
|
const work = links.filter((link) => workHrefs.includes(link.href));
|
|
const access = links.filter((link) => !workHrefs.includes(link.href));
|
|
return (
|
|
<nav
|
|
aria-label="Perfil e oportunidades"
|
|
className="flex flex-wrap gap-4 rounded border p-4"
|
|
>
|
|
{work.map((link) => (
|
|
<Link key={link.href} href={link.href} className="underline">
|
|
{link.title}
|
|
</Link>
|
|
))}
|
|
{access.length > 0 && <details className="basis-full">
|
|
<summary className="cursor-pointer font-medium">O meu acesso e administração</summary>
|
|
<div className="mt-3 flex flex-wrap gap-4">{access.map((link) =>
|
|
<Link key={link.href} href={link.href} className="underline">{link.title}</Link>
|
|
)}</div>
|
|
</details>}
|
|
</nav>
|
|
);
|
|
}
|