diff --git a/src/components/cards/ProductCard.tsx b/src/components/cards/ProductCard.tsx index 756a4a3..4ba374d 100644 --- a/src/components/cards/ProductCard.tsx +++ b/src/components/cards/ProductCard.tsx @@ -224,7 +224,7 @@ const ProductCard: React.FC = ({ product }) => { ) : ( = ({ searchQuery, setSearchQuery }) => { const [isLoggedIn, setIsLoggedIn] = useState(false); + const { profile } = useSelector((state: RootState) => state.usersProfile); const handleSearch = (e: React.ChangeEvent) => { setSearchQuery(e.target.value); }; - let userInfo; const accessToken = localStorage.getItem("accessToken"); if (accessToken) { @@ -32,6 +32,11 @@ const Header: React.FC = ({ searchQuery, setSearchQuery }) => { } const dispatch = useAppDispatch(); + useEffect(() => { + // @ts-ignore + dispatch(getProfile()); + }, [dispatch]); + useEffect(() => { if (accessToken) { try { @@ -106,7 +111,7 @@ const Header: React.FC = ({ searchQuery, setSearchQuery }) => { "" ) : (
- {userCart.length} + {userCart && userCart.length}
)} @@ -117,10 +122,10 @@ const Header: React.FC = ({ searchQuery, setSearchQuery }) => { - {userInfo.name} + {profile && profile.fullName} - {userInfo.email} + {profile && profile?.email} diff --git a/src/components/dashboard/SideBar.tsx b/src/components/dashboard/SideBar.tsx index a6b1980..c2646ee 100644 --- a/src/components/dashboard/SideBar.tsx +++ b/src/components/dashboard/SideBar.tsx @@ -14,7 +14,8 @@ interface SidebarProps { const SideBar: React.FC = ({ isOpen }) => { const location = useLocation(); - const getLinkClass = (path: string) => (location.pathname === path ? "text-primary" : "text-dark-gray"); + const getLinkClass = (path: string) => + (location.pathname === path ? "text-primary" : "text-dark-gray"); return (
= ({ isOpen }) => {

diff --git a/src/components/dashboard/wishesTable.tsx b/src/components/dashboard/wishesTable.tsx new file mode 100644 index 0000000..eed7cd4 --- /dev/null +++ b/src/components/dashboard/wishesTable.tsx @@ -0,0 +1,100 @@ +import React, { useEffect, useState } from "react"; +import { useDispatch, useSelector } from "react-redux"; + +import { fetchWishes } from "../../redux/reducers/wishListSlice"; +import { RootState, AppDispatch } from "../../redux/store"; + +import Spinner from "./Spinner"; + +const WishesTable: React.FC = () => { + const dispatch: AppDispatch = useDispatch(); + const { wishes, isLoading, error } = useSelector( + (state: RootState) => state.wishes, + ); + useEffect(() => { + const fetchData = async () => { + try { + await dispatch(fetchWishes()); + } catch (error) { + console.error(error); + } + }; + + fetchData(); + }, [dispatch]); + + return ( +
+
+ + + + + + + + + + + + {isLoading ? ( + + + + ) : wishes.length === 0 ? ( + + + + ) : ( + wishes.map((item) => ( + + + + + + + + )) + )} + +
+ Product + + Stock Quantity + + Price + + Buyer + + Email +
+ +
+ No products found. +
+ {item.product.name} + + {item?.product.name} + + + {item.product.stockQuantity} + + {item.product.price} + + {item.user.name} + + {item.user.email} +
+
+
+ ); +}; + +export default WishesTable; diff --git a/src/dashboard/sellers/wishesList.tsx b/src/dashboard/sellers/wishesList.tsx new file mode 100644 index 0000000..8e18053 --- /dev/null +++ b/src/dashboard/sellers/wishesList.tsx @@ -0,0 +1,18 @@ +import Layout from "../../components/layouts/SellerLayout"; +import WishesTable from "../../components/dashboard/wishesTable"; + +const Wishes = () => ( + +
+

Wishes List

+

+ Detailed information about your wished products +

+
+
+ +
+
+); + +export default Wishes; diff --git a/src/pages/ReviewList.tsx b/src/pages/ReviewList.tsx index 42d1fd7..6906162 100644 --- a/src/pages/ReviewList.tsx +++ b/src/pages/ReviewList.tsx @@ -70,7 +70,7 @@ const ReviewsList: React.FC = ({ productId }) => { setNewRating(""); setNewFeedback(""); // @ts-ignore - if (response.error) { + if (response && response.error) { // @ts-ignore toast.error(response.payload.message); } else { diff --git a/src/pages/Wishes.tsx b/src/pages/Wishes.tsx index 390ff32..15d7e0c 100644 --- a/src/pages/Wishes.tsx +++ b/src/pages/Wishes.tsx @@ -10,6 +10,7 @@ import Warning from "../components/common/notify/Warning"; import { deleteWish, fetchWishes } from "../redux/reducers/wishListSlice"; import { RootState, AppDispatch } from "../redux/store"; import { addToCart } from "../redux/reducers/cartSlice"; +import LinkToUpdatePage from "../components/profile/linkToUpdate"; // @ts-ignore const BuyerWishesList: React.FC = () => { @@ -31,7 +32,6 @@ const BuyerWishesList: React.FC = () => { fetchData(); }, [dispatch]); - const handleDeleteWish = async (productId) => { setLoadingWish(productId); try { @@ -75,19 +75,16 @@ const BuyerWishesList: React.FC = () => { return ; } - if (error) { - return ( -
-

{error}

-
- ); - } - return (
-

Home / Wishes

+

+ + Home + + / Wishes +

@@ -107,7 +104,7 @@ const BuyerWishesList: React.FC = () => { {wishes.length === 0 ? ( ) : ( diff --git a/src/pages/updateProfile.tsx b/src/pages/updateProfile.tsx index 63ebe33..64b2600 100644 --- a/src/pages/updateProfile.tsx +++ b/src/pages/updateProfile.tsx @@ -6,6 +6,7 @@ import { useSelector } from "react-redux"; import { ToastContainer, toast } from "react-toastify"; import { AxiosError } from "axios"; import { FaCircleUser } from "react-icons/fa6"; +import { useNavigate } from "react-router-dom"; import LinkPages from "../components/common/auth/LinkPages"; import { RootState } from "../redux/store"; @@ -30,6 +31,7 @@ export const convertUrlToFile = async (url: string): Promise => { const UpdateUserProfile: React.FC = () => { const dispatch = useAppDispatch(); + const navigate = useNavigate(); const { profile } = useSelector((state: RootState) => state.usersProfile); useEffect(() => { // @ts-ignore @@ -77,7 +79,6 @@ const UpdateUserProfile: React.FC = () => { setImagePreview(reader.result as string); }; reader.readAsDataURL(file); - // @ts-ignore setSelectedImage(file); } }; @@ -99,8 +100,7 @@ const UpdateUserProfile: React.FC = () => { const formData = new FormData(); if (selectedImage) { formData.append("profileImage", selectedImage); - } - if (profile?.profileImage) { + } else if (profile?.profileImage) { // @ts-ignore const newFile = await convertUrlToFile(profile.profileImage); formData.append("profileImage", newFile); @@ -137,7 +137,10 @@ const UpdateUserProfile: React.FC = () => { { value: "RWF", label: "RWF" }, { value: "USD", label: "USD" }, ]; - + const loggedInUserToken = localStorage.getItem("accessToken"); + if (!loggedInUserToken) { + navigate("/login"); + } return (
@@ -147,7 +150,7 @@ const UpdateUserProfile: React.FC = () => {

- Home + Home /My Account

@@ -206,11 +209,11 @@ const UpdateUserProfile: React.FC = () => { )} - +
{ dispatch(getProfile()); }, [dispatch]); const loggedInUserToken = localStorage.getItem("accessToken"); - // @ts-ignore - const userData = JSON.parse(atob(loggedInUserToken.split(".")[1])); + if (!loggedInUserToken) { + navigate("/login"); + } if (loading) { return (
@@ -38,8 +39,19 @@ const UsersProfile: React.FC = () => { ); } if (error) { - console.log(error); - navigate("/profile/update"); +
+
+ +
+ +

+ Home + /Profile + {" "} +

+
+

error;

+
; } return (
@@ -50,7 +62,7 @@ const UsersProfile: React.FC = () => {

- Home + Home /Profile {" "}

@@ -72,7 +84,7 @@ const UsersProfile: React.FC = () => {

{profile?.fullName}

-

{userData.email}

+

{profile?.email}

@@ -91,7 +103,7 @@ const UsersProfile: React.FC = () => { {profile && (
- + ) => { state.isLoading = false; + if (!Array.isArray(state.reviews)) { + state.reviews = []; + } state.reviews.push(action.payload); }) .addCase(addReview.rejected, (state, action) => { diff --git a/src/routes/AppRoutes.tsx b/src/routes/AppRoutes.tsx index 30160f4..31a5b3f 100644 --- a/src/routes/AppRoutes.tsx +++ b/src/routes/AppRoutes.tsx @@ -22,12 +22,13 @@ import Analytics from "../dashboard/admin/Analytics"; import Dashboard from "../dashboard/admin/Dashboard"; import CartManagement from "../pages/CartManagement"; import BuyerWishesList from "../pages/Wishes"; -import { setNavigateFunction } from "../redux/api/api"; +// import { setNavigateFunction } from "../redux/api/api"; +import Wishes from "../dashboard/sellers/wishesList"; const AppRoutes = () => { const navigate = useNavigate(); useEffect(() => { - setNavigateFunction(navigate); + // setNavigateFunction(navigate); }, [navigate]); const AlreadyLogged = ({ children }) => { @@ -79,6 +80,7 @@ const AppRoutes = () => { } /> } /> } /> + } /> ); }; diff --git a/type.d.ts b/type.d.ts index d67a736..8f3b4d2 100644 --- a/type.d.ts +++ b/type.d.ts @@ -48,6 +48,7 @@ type passwordType = { export type Profile = { profileImage: string; fullName: string; + email: string; gender: string; birthdate: string; preferredLanguage: string;
- No wishes found + No wishes found 😎