Skip to content

Commit

Permalink
Added private routes in App.jsx with logic in handleRedirections.js, …
Browse files Browse the repository at this point in the history
…introduced variable colors for dark & light modes, added media queries for input chips, and set isWidgetVisible in navbar to show only when user is logged in.
  • Loading branch information
RutikKulkarni committed Jun 24, 2024
1 parent f3db20a commit e3681b7
Show file tree
Hide file tree
Showing 12 changed files with 261 additions and 157 deletions.
84 changes: 57 additions & 27 deletions frontend/src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,49 +1,79 @@
import React from "react";
import { BrowserRouter as Router, Routes, Route } from "react-router-dom";
import NotFound from "./pages/Page404/Page404"
import {
BrowserRouter as Router,
Routes,
Route,
Navigate,
} from "react-router-dom";
import NotFound from "./pages/Page404/Page404";
import Home from "./pages/Home/Home";
import About from "./pages/About/About";
import Services from "./pages/Services/Services";
import Help from "./pages/Help/Help";
import Contact from "./pages/Contact/Contact";
import Signup from "./pages/Signup/Signup";
import Login from "./pages/Login/Login";
import ForgotPassword from "./pages/Forgot/Forgot"
import ForgotPassword from "./pages/Forgot/Forgot";
import MyAccount from "./pages/MyAccount/MyAccount";
import EditAccountInfo from "./pages/EditAccountInfo/EditAccountInfo";
import Explore from "./pages/Explore/Explore";
import ThemeProvider from "./context/ThemeProvider/ThemeProvider";
import { getConfig } from "./utility/envHelper/envHelper";
import Layout from "./Layout";
import { isLoggedIn } from "./utility/userPersistence";
// import { handleNavigate } from "./utility/handleRedirections";

export const Config = getConfig();

function App() {
const PrivateRoute = ({ element, ...rest }) => {
return isLoggedIn() ? element : <Navigate to="/login" />;
};

const RedirectIfLoggedIn = ({ element, ...rest }) => {
return isLoggedIn() ? <Navigate to="/explore" /> : element;
};

const App = () => {
return (
<Router>
<ThemeProvider>
<Layout>
<Routes>
<Route path="/" element={<Home />} />
<Route path="/about" element={<About />} />
<Route path="/services" element={<Services />} />
<Route path="/help" element={<Help />} />
<Route path="/contact" element={<Contact />} />
<Route path="/signup" element={<Signup />} />
<Route path="/login" element={<Login />} />
<Route path="/forgotpassword" element={<ForgotPassword />} />
<Route path="/myAccount" element={<MyAccount />} />
<Route
path="/editAccountInfo"
element={<EditAccountInfo />}
/>
<Route path="/explore" element={<Explore />} />
<Route path="*" element={<NotFound />} />
</Routes>
</Layout>
</ThemeProvider>
</Router>
<ThemeProvider>
<Layout>
<Routes>
<Route
path="/"
element={isLoggedIn() ? <Navigate to="/explore" /> : <Home />}
/>
<Route path="/about" element={<About />} />
<Route path="/services" element={<Services />} />
<Route path="/help" element={<Help />} />
<Route path="/contact" element={<Contact />} />
<Route
path="/signup"
element={<RedirectIfLoggedIn element={<Signup />} />}
/>
<Route
path="/login"
element={<RedirectIfLoggedIn element={<Login />} />}
/>
<Route path="/forgotpassword" element={<ForgotPassword />} />
<Route
path="/myAccount"
element={<PrivateRoute element={<MyAccount />} />}
/>
<Route
path="/editAccountInfo"
element={<PrivateRoute element={<EditAccountInfo />} />}
/>
<Route
path="/explore"
element={<PrivateRoute element={<Explore />} />}
/>
<Route path="*" element={<NotFound />} />
</Routes>
</Layout>
</ThemeProvider>
</Router>
);
}
};

export default App;
10 changes: 5 additions & 5 deletions frontend/src/components/Form/ChipTextField/ChipTextField.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ const ChipTextField = ({ placeholder, inputName, chips, setChips }) => {
if (inputValue.trim() !== "") {
setChips((prev) => ({
...prev,
[inputName] : [...chips, inputValue.trim()],
[inputName]: [...chips, inputValue.trim()],
}));
setInputValue("");
}
}
};

const handleDelete = (chipToDelete) => {
let filteredChips = chips?.filter((chip) => chip !== chipToDelete)
setChips((prev)=> ({
let filteredChips = chips?.filter((chip) => chip !== chipToDelete);
setChips((prev) => ({
...prev,
[inputName] : filteredChips
}))
[inputName]: filteredChips,
}));
};

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
flex-wrap: wrap;
align-items: center;
padding: 5px 20px;
border: 1px solid #ccc;
border: 1px solid var(--input-border-color);
border-radius: 4px;
width: 470px;
border-radius: 12px;
Expand All @@ -12,8 +12,8 @@
.chip {
display: flex;
align-items: center;
background-color: #e0e0e0;
border-radius: 16px;
border: 1px solid var(--input-border-color);
padding: 5px 10px;
margin: 5px;
font-size: 14px;
Expand All @@ -25,11 +25,7 @@
font-size: 16px;
cursor: pointer;
margin-left: 5px;
color: #666;
}

.chipDeleteButton:hover {
color: #000;
color: var(--text-color);
}

.chipInput {
Expand All @@ -40,4 +36,22 @@
outline: none;
min-width: 150px;
box-sizing: border-box;
background-color: transparent;
color: var(--text-color);
}

/* Media query for screens between 801px and 1349px */
@media (min-width: 801px) and (max-width: 1349px) {
.chipInputContainer {
width: 100%;
padding: 15px;
}
}

