Skip to content

Commit

Permalink
Marketplace integration-1: Buying Items
Browse files Browse the repository at this point in the history
  • Loading branch information
Tamoziit committed Jan 3, 2025
1 parent 9ca90f4 commit 4b12909
Show file tree
Hide file tree
Showing 17 changed files with 653 additions and 20 deletions.
16 changes: 16 additions & 0 deletions backend/controllers/elevatedUser.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,20 @@ export const getMetaData = async (req, res) => {
console.log("Error in get metadata", error.message);
res.status(500).json({ error: "Internal Server error" });
}
}

export const isElevatedUser = async (req, res) => {
try {
const user = await Metadata.findOne({ user: req.user._id });

if (user) {
if (user.totalGP >= parseFloat(200)) return res.status(200).json({ elevatedUser: true });
else return res.status(200).json({ elevatedUser: false });
} else {
return res.status(200).json({ message: "User not enrolled. Enroll first" });
}
} catch (error) {
console.log("Error in getting Elevated User", error);
res.status(500).json({ error: "Internal Server error" });
}
}
3 changes: 2 additions & 1 deletion backend/routes/elevatedUser.routes.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import express from "express";
import verifyToken from "../middlewares/auth.middleware.js";
import { createMetaData, getMetaData } from "../controllers/elevatedUser.controller.js";
import { createMetaData, getMetaData, isElevatedUser } from "../controllers/elevatedUser.controller.js";

const router = express.Router();

router.post("/metadata", verifyToken, createMetaData);
router.get("/get-metadata", verifyToken, getMetaData);
router.get("/isElevatedUser", verifyToken, isElevatedUser);

export default router;
96 changes: 96 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"@gsap/react": "^2.1.1",
"@react-three/drei": "^9.120.5",
"@react-three/fiber": "^8.17.10",
"@reduxjs/toolkit": "^2.5.0",
"aos": "^2.3.4",
"axios": "^1.7.9",
"browser-image-compression": "^2.0.2",
Expand All @@ -23,12 +24,14 @@
"react-dom": "^18.3.1",
"react-hot-toast": "^2.5.1",
"react-icons": "^5.4.0",
"react-redux": "^9.2.0",
"react-router-dom": "^7.1.1",
"react-select": "^5.9.0",
"react-slick": "^0.30.3",
"react-three-fiber": "^6.0.13",
"react-tsparticles": "^2.12.2",
"react-webcam": "^7.2.0",
"redux-persist": "^6.0.0",
"slick-carousel": "^1.8.1",
"three": "^0.172.0",
"tsparticles": "^3.7.1",
Expand Down
10 changes: 10 additions & 0 deletions frontend/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ import Dashboard from "./pages/dashboard/Dashboard";
import PersonalDashboard from "./pages/dashboard/PersonalDashboard";
import RegionalDashboard from "./pages/dashboard/RegionalDashboard";
import Profile from "./pages/profile/Profile";
import MarketPlace from "./pages/marketplace/Marketplace";
import MarketplaceBuy from "./pages/marketplace/MarketplaceBuy";
import CompletePayment from "./pages/payment/CompletePayment";
import CancelPayment from "./pages/payment/CancelPayment";
import Gratitude from "./pages/gratitude/Gratitude";

