Skip to content

Commit 1a54e80

Browse files
committed
save and close functionality for tabs
1 parent 4261e3d commit 1a54e80

2 files changed

Lines changed: 21 additions & 7 deletions

File tree

src/components/atoms/Tabs.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import ConfirmActionModal from 'components/molecules/modals/ConfirmActionModal';
55
import { isEqual } from 'lodash';
66
import { OBJ_TYPES } from 'constants/Common';
77
import { compare } from './util';
8+
import { saveHandle } from 'components/molecules/modals/SaveFlowModal';
89

910
const tabUnsavedChanges = (tab) => {
1011
if (tab.type === OBJ_TYPES.flowtest && tab.flowDataDraft) {
@@ -36,7 +37,7 @@ const Tabs = () => {
3637
const focusTab = tabs.find((t) => t.id === focusTabId);
3738
const [confirmActionModalOpen, setConfirmActionModalOpen] = useState(false);
3839
const closeTab = useTabStore((state) => state.closeTab);
39-
const [closingTabId, setClosingTabId] = useState('');
40+
const [closingTab, setClosingTab] = useState('');
4041
const [closingCollectionId, setClosingCollectionId] = useState('');
4142
// ToDo: change color according to theme
4243
const activeTabStyles = 'bg-cyan-900 text-white';
@@ -48,7 +49,7 @@ const Tabs = () => {
4849
event.stopPropagation();
4950
event.preventDefault();
5051

51-
setClosingTabId(tab.id);
52+
setClosingTab(tab);
5253
setClosingCollectionId(tab.collectionId);
5354

5455
if (tabUnsavedChanges(tab)) {
@@ -94,13 +95,19 @@ const Tabs = () => {
9495
);
9596
})}
9697
<ConfirmActionModal
97-
closeFn={() => setConfirmActionModalOpen(false)}
98+
closeFn={() => {
99+
closeTab(closingTab.id, closingCollectionId);
100+
setConfirmActionModalOpen(false);
101+
}}
98102
open={confirmActionModalOpen}
99103
message={messageForConfirmActionModal}
100104
actionFn={() => {
101-
closeTab(closingTabId, closingCollectionId);
105+
saveHandle(closingTab);
106+
closeTab(closingTab.id, closingCollectionId);
102107
setConfirmActionModalOpen(false);
103108
}}
109+
leftButtonMessage={'Close Withuout Saving'}
110+
rightButtonMessage={'Save And Close'}
104111
/>
105112
</div>
106113
);

src/components/molecules/modals/ConfirmActionModal.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,14 @@ import { Dialog, Transition } from '@headlessui/react';
44
import Button from 'components/atoms/common/Button';
55
import { BUTTON_TYPES, BUTTON_INTENT_TYPES } from 'constants/Common';
66

7-
const ConfirmActionModal = ({ message, actionFn = () => null, closeFn = () => null, open = false }) => {
7+
const ConfirmActionModal = ({
8+
message,
9+
actionFn = () => null,
10+
closeFn = () => null,
11+
open = false,
12+
leftButtonMessage = 'Cancel',
13+
rightButtonMessage = 'Continue',
14+
}) => {
815
return (
916
<Transition appear show={open} as={Fragment}>
1017
<Dialog as='div' className='relative z-10' onClose={closeFn}>
@@ -46,7 +53,7 @@ const ConfirmActionModal = ({ message, actionFn = () => null, closeFn = () => nu
4653
onClickHandle={closeFn}
4754
fullWidth={true}
4855
>
49-
Cancel
56+
{leftButtonMessage}
5057
</Button>
5158
<Button
5259
btnType={BUTTON_TYPES.secondary}
@@ -55,7 +62,7 @@ const ConfirmActionModal = ({ message, actionFn = () => null, closeFn = () => nu
5562
fullWidth={true}
5663
onClickHandle={actionFn}
5764
>
58-
Continue
65+
{rightButtonMessage}
5966
</Button>
6067
</div>
6168
</Dialog.Panel>

0 commit comments

Comments
 (0)