@@ -1,5 +1,8 @@
|
||||
import { useProcurementPreparationIdentity } from '@/hooks/use-procurement-preparation-identity';
|
||||
import { usePreparationDirty } from '@/hooks/use-preparation-dirty';
|
||||
import { hasPreparationChanges } from '@/lib/requisition-history';
|
||||
import { useEffect, useId, useState } from 'react';
|
||||
import { useForm } from '@inertiajs/react';
|
||||
import { router, useForm } from '@inertiajs/react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { FormErrors, controlClass } from '@/components/procurement';
|
||||
|
||||
@@ -218,25 +221,47 @@ export function AdministrativeLocation({
|
||||
);
|
||||
}
|
||||
|
||||
export function CompanyAdministrativeLocation({
|
||||
geography,
|
||||
}: {
|
||||
export function CompanyAdministrativeLocation(props: {
|
||||
geography: GeographyDescription;
|
||||
}) {
|
||||
const form = useForm({
|
||||
const identity = useProcurementPreparationIdentity(
|
||||
`company-location:${JSON.stringify(props.geography?.reference ?? null)}`,
|
||||
);
|
||||
return (
|
||||
<CompanyLocationFields key={identity} {...props} identity={identity} />
|
||||
);
|
||||
}
|
||||
function CompanyLocationFields({
|
||||
geography,
|
||||
identity,
|
||||
}: {
|
||||
identity: string;
|
||||
geography: GeographyDescription;
|
||||
}) {
|
||||
const initial = {
|
||||
geography_reference:
|
||||
geography?.reference ?? (null as GeographyReference | null),
|
||||
expected_reference: geography?.reference ?? null,
|
||||
});
|
||||
useEffect(() => {
|
||||
form.setData('expected_reference', geography?.reference ?? null);
|
||||
}, [geography]);
|
||||
};
|
||||
const form = useForm(identity, initial);
|
||||
const dirty = hasPreparationChanges(initial, form.data);
|
||||
const ref = usePreparationDirty(dirty);
|
||||
return (
|
||||
<form
|
||||
ref={ref}
|
||||
data-preparation-dirty={dirty ? 'true' : 'false'}
|
||||
className="space-y-4"
|
||||
onSubmit={(event) => {
|
||||
event.preventDefault();
|
||||
form.post('/empresa/localizacao', { preserveScroll: true });
|
||||
form.post('/empresa/localizacao', {
|
||||
preserveScroll: true,
|
||||
onSuccess: () => {
|
||||
form.setData(initial);
|
||||
form.clearErrors();
|
||||
router.remember(initial, `${identity}:data`);
|
||||
router.remember({}, `${identity}:errors`);
|
||||
},
|
||||
});
|
||||
}}
|
||||
>
|
||||
<FormErrors errors={form.errors} />
|
||||
|
||||
Reference in New Issue
Block a user