commit compras1 2811
tests / ci (push) Waiting to run

This commit is contained in:
2026-11-28 07:11:35 +02:00
parent d58b75c87a
commit eb32c74c56
202 changed files with 17463 additions and 1526 deletions
@@ -0,0 +1,10 @@
import { usePage } from '@inertiajs/react';
import type { WorkContextState } from '@/types/work-context';
export function useBudgetPreparationIdentity() {
const { auth, workContext, organizationAccess } = usePage().props;
const context = workContext as WorkContextState | null | undefined;
const access = organizationAccess as { permissions?: string[] } | null;
const permissions = [...(access?.permissions ?? [])].sort().join(',');
return `budgets:${auth.user?.tenant_id}:${auth.user?.id}:${context?.active ?? 'legacy'}:${permissions}`;
}
@@ -0,0 +1,9 @@
import { usePage } from '@inertiajs/react';
import type { WorkContextState } from '@/types/work-context';
export function useConflictPreparationIdentity() {
const { auth, workContext, organizationAccess } = usePage().props;
const context = workContext as WorkContextState | null | undefined;
const access = organizationAccess as { permissions?: string[] } | null;
return `conflicts:${auth.user?.tenant_id}:${auth.user?.id}:${context?.active ?? 'legacy'}:${[...(access?.permissions ?? [])].sort().join(',')}`;
}
@@ -0,0 +1,9 @@
import { usePage } from '@inertiajs/react';
import type { WorkContextState } from '@/types/work-context';
export function useInventoryPreparationIdentity(scope: string) {
const { auth, workContext, actorId } = usePage().props;
const context = workContext as WorkContextState | null | undefined;
const actor = typeof actorId === 'number' ? actorId : auth.user?.id;
return `inventory-events:${auth.user?.tenant_id}:${actor}:${context?.active ?? 'legacy'}:${scope}`;
}
@@ -0,0 +1,26 @@
import { useEffect, useRef } from 'react';
import { markPreparationDirty } from '@/lib/preparation-forms';
/** Publish preparation state to the existing context/departure guard; never save business data. */
export function usePreparationDirty(dirty: boolean, visible = true) {
const ref = useRef<HTMLFormElement>(null);
useEffect(() => {
const form = ref.current;
if (!form) return;
markPreparationDirty(form, visible && dirty);
window.dispatchEvent(
new CustomEvent('sgc:context-dirty', {
detail: { form, dirty: visible && dirty },
}),
);
return () => {
markPreparationDirty(form, false);
window.dispatchEvent(
new CustomEvent('sgc:context-dirty', {
detail: { form, dirty: false },
}),
);
};
}, [dirty, visible]);
return ref;
}
@@ -0,0 +1,9 @@
import { usePage } from '@inertiajs/react';
import type { WorkContextState } from '@/types/work-context';
export function useProcurementPreparationIdentity(scope: string) {
const { auth, workContext, organizationAccess } = usePage().props;
const context = workContext as WorkContextState | null | undefined;
const access = organizationAccess as { permissions?: string[] } | null;
return `procurement-preparations:${auth?.user?.tenant_id}:${auth?.user?.id}:${context?.active ?? 'legacy'}:${[...(access?.permissions ?? [])].sort().join(',')}:${scope}`;
}