refactor: add disabled to credits config

This commit is contained in:
javayhu 2025-07-10 16:30:56 +08:00
parent bbae584c88
commit 6c1a4685cd
5 changed files with 8 additions and 22 deletions

View File

@ -604,8 +604,7 @@
"purchaseFailed": "Purchase credits failed",
"checkoutFailed": "Failed to create checkout session",
"loading": "Loading...",
"pay": "Pay",
"notConfigured": "Not configured"
"pay": "Pay"
},
"tabs": {
"balance": "Balance",

View File

@ -605,8 +605,7 @@
"purchaseFailed": "购买积分失败",
"checkoutFailed": "创建支付会话失败",
"loading": "加载中...",
"pay": "支付",
"notConfigured": "未配置"
"pay": "支付"
},
"tabs": {
"balance": "积分余额",

View File

@ -53,20 +53,6 @@ export function CreditCheckoutButton({
try {
setIsLoading(true);
// Get the credit package to find the priceId
// const creditPackages = getCreditPackages();
// const creditPackage = creditPackages[packageId];
// if (!creditPackage) {
// toast.error('Invalid credit package');
// return;
// }
// if (!creditPackage.price.priceId) {
// toast.error(t('notConfigured'));
// return;
// }
const mergedMetadata = metadata ? { ...metadata } : {};
// add promotekit_referral to metadata if enabled promotekit affiliate

View File

@ -35,7 +35,10 @@ export function CreditPackages() {
const searchParams = useSearchParams();
const router = useLocaleRouter();
const creditPackages = Object.values(getCreditPackages());
// show only enabled packages
const creditPackages = Object.values(getCreditPackages()).filter(
(pkg) => !pkg.disabled && pkg.price.priceId
);
const fetchCredits = async () => {
try {
@ -168,9 +171,7 @@ export function CreditPackages() {
variant={creditPackage.popular ? 'default' : 'outline'}
disabled={!creditPackage.price.priceId}
>
{!creditPackage.price.priceId
? t('notConfigured')
: t('purchase')}
{t('purchase')}
</CreditCheckoutButton>
</CardContent>
</Card>

View File

@ -32,4 +32,5 @@ export interface CreditPackage {
name?: string; // Display name of the package
description?: string; // Description of the package
expireDays?: number; // Number of days to expire the credits, undefined means no expire
disabled?: boolean; // Whether the package is disabled in the UI
}