CJamie

Untitled

Apr 29th, 2022
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.49 KB | None | 0 0
  1. import React from "react";
  2. import AppBar from "@material-ui/core/AppBar";
  3. import Toolbar from "@material-ui/core/Toolbar";
  4. import Typography from "@material-ui/core/Typography";
  5. import IconButton from "@material-ui/core/IconButton";
  6. import HomeIcon from "@material-ui/icons/Home";
  7. import Button from "@material-ui/core/Button";
  8. import auth from "./../auth/auth-helper";
  9. import { Link, withRouter } from "react-router-dom";
  10. import CartIcon from "@material-ui/icons/LabelImportant";
  11. import Badge from "@material-ui/core/Badge";
  12. import cart from "./../cart/cart-helper";
  13.  
  14. const isActive = (history, path) => {
  15. if (history.location.pathname == path) return { color: "#bef67a" };
  16. else return { color: "#ffffff" };
  17. };
  18. const isPartActive = (history, path) => {
  19. if (history.location.pathname.includes(path)) return { color: "#bef67a" };
  20. else return { color: "#ffffff" };
  21. };
  22. const Menu = withRouter(({ history }) => (
  23. <AppBar position="static" style={{ backgroundColor: "blue" }}>
  24. <Toolbar>
  25. {/* <Typography variant="h6" color="inherit">
  26. SWIFT
  27. </Typography> */}
  28. <div>
  29. <img
  30. src="https://i.ibb.co/Rb5JLsv/logo.png"
  31. alt="logo"
  32. border="0"
  33. height={60}
  34. width={110}
  35. />
  36. </div>
  37. <div>
  38. <Link to="/">
  39. <IconButton aria-label="Home" style={isActive(history, "/")}>
  40. <HomeIcon />
  41. </IconButton>
  42. </Link>
  43. <Link to="/requests/all">
  44. <Button style={isActive(history, "/requests/all")}>
  45. All Active Requests
  46. </Button>
  47. </Link>
  48. <Link to="/cart">
  49. <Button style={isActive(history, "/cart")}>
  50. Pending
  51. <Badge
  52. color="secondary"
  53. invisible={false}
  54. badgeContent={cart.itemTotal()}
  55. style={{ marginLeft: "7px" }}
  56. >
  57. <CartIcon />
  58. </Badge>
  59. </Button>
  60. </Link>
  61. </div>
  62. <div style={{ position: "absolute", right: "10px" }}>
  63. <span style={{ float: "right" }}>
  64. {!auth.isAuthenticated() && (
  65. <span>
  66. <Link to="/signup">
  67. <Button style={isActive(history, "/signup")}>Sign up</Button>
  68. </Link>
  69. <Link to="/signin">
  70. <Button style={isActive(history, "/signin")}>Sign In</Button>
  71. </Link>
  72. </span>
  73. )}
  74. {auth.isAuthenticated() && (
  75. <span>
  76. {auth.isAuthenticated().user.seller && (
  77. <Link to="/seller/requests">
  78. <Button style={isPartActive(history, "/seller/")}>
  79. My Requests
  80. </Button>
  81. </Link>
  82. )}
  83. <Link to={"/user/" + auth.isAuthenticated().user._id}>
  84. <Button
  85. style={isActive(
  86. history,
  87. "/user/" + auth.isAuthenticated().user._id
  88. )}
  89. >
  90. My Profile
  91. </Button>
  92. </Link>
  93. <Button
  94. color="inherit"
  95. onClick={() => {
  96. auth.clearJWT(() => history.push("/"));
  97. }}
  98. >
  99. Sign out
  100. </Button>
  101. </span>
  102. )}
  103. </span>
  104. </div>
  105. </Toolbar>
  106. </AppBar>
  107. ));
  108.  
  109. export default Menu;
  110.  
Advertisement
Add Comment
Please, Sign In to add comment