Skip to content

Commit

Permalink
feat: implement unsaved changes warning on back button click in Updat…
Browse files Browse the repository at this point in the history
…eAgentPage
  • Loading branch information
truemiller authored and Tanya-atatakai committed Dec 25, 2024
1 parent 70512aa commit f5ba035
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions frontend/components/UpdateAgentPage/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { EditFilled } from '@ant-design/icons';
import { Button, Form, FormInstance } from 'antd';
import { noop } from 'lodash';
import {
createContext,
Dispatch,
Expand Down Expand Up @@ -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 (
<CardFlex
bordered={false}
title={
<CardTitle
showBackButton={true}
backButtonCallback={unsavedModal?.openModal ?? noop}
backButtonCallback={handleClickBack}
title={isEditing ? 'Edit agent settings' : 'Agent settings'}
/>
}
Expand Down

0 comments on commit f5ba035

Please sign in to comment.