@@ -1,18 +1,34 @@
|
||||
import { useForm } from '@inertiajs/react';
|
||||
import { router, useForm } from '@inertiajs/react';
|
||||
import { useProcurementPreparationIdentity } from '@/hooks/use-procurement-preparation-identity';
|
||||
import { usePreparationDirty } from '@/hooks/use-preparation-dirty';
|
||||
import { hasPreparationChanges } from '@/lib/requisition-history';
|
||||
import { FormErrors, Panel, controlClass } from '@/components/procurement';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import type { WorkContextState } from '@/types/work-context';
|
||||
|
||||
export function WorkContextSettings({
|
||||
export function WorkContextSettings(
|
||||
props: Omit<Parameters<typeof WorkContextFields>[0], 'identity'>,
|
||||
) {
|
||||
const identity = useProcurementPreparationIdentity(
|
||||
`work-contexts:${props.version}:${[...props.context.purchased].sort().join(',')}`,
|
||||
);
|
||||
return <WorkContextFields key={identity} {...props} identity={identity} />;
|
||||
}
|
||||
function WorkContextFields({
|
||||
context,
|
||||
enabled,
|
||||
version,
|
||||
identity,
|
||||
}: {
|
||||
identity: string;
|
||||
context: WorkContextState;
|
||||
enabled: string[];
|
||||
version: number;
|
||||
}) {
|
||||
const form = useForm({ version, enabled, reason: '', confirm: false });
|
||||
const initial = { version, enabled, reason: '', confirm: false };
|
||||
const form = useForm(identity, initial);
|
||||
const dirty = hasPreparationChanges(initial, form.data);
|
||||
const ref = usePreparationDirty(dirty);
|
||||
return (
|
||||
<Panel title="Áreas e opções do produto">
|
||||
<p className="mb-4 text-sm">
|
||||
@@ -29,11 +45,19 @@ export function WorkContextSettings({
|
||||
</p>
|
||||
)}
|
||||
<form
|
||||
ref={ref}
|
||||
data-preparation-dirty={dirty ? 'true' : 'false'}
|
||||
className="space-y-4"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
form.post('/administracao/parametrizacao/work_contexts', {
|
||||
preserveState: 'errors',
|
||||
preserveState: true,
|
||||
onSuccess: () => {
|
||||
form.setData(initial);
|
||||
form.clearErrors();
|
||||
router.remember(initial, `${identity}:data`);
|
||||
router.remember({}, `${identity}:errors`);
|
||||
},
|
||||
});
|
||||
}}
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user