fix: location validation in create collection form

This commit is contained in:
Its-treason 2023-09-29 21:20:36 +02:00
parent 45042cd52a
commit 8bb57aa41d

View File

@ -28,7 +28,9 @@ const CreateCollection = ({ onClose }) => {
.min(1, 'must be atleast 1 characters') .min(1, 'must be atleast 1 characters')
.max(50, 'must be 50 characters or less') .max(50, 'must be 50 characters or less')
.required('folder name is required'), .required('folder name is required'),
collectionLocation: Yup.string().required('location is required') collectionLocation: Yup.string()
.min(1, 'location is required')
.required('location is required')
}), }),
onSubmit: (values) => { onSubmit: (values) => {
dispatch(createCollection(values.collectionName, values.collectionFolderName, values.collectionLocation)) dispatch(createCollection(values.collectionName, values.collectionFolderName, values.collectionLocation))
@ -43,7 +45,10 @@ const CreateCollection = ({ onClose }) => {
const browse = () => { const browse = () => {
dispatch(browseDirectory()) dispatch(browseDirectory())
.then((dirPath) => { .then((dirPath) => {
formik.setFieldValue('collectionLocation', dirPath); // When the user closes the diolog without selecting anything dirPath will be false
if (typeof dirPath === 'string') {
formik.setFieldValue('collectionLocation', dirPath);
}
}) })
.catch((error) => { .catch((error) => {
formik.setFieldValue('collectionLocation', ''); formik.setFieldValue('collectionLocation', '');