├── .gitignore ├── README.md ├── package-lock.json ├── package.json ├── public └── index.html └── src ├── App.js ├── assets ├── img │ ├── pic1.svg │ └── wave.png └── styles │ ├── _login.scss │ ├── _signUp.scss │ ├── _validationError.scss │ └── index.scss ├── components ├── LogIn.js ├── SignUp.js └── Wave.js ├── functions └── toast.js └── index.js /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Getting Started with Create React App 2 | 3 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 4 | 5 | ## Available Scripts 6 | 7 | In the project directory, you can run: 8 | 9 | ### `npm start` 10 | 11 | Runs the app in the development mode.\ 12 | Open [http://localhost:3000](http://localhost:3000) to view it in your browser. 13 | 14 | The page will reload when you make changes.\ 15 | You may also see any lint errors in the console. 16 | 17 | ### `npm test` 18 | 19 | Launches the test runner in the interactive watch mode.\ 20 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 21 | 22 | ### `npm run build` 23 | 24 | Builds the app for production to the `build` folder.\ 25 | It correctly bundles React in production mode and optimizes the build for the best performance. 26 | 27 | The build is minified and the filenames include the hashes.\ 28 | Your app is ready to be deployed! 29 | 30 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 31 | 32 | ### `npm run eject` 33 | 34 | **Note: this is a one-way operation. Once you `eject`, you can't go back!** 35 | 36 | If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. 37 | 38 | Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own. 39 | 40 | You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it. 41 | 42 | ## Learn More 43 | 44 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 45 | 46 | To learn React, check out the [React documentation](https://reactjs.org/). 47 | 48 | ### Code Splitting 49 | 50 | This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting) 51 | 52 | ### Analyzing the Bundle Size 53 | 54 | This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size) 55 | 56 | ### Making a Progressive Web App 57 | 58 | This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app) 59 | 60 | ### Advanced Configuration 61 | 62 | This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration) 63 | 64 | ### Deployment 65 | 66 | This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment) 67 | 68 | ### `npm run build` fails to minify 69 | 70 | This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify) 71 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "formik", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "^5.16.4", 7 | "@testing-library/react": "^13.1.1", 8 | "@testing-library/user-event": "^13.5.0", 9 | "axios": "^0.27.2", 10 | "formik": "^2.2.9", 11 | "react": "^18.1.0", 12 | "react-dom": "^18.1.0", 13 | "react-icons": "^4.3.1", 14 | "react-router-dom": "^6.3.0", 15 | "react-scripts": "5.0.1", 16 | "react-toastify": "^8.2.0", 17 | "sass": "^1.51.0", 18 | "web-vitals": "^2.1.4", 19 | "yup": "^0.32.11" 20 | }, 21 | "scripts": { 22 | "start": "react-scripts start", 23 | "build": "react-scripts build", 24 | "test": "react-scripts test", 25 | "eject": "react-scripts eject" 26 | }, 27 | "eslintConfig": { 28 | "extends": [ 29 | "react-app", 30 | "react-app/jest" 31 | ] 32 | }, 33 | "browserslist": { 34 | "production": [ 35 | ">0.2%", 36 | "not dead", 37 | "not op_mini all" 38 | ], 39 | "development": [ 40 | "last 1 chrome version", 41 | "last 1 firefox version", 42 | "last 1 safari version" 43 | ] 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 11 | Form Validation 12 | 13 | 14 | 15 |
16 | 17 | 18 | -------------------------------------------------------------------------------- /src/App.js: -------------------------------------------------------------------------------- 1 | import { useState } from "react"; 2 | import { Navigate, Route, Routes } from "react-router-dom"; 3 | // icons 4 | import { MdDarkMode, MdLightMode } from "react-icons/md"; 5 | // components 6 | import LogIn from "./components/LogIn"; 7 | import SignUp from "./components/SignUp"; 8 | import Wave from "./components/Wave"; 9 | 10 | const App = () => { 11 | const [darkMode, setDarkMode] = useState(false); 12 | 13 | return ( 14 |
15 |
16 | setDarkMode(!darkMode)}> 17 | {darkMode ? ( 18 | 19 | ) : ( 20 | 21 | )} 22 | 23 |
24 | 25 | } /> 26 | } /> 27 | } /> 28 | 29 | 30 |
31 | ); 32 | }; 33 | export default App; 34 | -------------------------------------------------------------------------------- /src/assets/img/pic1.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/assets/img/wave.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/parham-ab/React-form-validation2/e1a6185bc19378491d9d11fe344b24b53764a6c1/src/assets/img/wave.png -------------------------------------------------------------------------------- /src/assets/styles/_login.scss: -------------------------------------------------------------------------------- 1 | .login-container { 2 | display: flex; 3 | align-items: center; 4 | justify-content: space-around; 5 | } 6 | // mediaQueries 7 | @media screen and(max-width:'986px') { 8 | .conatiner { 9 | margin: 30px 0; 10 | } 11 | .svg-icon { 12 | img { 13 | width: 400px; 14 | } 15 | } 16 | .customField { 17 | width: 240px !important; 18 | } 19 | } 20 | @media screen and(max-width:'713px') { 21 | .login-container { 22 | min-height: 100vh; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/assets/styles/_signUp.scss: -------------------------------------------------------------------------------- 1 | .signUp-container { 2 | display: flex; 3 | align-items: center; 4 | justify-content: space-around; 5 | } 6 | // mediaQueries 7 | @media screen and(max-width:'986px') { 8 | .signUp-container { 9 | min-height: 100vh; 10 | } 11 | .svg-icon { 12 | img { 13 | width: 400px; 14 | } 15 | } 16 | .customField { 17 | width: 240px !important; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/assets/styles/_validationError.scss: -------------------------------------------------------------------------------- 1 | .errorMsg { 2 | font-size: 0.9rem; 3 | font-weight: bold; 4 | color: #d91111; 5 | margin-top: 3px; 6 | } 7 | -------------------------------------------------------------------------------- /src/assets/styles/index.scss: -------------------------------------------------------------------------------- 1 | // CSS Resets 2 | *, 3 | *::before, 4 | *::after { 5 | margin: 0; 6 | padding: 0; 7 | box-sizing: border-box; 8 | outline: none; 9 | text-decoration: none; 10 | font-family: "Quicksand", sans-serif; 11 | font-family: "Rubik", sans-s; 12 | } 13 | // fonts 14 | @import url("https://fonts.googleapis.com/css2?family=Quicksand&family=Rubik:ital,wght@0,300;1,300&display=swap"); 15 | // Styles 16 | @import "signUp"; 17 | @import "login"; 18 | @import "validationError"; 19 | // inputs 20 | .customField { 21 | width: 300px; 22 | padding: 5px; 23 | border: none; 24 | border-bottom: solid 1px #0356bd; 25 | font-size: 18px; 26 | background-color: inherit; 27 | } 28 | .title { 29 | color: #0356bd; 30 | margin-bottom: 2rem; 31 | } 32 | .switch { 33 | display: flex; 34 | justify-content: center; 35 | margin-top: 5px; 36 | opacity: 0.8; 37 | p { 38 | font-size: 0.9rem; 39 | font-weight: bold; 40 | } 41 | a { 42 | color: #0356bd; 43 | } 44 | } 45 | .field-container { 46 | margin: 0 0 15px 0; 47 | } 48 | .submitBtn { 49 | width: 100%; 50 | border: none; 51 | padding: 5px; 52 | border-radius: 7px; 53 | background-color: #004ba0; 54 | color: #fff; 55 | cursor: pointer; 56 | transition: all 0.3s; 57 | font-size: 17px; 58 | &:hover { 59 | background-color: #0060ce; 60 | transition: all 0.3s; 61 | } 62 | &:active { 63 | background-color: #004ba0; 64 | transition: all 0.3s; 65 | } 66 | } 67 | .wave { 68 | img { 69 | bottom: 0 !important; 70 | position: fixed; 71 | z-index: -999; 72 | width: 100%; 73 | } 74 | } 75 | .container { 76 | label { 77 | cursor: pointer; 78 | } 79 | background-color: #d3d3d37a; 80 | backdrop-filter: blur(10px); 81 | padding: 20px; 82 | border-radius: 10px; 83 | box-shadow: 0 10px 29px 0 #64646f33; 84 | input[type="checkbox"] { 85 | appearance: none; 86 | border: 1px solid #004ba0; 87 | cursor: pointer; 88 | height: 20px; 89 | transition: all 0.1s; 90 | width: 20px !important; 91 | border-radius: 5px; 92 | &:checked { 93 | background-color: #004ba0; 94 | border-radius: 100%; 95 | width: 20px !important; 96 | } 97 | } 98 | } 99 | @media screen and(max-width:'545px') { 100 | .login-container, 101 | .signUp-container { 102 | justify-content: center; 103 | } 104 | .svg-icon { 105 | display: none; 106 | } 107 | } 108 | @media screen and(max-width:'710px') { 109 | .svg-icon { 110 | img { 111 | width: 250px; 112 | } 113 | } 114 | label, 115 | button { 116 | font-size: 15px !important; 117 | } 118 | .customField { 119 | width: 200px !important; 120 | } 121 | } 122 | // dark mode 123 | .dark { 124 | background-color: #262626; 125 | min-height: 100vh; 126 | .container { 127 | background-color: rgb(235 235 235); 128 | } 129 | .wave { 130 | display: none; 131 | } 132 | } 133 | .darkMode, 134 | .lightMode { 135 | font-size: 2.5rem; 136 | margin: 2px 7px; 137 | cursor: pointer; 138 | } 139 | .darkMode { 140 | color: #002881; 141 | } 142 | .lightMode { 143 | color: #fff; 144 | } 145 | -------------------------------------------------------------------------------- /src/components/LogIn.js: -------------------------------------------------------------------------------- 1 | // react router dom 2 | import { Link } from "react-router-dom"; 3 | // axios 4 | import axios from "axios"; 5 | // formik 6 | import { useFormik } from "formik"; 7 | import * as Yup from "yup"; 8 | // react toastify 9 | import { ToastContainer } from "react-toastify"; 10 | import { notify } from "../functions/toast"; 11 | // img 12 | import pic from "../assets/img/pic1.svg"; 13 | // initialValues 14 | const initialValues = { 15 | email: "", 16 | password: "", 17 | }; 18 | // validate function 19 | const validationSchema = Yup.object({ 20 | email: Yup.string() 21 | .matches( 22 | /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,3}$/i, 23 | "invalid Email address" 24 | ) 25 | .required("Email Required"), 26 | password: Yup.string() 27 | .min(8, "Password must be 8 or mor chars !") 28 | .matches(/(?=.*[0-9])/, "Password must contain a number.") 29 | .required("Password Required !"), 30 | }); 31 | // submit 32 | const onSubmit = (values) => { 33 | console.log("values", values); 34 | axios 35 | .post(`https://jsonplaceholder.typicode.com/posts`, { 36 | userData: values, 37 | }) 38 | .then((response) => { 39 | console.log(response.data); 40 | notify("success", "Logged In successfully !"); 41 | }) 42 | .catch((error) => notify("error", "Something went wrong !")); 43 | }; 44 | 45 | const Login = () => { 46 | const formik = useFormik({ 47 | initialValues, 48 | validationSchema, 49 | onSubmit, 50 | }); 51 | 52 | return ( 53 |
54 |
55 | pic 56 |
57 | 58 |
59 |
60 |

