fix: ensure active assistant is updated correctly on deletion (#3588)
- Modified the assistant deletion logic to check if the deleted assistant is the currently active one before updating the active assistant state. This prevents potential issues when the active assistant is removed.
This commit is contained in:
parent
9ca46ee3d3
commit
b89213b1ab
@ -31,11 +31,13 @@ const Assistants: FC<AssistantsTabProps> = ({
|
||||
const onDelete = useCallback(
|
||||
(assistant: Assistant) => {
|
||||
const remaining = assistants.filter((a) => a.id !== assistant.id)
|
||||
const newActive = remaining[remaining.length - 1]
|
||||
newActive ? setActiveAssistant(newActive) : onCreateDefaultAssistant()
|
||||
if (assistant.id === activeAssistant?.id) {
|
||||
const newActive = remaining[remaining.length - 1]
|
||||
newActive ? setActiveAssistant(newActive) : onCreateDefaultAssistant()
|
||||
}
|
||||
removeAssistant(assistant.id)
|
||||
},
|
||||
[assistants, removeAssistant, setActiveAssistant, onCreateDefaultAssistant]
|
||||
[activeAssistant, assistants, removeAssistant, setActiveAssistant, onCreateDefaultAssistant]
|
||||
)
|
||||
|
||||
return (
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user