From 2ac0e2061274ad9feb94041ccb8fd3aef70ec121 Mon Sep 17 00:00:00 2001 From: ISHIMWE Ami Paradis <141851169+amiparadis250@users.noreply.github.com> Date: Thu, 11 Jul 2024 11:56:19 +0200 Subject: [PATCH] ft(seller stats) seller should see statics on daily basis - Update pie chart to show Available, Expired, and Other product categories - Ensure percentages always sum to 100% by introducing, -indicating total number of total products, available products , expired products and wished products -Also the percentage is being on indicated regarding total products, available products , expired products and wished products --- src/components/SellerSummary.tsx | 55 +++++++------ src/components/chartssection.tsx | 127 ++++++++++++++++--------------- 2 files changed, 97 insertions(+), 85 deletions(-) diff --git a/src/components/SellerSummary.tsx b/src/components/SellerSummary.tsx index 627610a..cf70057 100644 --- a/src/components/SellerSummary.tsx +++ b/src/components/SellerSummary.tsx @@ -1,5 +1,5 @@ 'use client'; -import React, { useEffect, useState } from 'react'; +import React from 'react'; import ShortCard from '@/components/shortCard'; interface Params { @@ -8,10 +8,20 @@ interface Params { categories: any; users: []; } + const SellerSummary: React.FC = ({ user, data, categories, users }) => { + const calculatePercentage = (part: number, total: number) => { + return total > 0 ? Math.round((part / total) * 100) : 0; + }; + + const totalProducts = data?.productsStats || 0; + const availablePercentage = calculatePercentage(data?.availableProducts || 0, totalProducts); + const expiredPercentage = calculatePercentage(data?.expiredProducts || 0, totalProducts); + const wishedPercentage = calculatePercentage(data?.wishesStats || 0, totalProducts); + return ( -
-
+
+

Today Summary

@@ -19,39 +29,38 @@ const SellerSummary: React.FC = ({ user, data, categories, users }) => {
-
+
{user && user.Role.name === 'seller' ? ( <> - @@ -60,7 +69,7 @@ const SellerSummary: React.FC = ({ user, data, categories, users }) => { <> = ({ user, data, categories, users }) => { ); }; -export default SellerSummary; +export default SellerSummary; \ No newline at end of file diff --git a/src/components/chartssection.tsx b/src/components/chartssection.tsx index 56f0f31..6c6c370 100644 --- a/src/components/chartssection.tsx +++ b/src/components/chartssection.tsx @@ -1,33 +1,40 @@ 'use client'; -import React, { useEffect, useState } from 'react'; +import React from 'react'; import { Chart } from 'react-google-charts'; -import { unstable_noStore as noStore } from 'next/cache'; -import { useQuery } from '@tanstack/react-query'; -import request from '@/utils/axios'; + interface Params { user: any; data: any; categories: any; users: any; } -export const options = { - title: '', -}; + const Chartssection: React.FC = ({ user, data, categories, users }) => { + const totalProducts = data?.productsStats || 0; + + const calculatePercentage = (part: number, total: number) => { + return total > 0 ? Math.round((part / total) * 100) : 0; + }; + const data1 = [ - ['Task', 'Hours per Day'], - [ - 'availableProducts', - data?.availableProducts > 1 ? data?.availableProducts : 0.2, - ], - [ - 'expiredProducts', - data?.expiredProducts > 1 ? data?.expiredProducts : 0.2, - ], - ['wishesStats', data?.wishesStats > 1 ? data?.wishesStats : 0.2], - ['productsStats', data?.productsStats > 1 ? data?.productsStats : 0.2], + ['Category', 'Percentage'], + ['Available Products', calculatePercentage(data?.availableProducts || 0, totalProducts)], + ['Expired Products', calculatePercentage(data?.expiredProducts || 0, totalProducts)], + ['Wished Products', calculatePercentage(data?.wishesStats || 0, totalProducts)], ]; + const options = { + title: 'Product Distribution', + pieHole: 0.4, + is3D: false, + slices: { + 0: { color: '#9CA3AF' }, // gray-400 + 1: { color: '#34D399' }, // green-400 + 2: { color: '#F472B6' }, // pink-400 + }, + legend: { position: 'bottom' }, + }; + return (
{user && user?.Role?.name === 'seller' ? ( @@ -37,70 +44,66 @@ const Chartssection: React.FC = ({ user, data, categories, users }) => { chartType="PieChart" data={data1} options={options} - width={'90%'} - height={'260px'} + width={'100%'} + height={'300px'} />
) : (

- All Markert Users + All Market Users

-
+
    {users && - users?.map((el: any) => ( - <> -
  • -
    -
    -
    -

    - Names : -

    -

    {el.firstName}

    -
    -
    -

    - email : -

    -

    {el.email}

    -
    + users.map((el: any) => ( +
  • +
    +
    +
    +

    + Name: +

    +

    {el.firstName}

    -
    - +
    +

    + Email: +

    +

    {el.email}

    -
  • - +
    + +
    +
+ ))}
)} -
+

- All Categolie On Market + All Categories On Market

-
+
    {categories && - categories?.map((el: any) => ( - <> -
  • -
    -

    - Names : -

    -

    {el.categoryName}

    -
    -
  • - + categories.map((el: any) => ( +
  • +
    +

    + Name: +

    +

    {el.categoryName}

    +
    +
  • ))}
@@ -110,4 +113,4 @@ const Chartssection: React.FC = ({ user, data, categories, users }) => { ); }; -export default Chartssection; +export default Chartssection; \ No newline at end of file