function App() {
const { authUser } = useAuthContext();
Expand All @@ -31,6 +36,11 @@ function App() {
<Route path="/dashboard/personal" element={authUser ? <PersonalDashboard /> : <Navigate to={"/"} />} />
<Route path="/dashboard/:district" element={authUser ? <RegionalDashboard /> : <Navigate to={"/"} />} />
<Route path="/profile" element={authUser ? <Profile /> : <Navigate to={"/"} />} />
<Route path="/marketplace" element={authUser ? <MarketPlace /> : <Navigate to={"/"} />} />
<Route path="/marketplace/buy/:id" element={authUser ? <MarketplaceBuy /> : <Navigate to={"/"} />} exact />
<Route path="/complete-order" element={authUser ? <CompletePayment /> : <Navigate to={"/"} />} />
<Route path="/cancel-order" element={authUser ? <CancelPayment /> : <Navigate to={"/"} />} />
<Route path="/gratitude" element={authUser ? <Gratitude /> : <Navigate to={"/"} />} />

<Route path="*" element={authUser ? <Navigate to="/home" /> : <Navigate to="/" />} />
</Routes>
Expand Down
16 changes: 8 additions & 8 deletions frontend/src/components/Functionality.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,42 +45,42 @@ const Functionality = () => {
className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-6 w-full max-w-4xl justify-items-center"
ref={buttonContainerRef}
>
<button className="primary-button-new w-full">
<button className="primary-button-new w-full text-black">
<Link to="/upload" className="w-full block text-center">
Upload
</Link>
</button>
<button className="primary-button-new w-full">
<button className="primary-button-new w-full text-black">
<Link to="/capture" className="w-full block text-center">
Capture
</Link>
</button>
<button className="primary-button-new w-full">
<button className="primary-button-new w-full text-black">
<Link to="/dashboard" className="w-full block text-center">
Dashboard
</Link>
</button>
<button className="primary-button-new w-full">
<button className="primary-button-new w-full text-black">
<Link to="/marketplace" className="w-full block text-center">
Marketplace
</Link>
</button>
<button className="primary-button-new w-full">
<button className="primary-button-new w-full text-black">
<Link to="/history" className="w-full block text-center">
My History
</Link>
</button>
<button className="primary-button-new w-full">
<button className="primary-button-new w-full text-black">
<Link to="/elevated-user/contribute" className="w-full block text-center">
Contribute
</Link>
</button>
<button className="primary-button-new w-full">
<button className="primary-button-new w-full text-black">
<Link to="/profile" className="w-full block text-center">
Profile
</Link>
</button>
<button className="primary-button-new w-full">
<button className="primary-button-new w-full text-black">
<Link to="/info" className="w-full block text-center">
Details & Info
</Link>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/navbars/Navbar-actions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const Navbar = () => {
<Link to="/dashboard">Dashboard</Link>
<Link to="/history">History</Link>
<Link to="/marketplace"><BsCart2 /></Link>
<button onClick={logout} className="primary-button">Logout</button>
<button onClick={logout} className="primary-button text-black">Logout</button>
</div>
<div className="navbar-menu-container md:hidden">
<HiOutlineBars3 onClick={() => setOpenMenu(true)} />
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/navbars/Navbar-home.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const Navbar = () => {
<a onClick={() => navigate("/marketplace")} href="">
<BsCart2 className="navbar-cart-icon" />
</a>
<button onClick={logout} className="primary-button">Logout</button>
<button onClick={logout} className="primary-button text-black">Logout</button>
</div>
<div className="navbar-menu-container md:hidden">
<HiOutlineBars3 onClick={() => setOpenMenu(true)} />
Expand Down
27 changes: 27 additions & 0 deletions frontend/src/context/ElevatedUserContext.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* eslint-disable react-refresh/only-export-components */
import { createContext, useContext, useEffect, useState } from "react";
import useGetIsElevatedUser from "../hooks/getIsElevatedUser";

export const ElevatedUserContext = createContext();

export const useElevatedUserContext = () => {
return useContext(ElevatedUserContext);
}

export const ElevatedUserContextProvider = ({ children }) => {
const { isElevatedUser } = useGetIsElevatedUser();
const [elevatedUser, setElevatedUser] = useState(false);

const getElevatedUser = async () => {
const data = await isElevatedUser();
setElevatedUser(data);
}

useEffect(() => {
getElevatedUser();
}, []);

return <ElevatedUserContext.Provider value={{ elevatedUser, setElevatedUser }}>
{children}
</ElevatedUserContext.Provider>
}
35 changes: 35 additions & 0 deletions frontend/src/hooks/getIsElevatedUser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { useState } from "react";
import toast from "react-hot-toast";

const useGetIsElevatedUser = () => {
const [loading, setLoading] = useState(false);
const apiUrl = import.meta.env.VITE_API_URL;

const isElevatedUser = async (id) => {
setLoading(true);
try {
const res = await fetch(`${apiUrl}/elevatedUser/isElevatedUser`, {
method: "GET",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${localStorage.getItem("KS-token")}`,
}
});
const data = await res.json();

if (data.error) {
throw new Error(data.error);
}

return data.elevatedUser;
} catch (error) {
toast.error(error.message);
console.log(error);
} finally {
setLoading(false);
}
}
return { loading, isElevatedUser }
}

export default useGetIsElevatedUser;
Loading

0 comments on commit 4b12909

Please sign in to comment.