feat: improved error messaging while attempting to create duplicate requests and folders

This commit is contained in:
Anoop M D 2023-02-09 17:55:42 +05:30
parent 7405fa9709
commit ef8e8bf637
4 changed files with 18 additions and 11 deletions

View File

@ -1,4 +1,5 @@
import React, { useRef, useEffect } from 'react'; import React, { useRef, useEffect } from 'react';
import toast from 'react-hot-toast';
import { useFormik } from 'formik'; import { useFormik } from 'formik';
import * as Yup from 'yup'; import * as Yup from 'yup';
import Modal from 'components/Modal'; import Modal from 'components/Modal';
@ -19,8 +20,13 @@ const CloneCollectionItem = ({ collection, item, onClose }) => {
name: Yup.string().min(1, 'must be atleast 1 characters').max(50, 'must be 50 characters or less').required('name is required') name: Yup.string().min(1, 'must be atleast 1 characters').max(50, 'must be 50 characters or less').required('name is required')
}), }),
onSubmit: (values) => { onSubmit: (values) => {
dispatch(cloneItem(values.name, item.uid, collection.uid)); dispatch(cloneItem(values.name, item.uid, collection.uid))
onClose(); .then(() => {
onClose();
})
.catch((err) => {
toast.error(err ? err.message : 'An error occured while cloning the request')
});
} }
}); });

View File

@ -32,7 +32,7 @@ const NewFolder = ({ collection, item, onClose }) => {
onSubmit: (values) => { onSubmit: (values) => {
dispatch(newFolder(values.folderName, collection.uid, item ? item.uid : null)) dispatch(newFolder(values.folderName, collection.uid, item ? item.uid : null))
.then(() => onClose()) .then(() => onClose())
.catch(() => toast.error('An error occured while adding the request')); .catch((err) => toast.error(err ? err.message : 'An error occured while adding the request'));
} }
}); });

View File

@ -56,7 +56,7 @@ const NewRequest = ({ collection, item, isEphermal, onClose }) => {
); );
onClose(); onClose();
}) })
.catch(() => toast.error('An error occured while adding the request')); .catch((err) => toast.error(err ? err.message : 'An error occured while adding the request'));
} else { } else {
dispatch( dispatch(
newHttpRequest({ newHttpRequest({
@ -69,7 +69,7 @@ const NewRequest = ({ collection, item, isEphermal, onClose }) => {
}) })
) )
.then(() => onClose()) .then(() => onClose())
.catch(() => toast.error('An error occured while adding the request')); .catch((err) => toast.error(err ? err.message : 'An error occured while adding the request'));
} }
} }
}); });

View File

@ -1,6 +1,7 @@
import path from 'path'; import path from 'path';
import toast from 'react-hot-toast'; import toast from 'react-hot-toast';
import trim from 'lodash/trim'; import trim from 'lodash/trim';
import find from 'lodash/find';
import get from 'lodash/get'; import get from 'lodash/get';
import filter from 'lodash/filter'; import filter from 'lodash/filter';
import { uuid } from 'utils/common'; import { uuid } from 'utils/common';
@ -192,7 +193,7 @@ export const newFolder = (folderName, collectionUid, itemUid) => (dispatch, getS
.then(() => resolve()) .then(() => resolve())
.catch((error) => reject(error)); .catch((error) => reject(error));
} else { } else {
return reject(new Error('folder with same name already exists')); return reject(new Error('Duplicate folder names under same parent folder are not allowed'));
} }
} else { } else {
const currentItem = findItemInCollection(collection, itemUid); const currentItem = findItemInCollection(collection, itemUid);
@ -207,7 +208,7 @@ export const newFolder = (folderName, collectionUid, itemUid) => (dispatch, getS
.then(() => resolve()) .then(() => resolve())
.catch((error) => reject(error)); .catch((error) => reject(error));
} else { } else {
return reject(new Error('folder with same name already exists')); return reject(new Error('Duplicate folder names under same parent folder are not allowed'));
} }
} else { } else {
return reject(new Error('unable to find parent folder')); return reject(new Error('unable to find parent folder'));
@ -285,7 +286,7 @@ export const cloneItem = (newName, itemUid, collectionUid) => (dispatch, getStat
.then(resolve) .then(resolve)
.catch(reject); .catch(reject);
} else { } else {
return reject(new Error(`${requestName} already exists in collection`)); return reject(new Error('Duplicate request names are not allowed under the same folder'));
} }
} else { } else {
const reqWithSameNameExists = find(parentItem.items, (i) => i.type !== 'folder' && trim(i.filename) === trim(filename)); const reqWithSameNameExists = find(parentItem.items, (i) => i.type !== 'folder' && trim(i.filename) === trim(filename));
@ -302,7 +303,7 @@ export const cloneItem = (newName, itemUid, collectionUid) => (dispatch, getStat
.then(resolve) .then(resolve)
.catch(reject); .catch(reject);
} else { } else {
return reject(new Error(`${requestName} already exists in the folder`)); return reject(new Error('Duplicate request names are not allowed under the same folder'));
} }
} }
}); });
@ -544,7 +545,7 @@ export const newHttpRequest = (params) => (dispatch, getState) => {
ipcRenderer.invoke('renderer:new-request', fullName, item).then(resolve).catch(reject); ipcRenderer.invoke('renderer:new-request', fullName, item).then(resolve).catch(reject);
} else { } else {
return reject(new Error(`${requestName} already exists in collection`)); return reject(new Error('Duplicate request names are not allowed under the same folder'));
} }
} else { } else {
const currentItem = findItemInCollection(collection, itemUid); const currentItem = findItemInCollection(collection, itemUid);
@ -558,7 +559,7 @@ export const newHttpRequest = (params) => (dispatch, getState) => {
ipcRenderer.invoke('renderer:new-request', fullName, item).then(resolve).catch(reject); ipcRenderer.invoke('renderer:new-request', fullName, item).then(resolve).catch(reject);
} else { } else {
return reject(new Error(`${requestName} already exists in the folder`)); return reject(new Error('Duplicate request names are not allowed under the same folder'));
} }
} }
} }