Skip to content

Commit 3bf3ad7

Browse files
committed
top up card only showing production items
1 parent 0b9feef commit 3bf3ad7

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

src/components/interactive/TopUpCard.tsx

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ type Product = {
2222
description?: string | null;
2323
category?: string | null;
2424
stripe_product_id?: string | null;
25+
is_test?: boolean;
2526
};
2627

2728
type Props = {
@@ -30,14 +31,16 @@ type Props = {
3031
category?: string;
3132
limit?: number;
3233
className?: string;
34+
show_test?: boolean;
3335
};
3436

3537
export default function TopUpCard({
3638
directusUrl,
3739
readToken,
3840
category = "topup",
39-
limit = 3,
41+
limit = 10,
4042
className,
43+
show_test = false,
4144
}: Props) {
4245
const [items, setItems] = React.useState<Product[] | null>(null);
4346
const [error, setError] = React.useState<string | null>(null);
@@ -53,7 +56,7 @@ export default function TopUpCard({
5356
try {
5457
setLoading(true);
5558
const params = new URLSearchParams({
56-
fields: "id,name,price,description,category,stripe_product_id",
59+
fields: "id,name,price,description,category,stripe_product_id,is_test",
5760
limit: String(limit),
5861
sort: "price",
5962
});
@@ -76,7 +79,7 @@ export default function TopUpCard({
7679

7780
if (data.length === 0 && category) {
7881
const r = await fetch(
79-
`${directusUrl}/items/product?fields=id,name,price,description,category,stripe_product_id&limit=${limit}&sort=price`,
82+
`${directusUrl}/items/product?fields=id,name,price,description,category,stripe_product_id,is_test&limit=${limit}&sort=price`,
8083
{
8184
signal: controller.signal,
8285
headers: {
@@ -88,7 +91,9 @@ export default function TopUpCard({
8891
data = j.data || [];
8992
}
9093

91-
setItems(data.slice(0, limit));
94+
// Filter test items based on show_test parameter
95+
const filteredData = show_test ? data : data.filter(item => !item.is_test);
96+
setItems(filteredData.slice(0, limit));
9297
setError(null);
9398
} catch (e: any) {
9499
if (e?.name !== "AbortError") setError(e.message || String(e));
@@ -99,7 +104,7 @@ export default function TopUpCard({
99104

100105
load();
101106
return () => controller.abort();
102-
}, [directusUrl, readToken, category, limit]);
107+
}, [directusUrl, readToken, category, limit, show_test]);
103108

104109
const fmt = new Intl.NumberFormat(undefined, {
105110
style: "currency",
@@ -200,11 +205,18 @@ export default function TopUpCard({
200205
return (
201206
<Card key={p.id} className="border bg-white">
202207
<CardHeader className="space-y-2">
203-
{p.category ? (
204-
<Badge variant="outline" className="shrink-0 w-fit">
205-
{p.category}
206-
</Badge>
207-
) : null}
208+
<div className="flex gap-2 flex-wrap">
209+
{p.category ? (
210+
<Badge variant="outline" className="shrink-0 w-fit">
211+
{p.category}
212+
</Badge>
213+
) : null}
214+
{p.is_test ? (
215+
<Badge variant="secondary" className="shrink-0 w-fit">
216+
Test Item
217+
</Badge>
218+
) : null}
219+
</div>
208220
<CardTitle className="text-base">{p.name}</CardTitle>
209221
</CardHeader>
210222

src/pages/dashboard/role-fit-index/top-up/index.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import { EXTERNAL } from "@/constant";
3737
directusUrl={EXTERNAL.directus_url}
3838
readToken={EXTERNAL.directus_key}
3939
category="topup"
40-
limit={4}
40+
limit={10}
4141
/>
4242

4343
<PaymentEventTable

0 commit comments

Comments
 (0)