Add translations to the full credits and onboarding flows

This commit is contained in:
Alex Gleason committed 2025-11-03 12:43:47 -06:00
1 parent 37f2d937d8
commit 2399a618c7
5 files changed
+859 -151

No files matched your search

+90 -87
View File
@@ -2,6 +2,7 @@ import { useState, useEffect } from 'react';
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
import QRCode from 'qrcode';
import { CreditCard, Zap, ExternalLink, RefreshCw, Check, X, Clock, AlertCircle, Copy, RotateCcw, ArrowLeft, Gift, Plus, History, DollarSign, Printer, Download } from 'lucide-react';
import { useTranslation } from 'react-i18next';
import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
@@ -88,6 +89,7 @@ interface LightningPaymentProps {
}
function LightningPayment({ invoice, amount, onClose }: LightningPaymentProps) {
const { t } = useTranslation();
const [qrDataUrl, setQrDataUrl] = useState<string>('');
const [isWebLNAvailable, setIsWebLNAvailable] = useState(false);
const [isPayingWithWebLN, setIsPayingWithWebLN] = useState(false);
@@ -120,16 +122,16 @@ function LightningPayment({ invoice, amount, onClose }: LightningPaymentProps) {
await window.webln.sendPayment(invoice);
toast({
title: 'Payment sent!',
description: 'Your Lightning payment has been sent successfully.',
title: t('paymentSent'),
description: t('lightningPaymentSent'),
});
onClose();
} catch (error) {
console.error('WebLN payment failed:', error);
toast({
title: 'Payment failed',
description: error instanceof Error ? error.message : 'Failed to send Lightning payment',
title: t('paymentFailed'),
description: error instanceof Error ? error.message : t('failedToSendLightning'),
variant: 'destructive',
});
} finally {
@@ -155,9 +157,9 @@ function LightningPayment({ invoice, amount, onClose }: LightningPaymentProps) {
return (
<div className="space-y-4">
<div className="text-center">
<h3 className="text-lg font-semibold mb-2">Lightning Payment</h3>
<h3 className="text-lg font-semibold mb-2">{t('lightningPayment')}</h3>
<p className="text-sm text-muted-foreground">
Pay {formatCurrency(amount)} with Lightning Network
{t('payWithLightning', { amount: formatCurrency(amount) })}
</p>
</div>
@@ -185,7 +187,7 @@ function LightningPayment({ invoice, amount, onClose }: LightningPaymentProps) {
>
{isPayingWithWebLN && <RefreshCw className="h-4 w-4 mr-2 animate-spin" />}
<Zap className="h-4 w-4 mr-2" />
Pay with WebLN
{t('payWithWebLN')}
</Button>
)}
@@ -197,11 +199,11 @@ function LightningPayment({ invoice, amount, onClose }: LightningPaymentProps) {
size="lg"
>
<Copy className="h-4 w-4 mr-2" />
Copy Invoice
{t('copyInvoice')}
</Button>
{showCopiedTooltip && (
<div className="absolute -top-10 left-1/2 transform -translate-x-1/2 bg-foreground text-background text-xs px-2 py-1 rounded shadow-lg z-10 animate-in fade-in-0 duration-200">
Copied!
{t('copied')}
<div className="absolute top-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-l-4 border-r-4 border-t-4 border-transparent border-t-foreground"></div>
</div>
)}
@@ -212,6 +214,7 @@ function LightningPayment({ invoice, amount, onClose }: LightningPaymentProps) {
}
export function CreditsDialog({ open, onOpenChange, provider }: CreditsDialogProps) {
const { t } = useTranslation();
const { user } = useCurrentUser();
const { config } = useAppContext();
const { toast } = useToast();
@@ -292,8 +295,8 @@ export function CreditsDialog({ open, onOpenChange, provider }: CreditsDialogPro
// Open Stripe checkout in new window
window.open(payment.url, '_blank');
toast({
title: 'Payment initiated',
description: 'Stripe checkout opened in a new window.',
title: t('paymentInitiated'),
description: t('stripeCheckoutOpened'),
});
} else if (payment.method === 'lightning') {
// Show Lightning payment interface
@@ -311,9 +314,9 @@ export function CreditsDialog({ open, onOpenChange, provider }: CreditsDialogPro
});
},
onError: (error: Error) => {
const errorMessage = error?.message || 'Failed to initiate payment';
const errorMessage = error?.message || t('paymentFailed');
toast({
title: 'Payment failed',
title: t('paymentFailed'),
description: errorMessage,
variant: 'destructive',
});
@@ -355,19 +358,19 @@ export function CreditsDialog({ open, onOpenChange, provider }: CreditsDialogPro
queryKey: ['ai-credits', provider.nostr ? user?.pubkey ?? '' : '', provider.id],
});
toast({
title: 'Payment completed!',
description: `${formatCurrency(updatedPayment.amount)} has been added to your account.`,
title: t('paymentCompleted'),
description: t('creditsAddedToAccount', { amount: formatCurrency(updatedPayment.amount) }),
});
} else if (updatedPayment.status === 'failed') {
toast({
title: 'Payment failed',
description: 'The payment has failed. Please try again.',
title: t('paymentFailed'),
description: t('paymentFailed'),
variant: 'destructive',
});
} else if (updatedPayment.status === 'expired') {
toast({
title: 'Payment expired',
description: 'The payment has expired. Please create a new payment.',
title: t('paymentExpired'),
description: t('paymentExpiredMessage'),
variant: 'destructive',
});
}
@@ -380,9 +383,9 @@ export function CreditsDialog({ open, onOpenChange, provider }: CreditsDialogPro
return newSet;
});
const errorMessage = error?.message || 'Failed to check payment status';
const errorMessage = error?.message || t('failedToCheckPaymentStatus');
toast({
title: 'Refresh failed',
title: t('refreshFailed'),
description: errorMessage,
variant: 'destructive',
});
@@ -400,8 +403,8 @@ export function CreditsDialog({ open, onOpenChange, provider }: CreditsDialogPro
},
onSuccess: (giftcards) => {
toast({
title: 'Gift Cards created!',
description: `Successfully created ${giftcards.length} gift card${giftcards.length > 1 ? 's' : ''}.`,
title: t('giftCardCreated'),
description: t('successfullyCreatedGiftCards', { count: giftcards.length }),
});
// Refresh gift cards list
@@ -419,9 +422,9 @@ export function CreditsDialog({ open, onOpenChange, provider }: CreditsDialogPro
setGiftcardQuantity(1);
},
onError: (error: Error) => {
const errorMessage = error?.message || 'Failed to create gift cards';
const errorMessage = error?.message || t('failedToCreateGiftCards');
toast({
title: 'Creation failed',
title: t('creationFailed'),
description: errorMessage,
variant: 'destructive',
});
@@ -438,8 +441,8 @@ export function CreditsDialog({ open, onOpenChange, provider }: CreditsDialogPro
},
onSuccess: (redemption) => {
toast({
title: 'Gift Card redeemed!',
description: `${formatCurrency(redemption.amount)} has been added to your account.`,
title: t('giftCardRedeemed'),
description: t('creditsAddedToAccount', { amount: formatCurrency(redemption.amount) }),
});
// Refresh credits balance
@@ -451,9 +454,9 @@ export function CreditsDialog({ open, onOpenChange, provider }: CreditsDialogPro
setRedeemCode('');
},
onError: (error: Error) => {
const errorMessage = error?.message || 'Failed to redeem gift card';
const errorMessage = error?.message || t('failedToRedeemGiftCard');
toast({
title: 'Redemption failed',
title: t('redemptionFailed'),
description: errorMessage,
variant: 'destructive',
});
@@ -463,8 +466,8 @@ export function CreditsDialog({ open, onOpenChange, provider }: CreditsDialogPro
const handleAddCredits = () => {
if (amount <= 0) {
toast({
title: 'Invalid amount',
description: 'Please enter a valid amount.',
title: t('invalidAmount'),
description: t('enterValidAmount'),
variant: 'destructive',
});
return;
@@ -477,8 +480,8 @@ export function CreditsDialog({ open, onOpenChange, provider }: CreditsDialogPro
// Open Stripe checkout in new window
window.open(paymentPreview.url, '_blank');
toast({
title: 'Payment initiated',
description: 'Stripe checkout opened in a new window.',
title: t('paymentInitiated'),
description: t('stripeCheckoutOpened'),
});
} else if (paymentPreview.method === 'lightning') {
// Show Lightning payment interface
@@ -517,8 +520,8 @@ export function CreditsDialog({ open, onOpenChange, provider }: CreditsDialogPro
const handleCreateGiftcard = () => {
if (giftcardAmount <= 0) {
toast({
title: 'Invalid amount',
description: 'Please enter a valid amount.',
title: t('invalidAmount'),
description: t('enterValidAmount'),
variant: 'destructive',
});
return;
@@ -526,8 +529,8 @@ export function CreditsDialog({ open, onOpenChange, provider }: CreditsDialogPro
if (giftcardQuantity <= 0 || giftcardQuantity > 100) {
toast({
title: 'Invalid quantity',
description: 'Quantity must be between 1 and 100.',
title: t('invalidQuantity'),
description: t('quantityBetween'),
variant: 'destructive',
});
return;
@@ -543,8 +546,8 @@ export function CreditsDialog({ open, onOpenChange, provider }: CreditsDialogPro
const trimmedCode = redeemCode.trim();
if (!trimmedCode) {
toast({
title: 'Invalid code',
description: 'Please enter a gift card code.',
title: t('invalidCode'),
description: t('enterGiftCardCodePrompt'),
variant: 'destructive',
});
return;
@@ -573,8 +576,8 @@ export function CreditsDialog({ open, onOpenChange, provider }: CreditsDialogPro
const activeGiftcards = giftcards.filter(gc => !gc.redeemed);
if (activeGiftcards.length === 0) {
toast({
title: 'No active gift cards',
description: 'You have no active gift cards to print.',
title: t('noActiveGiftCards'),
description: t('noActiveGiftCardsToPrint'),
variant: 'destructive',
});
return;
@@ -605,7 +608,7 @@ export function CreditsDialog({ open, onOpenChange, provider }: CreditsDialogPro
// Create a new window for printing
const printWindow = window.open('', '_blank');
if (!printWindow) {
throw new Error('Failed to open print window. Please allow popups for this site.');
throw new Error(t('failedToOpenPrintWindow'));
}
// Generate the print HTML
@@ -725,8 +728,8 @@ export function CreditsDialog({ open, onOpenChange, provider }: CreditsDialogPro
} catch (error) {
console.error('Failed to generate QR codes:', error);
toast({
title: 'Print failed',
description: error instanceof Error ? error.message : 'Failed to generate QR codes for printing',
title: t('printFailed'),
description: error instanceof Error ? error.message : t('failedToGenerateQRCodes'),
variant: 'destructive',
});
} finally {
@@ -741,8 +744,8 @@ export function CreditsDialog({ open, onOpenChange, provider }: CreditsDialogPro
const activeGiftcards = giftcards.filter(gc => !gc.redeemed);
if (activeGiftcards.length === 0) {
toast({
title: 'No active gift cards',
description: 'You have no active gift cards to download.',
title: t('noActiveGiftCards'),
description: t('noActiveGiftCardsToDownload'),
variant: 'destructive',
});
return;
@@ -794,14 +797,14 @@ export function CreditsDialog({ open, onOpenChange, provider }: CreditsDialogPro
URL.revokeObjectURL(url);
toast({
title: 'CSV downloaded',
description: `Downloaded ${activeGiftcards.length} gift card${activeGiftcards.length > 1 ? 's' : ''}.`,
title: t('csvDownloaded'),
description: t('downloadedGiftCards', { count: activeGiftcards.length }),
});
} catch (error) {
console.error('Failed to generate CSV:', error);
toast({
title: 'Download failed',
description: error instanceof Error ? error.message : 'Failed to generate CSV file',
title: t('downloadFailed'),
description: error instanceof Error ? error.message : t('failedToGenerateCSV'),
variant: 'destructive',
});
}
@@ -827,7 +830,7 @@ export function CreditsDialog({ open, onOpenChange, provider }: CreditsDialogPro
minute: '2-digit',
}).format(date);
} else if (diffDays === 1) {
return 'Yesterday';
return t('yesterday');
} else if (diffDays < 7) {
return new Intl.DateTimeFormat('en-US', {
weekday: 'short',
@@ -866,13 +869,13 @@ export function CreditsDialog({ open, onOpenChange, provider }: CreditsDialogPro
className="flex items-center gap-2 hover:opacity-70 transition-opacity"
>
<ArrowLeft className="h-5 w-5" />
Back
{t('back')}
</button>
</>
) : (
<>
<CreditCard className="h-5 w-5" />
Credits
{t('credits')}
</>
)}
</DialogTitle>
@@ -895,13 +898,13 @@ export function CreditsDialog({ open, onOpenChange, provider }: CreditsDialogPro
<AccordionTrigger className="hover:no-underline">
<div className="flex items-center gap-2">
<DollarSign className="h-4 w-4" />
Buy Credits
{t('buyCredits')}
</div>
</AccordionTrigger>
<AccordionContent>
<div className="space-y-3 pt-2">
<div className="space-y-3">
<Label htmlFor="amount" className="text-sm font-medium">Amount (USD)</Label>
<Label htmlFor="amount" className="text-sm font-medium">{t('amountUSD')}</Label>
<div className="space-y-3">
<Input
id="amount"
@@ -909,7 +912,7 @@ export function CreditsDialog({ open, onOpenChange, provider }: CreditsDialogPro
step="0.01"
value={amount}
onChange={(e) => setAmount(Number(e.target.value))}
placeholder="Enter amount"
placeholder={t('enterAmount')}
className="text-center text-lg font-medium"
/>
<div className="grid grid-cols-5 gap-2">
@@ -929,16 +932,16 @@ export function CreditsDialog({ open, onOpenChange, provider }: CreditsDialogPro
</div>
<div className="space-y-3">
<Label className="text-sm font-medium">Payment Method</Label>
<Label className="text-sm font-medium">{t('paymentMethod')}</Label>
<Tabs value={paymentMethod} onValueChange={(value: 'stripe' | 'lightning') => setPaymentMethod(value)} className="w-full">
<TabsList className="grid w-full grid-cols-2">
<TabsTrigger value="stripe" className="flex items-center gap-2">
<CreditCard className="h-4 w-4" />
Credit Card
{t('creditCard')}
</TabsTrigger>
<TabsTrigger value="lightning" className="flex items-center gap-2">
<Zap className="h-4 w-4" />
Lightning
{t('lightning')}
</TabsTrigger>
</TabsList>
</Tabs>
@@ -948,15 +951,15 @@ export function CreditsDialog({ open, onOpenChange, provider }: CreditsDialogPro
{paymentPreview && paymentPreview.fee > 0 && (
<div className="space-y-1 text-sm">
<div className="flex justify-between text-muted-foreground">
<span>Credits</span>
<span>{t('credits')}</span>
<span>{formatCurrency(paymentPreview.amount)}</span>
</div>
<div className="flex justify-between text-muted-foreground">
<span>Processing Fee</span>
<span>{t('processingFee')}</span>
<span>{formatCurrency(paymentPreview.fee)}</span>
</div>
<div className="flex justify-between font-medium pt-1 border-t">
<span>Total</span>
<span>{t('total')}</span>
<span>{formatCurrency(paymentPreview.total)}</span>
</div>
</div>
@@ -969,7 +972,7 @@ export function CreditsDialog({ open, onOpenChange, provider }: CreditsDialogPro
size="lg"
>
{(addCreditsMutation.isPending || isLoadingPreview) && <RefreshCw className="h-4 w-4 mr-2 animate-spin" />}
{paymentMethod === 'stripe' ? 'Pay with Card' : 'Generate Invoice'}
{paymentMethod === 'stripe' ? t('payWithCard') : t('generateInvoice')}
{paymentPreview && paymentPreview.fee > 0
? ` - ${formatCurrency(paymentPreview.total)}`
: amount > 0
@@ -986,7 +989,7 @@ export function CreditsDialog({ open, onOpenChange, provider }: CreditsDialogPro
<AccordionTrigger className="hover:no-underline">
<div className="flex items-center gap-2">
<History className="h-4 w-4" />
Recent Transactions
{t('recentTransactions')}
</div>
</AccordionTrigger>
<AccordionContent>
@@ -1003,8 +1006,8 @@ export function CreditsDialog({ open, onOpenChange, provider }: CreditsDialogPro
) : !payments || payments.length === 0 ? (
<div className="py-8 text-center text-muted-foreground">
<CreditCard className="h-10 w-10 mx-auto mb-3 opacity-50" />
<p className="text-sm">No transactions yet</p>
<p className="text-xs">Your payment history will appear here</p>
<p className="text-sm">{t('noTransactionsYet')}</p>
<p className="text-xs">{t('paymentHistoryAppears')}</p>
</div>
) : (
<div className="space-y-2">
@@ -1017,7 +1020,7 @@ export function CreditsDialog({ open, onOpenChange, provider }: CreditsDialogPro
<div className="flex items-center gap-2 min-w-0 flex-1">
{getStatusIcon(payment.status)}
<span className="text-sm font-medium truncate">
{payment.method === 'stripe' ? 'Credit Card' : 'Lightning'}
{payment.method === 'stripe' ? t('creditCard') : t('lightning')}
</span>
</div>
<div className="text-right flex-shrink-0">
@@ -1058,7 +1061,7 @@ export function CreditsDialog({ open, onOpenChange, provider }: CreditsDialogPro
className="h-6 px-2 text-xs"
>
<ExternalLink className="h-3 w-3 mr-1" />
{payment.method === 'lightning' ? 'Pay' : 'Pay'}
{t('pay')}
</Button>
)}
</div>
@@ -1077,7 +1080,7 @@ export function CreditsDialog({ open, onOpenChange, provider }: CreditsDialogPro
<AccordionTrigger className="hover:no-underline">
<div className="flex items-center gap-2">
<Plus className="h-4 w-4" />
Redeem Gift Card
{t('redeemGiftCard')}
</div>
</AccordionTrigger>
<AccordionContent>
@@ -1088,7 +1091,7 @@ export function CreditsDialog({ open, onOpenChange, provider }: CreditsDialogPro
type="text"
value={redeemCode}
onChange={(e) => setRedeemCode(e.target.value)}
placeholder="Enter gift card code"
placeholder={t('enterGiftCardCode')}
className="flex-1"
/>
<Button
@@ -1097,7 +1100,7 @@ export function CreditsDialog({ open, onOpenChange, provider }: CreditsDialogPro
size="lg"
>
{redeemGiftcardMutation.isPending && <RefreshCw className="h-4 w-4 mr-2 animate-spin" />}
Redeem
{t('redeem')}
</Button>
</div>
</div>
@@ -1109,26 +1112,26 @@ export function CreditsDialog({ open, onOpenChange, provider }: CreditsDialogPro
<AccordionTrigger className="hover:no-underline">
<div className="flex items-center gap-2">
<Gift className="h-4 w-4" />
Create Gift Card
{t('createGiftCard')}
</div>
</AccordionTrigger>
<AccordionContent>
<div className="space-y-3 pt-2">
<div className="grid grid-cols-2 gap-2">
<div className="space-y-2">
<Label htmlFor="giftcard-amount" className="text-xs text-muted-foreground">Amount (USD)</Label>
<Label htmlFor="giftcard-amount" className="text-xs text-muted-foreground">{t('amountUSD')}</Label>
<Input
id="giftcard-amount"
type="number"
step="0.01"
value={giftcardAmount}
onChange={(e) => setGiftcardAmount(Number(e.target.value))}
placeholder="Amount"
placeholder={t('enterAmount')}
className="text-center"
/>
</div>
<div className="space-y-2">
<Label htmlFor="giftcard-quantity" className="text-xs text-muted-foreground">Quantity</Label>
<Label htmlFor="giftcard-quantity" className="text-xs text-muted-foreground">{t('quantity')}</Label>
<Input
id="giftcard-quantity"
type="number"
@@ -1136,7 +1139,7 @@ export function CreditsDialog({ open, onOpenChange, provider }: CreditsDialogPro
max="100"
value={giftcardQuantity}
onChange={(e) => setGiftcardQuantity(Number(e.target.value))}
placeholder="Qty"
placeholder={t('qty')}
className="text-center"
/>
</div>
@@ -1161,7 +1164,7 @@ export function CreditsDialog({ open, onOpenChange, provider }: CreditsDialogPro
size="lg"
>
{createGiftcardMutation.isPending && <RefreshCw className="h-4 w-4 mr-2 animate-spin" />}
Create {giftcardQuantity > 1 ? `${giftcardQuantity} ` : ''}Gift Card{giftcardQuantity > 1 ? 's' : ''}
{t('createGiftCards', { count: giftcardQuantity })}
{giftcardAmount > 0 && giftcardQuantity > 0 && ` - ${formatCurrency(giftcardAmount * giftcardQuantity)}`}
</Button>
</div>
@@ -1173,7 +1176,7 @@ export function CreditsDialog({ open, onOpenChange, provider }: CreditsDialogPro
<AccordionTrigger className="hover:no-underline">
<div className="flex items-center gap-2">
<CreditCard className="h-4 w-4" />
Your Gift Cards
{t('yourGiftCards')}
</div>
</AccordionTrigger>
<AccordionContent className="pb-0">
@@ -1191,7 +1194,7 @@ export function CreditsDialog({ open, onOpenChange, provider }: CreditsDialogPro
) : (
<Printer className="h-4 w-4 mr-2" />
)}
Print QR Codes
{t('printQRCodes')}
</Button>
<Button
onClick={handleDownloadCSV}
@@ -1199,7 +1202,7 @@ export function CreditsDialog({ open, onOpenChange, provider }: CreditsDialogPro
size="sm"
>
<Download className="h-4 w-4 mr-2" />
Download CSV
{t('downloadCSV')}
</Button>
</div>
)}
@@ -1215,8 +1218,8 @@ export function CreditsDialog({ open, onOpenChange, provider }: CreditsDialogPro
) : !giftcards || giftcards.length === 0 ? (
<div className="py-8 text-center text-muted-foreground">
<Gift className="h-10 w-10 mx-auto mb-3 opacity-50" />
<p className="text-sm">No gift cards yet</p>
<p className="text-xs">Create gift cards to share with others</p>
<p className="text-sm">{t('noGiftCardsYet')}</p>
<p className="text-xs">{t('createGiftCardsToShare')}</p>
</div>
) : (
<div className="space-y-2">
@@ -1229,10 +1232,10 @@ export function CreditsDialog({ open, onOpenChange, provider }: CreditsDialogPro
<div className="flex items-center gap-2 min-w-0 flex-1">
<Gift className="h-4 w-4 flex-shrink-0" />
<span className="text-sm font-medium truncate">
Gift Card
{t('giftCard')}
</span>
<Badge variant={giftcard.redeemed ? "secondary" : "default"} className="text-xs flex-shrink-0">
{giftcard.redeemed ? 'Redeemed' : 'Active'}
{giftcard.redeemed ? t('redeemed') : t('active')}
</Badge>
</div>
<div className="text-right flex-shrink-0">
@@ -1252,11 +1255,11 @@ export function CreditsDialog({ open, onOpenChange, provider }: CreditsDialogPro
className="h-6 px-2 text-xs"
>
<Copy className="h-3 w-3 mr-1" />
Copy
{t('copy')}
</Button>
{copiedCode === giftcard.code && (
<div className="absolute -top-8 right-0 bg-foreground text-background text-xs px-2 py-1 rounded shadow-lg z-10 animate-in fade-in-0 duration-200 whitespace-nowrap">
Copied!
{t('copied')}
</div>
)}
</div>
@@ -1264,7 +1267,7 @@ export function CreditsDialog({ open, onOpenChange, provider }: CreditsDialogPro
{giftcard.created_at && (
<div className="text-xs text-muted-foreground">
Created {formatDate(giftcard.created_at)}
{t('created')} {formatDate(giftcard.created_at)}
</div>
)}
</div>
+23 -21
View File
@@ -2,6 +2,7 @@ import { useState, useEffect } from 'react';
import { useNavigate } from 'react-router-dom';
import { useMutation, useQuery } from '@tanstack/react-query';
import { Gift, Check, LogIn, Settings as SettingsIcon } from 'lucide-react';
import { useTranslation } from 'react-i18next';
import { Dialog, DialogContent } from '@/components/ui/dialog';
import { Button } from '@/components/ui/button';
import { Skeleton } from '@/components/ui/skeleton';
@@ -63,6 +64,7 @@ type Step = 'preview' | 'login' | 'provider';
* @param code - Gift card code to redeem (e.g., XXXX-XXXX-XXXX-XXXX)
*/
export function GiftCardRedeemDialog({ open, onOpenChange, baseURL, code }: GiftCardRedeemDialogProps) {
const { t } = useTranslation();
const { user } = useCurrentUser();
const { settings } = useAISettings();
const { config } = useAppContext();
@@ -106,8 +108,8 @@ export function GiftCardRedeemDialog({ open, onOpenChange, baseURL, code }: Gift
},
onSuccess: (redemption) => {
toast({
title: '🎉 Gift card redeemed!',
description: `${formatCurrency(redemption.amount)} has been added to your account.`,
title: '🎉 ' + t('giftCardRedeemed'),
description: t('creditsAddedToAccount', { amount: formatCurrency(redemption.amount) }),
});
onOpenChange(false);
// Navigate to AI settings to show the new credits
@@ -115,8 +117,8 @@ export function GiftCardRedeemDialog({ open, onOpenChange, baseURL, code }: Gift
},
onError: (error: Error) => {
toast({
title: 'Redemption failed',
description: error.message || 'Failed to redeem gift card',
title: t('redemptionFailed'),
description: error.message || t('failedToRedeemGiftCard'),
variant: 'destructive',
});
},
@@ -204,12 +206,12 @@ export function GiftCardRedeemDialog({ open, onOpenChange, baseURL, code }: Gift
<div className="mb-4">
<Gift className="h-16 w-16 mx-auto text-muted-foreground opacity-50" />
</div>
<h2 className="text-2xl font-bold mb-2">Invalid Gift Card</h2>
<h2 className="text-2xl font-bold mb-2">{t('invalidGiftCard')}</h2>
<p className="text-muted-foreground">
{giftcardError instanceof Error ? giftcardError.message : 'This gift card could not be found.'}
{giftcardError instanceof Error ? giftcardError.message : t('giftCardNotFound')}
</p>
<Button onClick={() => onOpenChange(false)} className="mt-6">
Close
{t('close')}
</Button>
</div>
</DialogContent>
@@ -242,12 +244,12 @@ export function GiftCardRedeemDialog({ open, onOpenChange, baseURL, code }: Gift
<div className="mb-4">
<Check className="h-16 w-16 mx-auto text-green-500" />
</div>
<h2 className="text-2xl font-bold mb-2">Already Redeemed</h2>
<h2 className="text-2xl font-bold mb-2">{t('alreadyRedeemed')}</h2>
<p className="text-muted-foreground">
This gift card has already been redeemed.
{t('giftCardAlreadyRedeemed')}
</p>
<Button onClick={() => onOpenChange(false)} className="mt-6">
Close
{t('close')}
</Button>
</div>
</DialogContent>
@@ -273,12 +275,12 @@ export function GiftCardRedeemDialog({ open, onOpenChange, baseURL, code }: Gift
{/* Title and amount */}
<div>
<h2 className="text-3xl font-bold mb-2 bg-gradient-to-r from-primary to-accent bg-clip-text text-transparent">
You've got {giftcard && formatCurrency(giftcard.amount)}!
{t('youveGotCredits', { amount: giftcard && formatCurrency(giftcard.amount) })}
</h2>
<p className="text-muted-foreground">
{currentStep === 'preview' && 'Ready to add these credits to your account?'}
{currentStep === 'login' && 'First, let\'s get you logged in to redeem your credits'}
{currentStep === 'provider' && `Add ${matchingPreset?.name || 'the provider'} to redeem your credits`}
{currentStep === 'preview' && t('readyToAddCredits')}
{currentStep === 'login' && t('firstLogInToRedeem')}
{currentStep === 'provider' && t('addProviderToRedeem', { providerName: matchingPreset?.name || t('provider') })}
</p>
</div>
@@ -286,7 +288,7 @@ export function GiftCardRedeemDialog({ open, onOpenChange, baseURL, code }: Gift
{matchingPreset && (
<div className="bg-muted/50 rounded-lg p-4 text-sm">
<div className="flex items-center justify-center gap-2">
<span className="text-muted-foreground">Provider:</span>
<span className="text-muted-foreground">{t('provider')}:</span>
<span className="font-medium">{matchingPreset.name}</span>
</div>
</div>
@@ -295,7 +297,7 @@ export function GiftCardRedeemDialog({ open, onOpenChange, baseURL, code }: Gift
{/* Account preview (only show on preview step) */}
{currentStep === 'preview' && user && (
<div className="border rounded-lg p-4">
<p className="text-xs text-muted-foreground mb-3 text-left">Redeeming to account:</p>
<p className="text-xs text-muted-foreground mb-3 text-left">{t('redeemingToAccount')}</p>
<AccountSwitcher onAddAccountClick={handleAddAccountClick} />
</div>
)}
@@ -312,12 +314,12 @@ export function GiftCardRedeemDialog({ open, onOpenChange, baseURL, code }: Gift
{redeemMutation.isPending ? (
<>
<div className="animate-spin rounded-full h-5 w-5 border-b-2 border-white mr-2" />
Redeeming...
{t('redeeming')}
</>
) : (
<>
<Gift className="h-5 w-5 mr-2" />
Redeem Now
{t('redeemNow')}
</>
)}
</Button>
@@ -330,12 +332,12 @@ export function GiftCardRedeemDialog({ open, onOpenChange, baseURL, code }: Gift
{currentStep === 'login' ? (
<>
<LogIn className="h-5 w-5 mr-2" />
Log In to Continue
{t('logInToContinue')}
</>
) : (
<>
<SettingsIcon className="h-5 w-5 mr-2" />
Add Provider
{t('addProvider')}
</>
)}
</Button>
@@ -346,7 +348,7 @@ export function GiftCardRedeemDialog({ open, onOpenChange, baseURL, code }: Gift
onClick={() => onOpenChange(false)}
className="w-full"
>
Cancel
{t('cancel')}
</Button>
</div>
+5 -3
View File
@@ -10,7 +10,7 @@ vi.mock('@/hooks/useAISettings', () => ({
setProvider: vi.fn(),
removeProvider: vi.fn(),
setProviders: vi.fn(),
addRecentlyUsedModel: vi.fn(),
updateSettings: vi.fn(),
isConfigured: false,
@@ -42,9 +42,11 @@ describe('OnboardingDialog', () => {
</TestApp>
);
expect(screen.getByText('Welcome to Shakespeare!')).toBeInTheDocument(); // Only in dialog title now
// Translations are rendered, so we check for the actual English text
expect(screen.getByText('Welcome to Shakespeare!')).toBeInTheDocument();
expect(screen.getByText(/Your AI-powered development assistant/)).toBeInTheDocument();
expect(screen.getByRole('button', { name: /Get Started/i })).toBeInTheDocument();
// The button now shows the translated text "Get Started"
expect(screen.getByRole('button', { name: 'Get Started' })).toBeInTheDocument();
});
it('does not render when closed', () => {
+39 -40
View File
@@ -2,6 +2,7 @@ import { useState, useEffect, useRef } from 'react';
import { generateSecretKey } from 'nostr-tools';
import { nip19 } from 'nostr-tools';
import { Bot, Check, Sparkles, ArrowRight, ArrowLeft, ExternalLink, Search } from 'lucide-react';
import { useTranslation } from 'react-i18next';
import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog';
import { Button } from '@/components/ui/button';
import { Card, CardHeader, CardTitle } from '@/components/ui/card';
@@ -28,6 +29,7 @@ interface OnboardingDialogProps {
type OnboardingStep = 'welcome' | 'open-source' | 'provider-selection' | 'model-selection' | 'conclusion';
export function OnboardingDialog({ open, onOpenChange }: OnboardingDialogProps) {
const { t } = useTranslation();
const [step, setStep] = useState<OnboardingStep>('welcome');
const [selectedProvider, setSelectedProvider] = useState<PresetProvider | null>(null);
const [providerApiKey, setProviderApiKey] = useState<string>('');
@@ -222,7 +224,7 @@ export function OnboardingDialog({ open, onOpenChange }: OnboardingDialogProps)
</Button>
)}
<span className="text-xl">
{step === 'model-selection' && 'Choose Your AI Model'}
{step === 'model-selection' && t('chooseYourAIModel')}
</span>
</DialogTitle>
</DialogHeader>
@@ -235,26 +237,25 @@ export function OnboardingDialog({ open, onOpenChange }: OnboardingDialogProps)
</div>
<div className="space-y-3">
<h2 className="text-2xl font-bold bg-gradient-to-r from-primary to-accent bg-clip-text text-transparent">
Welcome to Shakespeare!
{t('welcomeToShakespeareOnboarding')}
</h2>
<p className="text-lg text-muted-foreground max-w-md mx-auto">
Your AI-powered development assistant for building custom applications.
Simply describe what you want to build, and AI will help you create it.
{t('aiPoweredDevelopmentAssistant')}
</p>
</div>
<div className="space-y-4">
<div className="grid grid-cols-1 md:grid-cols-3 gap-4 max-w-lg mx-auto">
<div className="text-center space-y-2">
<div className="text-2xl">💡</div>
<p className="text-sm text-muted-foreground">AI-Powered Development</p>
<p className="text-sm text-muted-foreground">{t('aiPoweredDevelopment')}</p>
</div>
<div className="text-center space-y-2">
<div className="text-2xl">⚡</div>
<p className="text-sm text-muted-foreground">Nostr Integration</p>
<p className="text-sm text-muted-foreground">{t('nostrIntegration')}</p>
</div>
<div className="text-center space-y-2">
<div className="text-2xl">🚀</div>
<p className="text-sm text-muted-foreground">Instant Preview</p>
<p className="text-sm text-muted-foreground">{t('instantPreview')}</p>
</div>
</div>
<Button
@@ -266,12 +267,12 @@ export function OnboardingDialog({ open, onOpenChange }: OnboardingDialogProps)
{isSettingUp ? (
<>
<div className="animate-spin rounded-full h-4 w-4 border-b-2 border-white" />
Setting up...
{t('settingUp')}
</>
) : (
<>
<Sparkles className="h-4 w-4" />
Get Started
{t('getStarted')}
</>
)}
</Button>
@@ -283,38 +284,36 @@ export function OnboardingDialog({ open, onOpenChange }: OnboardingDialogProps)
<div className="space-y-6 py-4">
<div className="text-center space-y-4">
<h2 className="text-2xl font-bold">
Shakespeare is Open Source software that runs entirely in your web&nbsp;browser
{t('shakespeareOpenSource')}
</h2>
</div>
<div className="grid gap-1 max-w-md mx-auto">
<div className="flex items-start gap-3 p-3 rounded-lg bg-muted/50">
<div className="h-2 w-2 rounded-full bg-primary mt-2 flex-shrink-0" />
<p className="text-sm">Your device connects directly to third-party AI providers of your choice</p>
<p className="text-sm">{t('yourDeviceConnects')}</p>
</div>
<div className="flex items-start gap-3 p-3 rounded-lg bg-muted/50">
<div className="h-2 w-2 rounded-full bg-primary mt-2 flex-shrink-0" />
<p className="text-sm">Your files are stored on your device in your browser</p>
<p className="text-sm">{t('filesStoredOnDevice')}</p>
</div>
<div className="flex items-start gap-3 p-3 rounded-lg bg-muted/50">
<div className="h-2 w-2 rounded-full bg-primary mt-2 flex-shrink-0" />
<p className="text-sm">Be careful not to delete your browser data or you may lose project files</p>
<p className="text-sm">{t('carefulBrowserData')}</p>
</div>
<div className="flex items-start gap-3 p-3 rounded-lg bg-muted/50">
<div className="h-2 w-2 rounded-full bg-primary mt-2 flex-shrink-0" />
<p className="text-sm">You are responsible for taking backups or syncing to git</p>
<p className="text-sm">{t('responsibleBackups')}</p>
</div>
<div className="flex items-start gap-3 p-3 rounded-lg bg-muted/50">
<div className="h-2 w-2 rounded-full bg-primary mt-2 flex-shrink-0" />
<p className="text-sm">Quality of output depends on quality of input and models used, and is not guaranteed</p>
<p className="text-sm">{t('qualityDependsOnInput')}</p>
</div>
</div>
<div className="space-y-3 max-w-md mx-auto">
<p className="text-xs text-muted-foreground max-w-xl mx-auto">
Shakespeare is not a cloud service. It's Open Source software that runs on your device.
You agree to the Terms of Service of AI providers you interact with.
Shakespeare is provided "as is" without warranty of any kind.
{t('shakespeareNotCloudService')}
</p>
<div className="flex items-center justify-center gap-2">
@@ -327,7 +326,7 @@ export function OnboardingDialog({ open, onOpenChange }: OnboardingDialogProps)
htmlFor="agree-terms"
className="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70 cursor-pointer"
>
I agree
{t('iAgree')}
</label>
</div>
</div>
@@ -338,7 +337,7 @@ export function OnboardingDialog({ open, onOpenChange }: OnboardingDialogProps)
disabled={!agreedToTerms}
className="gap-2 rounded-full w-full max-w-md"
>
Continue
{t('continueButton')}
<ArrowRight className="h-4 w-4" />
</Button>
</div>
@@ -348,9 +347,9 @@ export function OnboardingDialog({ open, onOpenChange }: OnboardingDialogProps)
{step === 'provider-selection' && (
<div className="space-y-6 py-4">
<div className="text-center space-y-4">
<h2 className="text-2xl font-bold">Choose your AI provider</h2>
<h2 className="text-2xl font-bold">{t('chooseAIProvider')}</h2>
<p className="text-muted-foreground max-w-md mx-auto">
Select an AI provider to power your development assistant. You can add more providers later in settings.
{t('selectAIProviderDescription')}
</p>
</div>
@@ -394,27 +393,28 @@ export function OnboardingDialog({ open, onOpenChange }: OnboardingDialogProps)
<div className="space-y-3 max-w-md mx-auto">
<div className="text-center">
<h3 className="text-lg font-semibold">
{selectedProvider.id === 'routstr' ? 'Enter Cashu Token' : 'Enter API Key'}
{selectedProvider.id === 'routstr' ? t('enterCashuToken') : t('enterApiKey')}
</h3>
<p className="text-sm text-muted-foreground">
{selectedProvider.id === 'routstr' ? (
<>{selectedProvider.name} requires a Cashu token</>
t('requiresCashuToken', { providerName: selectedProvider.name })
) : (
<>
{selectedProvider.name} requires an {selectedProvider.apiKeysURL ? (
{selectedProvider.name} {t('requiresAnApiKey')}{' '}
{selectedProvider.apiKeysURL ? (
<a className="text-foreground underline" href={selectedProvider.apiKeysURL} target="_blank">
API key
{t('apiKey')}
<ExternalLink className="inline-block h-4 w-4 ml-1" />
</a>
) : (
<>API key</>
t('apiKey')
)}
</>
)}
</p>
</div>
<PasswordInput
placeholder={selectedProvider.id === 'routstr' ? 'Enter a Cashu Token' : 'Enter your API key'}
placeholder={selectedProvider.id === 'routstr' ? t('enterCashuToken') : t('enterApiKey')}
value={providerApiKey}
onChange={(e) => setProviderApiKey(e.target.value)}
onKeyDown={(e) => {
@@ -439,7 +439,7 @@ export function OnboardingDialog({ open, onOpenChange }: OnboardingDialogProps)
htmlFor="agree-provider-terms"
className="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70 cursor-pointer"
>
I agree to {selectedProvider.name}'s{' '}
{t('agreeToTermsOfService', { providerName: selectedProvider.name })}{' '}
{selectedProvider.tosURL ? (
<a
href={selectedProvider.tosURL}
@@ -448,10 +448,10 @@ export function OnboardingDialog({ open, onOpenChange }: OnboardingDialogProps)
className="text-primary underline hover:no-underline"
onClick={(e) => e.stopPropagation()}
>
Terms of Service
{t('termsOfService')}
</a>
) : (
'Terms of Service'
t('termsOfService')
)}
</label>
</div>
@@ -472,11 +472,11 @@ export function OnboardingDialog({ open, onOpenChange }: OnboardingDialogProps)
{isSettingUp ? (
<>
<div className="animate-spin rounded-full h-4 w-4 border-b-2 border-white" />
Setting up...
{t('settingUp')}
</>
) : (
<>
Continue
{t('continueButton')}
<ArrowRight className="h-4 w-4" />
</>
)}
@@ -494,7 +494,7 @@ export function OnboardingDialog({ open, onOpenChange }: OnboardingDialogProps)
<Search className="absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-muted-foreground" />
<Input
type="text"
placeholder="Search models..."
placeholder={t('searchModels')}
value={modelSearchQuery}
onChange={(e) => setModelSearchQuery(e.target.value)}
className="pl-9"
@@ -528,7 +528,7 @@ export function OnboardingDialog({ open, onOpenChange }: OnboardingDialogProps)
<div className="space-y-2">
<Bot className="h-8 w-8 mx-auto text-muted-foreground" />
<p className="text-muted-foreground">
{modelSearchQuery ? 'No models found matching your search.' : 'No models available. Please check your connection and try again.'}
{modelSearchQuery ? t('noModelsMatchingSearch') : t('noModelsAvailable')}
</p>
</div>
</Card>
@@ -580,7 +580,7 @@ export function OnboardingDialog({ open, onOpenChange }: OnboardingDialogProps)
disabled={!selectedModel}
className="gap-2"
>
Continue
{t('continueButton')}
<ArrowRight className="h-4 w-4" />
</Button>
</div>
@@ -591,15 +591,14 @@ export function OnboardingDialog({ open, onOpenChange }: OnboardingDialogProps)
<div className="text-center space-y-6 py-8">
<div className="text-5xl mb-4">🎉</div>
<div className="space-y-3">
<h2 className="text-2xl font-bold">Now you're ready to build!</h2>
<h2 className="text-2xl font-bold">{t('nowYoureReady')}</h2>
<p className="text-lg text-muted-foreground max-w-md mx-auto">
Your AI assistant is configured and ready to help.
Just enter your prompt to start building amazing Nostr applications.
{t('aiAssistantConfigured')}
</p>
</div>
<Button onClick={handleFinish} size="lg" className="gap-2">
<Sparkles className="h-4 w-4" />
Start Building
{t('startBuilding')}
</Button>
</div>
)}