diff --git a/packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/RenameCollectionItem/index.js b/packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/RenameCollectionItem/index.js index 97c3399ae..74b25de47 100644 --- a/packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/RenameCollectionItem/index.js +++ b/packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/RenameCollectionItem/index.js @@ -4,7 +4,7 @@ import * as Yup from 'yup'; import Modal from 'components/Modal'; import { useDispatch } from 'react-redux'; import { isItemAFolder } from 'utils/tabs'; -import { renameItem } from 'providers/ReduxStore/slices/collections/actions'; +import { renameItem, saveRequest } from 'providers/ReduxStore/slices/collections/actions'; const RenameCollectionItem = ({ collection, item, onClose }) => { const dispatch = useDispatch(); @@ -21,7 +21,12 @@ const RenameCollectionItem = ({ collection, item, onClose }) => { .max(50, 'must be 50 characters or less') .required('name is required') }), - onSubmit: (values) => { + onSubmit: async (values) => { + // if there is unsaved changes in the request, + // save them before renaming the request + if (!isFolder && item.draft) { + await dispatch(saveRequest(item.uid, collection.uid, true)); + } dispatch(renameItem(values.name, item.uid, collection.uid)); onClose(); } diff --git a/packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/index.js b/packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/index.js index 6fd863429..bf84b8289 100644 --- a/packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/index.js +++ b/packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/index.js @@ -6,9 +6,8 @@ import { useDrag, useDrop } from 'react-dnd'; import { IconChevronRight, IconDots } from '@tabler/icons'; import { useSelector, useDispatch } from 'react-redux'; import { addTab, focusTab } from 'providers/ReduxStore/slices/tabs'; +import { moveItem, sendRequest } from 'providers/ReduxStore/slices/collections/actions'; import { collectionFolderClicked } from 'providers/ReduxStore/slices/collections'; -import { moveItem } from 'providers/ReduxStore/slices/collections/actions'; -import { sendRequest } from 'providers/ReduxStore/slices/collections/actions'; import Dropdown from 'components/Dropdown'; import NewRequest from 'components/Sidebar/NewRequest'; import NewFolder from 'components/Sidebar/NewFolder'; diff --git a/packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js b/packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js index 08e982c05..526b43a1e 100644 --- a/packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js +++ b/packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js @@ -55,7 +55,7 @@ export const renameCollection = (newName, collectionUid) => (dispatch, getState) }); }; -export const saveRequest = (itemUid, collectionUid) => (dispatch, getState) => { +export const saveRequest = (itemUid, collectionUid, saveSilently) => (dispatch, getState) => { const state = getState(); const collection = findCollectionByUid(state.collections.collections, collectionUid); @@ -76,7 +76,11 @@ export const saveRequest = (itemUid, collectionUid) => (dispatch, getState) => { itemSchema .validate(itemToSave) .then(() => ipcRenderer.invoke('renderer:save-request', item.pathname, itemToSave)) - .then(() => toast.success('Request saved successfully')) + .then(() => { + if (!saveSilently) { + toast.success('Request saved successfully'); + } + }) .then(resolve) .catch((err) => { toast.error('Failed to save request!');