Login

61 |
62 |
63 |
64 |
65 | 66 |
67 | 74 |
75 | 76 | {formik.errors.email && 77 | formik.touched.email && 78 | formik.errors.email} 79 | 80 |
81 |
82 | 83 |
84 |
85 | 86 |
87 | 94 |
95 | 96 | {formik.errors.password && 97 | formik.touched.password && 98 | formik.errors.password} 99 | 100 |
101 |
102 | 103 | 106 |
107 |

108 | Dont have an account ? SignUp 109 |

110 |
111 |
112 |
113 | 114 |
115 | ); 116 | }; 117 | 118 | export default Login; 119 | -------------------------------------------------------------------------------- /src/components/SignUp.js: -------------------------------------------------------------------------------- 1 | // react router dom 2 | import { Link } from "react-router-dom"; 3 | // axios 4 | import axios from "axios"; 5 | // formik 6 | import { useFormik } from "formik"; 7 | import * as Yup from "yup"; 8 | // react toastify 9 | import { ToastContainer } from "react-toastify"; 10 | import { notify } from "../functions/toast"; 11 | // img 12 | import pic from "../assets/img/pic1.svg"; 13 | // initialValues 14 | const initialValues = { 15 | name: "", 16 | email: "", 17 | password: "", 18 | confirmPassword: "", 19 | regulations: false, 20 | }; 21 | // validate function 22 | const validationSchema = Yup.object({ 23 | name: Yup.string().trim().required("Name Required !"), 24 | email: Yup.string() 25 | .matches( 26 | /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,3}$/i, 27 | "invalid Email address" 28 | ) 29 | .required("Email Required"), 30 | password: Yup.string() 31 | .min(8, "Password must be 8 or mor chars !") 32 | .matches(/(?=.*[0-9])/, "Password must contain a number.") 33 | .required("Password Required !"), 34 | confirmPassword: Yup.string() 35 | .oneOf([Yup.ref("password"), null], "Passwords do not match !") 36 | .required("Confirm Password !"), 37 | regulations: Yup.boolean().oneOf([true], "Accept Our Regulations !"), 38 | }); 39 | // submit 40 | const onSubmit = (values) => { 41 | console.log("values", values); 42 | axios 43 | .post(`https://jsonplaceholder.typicode.com/posts`, { 44 | userData: values, 45 | }) 46 | .then((response) => { 47 | console.log(response.data); 48 | notify("success", "Signed Up successfully !"); 49 | }) 50 | .catch((error) => notify("error", "Something went wrong !")); 51 | }; 52 | 53 | const SignUp = () => { 54 | const formik = useFormik({ 55 | initialValues, 56 | validationSchema, 57 | onSubmit, 58 | }); 59 | 60 | return ( 61 |
62 |
63 | pic 64 |
65 | 66 |
67 |
68 |

