From f5ba0352b80ad2ee0bc538f382d9fd00d87289ba Mon Sep 17 00:00:00 2001 From: truemiller Date: Tue, 24 Dec 2024 14:06:56 +0000 Subject: [PATCH] feat: implement unsaved changes warning on back button click in UpdateAgentPage --- frontend/components/UpdateAgentPage/index.tsx | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/frontend/components/UpdateAgentPage/index.tsx b/frontend/components/UpdateAgentPage/index.tsx index a579a1c8..fe0f2a74 100644 --- a/frontend/components/UpdateAgentPage/index.tsx +++ b/frontend/components/UpdateAgentPage/index.tsx @@ -1,6 +1,5 @@ import { EditFilled } from '@ant-design/icons'; import { Button, Form, FormInstance } from 'antd'; -import { noop } from 'lodash'; import { createContext, Dispatch, @@ -124,14 +123,26 @@ export const UpdateAgentPage = () => { const UpdateAgentPageCard = () => { const { selectedAgentType } = useServices(); - const { unsavedModal, isEditing } = useContext(UpdateAgentContext); + const { goto } = usePageState(); + const { unsavedModal, isEditing, form } = useContext(UpdateAgentContext); + + const hasUnsavedChanges = form?.isFieldsTouched(); + + const handleClickBack = () => { + if (hasUnsavedChanges) { + unsavedModal?.openModal?.(); + } else { + goto(Pages.Main); + } + }; + return ( }