diff --git a/src/API/UserAPI.jsx b/src/API/UserAPI.jsx
index b0345839..277d06aa 100644
--- a/src/API/UserAPI.jsx
+++ b/src/API/UserAPI.jsx
@@ -23,6 +23,7 @@ function UserAPI(token) {
const [history, setHistory] = useState([]);
const [user, setUser] = useState(initialState);
const [authenticated, isAuthenticated] = useState(false);
+ const [cart, setCart] = useState([]);
useEffect(() => {
if (token) {
@@ -31,6 +32,7 @@ function UserAPI(token) {
const res = await axios.get("/api/user/info", {
headers: { Authorization: token },
});
+ console.log(res.data._id)
setIsLoggedIn(true);
isAuthenticated(true);
setUser(res.data);
@@ -44,11 +46,35 @@ function UserAPI(token) {
}
}, [token]);
+ const addCart = async (product) => {
+ if (!isLoggedIn) return alert("Please login to continue buying");
+
+ const check = cart.every((item) => {
+ return item._id !== product._id;
+ });
+
+ if (check) {
+ setCart([...cart, { ...product, quantity: 1 }]);
+
+ await axios.patch(
+ "/api/user/addcart",
+ { cart: [...cart, { ...product, quantity: 1 }] },
+ {
+ headers: { Authorization: token },
+ }
+ );
+ } else {
+ alert("This product has been added to the cart");
+ }
+ };
+
return {
isLoggedIn: [isLoggedIn, setIsLoggedIn],
isAdmin: [isAdmin, setIsAdmin],
history: [history, setHistory],
user: [user, setUser],
+ cart: [cart, setCart],
+ addCart: addCart,
authenticated: [authenticated, isAuthenticated],
};
}
diff --git a/src/Components/Article/MainContainer.jsx b/src/Components/Article/MainContainer.jsx
index 2db91a48..31097350 100644
--- a/src/Components/Article/MainContainer.jsx
+++ b/src/Components/Article/MainContainer.jsx
@@ -1,98 +1,72 @@
import React from 'react';
import Alert from 'react-bootstrap/Alert'
-import { AiFillStar, AiFillPlayCircle, AiFillTwitterCircle } from 'react-icons/ai';
-import {FaRegThumbsUp, FaRegComment, FaFacebook} from 'react-icons/fa';
-import {TiSocialLinkedinCircular} from 'react-icons/ti';
-import {MdBookmarkBorder} from 'react-icons/md';
-import {RiShareCircleFill} from 'react-icons/ri';
-import Sticky from 'react-sticky-state';
+import { AiFillStar, AiFillPlayCircle } from 'react-icons/ai';
import {JustifyContent, StyledMainContainer,
PaddingContent, BlogCard, BlogPost} from '../../Layout/Container/styledArticle';
import {CircleImage, BlogDisplayImage} from '../../Layout/Image/styledImage';
import {NamePlate, WarppedDate, GrayText, DisplayItem, BlogTitle, BlogSubTitle,
- BlogPhotoCredit, BlogContent, Font2} from '../../Layout/Text/styledText';
+ BlogPhotoCredit, BlogContent} from '../../Layout/Text/styledText';
import {ArticleHr} from '../../Layout/Hr/styledHr';
import {AlertP} from '../../Layout/Paragraph/styledParagraph';
import {AlertLink} from '../../Layout/ATag/styledATag';
import marked from 'marked';
-import './StickyState.css';
import Newsletter from '../Subscribe/Newsletter';
import RelatedPosts from './RelatedPosts';
+import StickyFooter from '../Sticky/StickyFooter';
const MainContainer = (props) => {
- const { title, subtitle, description, images, markdown } = props.detailArticle;
+ const { title, subtitle, description, images, markdown } = props.detailArticle;
const timeFormater = props.timeFormater;
const readTime = props.readTime;
return (
-
-
-
-
-
+
+
+
+
+
Avatar | +First Name | +Last Name | +Email ID | +Account Type | +Anniversary | +Member Since | +Actions | +
---|---|---|---|---|---|---|---|
|
+ {user.name.split(' ')[0]} | +{user.name.split(' ')[1] || "N/A"} | +{user.email} | +{user.role === 1 ? "Admin" : "Basic"} | +{timeFormater(user.createdAt)} | +{joinedDate(user.createdAt)} | ++ {/* */} + + | +