Atalho Nova requisição só no contexto de Compras, como o menu
This commit is contained in:
@@ -36,6 +36,7 @@ import type {
|
||||
import { roleLabels } from '@/types/procurement';
|
||||
import type { WorkContextState } from '@/types/work-context';
|
||||
import { WorkContextChange } from '@/components/work-context-change';
|
||||
import { contextOffersPath } from '@/lib/work-context-paths';
|
||||
import { ProcurementMenuResults } from '@/components/procurement-menu-results';
|
||||
import {
|
||||
matchesMenuSearch,
|
||||
@@ -559,18 +560,22 @@ export function SgcWorkspaceShell({ children }: { children: ReactNode }) {
|
||||
<Link href="/login">Entrar</Link>
|
||||
</Button>
|
||||
)}
|
||||
{page.props.canRequest === true && (
|
||||
<Button
|
||||
asChild
|
||||
size="sm"
|
||||
className="hidden bg-[#ed1c24] text-white hover:bg-[#d01720] sm:inline-flex"
|
||||
>
|
||||
<Link href="/requisicoes/criar">
|
||||
<Plus className="size-4" />
|
||||
Nova requisição
|
||||
</Link>
|
||||
</Button>
|
||||
)}
|
||||
{page.props.canRequest === true &&
|
||||
contextOffersPath(
|
||||
context,
|
||||
'/requisicoes/criar',
|
||||
) && (
|
||||
<Button
|
||||
asChild
|
||||
size="sm"
|
||||
className="hidden bg-[#ed1c24] text-white hover:bg-[#d01720] sm:inline-flex"
|
||||
>
|
||||
<Link href="/requisicoes/criar">
|
||||
<Plus className="size-4" />
|
||||
Nova requisição
|
||||
</Link>
|
||||
</Button>
|
||||
)}
|
||||
{user && (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
import type { WorkContextState } from '@/types/work-context';
|
||||
|
||||
/**
|
||||
* Indica se um atalho para `path` deve aparecer no contexto de trabalho actual.
|
||||
* Segue a mesma regra do menu: com contextos activos, só aparecem os caminhos do contexto
|
||||
* escolhido. Não decide permissões: o servidor continua a autorizar cada pedido.
|
||||
*/
|
||||
export function contextOffersPath(
|
||||
context: WorkContextState | null | undefined,
|
||||
path: string,
|
||||
): boolean {
|
||||
if (!context?.enforced) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return context.paths.includes(path.split('?')[0]);
|
||||
}
|
||||
@@ -9,8 +9,10 @@ import {
|
||||
} from 'lucide-react';
|
||||
import { PageTitle, Panel, RequisitionTable } from '@/components/procurement';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { contextOffersPath } from '@/lib/work-context-paths';
|
||||
import { money } from '@/types/procurement';
|
||||
import type { Company, Requisition } from '@/types/procurement';
|
||||
import type { WorkContextState } from '@/types/work-context';
|
||||
|
||||
type Props = {
|
||||
company: Company | null;
|
||||
@@ -30,8 +32,14 @@ export default function Dashboard({
|
||||
recent,
|
||||
approvals,
|
||||
}: Props) {
|
||||
const canRequest = usePage().props.canRequest === true;
|
||||
const publicNavigation = !!usePage().props.publicNavigation;
|
||||
const { props } = usePage();
|
||||
const canRequest =
|
||||
props.canRequest === true &&
|
||||
contextOffersPath(
|
||||
props.workContext as WorkContextState | null | undefined,
|
||||
'/requisicoes/criar',
|
||||
);
|
||||
const publicNavigation = !!props.publicNavigation;
|
||||
const cards = [
|
||||
{
|
||||
label: 'Requisições',
|
||||
|
||||
Reference in New Issue
Block a user