diff --git a/messages/en.json b/messages/en.json index d7c5b57..25d07b9 100644 --- a/messages/en.json +++ b/messages/en.json @@ -633,9 +633,9 @@ "types": { "MONTHLY_REFRESH": "Monthly Refresh", "REGISTER_GIFT": "Register Gift", - "PURCHASE": "Purchase", - "USAGE": "Usage", - "EXPIRE": "Expire", + "PURCHASE": "Purchased Credits", + "USAGE": "Consumed Credits", + "EXPIRE": "Expired Credits", "SUBSCRIPTION_RENEWAL": "Subscription Renewal", "LIFETIME_MONTHLY": "Lifetime Monthly" }, diff --git a/src/ai/text/components/consume-credit-card.tsx b/src/ai/text/components/consume-credit-card.tsx new file mode 100644 index 0000000..478bf76 --- /dev/null +++ b/src/ai/text/components/consume-credit-card.tsx @@ -0,0 +1,51 @@ +'use client'; + +import { CreditsBalanceButton } from '@/components/layout/credits-balance-button'; +import { Button } from '@/components/ui/button'; +import { useCredits } from '@/hooks/use-credits'; +import { CoinsIcon } from 'lucide-react'; +import { useState } from 'react'; +import { toast } from 'sonner'; + +const CONSUME_CREDITS = 50; + +export function ConsumeCreditCard() { + const { consumeCredits, hasEnoughCredits, isLoading } = useCredits(); + const [loading, setLoading] = useState(false); + + const handleConsume = async () => { + if (!hasEnoughCredits(CONSUME_CREDITS)) { + toast.error('Insufficient credits, please buy more credits.'); + return; + } + setLoading(true); + const success = await consumeCredits( + CONSUME_CREDITS, + `AI Text Credit Consumption (${CONSUME_CREDITS} credits)` + ); + setLoading(false); + if (success) { + toast.success(`${CONSUME_CREDITS} credits have been consumed.`); + } else { + toast.error('Failed to consume credits, please try again later.'); + } + }; + + return ( +
+
+ +
+ +
+ ); +} diff --git a/src/app/[locale]/(marketing)/ai/text/page.tsx b/src/app/[locale]/(marketing)/ai/text/page.tsx index 95982bb..5702bfc 100644 --- a/src/app/[locale]/(marketing)/ai/text/page.tsx +++ b/src/app/[locale]/(marketing)/ai/text/page.tsx @@ -1,3 +1,4 @@ +import { ConsumeCreditCard } from '@/ai/text/components/consume-credit-card'; import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar'; import { constructMetadata } from '@/lib/metadata'; import { getUrlWithLocale } from '@/lib/urls/urls'; @@ -28,7 +29,7 @@ export default async function AITextPage() {
{/* about section */}
-
+
{/* avatar and name */}
@@ -48,6 +49,9 @@ export default async function AITextPage() {
+ + {/* simulate consume credits */} +
diff --git a/src/components/settings/credits/credit-transactions-table.tsx b/src/components/settings/credits/credit-transactions-table.tsx index d9a3d89..9136e5a 100644 --- a/src/components/settings/credits/credit-transactions-table.tsx +++ b/src/components/settings/credits/credit-transactions-table.tsx @@ -223,17 +223,6 @@ export function CreditTransactionsTable({ } }; - // Get transaction type badge variant - const getTransactionTypeBadgeVariant = (type: string) => { - switch (type) { - case CREDIT_TRANSACTION_TYPE.USAGE: - case CREDIT_TRANSACTION_TYPE.EXPIRE: - return 'destructive' as const; - default: - return 'outline' as const; - } - }; - // Get transaction type display name const getTransactionTypeDisplayName = (type: string) => { switch (type) { @@ -268,8 +257,8 @@ export function CreditTransactionsTable({ return (
{getTransactionTypeIcon(transaction.type)} {getTransactionTypeDisplayName(transaction.type)} diff --git a/src/credits/credit-detail-viewer.tsx b/src/credits/credit-detail-viewer.tsx index 7fd36ba..3842313 100644 --- a/src/credits/credit-detail-viewer.tsx +++ b/src/credits/credit-detail-viewer.tsx @@ -70,17 +70,6 @@ export function CreditDetailViewer({ transaction }: CreditDetailViewerProps) { } }; - // Get transaction type badge variant - const getTransactionTypeBadgeVariant = (type: string) => { - switch (type) { - case CREDIT_TRANSACTION_TYPE.USAGE: - case CREDIT_TRANSACTION_TYPE.EXPIRE: - return 'destructive' as const; - default: - return 'outline' as const; - } - }; - // Get transaction type display name const getTransactionTypeDisplayName = (type: string) => { switch (type) { @@ -131,8 +120,8 @@ export function CreditDetailViewer({ transaction }: CreditDetailViewerProps) {
{/* Transaction Type Badge */} {getTransactionTypeIcon(transaction.type)} {getTransactionTypeDisplayName(transaction.type)}