fix: save unsaved request changes before moving to new location

This commit is contained in:
therealrinku 2024-04-20 22:04:29 +05:45
parent 59ffb0166f
commit dd393babd9

View File

@ -6,7 +6,7 @@ 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 { moveItem, sendRequest, saveRequest } from 'providers/ReduxStore/slices/collections/actions';
import { collectionFolderClicked } from 'providers/ReduxStore/slices/collections';
import Dropdown from 'components/Dropdown';
import NewRequest from 'components/Sidebar/NewRequest';
@ -50,8 +50,12 @@ const CollectionItem = ({ item, collection, searchText }) => {
const [{ isOver }, drop] = useDrop({
accept: `COLLECTION_ITEM_${collection.uid}`,
drop: (draggedItem) => {
drop: async (draggedItem) => {
if (draggedItem.uid !== item.uid) {
// save unsaved request changes before moving the request item
if (draggedItem.draft) {
await dispatch(saveRequest(draggedItem.uid, collection.uid, true));
}
dispatch(moveItem(collection.uid, draggedItem.uid, item.uid));
}
},