From 5d8b32a2497de43043261b6b4243a1a981c8c2b5 Mon Sep 17 00:00:00 2001 From: Kalo Chin <91766386+fdb02983rhy@users.noreply.github.com> Date: Tue, 11 Mar 2025 23:23:06 +0900 Subject: [PATCH] feat: add click-away and mounting logic to agent setting component (#15521) --- .../config/agent/agent-setting/index.tsx | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/web/app/components/app/configuration/config/agent/agent-setting/index.tsx b/web/app/components/app/configuration/config/agent/agent-setting/index.tsx index 9fae3417b9..50903b0b6e 100644 --- a/web/app/components/app/configuration/config/agent/agent-setting/index.tsx +++ b/web/app/components/app/configuration/config/agent/agent-setting/index.tsx @@ -1,8 +1,9 @@ 'use client' import type { FC } from 'react' -import React, { useState } from 'react' +import React, { useEffect, useRef, useState } from 'react' import { useTranslation } from 'react-i18next' import { RiCloseLine } from '@remixicon/react' +import { useClickAway } from 'ahooks' import ItemPanel from './item-panel' import Button from '@/app/components/base/button' import { CuteRobot } from '@/app/components/base/icons/src/vender/solid/communication' @@ -31,6 +32,18 @@ const AgentSetting: FC = ({ }) => { const { t } = useTranslation() const [tempPayload, setTempPayload] = useState(payload) + const ref = useRef(null) + const [mounted, setMounted] = useState(false) + + useClickAway(() => { + if (mounted) + onCancel() + }, ref) + + useEffect(() => { + setMounted(true) + }, []) + const handleSave = () => { onSave(tempPayload) } @@ -42,6 +55,7 @@ const AgentSetting: FC = ({ }} >