@@ -1,4 +1,7 @@
|
||||
import { 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 { router, useForm } from '@inertiajs/react';
|
||||
import { Panel, FormErrors, controlClass } from '@/components/procurement';
|
||||
import { Button } from '@/components/ui/button';
|
||||
|
||||
@@ -14,20 +17,30 @@ export type AiPlan = {
|
||||
max_output_tokens: number;
|
||||
};
|
||||
|
||||
export function AiPlanSettings({
|
||||
export function AiPlanSettings(
|
||||
props: Omit<Parameters<typeof AiPlanFields>[0], 'identity'>,
|
||||
) {
|
||||
const identity = useProcurementPreparationIdentity(
|
||||
`ai-plan:${props.version}:${props.ready}`,
|
||||
);
|
||||
return <AiPlanFields key={identity} {...props} identity={identity} />;
|
||||
}
|
||||
function AiPlanFields({
|
||||
plan,
|
||||
domains,
|
||||
scopes,
|
||||
version,
|
||||
ready,
|
||||
identity,
|
||||
}: {
|
||||
identity: string;
|
||||
plan: AiPlan;
|
||||
domains: Record<string, string>;
|
||||
scopes: Record<string, string>;
|
||||
version: number;
|
||||
ready: boolean;
|
||||
}) {
|
||||
const form = useForm({
|
||||
const initial = {
|
||||
version,
|
||||
provider: plan.provider,
|
||||
model: plan.model,
|
||||
@@ -38,7 +51,16 @@ export function AiPlanSettings({
|
||||
max_input_bytes: plan.max_input_bytes,
|
||||
max_output_tokens: plan.max_output_tokens,
|
||||
reason: '',
|
||||
});
|
||||
};
|
||||
const form = useForm(identity, initial);
|
||||
const dirty = hasPreparationChanges(initial, form.data);
|
||||
const ref = usePreparationDirty(dirty);
|
||||
const clearPreparation = () => {
|
||||
form.setData(initial);
|
||||
form.clearErrors();
|
||||
router.remember(initial, `${identity}:data`);
|
||||
router.remember({}, `${identity}:errors`);
|
||||
};
|
||||
function choices(
|
||||
field: 'domains' | 'data_scopes',
|
||||
labels: Record<string, string>,
|
||||
@@ -76,10 +98,13 @@ export function AiPlanSettings({
|
||||
<p>Instalação da configuração pendente.</p>
|
||||
) : (
|
||||
<form
|
||||
ref={ref}
|
||||
data-preparation-dirty={dirty ? 'true' : 'false'}
|
||||
className="space-y-4"
|
||||
onSubmit={(event) => {
|
||||
event.preventDefault();
|
||||
form.post('/administracao/parametrizacao/ai_plan', {
|
||||
onSuccess: clearPreparation,
|
||||
preserveScroll: true,
|
||||
});
|
||||
}}
|
||||
|
||||
Reference in New Issue
Block a user