commit13
This commit is contained in:
@@ -30,6 +30,8 @@ import {
|
||||
procurementNavigation,
|
||||
} from '@/lib/procurement-navigation';
|
||||
import { roleLabels } from '@/types/procurement';
|
||||
import type { WorkContextState } from '@/types/work-context';
|
||||
import { WorkContextChange } from '@/components/work-context-change';
|
||||
|
||||
export function SgcWorkspaceShell({ children }: { children: ReactNode }) {
|
||||
const page = usePage();
|
||||
@@ -44,11 +46,31 @@ export function SgcWorkspaceShell({ children }: { children: ReactNode }) {
|
||||
active: boolean;
|
||||
permissions: string[];
|
||||
} | null;
|
||||
const context = page.props.workContext as WorkContextState | null;
|
||||
const scopedEntries = new Set(
|
||||
procurementNavigation(
|
||||
context?.permissions ?? [],
|
||||
page.props.payablesAvailable === true,
|
||||
).flatMap((group) => group.entries.map((entry) => entry.id)),
|
||||
);
|
||||
const groups = procurementNavigation(
|
||||
access?.active ? access.permissions : (user?.purchasing_role ?? ''),
|
||||
page.props.payablesAvailable === true,
|
||||
publicNavigation?.paths,
|
||||
);
|
||||
)
|
||||
.map((group) => ({
|
||||
...group,
|
||||
entries: group.entries.filter(
|
||||
(entry) =>
|
||||
!context?.enforced ||
|
||||
(context.paths.includes(entry.path.split('?')[0]) &&
|
||||
(context.sharedPaths.includes(
|
||||
entry.path.split('?')[0],
|
||||
) ||
|
||||
scopedEntries.has(entry.id))),
|
||||
),
|
||||
}))
|
||||
.filter((group) => group.entries.length);
|
||||
const activeId = activeProcurementEntry(groups, page.url);
|
||||
const activeGroup = groups.find((group) =>
|
||||
group.entries.some((entry) => entry.id === activeId),
|
||||
@@ -278,6 +300,20 @@ export function SgcWorkspaceShell({ children }: { children: ReactNode }) {
|
||||
);
|
||||
return (
|
||||
<div className="min-h-screen bg-slate-50 text-foreground dark:bg-background print:block">
|
||||
{context?.enforced && <WorkContextChange />}
|
||||
{context?.enforced && (
|
||||
<div
|
||||
className="border-b bg-background px-5 py-2 text-sm"
|
||||
role="status"
|
||||
>
|
||||
{context.active
|
||||
? `${context.options[context.active].areaLabel} · ${context.options[context.active].label}`
|
||||
: 'Sem contexto seleccionado'}{' '}
|
||||
<Link className="ml-3 underline" href="/dashboard">
|
||||
Mudar contexto
|
||||
</Link>
|
||||
</div>
|
||||
)}
|
||||
{publicNavigation && (
|
||||
<p className="border-b bg-background p-3 text-center text-sm">
|
||||
Consulta pública de desenvolvimento · Sem organização
|
||||
|
||||
Reference in New Issue
Block a user