-
Notifications
You must be signed in to change notification settings - Fork 14
/
sellerStats.tsx
70 lines (65 loc) · 2.29 KB
/
sellerStats.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
"use client";
import { useEffect, useState } from "react";
import {
getNumberOfRatingsForTarget,
getStarsForTarget,
getUserNumberOfPurchases,
getUserNumberOfSales,
} from "@/db/utils";
import { User } from "@/db/schema";
import { Star } from "lucide-react";
export default function SellerStats({ seller }: { seller: User }) {
const [numberOfSales, setNumberOfSales] = useState(0); // The number of sales the seller has made
const [numberOfPurchases, setNumberOfPurchases] = useState(0); // The number of purchases the seller has made
const [stars, setStars] = useState<number | null>(null); // The seller's average rating
const [ratingCount, setRatingCount] = useState(0); // The number of ratings the seller has received
/*
On page load and when the seller changes, get the seller's stats and update the state variables
accordingly.
*/
useEffect(() => {
/*
TODO: Get and update the seller's stats.
- The number of sales the seller has made
- The number of purchases the seller has made
- The seller's average rating
- The number of ratings the seller has received
*/
}, [seller]);
return (
<div className="flex flex-row justify-center items-center mb-1">
<span className="text-sm text-gray-500 whitespace-nowrap">
{numberOfSales} Sales
</span>
<span className="text-sm text-gray-500 mx-2">•</span>
<span className="text-sm text-gray-500 whitespace-nowrap">
{numberOfPurchases} Purchases
</span>
<span className="text-sm text-gray-500 mx-2">•</span>
{stars == null ? (
<span className="text-sm text-gray-500 whitespace-nowrap">
No reviews yet
</span>
) : (
<div className="text-sm text-gray-500 flex flex-row gap-2 items-center">
<div className="flex flex-row">
{[1, 2, 3, 4, 5].map((i) => {
return (
<Star
key={i}
size={13}
className={
i <= Math.round(stars)
? "text-gray-500 fill-gray-500"
: "text-gray-500"
}
/>
);
})}
</div>
<span>({ratingCount})</span>
</div>
)}
</div>
);
}