/* Mobile screens */
@media (max-width: 800px) {
.chipInputContainer {
width: 100%;
padding: 10px;
}
}
92 changes: 46 additions & 46 deletions frontend/src/components/Form/EducationInfo/EducationInfo.jsx
Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
import styles from '../Form.module.css'
import { handleChange } from '../formHelperFunc'
import styles from "../Form.module.css";
import { handleChange } from "../formHelperFunc";

const EducationInfo = ({education, setEducation}) => {
return(
<div className={styles.educationInfo}>
<h3>Education</h3>
<div className={styles.inputRow}>
<input
type="text"
placeholder="Highest Degree Attained"
name='highestDegreeAttained'
value={education.highestDegreeAttained}
onChange={(e) => handleChange(e, setEducation)}
className={styles.inputField}
/>
<input
type="text"
placeholder="University/Institution Name"
name='uniInsName'
value={education.uniInsName}
onChange={(e) => handleChange(e, setEducation)}
className={styles.inputField}
/>
</div>
<div className={styles.inputRow}>
<input
type="text"
placeholder="Field of Study"
name='fieldOfStudy'
value={education.fieldOfStudy}
onChange={(e) => handleChange(e, setEducation)}
className={styles.inputField}
/>
<input
type="number"
placeholder="Graduation Year"
name='graduationYear'
value={education.graduationYear}
onChange={(e) => handleChange(e, setEducation)}
className={styles.inputField}
/>
</div>
</div>
)
}
const EducationInfo = ({ education, setEducation }) => {
return (
<div className={styles.educationInfo}>
<h3>Education</h3>
<div className={styles.inputRow}>
<input
type="text"
placeholder="Highest Degree Attained"
name="highestDegreeAttained"
value={education.highestDegreeAttained}
onChange={(e) => handleChange(e, setEducation)}
className={styles.inputField}
/>
<input
type="text"
placeholder="University/Institution Name"
name="uniInsName"
value={education.uniInsName}
onChange={(e) => handleChange(e, setEducation)}
className={styles.inputField}
/>
</div>
<div className={styles.inputRow}>
<input
type="text"
placeholder="Field of Study"
name="fieldOfStudy"
value={education.fieldOfStudy}
onChange={(e) => handleChange(e, setEducation)}
className={styles.inputField}
/>
<input
type="number"
placeholder="Graduation Year"
name="graduationYear"
value={education.graduationYear}
onChange={(e) => handleChange(e, setEducation)}
className={styles.inputField}
/>
</div>
</div>
);
};

export default EducationInfo
export default EducationInfo;
18 changes: 14 additions & 4 deletions frontend/src/components/Form/Form.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const Form = () => {
gitHubUrl: "",
websiteUrl: "",
});
const [termsAndConditions, setTermsAndConditions] = useState(false)
const [termsAndConditions, setTermsAndConditions] = useState(false);

const handleOptionClick = (option) => {
setSelectedOption(option);
Expand All @@ -70,8 +70,12 @@ const Form = () => {
const handleSubmit = (e) => {
e.preventDefault();

if(!termsAndConditions){
generateSnackbar("You must have checked Terms & Conditions Box!", 'warning', 2000)
if (!termsAndConditions) {
generateSnackbar(
"You must have checked Terms & Conditions Box!",
"warning",
2000
);
return;
}

Expand Down Expand Up @@ -140,7 +144,13 @@ const Form = () => {
<div className={styles.footerInputes}>
<div className={styles.termsAndConditions}>
<label>
<input type="checkbox" value="termsAndConditions" checked={termsAndConditions} onChange={() => setTermsAndConditions(!termsAndConditions)} /> Accept Terms & Conditions
<input
type="checkbox"
value="termsAndConditions"
checked={termsAndConditions}
onChange={() => setTermsAndConditions(!termsAndConditions)}
/>{" "}
Accept Terms & Conditions
</label>
</div>
<button className={styles.saveButton}>Save</button>
Expand Down
31 changes: 26 additions & 5 deletions frontend/src/components/Form/ImageSection/ImageSection.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React from "react";
import { ReactComponent as UserSvg } from "../../../assets/svg/user.svg";
import styles from "../Form.module.css";
import styles1 from './ImageSection.module.css';
import styles1 from "./ImageSection.module.css";
import { handleChange } from "../formHelperFunc";

const ImageSection = ({setProfileInfo, socialLinks, setSocialLinks}) => {
const ImageSection = ({ setProfileInfo, socialLinks, setSocialLinks }) => {
return (
<div className={styles.imageSection}>
<div className={styles.uploadImage}>
Expand Down Expand Up @@ -39,13 +39,34 @@ const ImageSection = ({setProfileInfo, socialLinks, setSocialLinks}) => {
</div>
<div className={styles.genderSection}>
<label>
<input type="radio" name="gender" value="male" onChange={(e) => handleChange(e, setProfileInfo)} required /> Male
<input
type="radio"
name="gender"
value="male"
onChange={(e) => handleChange(e, setProfileInfo)}
required
/>{" "}
Male
</label>
<label>
<input type="radio" name="gender" value="female" onChange={(e) => handleChange(e, setProfileInfo)} required /> Female
<input
type="radio"
name="gender"
value="female"
onChange={(e) => handleChange(e, setProfileInfo)}
required
/>{" "}
Female
</label>
<label>
<input type="radio" name="gender" value="other" onChange={(e) => handleChange(e, setProfileInfo)} required /> Other
<input
type="radio"
name="gender"
value="other"
onChange={(e) => handleChange(e, setProfileInfo)}
required
/>{" "}
Other
</label>
</div>
</div>
Expand Down
Loading

0 comments on commit e3681b7

Please sign in to comment.