Signup

69 |
70 |
71 |
72 |
73 | 74 |
75 | 82 |
83 | 84 | {formik.errors.name && 85 | formik.touched.name && 86 | formik.errors.name} 87 | 88 |
89 |
90 | 91 |
92 |
93 | 94 |
95 | 102 |
103 | 104 | {formik.errors.email && 105 | formik.touched.email && 106 | formik.errors.email} 107 | 108 |
109 |
110 | 111 |
112 |
113 | 114 |
115 | 122 |
123 | 124 | {formik.errors.password && 125 | formik.touched.password && 126 | formik.errors.password} 127 | 128 |
129 |
130 | 131 |
132 |
133 | 134 |
135 | 142 |
143 | 144 | {formik.errors.confirmPassword && 145 | formik.touched.confirmPassword && 146 | formik.errors.confirmPassword} 147 | 148 |
149 |
150 | 151 |
152 |
158 |
159 | 160 |
161 |
162 | 169 |
170 |
171 | 172 | {formik.errors.regulations && 173 | formik.touched.regulations && 174 | formik.errors.regulations} 175 | 176 |
177 | 178 | 181 |
182 |

183 | Have an account already ? Login 184 |

185 |
186 |
187 |
188 | 189 |
190 | ); 191 | }; 192 | 193 | export default SignUp; 194 | -------------------------------------------------------------------------------- /src/components/Wave.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | // img 3 | import wave from "../assets/img/wave.png"; 4 | 5 | const Wave = () => { 6 | return ( 7 |
8 |
9 | wave 10 |
11 |
12 | ); 13 | }; 14 | 15 | export default Wave; 16 | -------------------------------------------------------------------------------- /src/functions/toast.js: -------------------------------------------------------------------------------- 1 | import { toast } from "react-toastify"; 2 | 3 | const notify = (type, text) => { 4 | if (type === "success") { 5 | toast.success(text, { 6 | position: "top-right", 7 | autoClose: 1300, 8 | hideProgressBar: false, 9 | closeOnClick: true, 10 | pauseOnHover: true, 11 | draggable: true, 12 | progress: undefined, 13 | theme: "colored", 14 | }); 15 | } else { 16 | toast.error(text, { 17 | position: "top-right", 18 | autoClose: 1300, 19 | hideProgressBar: false, 20 | closeOnClick: true, 21 | pauseOnHover: true, 22 | draggable: true, 23 | progress: undefined, 24 | theme: "colored", 25 | }); 26 | } 27 | }; 28 | export { notify }; 29 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import ReactDOM from "react-dom/client"; 3 | import App from "./App"; 4 | import { BrowserRouter } from "react-router-dom"; 5 | // styles 6 | import "./assets/styles/index.scss"; 7 | import "react-toastify/dist/ReactToastify.css"; 8 | 9 | const root = ReactDOM.createRoot(document.getElementById("root")); 10 | root.render( 11 | 12 | 13 | 14 | ); --------------------------------------------------------------------------------