@@ -3,7 +3,9 @@ import type {
|
||||
GeographyDescription,
|
||||
GeographyReference,
|
||||
} from '@/components/administrative-location';
|
||||
import { Head, Link, useForm } from '@inertiajs/react';
|
||||
import { Head, Link, useForm, usePage } from '@inertiajs/react';
|
||||
import type { ComponentProps } from 'react';
|
||||
import { usePreparationDirty } from '@/hooks/use-preparation-dirty';
|
||||
import {
|
||||
ActionBar,
|
||||
FormErrors,
|
||||
@@ -17,7 +19,7 @@ import { Label } from '@/components/ui/label';
|
||||
import { supplierFields } from '@/types/supplier';
|
||||
import type { Supplier } from '@/types/supplier';
|
||||
|
||||
export default function EditSupplier({
|
||||
function EditSupplierContent({
|
||||
supplier,
|
||||
geographyEnabled = false,
|
||||
geography = null,
|
||||
@@ -26,23 +28,29 @@ export default function EditSupplier({
|
||||
geographyEnabled?: boolean;
|
||||
geography?: GeographyDescription;
|
||||
}) {
|
||||
const form = useForm({
|
||||
geography_reference:
|
||||
supplier.geography_reference ?? (null as GeographyReference | null),
|
||||
name: supplier.name,
|
||||
nuit: supplier.nuit,
|
||||
contact: supplier.contact,
|
||||
email: supplier.email,
|
||||
phone: supplier.phone,
|
||||
address: supplier.address,
|
||||
category: supplier.category,
|
||||
beneficiaries: supplier.beneficiaries,
|
||||
document_references: supplier.document_references,
|
||||
diligence_notes: supplier.diligence_notes,
|
||||
next_review: supplier.next_review.slice(0, 10),
|
||||
blocked: supplier.blocked,
|
||||
version: supplier.version,
|
||||
});
|
||||
const actor = usePage().props.auth?.user;
|
||||
const form = useForm(
|
||||
`supplier-preparation:${actor?.tenant_id}:${actor?.id}:${supplier.id}:${supplier.version}`,
|
||||
{
|
||||
geography_reference:
|
||||
supplier.geography_reference ??
|
||||
(null as GeographyReference | null),
|
||||
name: supplier.name,
|
||||
nuit: supplier.nuit,
|
||||
contact: supplier.contact,
|
||||
email: supplier.email,
|
||||
phone: supplier.phone,
|
||||
address: supplier.address,
|
||||
category: supplier.category,
|
||||
beneficiaries: supplier.beneficiaries,
|
||||
document_references: supplier.document_references,
|
||||
diligence_notes: supplier.diligence_notes,
|
||||
next_review: supplier.next_review.slice(0, 10),
|
||||
blocked: supplier.blocked,
|
||||
version: supplier.version,
|
||||
},
|
||||
);
|
||||
const preparationRef = usePreparationDirty(form.isDirty);
|
||||
return (
|
||||
<>
|
||||
<Head title={`Editar ${supplier.name}`} />
|
||||
@@ -59,6 +67,7 @@ export default function EditSupplier({
|
||||
elegível para novas cotações.
|
||||
</p>
|
||||
<form
|
||||
ref={preparationRef}
|
||||
className="space-y-5"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
@@ -162,6 +171,17 @@ export default function EditSupplier({
|
||||
</>
|
||||
);
|
||||
}
|
||||
export default function EditSupplier(
|
||||
props: ComponentProps<typeof EditSupplierContent>,
|
||||
) {
|
||||
const actor = usePage().props.auth?.user;
|
||||
return (
|
||||
<EditSupplierContent
|
||||
key={`${actor?.tenant_id}:${actor?.id}:${props.supplier.id}:${props.supplier.version}`}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
EditSupplier.layout = {
|
||||
breadcrumbs: [
|
||||
{ title: 'Fornecedores', href: '/fornecedores' },
|
||||
|
||||
Reference in New Issue
Block a user