Skip to content

Commit

Permalink
Refactored Signup component
Browse files Browse the repository at this point in the history
  • Loading branch information
amantaphelix committed Jun 21, 2024
2 parents 28332b7 + b66a341 commit d8a8edb
Show file tree
Hide file tree
Showing 20 changed files with 274 additions and 279 deletions.
25 changes: 12 additions & 13 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,32 @@
Please include a summary of the changes and the related issue. Please also include relevant motivation and context. List any dependencies that are required for this change.


Fixes # (issue)


## Type of change

Please give a X on it which is applicable
Please mark with an X the type that applies:

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Refactor Code
- [ ] A documentation update
- [ ] Others(mentioned in the issue number)
- [ ] Refactor code
- [ ] Documentation update
- [ ] Other (mentioned in the issue number)

# How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce them. Please also list any relevant details for your test configuration.

**_Test A: Describe here_**

**_Test A Describe here_**
**_Test B: Describe here (if required)_**

**_Test B Describe here (if Requred)_**
# Screenshots and Videos

# Screenshorts and Vedios:
Please provide screenshots and videos of the changes you made.

give screenshorts and vedio of the changes you made
# Checklist

# Checklist:
give a X on it which is applicable
Please mark with an X the items that apply:

- [ ] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my code
Expand Down
1 change: 1 addition & 0 deletions envexample
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
REACT_APP_BASE_URL=localhost:8000/api/v1 8000 can be replaced by the server you are running backend on
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"aos": "^2.3.4",
"axios": "^1.5.1",
"framer-motion": "^11.1.9",
"jwt-decode": "^4.0.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-hot-toast": "^2.4.1",
Expand Down
6 changes: 4 additions & 2 deletions server/controllers/Auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const {
findUserById,
} = require("../utils/PasswordTokenAndUser");
const nodemailer = require("nodemailer");

require("dotenv").config();

exports.studentSignup = async (req, res) => {
Expand Down Expand Up @@ -264,7 +265,7 @@ exports.canteenSignup = async (req, res) => {

// Create a token
const token = jwt.sign(
{ id: canteen._id, email: canteen.email },
{ id: canteen._id, email: canteen.email, accountType: canteen.accountType, },
process.env.JWT_SECRET,
{
expiresIn: "1h", // Set token expiration time as needed
Expand Down Expand Up @@ -441,6 +442,7 @@ exports.changeCanteenPassword = async (req, res) => {
});
};


//contactUs

exports.saveContactMessage = async (req, res) => {
Expand All @@ -457,6 +459,7 @@ exports.saveContactMessage = async (req, res) => {
res.status(500).send('Error saving message');
}
};

// verify user for reset password
exports.forgotPassword = async (req, res) => {
try {
Expand Down Expand Up @@ -594,4 +597,3 @@ exports.resetPassword = async (req, res) => {
res.status(500).json("Some error occurred!");
}
};

6 changes: 6 additions & 0 deletions server/envexample
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
PORT=8000
DATABASE_URL=
JWT_SECRET=
CLOUDINARY_CLOUD_NAME=
CLOUDINARY_API_KEY=
CLOUDINARY_API_SECRET=
29 changes: 25 additions & 4 deletions src/authContext.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createContext, useContext, useState } from "react";
import { createContext, useContext, useState, useEffect } from "react";

const authContext = createContext({
isAuthenticated: false
Expand All @@ -8,13 +8,34 @@ export const useAuth = () => useContext(authContext);

const AuthProvider = ({ children }) => {
const [isAuthenticated, setAuthenticated] = useState(false);

useEffect(() => {
const token = localStorage.getItem('authToken');
if (token) {
setAuthenticated(true);
}
}, []);

const checkAuthentication = (token) => {
setAuthenticated(!!token);
const login = (token) => {
// saving the token to local storage when canteen user logIn
localStorage.setItem('authToken', token);
setAuthenticated(true);
};

const signUp = (token) => {
// saving the token to local storage when canteen user logIn
localStorage.setItem('authToken', token);
setAuthenticated(true);
};

const logout = () => {

localStorage.removeItem('authToken');
setAuthenticated(false);
};

return (
<authContext.Provider value={{ isAuthenticated, checkAuthentication }}>
<authContext.Provider value={{ isAuthenticated, login, logout, signUp }}>
{children}
</authContext.Provider>
);
Expand Down
2 changes: 1 addition & 1 deletion src/components/CanteenCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const CanteenCard = ({ canteen }) => {
<a href="#">
<img
className="rounded-t-lg h-48 w-full object-cover"
src={imageSrc || 'default-image-url'}
src={canteen.canteenImage ? canteen.canteenImage : imageSrc}
alt={canteen.name}
/>
</a>
Expand Down
15 changes: 7 additions & 8 deletions src/components/CanteenList.jsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@

import React, { useEffect, useState } from 'react';
import React from 'react';
import CanteenCard from './CanteenCard';



const CanteenList = ({canteenData}) => {
const CanteenList = ({ canteenData }) => {
if (!canteenData || !canteenData.data) {
return <p>No canteen data available.</p>;
}

return (
<div className="flex flex-wrap justify-center mt-20">
{canteenData?.data.map(canteen => (
<CanteenCard key={canteen.id} canteen={canteen} />
{canteenData.data.map((canteen) => (
<CanteenCard key={canteen._id} canteen={canteen} />
))}
</div>
);

};

export default CanteenList;
6 changes: 3 additions & 3 deletions src/components/ModalForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const ModalForm = ({ onSubmit , sectionName , canteenData , id}) => {

if(sectionName === "Breakfast"){

const apiUrl = `http://localhost:8000/api/v1/${id}/breakfast/add`;
const apiUrl = `${process.env.REACT_APP_BASE_URL}/${id}/breakfast/add`;

axios.post(apiUrl , foodDetails)
.then((response)=>{
Expand All @@ -75,7 +75,7 @@ const ModalForm = ({ onSubmit , sectionName , canteenData , id}) => {
}
else if(sectionName === "Lunch"){

const apiUrl = `http://localhost:8000/api/v1/${id}/lunch/add`;
const apiUrl = `${process.env.REACT_APP_BASE_URL}/${id}/lunch/add`;

axios.post(apiUrl , foodDetails)
.then((response)=>{
Expand All @@ -92,7 +92,7 @@ const ModalForm = ({ onSubmit , sectionName , canteenData , id}) => {
}
else{

const apiUrl = `http://localhost:8000/api/v1/${id}/dinner/add`;
const apiUrl = `${process.env.REACT_APP_BASE_URL}/${id}/dinner/add`;

axios.post(apiUrl , foodDetails)
.then((response)=>{
Expand Down
Loading

0 comments on commit d8a8edb

Please sign in to comment.