From ba9505ff75d12d9a0ed55e9081fe7198f7cdfc91 Mon Sep 17 00:00:00 2001 From: tchami <131756888+tchamianest@users.noreply.github.com> Date: Thu, 18 Jul 2024 10:33:29 +0200 Subject: [PATCH] bugFix(allPage): Fix all remain bug into champs Bay --- src/app/globals.css | 3 ++ src/app/products/[id]/page.tsx | 58 +++++++++++---------- src/components/Card.tsx | 87 +++++++++++++++++++------------- src/components/DashNavbar.tsx | 4 +- src/components/LatestCard.tsx | 6 ++- src/components/Table.tsx | 35 +++++++++++-- src/components/chartssection.tsx | 61 +++++++++++----------- src/components/singleproduct.tsx | 2 +- src/utils/axios.ts | 2 +- 9 files changed, 160 insertions(+), 98 deletions(-) diff --git a/src/app/globals.css b/src/app/globals.css index 58148d9..2aae8bc 100644 --- a/src/app/globals.css +++ b/src/app/globals.css @@ -29,6 +29,9 @@ body {} .hide-scrollbar::-webkit-scrollbar { display: none; } +.capitalize-first::first-letter { + text-transform: uppercase; +} /* Hide scrollbar for IE, Edge and Firefox */ .hide-scrollbar { diff --git a/src/app/products/[id]/page.tsx b/src/app/products/[id]/page.tsx index 2b54f7d..add074b 100644 --- a/src/app/products/[id]/page.tsx +++ b/src/app/products/[id]/page.tsx @@ -28,23 +28,19 @@ import ReviewWrapper from '@/components/ReviewsWrapper'; //import StripeProvider from '@/components/StripeProvider'; function Page() { - const { wishNumber } = useAppSelector( - (state: RootState) => state.wishlist - ) + const { wishNumber } = useAppSelector((state: RootState) => state.wishlist); const [thumbsSwiper, setThumbsSwiper] = useState(null); - const [addProductToCart, setAddProductToCart]=useState(false) - - const {cart} = useAppSelector( - (state: RootState) => state.userCartData, - ); + const [addProductToCart, setAddProductToCart] = useState(false); + + const { cart } = useAppSelector((state: RootState) => state.userCartData); - const carts=cart as IUSERCART - const { id } :any= useParams(); + const carts = cart as IUSERCART; + const { id }: any = useParams(); const handleSwiper = (swiper: any) => { setThumbsSwiper(swiper); }; const _id: string = id.toLocaleString(); - const { data, isLoading, error , refetch} = useQuery({ + const { data, isLoading, error, refetch } = useQuery({ queryKey: ['product', id], queryFn: async () => { try { @@ -71,17 +67,20 @@ function Page() { const productId = data.product.id; dispatch(handleUserAddCart({ productPrice, productId })); }; - const handleAddRemoveWish = async(event: { preventDefault: () => void; })=>{ + const handleAddRemoveWish = async (event: { preventDefault: () => void }) => { event.preventDefault(); - const response:any = await request.post('/wishes', { productId:id }); - if(response.status == 200 || response.status == 203){ + const response: any = await request.post('/wishes', { productId: id }); + if (response.status == 200 || response.status == 203) { const { status } = response; - dispatch(handleWishlistCount(status == 200 ? await wishNumber + 1 : await wishNumber - 1)); - showToast(response.message, 'success') + dispatch( + handleWishlistCount( + status == 200 ? (await wishNumber) + 1 : (await wishNumber) - 1, + ), + ); + showToast(response.message, 'success'); } - console.log('this is response', response) - - } + + }; return (
{/* // */} @@ -163,18 +162,22 @@ function Page() {
-

+

{productName}

-
+
-
item.product ===data.product.id)) ?' bg-red-500 pointer-events-none':'pointer-events-auto bg-gray-200'}`}> +
item.product === data.product.id) ? ' bg-red-500 pointer-events-none' : 'pointer-events-auto bg-gray-200'}`} + > { handleNewItem(); }} @@ -227,10 +230,13 @@ function Page() {
- +
-
)} @@ -239,4 +245,4 @@ function Page() {
); } -export default Page; \ No newline at end of file +export default Page; diff --git a/src/components/Card.tsx b/src/components/Card.tsx index b8f360f..4146f71 100644 --- a/src/components/Card.tsx +++ b/src/components/Card.tsx @@ -23,57 +23,61 @@ function Card({ id, reviews, }: Cards) { + const [addProductToCart, setAddProductToCart] = useState(false); + const { cart } = useAppSelector((state: RootState) => state.userCartData); - const [addProductToCart, setAddProductToCart]=useState(false) - const {cart} = useAppSelector( - (state: RootState) => state.userCartData, - ); - - const carts=cart as IUSERCART + const carts = cart as IUSERCART; const productId = id; const dispatch = useAppDispatch(); const handleNewItem = () => { - setAddProductToCart(true) + setAddProductToCart(true); dispatch(handleUserAddCart({ productPrice, productId })); - } - const handleImageError = (event: React.SyntheticEvent) => { + }; + const handleImageError = ( + event: React.SyntheticEvent, + ) => { event.currentTarget.src = defaultProductImage.src; }; -const { wishNumber } = useAppSelector( - (state: RootState) => state.wishlist -) + const { wishNumber } = useAppSelector((state: RootState) => state.wishlist); -const handleAddRemoveWish = async(event: { preventDefault: () => void; })=>{ - event.preventDefault(); - const response:any = await request.post('/wishes', { productId:id }); - - if(response.status == 200 || response.status == 203){ - const { status } = response; - dispatch(handleWishlistCount(status == 200 ? await wishNumber + 1 : await wishNumber - 1)); - showToast(response.message, 'success') - } - console.log('this is response', response) - -} + const handleAddRemoveWish = async (event: { preventDefault: () => void }) => { + event.preventDefault(); + const response: any = await request.post('/wishes', { productId: id }); + + if (response.status == 200 || response.status == 203) { + const { status } = response; + dispatch( + handleWishlistCount( + status == 200 ? (await wishNumber) + 1 : (await wishNumber) - 1, + ), + ); + showToast(response.message, 'success'); + } + console.log('this is response', response); + }; return (
- {productName}
-
- {productName.length < 30 ? productName : `${productName.substring(0, 30)}...`} +
+ {productName.length < 30 + ? productName + : `${productName.substring(0, 30)}...`}

- {productDescription.length < 50 ? productDescription : `${productDescription.substring(0, 50)}...`} + {productDescription.length < 50 + ? productDescription + : `${productDescription.substring(0, 50)}...`}

@@ -92,11 +96,26 @@ const handleAddRemoveWish = async(event: { preventDefault: () => void; })=>{
- + - - item.product === id) ? - 'text-red-600 pointer-events-none':'text-gray-600'}`} size={20} onClick={handleNewItem} /> + + item.product === id) + ? 'text-red-600 pointer-events-none' + : 'text-gray-600' + }`} + size={20} + onClick={handleNewItem} + />
diff --git a/src/components/DashNavbar.tsx b/src/components/DashNavbar.tsx index 306172f..aae0e42 100644 --- a/src/components/DashNavbar.tsx +++ b/src/components/DashNavbar.tsx @@ -162,7 +162,7 @@ const DashNavbar: React.FC = ({ role }) => { - + {/*
  • = ({ role }) => { Create Product
  • - + */} )}
    diff --git a/src/components/LatestCard.tsx b/src/components/LatestCard.tsx index 889f4ed..d5e69df 100644 --- a/src/components/LatestCard.tsx +++ b/src/components/LatestCard.tsx @@ -15,7 +15,7 @@ const LatestCard: React.FC = ({ }) => { return (
    -
    +
    = ({
    -

    {name}

    +

    + {name} +

    Price:{price.toLocaleString()} RWF

    diff --git a/src/components/Table.tsx b/src/components/Table.tsx index f961f43..4131c31 100644 --- a/src/components/Table.tsx +++ b/src/components/Table.tsx @@ -61,10 +61,38 @@ const ProductsTable: React.FC = ({ Role }) => {
    ); - if (error) return Error: {error.message}; + if (error) + return ( +
    +
    + {' '} + + + +
    +
    + Not found + No Product Available +
    +
    + ); return ( <>
    +
    + {' '} + + + +
    @@ -103,7 +131,7 @@ const ProductsTable: React.FC = ({ Role }) => { - {data.map( + {data?.map( ( product: { id: string; @@ -129,7 +157,8 @@ const ProductsTable: React.FC = ({ Role }) => {
    {product.productName} {product.stockLevel} - {product.productPrice?.toLocaleString()} {product.productCurrency} + {product.productPrice?.toLocaleString()}{' '} + {product.productCurrency} {product.productDiscount} diff --git a/src/components/chartssection.tsx b/src/components/chartssection.tsx index 8a0fa94..47aeca7 100644 --- a/src/components/chartssection.tsx +++ b/src/components/chartssection.tsx @@ -18,7 +18,6 @@ export const options = { title: '', }; const Chartssection: React.FC = ({ user, data, categories, users }) => { - const ProductCategory = useRef(null); const data1 = [ ['Task', 'Hours per Day'], @@ -34,40 +33,36 @@ const Chartssection: React.FC = ({ user, data, categories, users }) => { ['productsStats', data?.productsStats > 1 ? data?.productsStats : 0.2], ]; - - const mutation = useMutation({ mutationFn: (product_categories: string) => { - return request.post(`/categories`, {categoryName:product_categories}) + return request.post(`/categories`, { categoryName: product_categories }); }, onError: (error: any) => { showToast(error.response.data.error, 'error'); }, - onSuccess: async (result:any) => { - window.location.reload(); - }, - - onSettled: (result, error) => { - showToast(error.response.data.message, 'error'); - }, - }) + onSuccess: async (result: any) => { + window.location.reload(); + }, - const handleAddCategory= async () => { + onSettled: (result, error) => { + showToast(error.response.data.message, 'error'); + }, + }); - const product_categories=ProductCategory.current?.value as string - if(product_categories.length>2){ - - await mutation.mutate(product_categories); - - }else{ - showToast('Product category must be atleast 3 characters length', 'error'); + const handleAddCategory = async () => { + const product_categories = ProductCategory.current?.value as string; + if (product_categories.length > 2) { + await mutation.mutate(product_categories); + } else { + showToast( + 'Product category must be atleast 3 characters length', + 'error', + ); } //alert(product_categories) - }; - return (
    {user && user?.Role?.name === 'seller' ? ( @@ -127,14 +122,22 @@ const Chartssection: React.FC = ({ user, data, categories, users }) => {

    All Categolie On Market

    - -
    - - -
    + {user && user?.Role?.name === 'admin' && ( +
    + + +
    + )}
    -
      {categories && categories?.map((el: any) => ( @@ -157,4 +160,4 @@ const Chartssection: React.FC = ({ user, data, categories, users }) => { ); }; -export default Chartssection; \ No newline at end of file +export default Chartssection; diff --git a/src/components/singleproduct.tsx b/src/components/singleproduct.tsx index 1cc8383..ae1b645 100644 --- a/src/components/singleproduct.tsx +++ b/src/components/singleproduct.tsx @@ -137,7 +137,7 @@ const Singleproduct: React.FC = ({ role }) => {
    -

    +

    {productName}

    diff --git a/src/utils/axios.ts b/src/utils/axios.ts index 698eba5..ffb0441 100644 --- a/src/utils/axios.ts +++ b/src/utils/axios.ts @@ -32,7 +32,7 @@ axiosInstance.interceptors.response.use( if (!error.response) { showToast('Server Network Error!', 'error'); } - if (error.response.status === 401) { + if (error?.response?.status === 401) { if (typeof window !== 'undefined') { localStorage.clear(); window.location.href = '/auth/login';