mirror of
https://github.com/usebruno/bruno.git
synced 2025-03-06 18:41:21 +01:00
Fix/improve env modal error when duplicate names (#3557)
* Enhance environment creation validation and improve error handling Co-authored-by: Anoop M D <anoop.md1421@gmail.com>
This commit is contained in:
parent
bd2cf554b6
commit
514da55923
@ -10,6 +10,12 @@ import Modal from 'components/Modal';
|
||||
const CreateEnvironment = ({ collection, onClose }) => {
|
||||
const dispatch = useDispatch();
|
||||
const inputRef = useRef();
|
||||
|
||||
// todo: Add this to global env too.
|
||||
const validateEnvironmentName = (name) => {
|
||||
return !collection.environments.some((env) => env?.name?.toLowerCase().trim() === name?.toLowerCase().trim());
|
||||
};
|
||||
|
||||
const formik = useFormik({
|
||||
enableReinitialize: true,
|
||||
initialValues: {
|
||||
@ -17,9 +23,10 @@ const CreateEnvironment = ({ collection, onClose }) => {
|
||||
},
|
||||
validationSchema: Yup.object({
|
||||
name: Yup.string()
|
||||
.min(1, 'must be at least 1 character')
|
||||
.max(50, 'must be 50 characters or less')
|
||||
.required('name is required')
|
||||
.min(1, 'Must be at least 1 character')
|
||||
.max(50, 'Must be 50 characters or less')
|
||||
.required('Name is required')
|
||||
.test('duplicate-name', 'Environment already exists', validateEnvironmentName)
|
||||
}),
|
||||
onSubmit: (values) => {
|
||||
dispatch(addEnvironment(values.name, collection.uid))
|
||||
|
Loading…
Reference in New Issue
Block a user