diff --git a/packages/grafnode-components/package.json b/packages/grafnode-components/package.json index b78b877e2..6cfe4ce51 100644 --- a/packages/grafnode-components/package.json +++ b/packages/grafnode-components/package.json @@ -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" } } diff --git a/packages/grafnode-components/src/components/Sidebar/CreateCollection/index.js b/packages/grafnode-components/src/components/Sidebar/CreateCollection/index.js index 9f9dad95e..b594610b3 100644 --- a/packages/grafnode-components/src/components/Sidebar/CreateCollection/index.js +++ b/packages/grafnode-components/src/components/Sidebar/CreateCollection/index.js @@ -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 ( -
- - + +
+ + + {formik.touched.collectionName && formik.errors.collectionName ? ( +
{formik.errors.collectionName}
+ ) : null} +
); diff --git a/packages/grafnode-components/src/components/Sidebar/index.js b/packages/grafnode-components/src/components/Sidebar/index.js index 75a429e80..24aeba60e 100644 --- a/packages/grafnode-components/src/components/Sidebar/index.js +++ b/packages/grafnode-components/src/components/Sidebar/index.js @@ -23,7 +23,8 @@ const Sidebar = ({collections, actions, dispatch, activeRequestTabId}) => { setModalOpen(false); }; - const handleConfirm = () => { + const handleConfirm = (values) => { + console.log(values); setModalOpen(false); }; diff --git a/packages/grafnode-components/webpack.config.js b/packages/grafnode-components/webpack.config.js index e23f2f81b..eafaba36c 100644 --- a/packages/grafnode-components/webpack.config.js +++ b/packages/grafnode-components/webpack.config.js @@ -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() diff --git a/packages/grafnode-run/package.json b/packages/grafnode-run/package.json index 987690897..8d7aed997 100644 --- a/packages/grafnode-run/package.json +++ b/packages/grafnode-run/package.json @@ -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",