Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ft(seller stats) seller should see statics on daily basis-#187300236 #60

Merged
merged 2 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 120 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 9 additions & 8 deletions src/app/dashboard/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,19 @@ function Page() {
noStore();
let data;
const date = new Date();
const dataDateNow = date
.toLocaleDateString()
.replaceAll('/', '-')
.split('-');
const response: any = await request.get(
`/stats?start=2023-02-06&end=${dataDateNow[2]}-${dataDateNow[0].length > 1 ? dataDateNow[0] : '0' + dataDateNow[0]}-${dataDateNow[1].length > 1 ? dataDateNow[1] : '0' + dataDateNow[1]}`,
);
const year = date.getFullYear();
const month = (date.getMonth() + 1).toString().padStart(2, '0');
const day = date.getDate().toString().padStart(2, '0');
const formattedDate = `${year}-${month}-${day}`;

const response: any = await request.get(`/stats?start=2023-02-06&end=${formattedDate}`);
data = response.data;

console.log("............", data);
console.log("statics are recorded properly here ...........................");
return data;
},
});


useEffect(() => {
const categ = async () => {
Expand Down
55 changes: 32 additions & 23 deletions src/components/SellerSummary.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use client';
import React, { useEffect, useState } from 'react';
import React from 'react';
import ShortCard from '@/components/shortCard';

interface Params {
Expand All @@ -8,50 +8,59 @@ interface Params {
categories: any;
users: [];
}

const SellerSummary: React.FC<Params> = ({ 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 (
<div className="flex justify-between border-[1px] p-5 sm:w-[80%] w-[90%]">
<div className="flex flex-col p-3 w-full ">
<div className="flex justify-between border-[1px] p-5 sm:w-[80%] w-[90%]">
<div className="flex flex-col p-3 w-full">
<div className="flex justify-between w-full">
<div>
<h1 className="font-semibold">Today Summary</h1>
<p className="pl-2">seller summary</p>
</div>
</div>

<div className="grid sm:grid-cols-4 grid-cols-2 p-2 sm:gap-4 gap-1 w-full">
<div className="grid sm:grid-cols-4 grid-cols-2 p-2 sm:gap-4 gap-1 w-full">
{user && user.Role.name === 'seller' ? (
<>
<ShortCard
imagelink="/wishdash.png"
name="Total whishers"
number={data?.wishesStats}
bgcolor="bg-pink-400"
imagelink="/dash2.png"
name="Total Products"
number={totalProducts}
bgcolor="bg-blue-400"
numbercolor="text-black"
namecolor="text-black"
/>
<ShortCard
imagelink="/orderdash.png"
name="Expired product"
number={`${data?.expiredProducts}`}
bgcolor="bg-green-400"
imagelink="/dash1.png"
name="Available Products"
number={`${availablePercentage}% (${data?.availableProducts})`}
bgcolor="bg-gray-400"
numbercolor="text-black"
namecolor="text-black"
/>

<ShortCard
imagelink="/dash1.png"
name="available Products"
number={data?.availableProducts}
bgcolor="bg-gray-400"
imagelink="/wishdash.png"
name="Wished Products"
number={`${wishedPercentage}% (${data?.wishesStats})`}
bgcolor="bg-pink-400"
numbercolor="text-black"
namecolor="text-black"
/>
<ShortCard
imagelink="/dash2.png"
name="stockLevel Stats"
number={data?.stockLevelStats}
bgcolor="bg-blue-400"
imagelink="/orderdash.png"
name="Expired Products"
number={`${expiredPercentage}% (${data?.expiredProducts})`}
bgcolor="bg-green-400"
numbercolor="text-black"
namecolor="text-black"
/>
Expand All @@ -60,7 +69,7 @@ const SellerSummary: React.FC<Params> = ({ user, data, categories, users }) => {
<>
<ShortCard
imagelink="/wishdash.png"
name="Categories Available "
name="Categories Available"
number={`${categories?.length}`}
bgcolor="bg-pink-400"
numbercolor="text-black"
Expand All @@ -82,4 +91,4 @@ const SellerSummary: React.FC<Params> = ({ user, data, categories, users }) => {
);
};

export default SellerSummary;
export default SellerSummary;
Loading