Skip to content

Commit

Permalink
fix: updates (#3158)
Browse files Browse the repository at this point in the history
  • Loading branch information
lohxt1 authored Sep 21, 2024
1 parent 6c66937 commit fc79436
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const CopyEnvironment = ({ collection, environment, onClose }) => {
return (
<Portal>
<Modal size="sm" title={'Copy Environment'} confirmText="Copy" handleConfirm={onSubmit} handleCancel={onClose}>
<form className="bruno-form" onSubmit={formik.handleSubmit}>
<form className="bruno-form" onSubmit={e => e.preventDefault()}>
<div>
<label htmlFor="name" className="block font-semibold">
New Environment Name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const CreateEnvironment = ({ collection, onClose }) => {
handleConfirm={onSubmit}
handleCancel={onClose}
>
<form className="bruno-form" onSubmit={formik.handleSubmit}>
<form className="bruno-form" onSubmit={e => e.preventDefault()}>
<div>
<label htmlFor="name" className="block font-semibold">
Environment Name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const RenameEnvironment = ({ onClose, environment, collection }) => {
handleConfirm={onSubmit}
handleCancel={onClose}
>
<form className="bruno-form" onSubmit={formik.handleSubmit}>
<form className="bruno-form" onSubmit={e => e.preventDefault()}>
<div>
<label htmlFor="name" className="block font-semibold">
Environment Name
Expand Down
7 changes: 4 additions & 3 deletions packages/bruno-app/src/components/Modal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,15 @@ const Modal = ({
const modalRef = useRef(null);
const [isClosing, setIsClosing] = useState(false);

const handleKeydown = ({ keyCode }) => {
const handleKeydown = (event) => {
const { keyCode, shiftKey, ctrlKey, altKey, metaKey } = event;
switch (keyCode) {
case ESC_KEY_CODE: {
if (disableEscapeKey) return;
return closeModal({ type: 'esc' });
}
case ENTER_KEY_CODE: {
if(handleConfirm) {
if (!shiftKey && !ctrlKey && !altKey && !metaKey && handleConfirm) {
return handleConfirm();
}
}
Expand All @@ -97,7 +99,6 @@ const Modal = ({
};

useEffect(() => {
if (disableEscapeKey) return;
document.addEventListener('keydown', handleKeydown, false);
return () => {
document.removeEventListener('keydown', handleKeydown);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const CloneCollection = ({ onClose, collection }) => {
)
)
.then(() => {
toast.success('Collection created');
toast.success('Collection created!');
onClose();
})
.catch((e) => toast.error('An error occurred while creating the collection - ' + e));
Expand Down Expand Up @@ -72,7 +72,7 @@ const CloneCollection = ({ onClose, collection }) => {

return (
<Modal size="sm" title="Clone Collection" confirmText="Create" handleConfirm={onSubmit} handleCancel={onClose}>
<form className="bruno-form" onSubmit={formik.handleSubmit}>
<form className="bruno-form" onSubmit={e => e.preventDefault()}>
<div>
<label htmlFor="collection-name" className="flex items-center font-semibold">
Name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const CloneCollectionItem = ({ collection, item, onClose }) => {
onSubmit: (values) => {
dispatch(cloneItem(values.name, item.uid, collection.uid))
.then(() => {
toast.success('Request cloned!');
onClose();
})
.catch((err) => {
Expand All @@ -49,7 +50,7 @@ const CloneCollectionItem = ({ collection, item, onClose }) => {
handleConfirm={onSubmit}
handleCancel={onClose}
>
<form className="bruno-form" onSubmit={formik.handleSubmit}>
<form className="bruno-form" onSubmit={e => e.preventDefault()}>
<div>
<label htmlFor="name" className="block font-semibold">
{isFolder ? 'Folder' : 'Request'} Name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Modal from 'components/Modal';
import { useDispatch } from 'react-redux';
import { isItemAFolder } from 'utils/tabs';
import { renameItem, saveRequest } from 'providers/ReduxStore/slices/collections/actions';
import toast from 'react-hot-toast';

const RenameCollectionItem = ({ collection, item, onClose }) => {
const dispatch = useDispatch();
Expand All @@ -27,8 +28,14 @@ const RenameCollectionItem = ({ collection, item, onClose }) => {
if (!isFolder && item.draft) {
await dispatch(saveRequest(item.uid, collection.uid, true));
}
dispatch(renameItem(values.name, item.uid, collection.uid));
onClose();
dispatch(renameItem(values.name, item.uid, collection.uid))
.then(() => {
toast.success('Request renamed!');
onClose();
})
.catch((err) => {
toast.error(err ? err.message : 'An error occurred while renaming the request');
});
}
});

Expand All @@ -48,7 +55,7 @@ const RenameCollectionItem = ({ collection, item, onClose }) => {
handleConfirm={onSubmit}
handleCancel={onClose}
>
<form className="bruno-form" onSubmit={formik.handleSubmit}>
<form className="bruno-form" onSubmit={e => e.preventDefault()}>
<div>
<label htmlFor="name" className="block font-semibold">
{isFolder ? 'Folder' : 'Request'} Name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,14 @@ const RenameCollection = ({ collection, onClose }) => {
.required('name is required')
}),
onSubmit: (values) => {
dispatch(renameCollection(values.name, collection.uid));
toast.success('Collection renamed!');
onClose();
dispatch(renameCollection(values.name, collection.uid))
.then(() => {
toast.success('Collection renamed!');
onClose();
})
.catch((err) => {
toast.error(err ? err.message : 'An error occurred while renaming the collection');
});
}
});

Expand All @@ -37,7 +42,7 @@ const RenameCollection = ({ collection, onClose }) => {

return (
<Modal size="sm" title="Rename Collection" confirmText="Rename" handleConfirm={onSubmit} handleCancel={onClose}>
<form className="bruno-form" onSubmit={formik.handleSubmit}>
<form className="bruno-form" onSubmit={e => e.preventDefault()}>
<div>
<label htmlFor="name" className="block font-semibold">
Name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const CreateCollection = ({ onClose }) => {
onSubmit: (values) => {
dispatch(createCollection(values.collectionName, values.collectionFolderName, values.collectionLocation))
.then(() => {
toast.success('Collection created');
toast.success('Collection created!');
onClose();
})
.catch((e) => toast.error('An error occurred while creating the collection - ' + e));
Expand Down Expand Up @@ -65,7 +65,7 @@ const CreateCollection = ({ onClose }) => {

return (
<Modal size="sm" title="Create Collection" confirmText="Create" handleConfirm={onSubmit} handleCancel={onClose}>
<form className="bruno-form" onSubmit={formik.handleSubmit}>
<form className="bruno-form" onSubmit={e => e.preventDefault()}>
<div>
<label htmlFor="collection-name" className="flex items-center font-semibold">
Name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ const ImportCollectionLocation = ({ onClose, handleSubmit, collectionName, trans

return (
<Modal size="sm" title="Import Collection" confirmText="Import" handleConfirm={onSubmit} handleCancel={onClose}>
<form className="bruno-form" onSubmit={formik.handleSubmit}>
<form className="bruno-form" onSubmit={e => e.preventDefault()}>
<div>
<label htmlFor="collectionName" className="block font-semibold">
Name
Expand Down
7 changes: 5 additions & 2 deletions packages/bruno-app/src/components/Sidebar/NewFolder/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ const NewFolder = ({ collection, item, onClose }) => {
}),
onSubmit: (values) => {
dispatch(newFolder(values.folderName, collection.uid, item ? item.uid : null))
.then(() => onClose())
.then(() => {
toast.success('New folder created!');
onClose()
})
.catch((err) => toast.error(err ? err.message : 'An error occurred while adding the folder'));
}
});
Expand All @@ -47,7 +50,7 @@ const NewFolder = ({ collection, item, onClose }) => {

return (
<Modal size="sm" title="New Folder" confirmText="Create" handleConfirm={onSubmit} handleCancel={onClose}>
<form className="bruno-form" onSubmit={formik.handleSubmit}>
<form className="bruno-form" onSubmit={e => e.preventDefault()}>
<div>
<label htmlFor="folderName" className="block font-semibold">
Folder Name
Expand Down
12 changes: 9 additions & 3 deletions packages/bruno-app/src/components/Sidebar/NewRequest/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,10 @@ const NewRequest = ({ collection, item, isEphemeral, onClose }) => {
auth: request.auth
})
)
.then(() => onClose())
.then(() => {
toast.success('New request created!');
onClose()
})
.catch((err) => toast.error(err ? err.message : 'An error occurred while adding the request'));
} else {
dispatch(
Expand All @@ -126,7 +129,10 @@ const NewRequest = ({ collection, item, isEphemeral, onClose }) => {
itemUid: item ? item.uid : null
})
)
.then(() => onClose())
.then(() => {
toast.success('New request created!');
onClose()
})
.catch((err) => toast.error(err ? err.message : 'An error occurred while adding the request'));
}
}
Expand Down Expand Up @@ -162,7 +168,7 @@ const NewRequest = ({ collection, item, isEphemeral, onClose }) => {
return (
<StyledWrapper>
<Modal size="md" title="New Request" confirmText="Create" handleConfirm={onSubmit} handleCancel={onClose}>
<form className="bruno-form" onSubmit={formik.handleSubmit}>
<form className="bruno-form" onSubmit={e => e.preventDefault()}>
<div>
<label htmlFor="requestName" className="block font-semibold">
Type
Expand Down

0 comments on commit fc79436

Please sign in to comment.