Merge pull request #2 from anusreesubash/feature/create-collection-form-validation

feat: create collection form validation
This commit is contained in:
Anoop M D 2022-01-21 14:48:05 +05:30 committed by GitHub
commit 070a34883a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 46 additions and 13 deletions

View File

@ -27,12 +27,14 @@
"classnames": "^2.3.1",
"codemirror": "^5.64.0",
"escape-html": "^1.0.3",
"formik": "^2.2.9",
"markdown-it": "^12.2.0",
"nanoid": "^3.1.30",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-tabs": "^3.2.3",
"styled-components": "^5.3.3",
"tailwindcss": "^2.2.19"
"tailwindcss": "^2.2.19",
"yup": "^0.32.11"
}
}

View File

@ -1,21 +1,47 @@
import React from 'react';
import React, { useState } from 'react';
import {useFormik} from 'formik';
import * as Yup from 'yup';
import Modal from '../../Modal';
const CreateCollection = ({handleConfirm, handleCancel, actions, dispatch}) => {
const formik = useFormik({
enableReinitialize: true,
initialValues: {
collectionName: ''
},
validationSchema: Yup.object({
collectionName: Yup.string()
.min(3, 'must be atleast 3 characters')
.max(50, 'must be 50 characters or less')
.required('name is required')
}),
onSubmit: (values) => {
handleConfirm(values);
}
});
const onSubmit = () => formik.handleSubmit();
return (
<Modal
size="sm"
title='Create Collection'
handleConfirm={handleConfirm}
handleConfirm={onSubmit}
handleCancel={handleCancel}
>
<form className="grafnode-form">
<label htmlFor="name" className="block font-semibold">Name</label>
<form className="grafnode-form" onSubmit={formik.handleSubmit}>
<div>
<label htmlFor="collectionName" className="block font-semibold">Name</label>
<input
id="collection-name" type="text" name="collection-name"
id="collection-name" type="text" name="collectionName"
className="block textbox mt-2 w-full"
required
onChange={formik.handleChange}
value={formik.values.collectionName || ''}
/>
{formik.touched.collectionName && formik.errors.collectionName ? (
<div className="text-red-500">{formik.errors.collectionName}</div>
) : null}
</div>
</form>
</Modal>
);

View File

@ -23,7 +23,8 @@ const Sidebar = ({collections, actions, dispatch, activeRequestTabId}) => {
setModalOpen(false);
};
const handleConfirm = () => {
const handleConfirm = (values) => {
console.log(values);
setModalOpen(false);
};

View File

@ -47,9 +47,11 @@ module.exports = {
'codemirror': 'codemirror',
'graphql': 'graphql',
'escape-html': 'escape-html',
'formik': 'formik',
'markdown-it': 'markdown-it',
'nanoid': 'nanoid',
'graphql-request': 'graphql-request'
'graphql-request': 'graphql-request',
'yup': 'yup'
},
plugins: [
new MiniCssExtractPlugin()

View File

@ -32,6 +32,7 @@
"codemirror": "^5.64.0",
"codemirror-graphql": "^1.2.5",
"escape-html": "^1.0.3",
"formik": "^2.2.9",
"graphiql": "^1.5.9",
"graphql": "^16.2.0",
"graphql-request": "^3.7.0",
@ -45,7 +46,8 @@
"react-tabs": "^3.2.3",
"sass": "^1.46.0",
"styled-components": "^5.3.3",
"tailwindcss": "^2.2.19"
"tailwindcss": "^2.2.19",
"yup": "^0.32.11"
},
"devDependencies": {
"babel-plugin-styled-components": "^2.0.2",