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
@@ -1,5 +1,5 @@
import { Head, Link, useForm, usePage } from '@inertiajs/react';
import { useEffect, useRef } from 'react';
import { usePreparationDirty } from '@/hooks/use-preparation-dirty';
import { hasPreparationChanges } from '@/lib/requisition-history';
import BudgetDistributionFields, {
type BudgetDistributionOption,
@@ -13,7 +13,7 @@ import {
import { Button } from '@/components/ui/button';
import { money } from '@/types/procurement';
export default function Amendment({
function AmendmentContent({
order,
options,
planHash,
@@ -58,15 +58,8 @@ export default function Amendment({
`distribution-amendment:${actor?.tenant_id}:${actor?.id}:${order.id}:${planHash}`,
initial,
);
const formElement = useRef<HTMLFormElement>(null);
const dirty = hasPreparationChanges(initial, form.data);
useEffect(() => {
window.dispatchEvent(
new CustomEvent('sgc:context-dirty', {
detail: { form: formElement.current, dirty },
}),
);
}, [dirty]);
const formElement = usePreparationDirty(dirty);
return (
<>
<Head title={`Reafectação · ${order.number}`} />
@@ -85,6 +78,7 @@ export default function Amendment({
<FormErrors errors={form.errors} />
<form
ref={formElement}
data-preparation-dirty={dirty ? 'true' : 'false'}
className="space-y-5"
onSubmit={(event) => {
event.preventDefault();
@@ -142,3 +136,15 @@ export default function Amendment({
</>
);
}
export default function Amendment(
props: Parameters<typeof AmendmentContent>[0],
) {
const actor = usePage().props.auth?.user;
return (
<AmendmentContent
key={`distribution-amendment:${actor?.tenant_id}:${actor?.id}:${props.order.id}:${props.planHash}`}
{...props}
/>
);
}
@@ -1,5 +1,6 @@
import { Head, Link, useForm, usePage } from '@inertiajs/react';
import { useEffect, useRef } from 'react';
import { usePreparationDirty } from '@/hooks/use-preparation-dirty';
import { hasPreparationChanges } from '@/lib/requisition-history';
import { FormErrors, PageTitle, Panel } from '@/components/procurement';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
@@ -18,7 +19,7 @@ type Source = {
}[];
};
export default function Amendment({
function AmendmentContent({
order,
sources,
history,
@@ -41,41 +42,28 @@ export default function Amendment({
}[];
}) {
const actor = usePage().props.auth?.user;
const initial = {
operation_key: crypto.randomUUID(),
reason: '',
sources: sources.map((source) => ({
origin: source.origin,
version: source.version,
plan_hash: source.plan_hash,
allocations: source.allocations.map(
({ allocation_key, subtotal, total }) => ({
allocation_key,
subtotal,
total,
}),
),
})),
};
const form = useForm(
`order-parts-amendment:${actor?.tenant_id}:${actor?.id}:${order.id}:${sources.map((s) => `${s.origin}:${s.version}:${s.plan_hash}`).join(',')}`,
{
operation_key: crypto.randomUUID(),
reason: '',
sources: sources.map((source) => ({
origin: source.origin,
version: source.version,
plan_hash: source.plan_hash,
allocations: source.allocations.map(
({ allocation_key, subtotal, total }) => ({
allocation_key,
subtotal,
total,
}),
),
})),
},
initial,
);
const ref = useRef<HTMLFormElement>(null);
useEffect(() => {
const current = ref.current;
window.dispatchEvent(
new CustomEvent('sgc:context-dirty', {
detail: { form: current, dirty: form.isDirty },
}),
);
return () => {
window.dispatchEvent(
new CustomEvent('sgc:context-dirty', {
detail: { form: current, dirty: false },
}),
);
};
}, [form.isDirty]);
const dirty = hasPreparationChanges(initial, form.data);
const ref = usePreparationDirty(dirty);
const update = (
origin: number,
allocation: number,
@@ -115,6 +103,7 @@ export default function Amendment({
</p>
<form
ref={ref}
data-preparation-dirty={dirty ? 'true' : 'false'}
className="grid gap-4"
onSubmit={(event) => {
event.preventDefault();
@@ -261,3 +250,11 @@ export default function Amendment({
</>
);
}
export default function Amendment(
props: Parameters<typeof AmendmentContent>[0],
) {
const actor = usePage().props.auth?.user;
const identity = `order-parts-amendment:${actor?.tenant_id}:${actor?.id}:${props.order.id}:${props.sources.map((source) => `${source.origin}:${source.version}:${source.plan_hash}`).join(',')}`;
return <AmendmentContent key={identity} {...props} />;
}
+18 -22
View File
@@ -1,5 +1,6 @@
import { Head, Link, useForm, usePage } from '@inertiajs/react';
import { useEffect, useRef, type RefObject } from 'react';
import { useEffect } from 'react';
import { usePreparationDirty } from '@/hooks/use-preparation-dirty';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
import { FormErrors, PageTitle, Panel } from '@/components/procurement';
@@ -79,22 +80,6 @@ type Props = {
preview: Preview | null;
};
function useGuard(ref: RefObject<HTMLFormElement | null>, dirty: boolean) {
useEffect(() => {
const form = ref.current;
window.dispatchEvent(
new CustomEvent('sgc:context-dirty', { detail: { form, dirty } }),
);
return () => {
window.dispatchEvent(
new CustomEvent('sgc:context-dirty', {
detail: { form, dirty: false },
}),
);
};
}, [dirty, ref]);
}
function Adoption({
source,
currency,
@@ -226,7 +211,6 @@ function Prepared({
})),
};
const form = useForm(historyKey, initial);
const ref = useRef<HTMLFormElement>(null);
const changed = form.data.budget_sources.some((source, i) =>
source.allocations.some(
(row, j) =>
@@ -235,7 +219,7 @@ function Prepared({
row.total !== initial.budget_sources[i]?.allocations[j]?.total,
),
);
useGuard(ref, changed);
const ref = usePreparationDirty(changed);
return (
<div id="order-parts-review" tabIndex={-1} className="scroll-mt-24">
<Panel title="Conferir e emitir a ordem">
@@ -247,6 +231,7 @@ function Prepared({
</p>
<form
ref={ref}
data-preparation-dirty={changed ? 'true' : 'false'}
className="grid min-w-0 gap-5"
onSubmit={(event) => {
event.preventDefault();
@@ -489,14 +474,14 @@ function Prepared({
);
}
export default function Parts({ candidates, preview }: Props) {
function PartsContent({ candidates, preview }: Props) {
const actor = usePage().props.auth?.user;
const historyKey = `order-parts:${actor?.tenant_id}:${actor?.id}`;
const form = useForm<{ sources: Selection[] }>(`${historyKey}:selection`, {
sources: [],
});
const ref = useRef<HTMLFormElement>(null);
useGuard(ref, form.data.sources.length > 0);
const dirty = form.data.sources.length > 0;
const ref = usePreparationDirty(dirty);
useEffect(() => {
if (preview) {
const review = document.getElementById('order-parts-review');
@@ -520,6 +505,7 @@ export default function Parts({ candidates, preview }: Props) {
<Panel title="Escolher origens e quantidades">
<form
ref={ref}
data-preparation-dirty={dirty ? 'true' : 'false'}
className="grid min-w-0 gap-4"
onSubmit={(event) => {
event.preventDefault();
@@ -739,3 +725,13 @@ export default function Parts({ candidates, preview }: Props) {
</>
);
}
export default function Parts(props: Props) {
const actor = usePage().props.auth?.user;
return (
<PartsContent
key={`order-parts:${actor?.tenant_id}:${actor?.id}`}
{...props}
/>
);
}
+4
View File
@@ -10,6 +10,7 @@ import { ExchangeSummary } from '@/components/quotation-exchange-panel';
import type { PurchaseOrder } from '@/types/purchase';
import ImportTariffSummary from '@/components/import-tariff-summary';
import CapitalAssignmentSummary from '@/components/capital-assignment-summary';
import RequisitionAccountSummary from '@/components/requisition-account-summary';
import OrderCancellationRequest, {
type OrderCancellationState,
} from '@/components/order-cancellation-request';
@@ -175,6 +176,9 @@ export default function OrderShow({
<CapitalAssignmentSummary
records={snapshot.capital_assignments}
/>
<RequisitionAccountSummary
records={snapshot.account_assignments}
/>
<div className="grid gap-6 md:grid-cols-2">
{snapshot.investment_rules && (
<Panel title="Regra de investimento congelada">