From 103065833c26f9e743d2e8556ae3c0a55a56f5df Mon Sep 17 00:00:00 2001 From: Kompal Poorkar Date: Tue, 1 Oct 2024 22:28:14 +0530 Subject: [PATCH 1/3] validations to important fields added in all 3 parts of the registration form basic UI changes to form to accomodate newly applied validations Editing validation messages to make them more concise fix create CODE_OF_CONDUCT.md This PR adds a CODE_OF_CONDUCT.md to the project to outline the expected behavior of all contributors. The purpose of this document is to maintain a respectful, welcoming, and constructive environment for everyone involved in the project. Key Highlights: Purpose: Establishes a harassment-free, inclusive environment for all contributors. Acceptable Behavior: Emphasizes respectful communication, inclusivity, constructive criticism, and community-oriented behavior. Unacceptable Behavior: Clearly states unacceptable actions, including harassment, discrimination, and threats. Reporting Violations: Details the process for reporting unacceptable behavior, providing contact information and assurances of confidentiality. Enforcement Guidelines: Lists possible consequences for violations, ranging from warnings to temporary or permanent bans. Scope: Applies to all community spaces and official representation in public contexts. Attribution: Acknowledges the use of the Contributor Covenant as the foundation for this document. age input box error fixed Implemented denied page and restricted route handling (#19) refactor: removed RequireAuth component and applied restrictions directly in App.jsx(#19) removed RequireAuth imports and components Implemented Denied Page for Restricted Routes (#19) --- CODE_OF_CONDUCT.md | 87 +++++++++++++++++++++++++++++++++++ README.md | 4 ++ package-lock.json | 12 +++++ package.json | 1 + process.env | 7 +++ src/App.jsx | 45 +++++++++--------- src/components/FormStep1.jsx | 33 ++++++++++++- src/components/FormStep2.jsx | 34 ++++++++++++-- src/components/FormStep21.jsx | 31 +++++++++++-- src/pages/Denied.jsx | 65 ++++++++++++++++++++++++++ src/pages/Register.jsx | 4 +- src/utils/formValidations.js | 53 +++++++++++++++++++++ 12 files changed, 341 insertions(+), 35 deletions(-) create mode 100644 CODE_OF_CONDUCT.md create mode 100644 process.env create mode 100644 src/pages/Denied.jsx create mode 100644 src/utils/formValidations.js diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..d352b62 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,87 @@ +# Contributor Covenant Code of Conduct + +# Purpose + +The purpose of this Code of Conduct is to ensure a positive, respectful, and constructive environment for all contributors to this project. We value the participation of every individual and strive to create an inclusive and harassment-free experience, both within the project spaces and when representing the community in public. We pledge to act in ways that foster an open, welcoming, diverse, inclusive, and professional community. + +## Our Pledge +We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socioeconomic status, nationality, personal appearance, race, religion, or sexual identity and orientation. + +We pledge to act and interact in ways that contribute to a respectful, inclusive, and healthy community. + +# Our Standards + +# Acceptable Behavior + +Examples of behavior that contributes to a positive environment for our community include: + +* Respectful Communication: Being polite, empathetic, and supportive in all interactions. +* Inclusivity: Welcoming different perspectives and experiences. +* Constructive Criticism: Giving and gracefully accepting feedback while focusing on improvements. +* Accountability: Acknowledging mistakes, apologizing to those affected, and learning from the experience. +* Community First: Prioritizing what is best for the overall community. + +# Unacceptable Behavior + +Examples of unacceptable behavior include: + +* The use of sexualized language or imagery, and sexual attention or advances of any kind. +* Trolling, insulting, or derogatory comments, and personal or political attacks. +* Public or private harassment. +* Publishing others' private information without their explicit permission. +* Any other conduct that could reasonably be considered inappropriate in a professional setting. +* Intimidation, threats, or aggressive behavior. +* Discrimination or exclusion based on individual characteristics. + +# Reporting Violations +If you experience or witness unacceptable behavior, you can report it by submitting a Report: + +Email a detailed report to rishyym0927@gmail.com. + +# Information to Include: + +When submitting a report, include your contact information, a detailed account of the incident (including dates, times, and individuals involved), and any relevant supporting materials. +Confidentiality Assurance: All reports will be treated confidentially. We prioritize the safety and well-being of everyone involved. +Enforcement Responsibilities.Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful. + +Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned with this Code of Conduct, and will communicate reasons for moderation decisions when appropriate. + +# Enforcement Guidelines +Community leaders will follow these Community Impact Guidelines to determine the consequences for any action they deem in violation of this Code of Conduct: + +1. Correction +* Community Impact: Minor unprofessional or unwelcome behavior. +* Consequence: A private written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested. +2. Warning +* Community Impact: A violation through a single incident or series of actions. +* Consequence: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. Violating these terms may lead to a temporary or permanent ban. +3. Temporary Ban +* Community Impact: A serious violation of community standards. +* Consequence: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban. +4. Permanent Ban +* Community Impact: Repeated violations, harassment, or aggression. +* Consequence: A permanent ban from any sort of public interaction within the community. + +## Scope + +This Code of Conduct applies within all project spaces, including repositories, issue trackers, chat channels, mailing lists, and any other forms of communication. It also applies when an individual is officially representing the community in public spaces. Examples of representation include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an event. + +## Attribution + +This Code of Conduct is adapted from the [Contributor +Covenant][homepage], version 2.0, available at +https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. + +Community Impact Guidelines were inspired by [Mozilla's code of +conduct enforcement ladder](https://github.com/mozilla/diversity). + +[homepage]: https://www.contributor-covenant.org + +For answers to common questions about this code of conduct, see the +FAQ at https://www.contributor-covenant.org/faq. Translations are +available at https://www.contributor-covenant.org/translations. + + +## Contact Information + +For any questions or further clarification, please contact rishyym0927@gmail.com. \ No newline at end of file diff --git a/README.md b/README.md index 6a731ea..6b6210d 100644 --- a/README.md +++ b/README.md @@ -131,6 +131,10 @@ This will start the development server and you can view the application in your Chatbot /chatbot + + Denied + /denied + diff --git a/package-lock.json b/package-lock.json index df6e178..a06b783 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,6 +11,7 @@ "@react-google-maps/api": "^2.19.3", "@yaireo/tagify": "^4.27.0", "axios": "^1.7.4", + "dotenv": "^16.4.5", "framer-motion": "^11.3.28", "gsap": "^3.12.5", "moment": "^2.30.1", @@ -2084,6 +2085,17 @@ "node": ">=0.10.0" } }, + "node_modules/dotenv": { + "version": "16.4.5", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.5.tgz", + "integrity": "sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://dotenvx.com" + } + }, "node_modules/eastasianwidth": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/eastasianwidth/-/eastasianwidth-0.2.0.tgz", diff --git a/package.json b/package.json index b764519..7177a42 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "@react-google-maps/api": "^2.19.3", "@yaireo/tagify": "^4.27.0", "axios": "^1.7.4", + "dotenv": "^16.4.5", "framer-motion": "^11.3.28", "gsap": "^3.12.5", "moment": "^2.30.1", diff --git a/process.env b/process.env new file mode 100644 index 0000000..7f4f58c --- /dev/null +++ b/process.env @@ -0,0 +1,7 @@ +export const AI_CHATBOT_URL=localhost:3000 +export const MACHINE_CHATBOT_URL=localhost:3000 +export const AI_MAIN_URL=localhost:3000 +export const RUST_MAIN_URL=localhost:3000 +export const RUST_BACKEND_URL_SCORE=localhost:3000 +export const MAJOR_CHAT_SERVICE=localhost:3000 +export const chatBaseURL=localhost:3000 \ No newline at end of file diff --git a/src/App.jsx b/src/App.jsx index c5ae020..d7637a2 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -17,6 +17,8 @@ import Requests from "./pages/Requests"; import CodeRun from "./pages/CodeRun"; import Matches from "./pages/Matches"; import RoomPage from "./pages/Room"; +import Denied from "./pages/Denied"; +import Chat from "./pages/Matches"; /* TO ACCESS ANY PAGE YOU CAN REMOVE THE RESTRICTIONS BY SIMPLY REPLACING THE @@ -38,68 +40,63 @@ const App = () => { } /> } /> } /> - }/> - : } /> + } /> + : } /> - {/* Restrict access to Dashboard if user is Male */} + {/* Restrict Access to dashboard for Males */} ) : ( - + ) } /> - - + ) : ( - + ) } /> - - - {/* Restrict access to Requests if user is Female */} + {/* Restrict Access for Females */} ) : ( - + ) } /> - - + {/* Restricted Access for Unauthenticated Users */} - + ) : ( - + ) } /> - { ) : ( - + ) } /> + + } /> diff --git a/src/components/FormStep1.jsx b/src/components/FormStep1.jsx index 593d6f4..2082cea 100644 --- a/src/components/FormStep1.jsx +++ b/src/components/FormStep1.jsx @@ -1,9 +1,34 @@ -import React, { useContext } from 'react'; +import React, { useContext, useState } from 'react'; import { motion } from 'framer-motion'; import { AuthContext } from '../context/AuthContext'; import { Link } from 'react-router-dom'; +import { validations } from '../utils/formValidations'; + const FormStep1 = ({ onNext }) => { const { updateRegisterInfo, registerInfo } = useContext(AuthContext); + const [errors, setErrors] = useState({}); + + const handleNext = () => { + const newErrors = {}; + + const fieldsToValidate = ['first_name', 'last_name', 'email', 'password']; + + fieldsToValidate.forEach((field) => { + const error = validations(field, registerInfo[field]); + if (error) { + newErrors[field] = error; + } + }); + + if (Object.keys(newErrors).length > 0) { + setErrors(newErrors); + return; + } + + setErrors({}); + onNext(); + }; + return ( { onChange={(e) => updateRegisterInfo({ ...registerInfo, first_name: e.target.value })} className="mt-1 block w-full p-2 rounded-md bg-neutral-800 outline-none text-white border border-gray-600" /> + {errors.first_name &&

{errors.first_name}

} @@ -60,13 +88,14 @@ const FormStep1 = ({ onNext }) => { onChange={(e) => updateRegisterInfo({ ...registerInfo, password: e.target.value })} className="mt-1 block w-full p-2 rounded-md bg-neutral-800 outline-none text-white border border-gray-600" /> + {errors.password &&

{errors.password}

} ))} + {errors.gender &&

{errors.gender}

} @@ -68,6 +93,7 @@ const FormStep2 = ({ onNext, onBack }) => { onChange={(e) => updateRegisterInfo({ ...registerInfo, location: e.target.value })} className="mt-1 block w-full p-2 rounded-md bg-neutral-800 outline-none text-white border border-gray-600" /> + {errors.location &&

{errors.location}

}
-
+
-
diff --git a/src/components/FormStep21.jsx b/src/components/FormStep21.jsx index c73d8e4..70262ef 100644 --- a/src/components/FormStep21.jsx +++ b/src/components/FormStep21.jsx @@ -1,12 +1,33 @@ -import React, { useContext, useRef } from "react"; +import React, { useContext, useRef , useState } from "react"; import { motion } from "framer-motion"; import { AuthContext } from "../context/AuthContext"; import axios from "axios"; - +import { validations } from "../utils/formValidations"; const FormStep21 = ({ onNext, onBack }) => { const { updateRegisterInfo, registerInfo } = useContext(AuthContext); const interestsInputRef = useRef(null); const socialHabitsInputRef = useRef(null); + const [errors, setErrors] = useState({}); + + const handleNext = () =>{ + const newErrors ={}; + const fieldsToValidate = ['interests','past_relationships'] ; + + fieldsToValidate.forEach((field) => { + const error = validations(field, registerInfo[field]); + if (error) { + newErrors[field] = error; + } + }); + + if (Object.keys(newErrors).length > 0) { + setErrors(newErrors); + return; + } + + setErrors({}); + onNext(); + } async function onFileSelect(e) { try { @@ -62,6 +83,7 @@ const FormStep21 = ({ onNext, onBack }) => { onChange={(e) => updateRegisterInfo({ ...registerInfo, interests: e.target.value })} className="mt-1 block w-full p-2 rounded-md bg-neutral-800 outline-none text-white border border-gray-600" /> + {errors.interests &&

{errors.interests}

}
+ {errors.past_relationships &&

{errors.past_relationships}

}
@@ -124,11 +147,11 @@ const FormStep21 = ({ onNext, onBack }) => {
-
+
-
diff --git a/src/pages/Denied.jsx b/src/pages/Denied.jsx new file mode 100644 index 0000000..8caca8a --- /dev/null +++ b/src/pages/Denied.jsx @@ -0,0 +1,65 @@ +import React from "react"; +import { Link } from "react-router-dom"; +import { FaLock } from "react-icons/fa"; +import { motion } from "framer-motion"; + +const Denied = () => { + return ( +
+ + + + + + + +

+ Access Denied! +

+ + + + Oops! Looks like you're trying to unlock a door that doesn’t belong to you. + + + + + + Take Me Home + + + + + + Want to explore? Maybe you need the right key. 🗝️ + +
+
+ ); +}; + +export default Denied; diff --git a/src/pages/Register.jsx b/src/pages/Register.jsx index ef23102..7d0154a 100644 --- a/src/pages/Register.jsx +++ b/src/pages/Register.jsx @@ -27,8 +27,8 @@ function Register() { backgroundColor: 'black' }} > -
-
+
+
diff --git a/src/utils/formValidations.js b/src/utils/formValidations.js new file mode 100644 index 0000000..25f70f2 --- /dev/null +++ b/src/utils/formValidations.js @@ -0,0 +1,53 @@ +export const validations = (name, value) => { + const rules = { + first_name: { + regex: /^[a-zA-Z]{1,}$/, + message: '*Must be letters only', + }, + last_name: { + regex: /^[a-zA-Z]{1,}$/, + message: '*Must be letters only', + }, + email: { + regex: /^[^\s@]+@[^\s@]+\.[^\s@]+$/, + message: '*Invalid email address', + }, + password: { + regex: /^(?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%^&*])(?=.{6,}).*$/, + message: '*Must be at least 6 characters long, include at least one uppercase letter, one lowercase letter, and one special character', + }, + gender: { + regex: /^(Male|Female)$/, + message: '*Required', + }, + age: { + regex: /^[1-9]\d*$/, + message: '*Must be a valid number', + }, + username: { + regex: /^[a-zA-Z0-9_]{3,}$/, + message: '*Must be at least 3 characters long', + }, + location: { + regex: /^.{1,}$/, + message: '*Required', + }, + interests: { + regex: /^.{1,}$/, + message: '*Required', + }, + past_relationships: { + regex: /^(Yes|No)$/, + message: '*Required', + }, + }; + + if (rules[name]) { + if (!value) { + return `*Required`; + } + return rules[name].regex.test(value) ? '' : rules[name].message; + } + return ''; + }; + \ No newline at end of file From 5f98dc6841f7d9096d78b8de02e8448dd5fffcd3 Mon Sep 17 00:00:00 2001 From: Kompal Poorkar Date: Mon, 7 Oct 2024 15:46:06 +0530 Subject: [PATCH 2/3] dark/light mode implemented for existing pages --- src/components/DarkModeToggle.jsx | 49 ++++++++++++++ src/components/FormStep1.jsx | 88 ++++++++++++------------ src/components/FormStep2.jsx | 108 ++++++++++++++++-------------- src/components/FormStep21.jsx | 90 +++++++++++++++---------- src/components/FormStep3.jsx | 64 +++++++++--------- src/pages/Landing.jsx | 74 ++++++++++---------- src/pages/Login.jsx | 23 +++---- src/pages/Register.jsx | 8 +-- src/utils/formValidations.js | 8 +-- tailwind.config.js | 2 +- 10 files changed, 296 insertions(+), 218 deletions(-) create mode 100644 src/components/DarkModeToggle.jsx diff --git a/src/components/DarkModeToggle.jsx b/src/components/DarkModeToggle.jsx new file mode 100644 index 0000000..cb05ee5 --- /dev/null +++ b/src/components/DarkModeToggle.jsx @@ -0,0 +1,49 @@ +import React, {useState,useEffect} from 'react' + +const DarkModeToggle = () => { + const [theme, setTheme] = useState('dark'); + + useEffect(() => { + const savedTheme = localStorage.getItem('theme'); + if (savedTheme) { + setTheme(savedTheme); + } else { + setTheme('dark'); + localStorage.setItem('theme', 'dark'); + } + }, []); + + useEffect(() => { + if (theme === 'dark') { + document.documentElement.classList.add('dark'); + } else { + document.documentElement.classList.remove('dark'); + } + localStorage.setItem('theme', theme); + }, [theme]); + + const toggleTheme = () => { + const newTheme = theme === 'dark' ? 'light' : 'dark'; + setTheme(newTheme); + }; + + return ( +
+
+ {/* Circle inside the switch */} +
+
+
+ ) +} + +export default DarkModeToggle diff --git a/src/components/FormStep1.jsx b/src/components/FormStep1.jsx index 2082cea..1fed375 100644 --- a/src/components/FormStep1.jsx +++ b/src/components/FormStep1.jsx @@ -28,7 +28,6 @@ const FormStep1 = ({ onNext }) => { setErrors({}); onNext(); }; - return ( { animate={{ opacity: 1, y: 0 }} exit={{ opacity: 0, y: 20 }} transition={{ duration: 0.5 }} - className="p-6 rounded-lg shadow-lg h-full " + className="p-6 rounded-lg shadow-lg h-full bg-white dark:bg-neutral-900" > -

START FOR FREE

-

Create your account

-

Already a member ? Log in

+

START FOR FREE

+

Create your account

+

+ Already a member? + + Log in + +

- - + +
- - -
); }; diff --git a/src/components/FormStep2.jsx b/src/components/FormStep2.jsx index 95e135e..b98d59c 100644 --- a/src/components/FormStep2.jsx +++ b/src/components/FormStep2.jsx @@ -1,4 +1,4 @@ -import React, { useContext,useState } from 'react'; +import React, { useContext, useState } from 'react'; import { motion } from 'framer-motion'; import { AuthContext } from '../context/AuthContext'; import { validations } from '../utils/formValidations'; @@ -7,9 +7,9 @@ const FormStep2 = ({ onNext, onBack }) => { const { updateRegisterInfo, registerInfo } = useContext(AuthContext); const [errors, setErrors] = useState({}); - const handleNext = () =>{ - const newErrors ={}; - const fieldsToValidate = ['gender','age','username','location'] ; + const handleNext = () => { + const newErrors = {}; + const fieldsToValidate = ['gender', 'age', 'username', 'location']; fieldsToValidate.forEach((field) => { const error = validations(field, registerInfo[field]); @@ -22,10 +22,10 @@ const FormStep2 = ({ onNext, onBack }) => { setErrors(newErrors); return; } - + setErrors({}); onNext(); - } + }; return ( { animate={{ opacity: 1, y: 0 }} exit={{ opacity: 0, y: 20 }} transition={{ duration: 0.5 }} - className="p-6 rounded-lg shadow-lg h-full flex flex-col justify-around" + className="p-6 rounded-lg shadow-lg h-full flex flex-col justify-around bg-white dark:bg-neutral-900" >
-

Contact Information

-

Don't worry we will keep it to ourselves only !

+

+ Contact Information +

+

+ Don't worry, we will keep it to ourselves only! +

- +
-
+
+ + + Username: + updateRegisterInfo({ ...registerInfo, username: e.target.value })} + className="mt-1 block w-full p-2 rounded-md bg-gray-200 dark:bg-neutral-800 border border-gray-300 dark:border-gray-600 outline-none text-black dark:text-white" + /> + {errors.username &&

{errors.username}

} +
-
+ +
+ -
-