@@ -1,4 +1,9 @@
|
||||
import { Head, Link, useForm } from '@inertiajs/react';
|
||||
import { Head, Link, useForm, usePage } from '@inertiajs/react';
|
||||
import { usePreparationDirty } from '@/hooks/use-preparation-dirty';
|
||||
import {
|
||||
receiptPreparationKey,
|
||||
receiptPreparationChanged,
|
||||
} from '@/lib/receipt-preparation';
|
||||
import { ReceiptConversionFields } from '@/components/receipt-conversion';
|
||||
import type { ReceiptConversion } from '@/components/receipt-conversion';
|
||||
import { InventoryNotice, ReceiptProgressTable } from '@/components/inventory';
|
||||
@@ -50,7 +55,7 @@ type Props = {
|
||||
quarantine_on_receipt: boolean;
|
||||
}[];
|
||||
};
|
||||
export default function ReceiveOrder({
|
||||
function ReceiveOrderContent({
|
||||
order,
|
||||
supplier_name,
|
||||
progress,
|
||||
@@ -61,7 +66,14 @@ export default function ReceiveOrder({
|
||||
conversionQaEnabled = false,
|
||||
lotScopes,
|
||||
}: Props) {
|
||||
const form = useForm({
|
||||
const actor = usePage().props.auth?.user;
|
||||
const historyKey = receiptPreparationKey(
|
||||
actor?.tenant_id,
|
||||
actor?.id,
|
||||
order.id,
|
||||
progress,
|
||||
);
|
||||
const initialData = {
|
||||
idempotency_key: crypto.randomUUID(),
|
||||
delivery_note: '',
|
||||
received_on: '',
|
||||
@@ -82,7 +94,12 @@ export default function ReceiveOrder({
|
||||
},
|
||||
lots: [] as Line['lots'],
|
||||
})),
|
||||
});
|
||||
};
|
||||
const form = useForm(historyKey, initialData);
|
||||
const preparationRef = usePreparationDirty(
|
||||
receiptPreparationChanged(initialData, form.data),
|
||||
canConfirm,
|
||||
);
|
||||
const change = (index: number, updates: Partial<Line>) =>
|
||||
form.setData(
|
||||
'items',
|
||||
@@ -117,6 +134,7 @@ export default function ReceiveOrder({
|
||||
description="A confirmação é definitiva e auditada. O emitente da ordem não pode confirmar a recepção."
|
||||
>
|
||||
<form
|
||||
ref={preparationRef}
|
||||
className="space-y-5"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
@@ -899,6 +917,20 @@ export default function ReceiveOrder({
|
||||
</>
|
||||
);
|
||||
}
|
||||
export default function ReceiveOrder(props: Props) {
|
||||
const actor = usePage().props.auth?.user;
|
||||
return (
|
||||
<ReceiveOrderContent
|
||||
key={receiptPreparationKey(
|
||||
actor?.tenant_id,
|
||||
actor?.id,
|
||||
props.order.id,
|
||||
props.progress,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
ReceiveOrder.layout = {
|
||||
breadcrumbs: [
|
||||
{ title: 'Recepção', href: '/recepcoes' },
|
||||
|
||||
Reference in New Issue
Block a user