Edit agent name: save on Save Alterações
Update inline name editing to local state only; persist on Save Alterações button. Remove instant save behavior and inline confirm/cancel actions; simplify to editable input with local state updates and final save handled by existing SaveVersionDialog.
This commit is contained in:
+18
-39
@@ -5,7 +5,7 @@ import { Textarea } from "@/components/ui/textarea";
|
|||||||
import { Badge } from "@/components/ui/badge";
|
import { Badge } from "@/components/ui/badge";
|
||||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
|
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
|
||||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
||||||
import { ArrowLeft, Save, History, Power, Pencil, Check, X } from "lucide-react";
|
import { ArrowLeft, Save, History, Power, Pencil } from "lucide-react";
|
||||||
import { useToast } from "@/hooks/use-toast";
|
import { useToast } from "@/hooks/use-toast";
|
||||||
import { VersionHistoryDialog } from "@/components/agents/VersionHistoryDialog";
|
import { VersionHistoryDialog } from "@/components/agents/VersionHistoryDialog";
|
||||||
import { SaveVersionDialog } from "@/components/agents/SaveVersionDialog";
|
import { SaveVersionDialog } from "@/components/agents/SaveVersionDialog";
|
||||||
@@ -124,20 +124,13 @@ export default function AgentDetails() {
|
|||||||
setIsEditingName(true);
|
setIsEditingName(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSaveName = () => {
|
const handleNameBlur = () => {
|
||||||
if (tempName.trim()) {
|
if (tempName.trim()) {
|
||||||
setAgent({ ...agent, name: tempName.trim() });
|
setAgent({ ...agent, name: tempName.trim() });
|
||||||
setIsEditingName(false);
|
} else {
|
||||||
toast({
|
setTempName(agent.name);
|
||||||
title: "Nome atualizado",
|
|
||||||
description: "O nome do agente foi alterado com sucesso.",
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
const handleCancelEditName = () => {
|
|
||||||
setIsEditingName(false);
|
setIsEditingName(false);
|
||||||
setTempName("");
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -156,34 +149,20 @@ export default function AgentDetails() {
|
|||||||
<div className="flex flex-col md:flex-row md:items-center justify-between gap-4">
|
<div className="flex flex-col md:flex-row md:items-center justify-between gap-4">
|
||||||
<div className="flex items-center gap-3">
|
<div className="flex items-center gap-3">
|
||||||
{isEditingName ? (
|
{isEditingName ? (
|
||||||
<div className="flex items-center gap-2">
|
<Input
|
||||||
<Input
|
value={tempName}
|
||||||
value={tempName}
|
onChange={(e) => setTempName(e.target.value)}
|
||||||
onChange={(e) => setTempName(e.target.value)}
|
className="text-2xl md:text-3xl font-bold h-auto py-1"
|
||||||
className="text-2xl md:text-3xl font-bold h-auto py-1"
|
onBlur={handleNameBlur}
|
||||||
onKeyDown={(e) => {
|
onKeyDown={(e) => {
|
||||||
if (e.key === "Enter") handleSaveName();
|
if (e.key === "Enter") handleNameBlur();
|
||||||
if (e.key === "Escape") handleCancelEditName();
|
if (e.key === "Escape") {
|
||||||
}}
|
setTempName(agent.name);
|
||||||
autoFocus
|
setIsEditingName(false);
|
||||||
/>
|
}
|
||||||
<Button
|
}}
|
||||||
size="sm"
|
autoFocus
|
||||||
variant="ghost"
|
/>
|
||||||
className="h-8 w-8 p-0"
|
|
||||||
onClick={handleSaveName}
|
|
||||||
>
|
|
||||||
<Check className="h-4 w-4 text-green-600" />
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
size="sm"
|
|
||||||
variant="ghost"
|
|
||||||
className="h-8 w-8 p-0"
|
|
||||||
onClick={handleCancelEditName}
|
|
||||||
>
|
|
||||||
<X className="h-4 w-4" />
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
<h1 className="text-2xl md:text-3xl font-bold text-foreground">{agent.name}</h1>
|
<h1 className="text-2xl md:text-3xl font-bold text-foreground">{agent.name}</h1>
|
||||||
|
|||||||
Reference in New Issue
Block a user