Skip to content

Commit

Permalink
cart and userProfile vid 25
Browse files Browse the repository at this point in the history
complete code till video no 25
  • Loading branch information
techinfo-youtube committed Feb 16, 2023
1 parent 2607faa commit f6d8766
Show file tree
Hide file tree
Showing 54 changed files with 3,954 additions and 45 deletions.
737 changes: 737 additions & 0 deletions client/package-lock.json

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions client/package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
{
"name": "client",
"proxy": "http://localhost:8080",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"antd": "^5.1.7",
"axios": "^1.2.5",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-helmet": "^6.1.0",
"react-hot-toast": "^2.4.0",
"react-router-dom": "^6.7.0",
"react-scripts": "5.0.1",
"react-toastify": "^9.1.1",
"web-vitals": "^2.1.4"
},
"scripts": {
Expand Down
40 changes: 40 additions & 0 deletions client/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,51 @@ import About from "./pages/About";
import Contact from "./pages/Contact";
import Policy from "./pages/Policy";
import Pagenotfound from "./pages/Pagenotfound";
import Register from "./pages/Auth/Register";
import Login from "./pages/Auth/Login";
import Dashboard from "./pages/user/Dashboard";
import PrivateRoute from "./components/Routes/Private";
import ForgotPasssword from "./pages/Auth/ForgotPasssword";
import AdminRoute from "./components/Routes/AdminRoute";
import AdminDashboard from "./pages/Admin/AdminDashboard";
import CreateCategory from "./pages/Admin/CreateCategory";
import CreateProduct from "./pages/Admin/CreateProduct";
import Users from "./pages/Admin/Users";
import Orders from "./pages/user/Orders";
import Profile from "./pages/user/Profile";
import Products from "./pages/Admin/Products";
import UpdateProduct from "./pages/Admin/UpdateProduct";
import Search from "./pages/Search";
import ProductDetails from "./pages/ProductDetails";
import Categories from "./pages/Categories";
import CategoryProduct from "./pages/CategoryProduct";
import CartPage from "./pages/CartPage";
function App() {
return (
<>
<Routes>
<Route path="/" element={<HomePage />} />
<Route path="/product/:slug" element={<ProductDetails />} />
<Route path="/categories" element={<Categories />} />
<Route path="/cart" element={<CartPage />} />
<Route path="/category/:slug" element={<CategoryProduct />} />
<Route path="/search" element={<Search />} />
<Route path="/dashboard" element={<PrivateRoute />}>
<Route path="user" element={<Dashboard />} />
<Route path="user/orders" element={<Orders />} />
<Route path="user/profile" element={<Profile />} />
</Route>
<Route path="/dashboard" element={<AdminRoute />}>
<Route path="admin" element={<AdminDashboard />} />
<Route path="admin/create-category" element={<CreateCategory />} />
<Route path="admin/create-product" element={<CreateProduct />} />
<Route path="admin/product/:slug" element={<UpdateProduct />} />
<Route path="admin/products" element={<Products />} />
<Route path="admin/users" element={<Users />} />
</Route>
<Route path="/register" element={<Register />} />
<Route path="/forgot-password" element={<ForgotPasssword />} />
<Route path="/login" element={<Login />} />
<Route path="/about" element={<About />} />
<Route path="/contact" element={<Contact />} />
<Route path="/policy" element={<Policy />} />
Expand Down
25 changes: 25 additions & 0 deletions client/src/components/Form/CategoryForm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React from "react";

const CategoryForm = ({ handleSubmit, value, setValue }) => {
return (
<>
<form onSubmit={handleSubmit}>
<div className="mb-3">
<input
type="text"
className="form-control"
placeholder="Enter new category"
value={value}
onChange={(e) => setValue(e.target.value)}
/>
</div>

<button type="submit" className="btn btn-primary">
Submit
</button>
</form>
</>
);
};

export default CategoryForm;
40 changes: 40 additions & 0 deletions client/src/components/Form/SearchInput.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React from "react";
import { useSearch } from "../../context/search";
import axios from "axios";
import { useNavigate } from "react-router-dom";
const SearchInput = () => {
const [values, setValues] = useSearch();
const navigate = useNavigate();

const handleSubmit = async (e) => {
e.preventDefault();
try {
const { data } = await axios.get(
`/api/v1/product/search/${values.keyword}`
);
setValues({ ...values, results: data });
navigate("/search");
} catch (error) {
console.log(error);
}
};
return (
<div>
<form className="d-flex" role="search" onSubmit={handleSubmit}>
<input
className="form-control me-2"
type="search"
placeholder="Search"
aria-label="Search"
value={values.keyword}
onChange={(e) => setValues({ ...values, keyword: e.target.value })}
/>
<button className="btn btn-outline-success" type="submit">
Search
</button>
</form>
</div>
);
};

export default SearchInput;
39 changes: 39 additions & 0 deletions client/src/components/Layout/AdminMenu.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import React from "react";
import { NavLink } from "react-router-dom";
const AdminMenu = () => {
return (
<>
<div className="text-center">
<div className="list-group">
<h4>Admin Panel</h4>
<NavLink
to="/dashboard/admin/create-category"
className="list-group-item list-group-item-action"
>
Create Category
</NavLink>
<NavLink
to="/dashboard/admin/create-product"
className="list-group-item list-group-item-action"
>
Create Product
</NavLink>
<NavLink
to="/dashboard/admin/products"
className="list-group-item list-group-item-action"
>
Products
</NavLink>
<NavLink
to="/dashboard/admin/users"
className="list-group-item list-group-item-action"
>
Users
</NavLink>
</div>
</div>
</>
);
};

export default AdminMenu;
117 changes: 99 additions & 18 deletions client/src/components/Layout/Header.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
import React from "react";
import { NavLink, Link } from "react-router-dom";
import { GiShoppingBag } from "react-icons/gi";
import { useAuth } from "../../context/auth";
import toast from "react-hot-toast";
import SearchInput from "../Form/SearchInput";
import useCategory from "../../hooks/useCategory";
import { useCart } from "../../context/cart";
import { Badge } from "antd";

const Header = () => {
const [auth, setAuth] = useAuth();
const [cart] = useCart();
const categories = useCategory();
const handleLogout = () => {
setAuth({
...auth,
user: null,
token: "",
});
localStorage.removeItem("auth");
toast.success("Logout Successfully");
};
return (
<>
<nav className="navbar navbar-expand-lg bg-body-tertiary">
Expand All @@ -23,30 +40,94 @@ const Header = () => {
🛒 Ecommerce App
</Link>
<ul className="navbar-nav ms-auto mb-2 mb-lg-0">
<SearchInput />
<li className="nav-item">
<NavLink to="/" className="nav-link ">
Home
</NavLink>
</li>
<li className="nav-item">
<NavLink to="/category" className="nav-link ">
Category
</NavLink>
</li>
<li className="nav-item">
<NavLink to="/register" className="nav-link">
Register
</NavLink>
</li>
<li className="nav-item">
<NavLink to="/login" className="nav-link">
Login
</NavLink>
<li className="nav-item dropdown">
<Link
className="nav-link dropdown-toggle"
to={"/categories"}
data-bs-toggle="dropdown"
>
Categories
</Link>
<ul className="dropdown-menu">
<li>
<Link className="dropdown-item" to={"/categories"}>
All Categories
</Link>
</li>
{categories?.map((c) => (
<li>
<Link
className="dropdown-item"
to={`/category/${c.slug}`}
>
{c.name}
</Link>
</li>
))}
</ul>
</li>

{!auth?.user ? (
<>
<li className="nav-item">
<NavLink to="/register" className="nav-link">
Register
</NavLink>
</li>
<li className="nav-item">
<NavLink to="/login" className="nav-link">
Login
</NavLink>
</li>
</>
) : (
<>
<li className="nav-item dropdown">
<NavLink
className="nav-link dropdown-toggle"
href="#"
role="button"
data-bs-toggle="dropdown"
style={{ border: "none" }}
>
{auth?.user?.name}
</NavLink>
<ul className="dropdown-menu">
<li>
<NavLink
to={`/dashboard/${
auth?.user?.role === 1 ? "admin" : "user"
}`}
className="dropdown-item"
>
Dashboard
</NavLink>
</li>
<li>
<NavLink
onClick={handleLogout}
to="/login"
className="dropdown-item"
>
Logout
</NavLink>
</li>
</ul>
</li>
</>
)}
<li className="nav-item">
<NavLink to="/cart" className="nav-link">
Cart (0)
</NavLink>
<Badge count={cart?.length} showZero>
<NavLink to="/cart" className="nav-link">
Cart
</NavLink>
</Badge>
</li>
</ul>
</div>
Expand Down
25 changes: 22 additions & 3 deletions client/src/components/Layout/Layout.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,34 @@
import React from "react";
import Footer from "./Footer";
import Header from "./Header";

const Layout = ({ children }) => {
import { Helmet } from "react-helmet";
import { Toaster } from "react-hot-toast";
const Layout = ({ children, title, description, keywords, author }) => {
return (
<div>
<Helmet>
<meta charSet="utf-8" />
<meta name="description" content={description} />
<meta name="keywords" content={keywords} />
<meta name="author" content={author} />
<title>{title}</title>
</Helmet>
<Header />
<main style={{ minHeight: "70vh" }}>{children}</main>
<main style={{ minHeight: "70vh" }}>
<Toaster />

{children}
</main>
<Footer />
</div>
);
};

Layout.defaultProps = {
title: "Ecommerce app - shop now",
description: "mern stack project",
keywords: "mern,react,node,mongodb",
author: "Techinfoyt",
};

export default Layout;
27 changes: 27 additions & 0 deletions client/src/components/Layout/UserMenu.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React from "react";
import { NavLink } from "react-router-dom";
const UserMenu = () => {
return (
<div>
<div className="text-center">
<div className="list-group">
<h4>Dashboard</h4>
<NavLink
to="/dashboard/user/profile"
className="list-group-item list-group-item-action"
>
Profile
</NavLink>
<NavLink
to="/dashboard/user/orders"
className="list-group-item list-group-item-action"
>
Orders
</NavLink>
</div>
</div>
</div>
);
};

export default UserMenu;
Loading

0 comments on commit f6d8766

Please sign in to comment.