|
| 1 | +import { Progress } from '@/components/ui/progress' |
| 2 | +import { Card, CardContent } from '@/components/ui/card' |
| 3 | +import { useCurrentGoal } from '@/hooks/use-goal' |
| 4 | +import { Target, TrendingUp } from 'lucide-react' |
| 5 | +import { useTranslation } from 'react-i18next' |
| 6 | +import { Skeleton } from '@/components/ui/skeleton' |
| 7 | +import { cn } from '@/lib/utils' |
| 8 | + |
| 9 | +export function GoalProgress() { |
| 10 | + const { data: goal, isLoading, isError } = useCurrentGoal() |
| 11 | + const { t } = useTranslation() |
| 12 | + |
| 13 | + if (isLoading) { |
| 14 | + return ( |
| 15 | + <div className="space-y-2 px-4 py-3"> |
| 16 | + <Skeleton className="h-4 w-24" /> |
| 17 | + <Skeleton className="h-2 w-full" /> |
| 18 | + <Skeleton className="h-3 w-32" /> |
| 19 | + </div> |
| 20 | + ) |
| 21 | + } |
| 22 | + |
| 23 | + if (isError || !goal) { |
| 24 | + return null |
| 25 | + } |
| 26 | + |
| 27 | + const progress = Math.min((goal.paid_amount / goal.price) * 100, 100) |
| 28 | + const remaining = Math.max(goal.price - goal.paid_amount, 0) |
| 29 | + |
| 30 | + return ( |
| 31 | + <Card className="mx-2 mb-2 border-primary/20 bg-gradient-to-br from-primary/5 to-primary/10 dark:from-primary/10 dark:to-primary/20"> |
| 32 | + <CardContent className="p-3"> |
| 33 | + <div className="space-y-2.5"> |
| 34 | + {/* Header */} |
| 35 | + <div className="flex items-start justify-between gap-2"> |
| 36 | + <div className="flex items-center gap-2"> |
| 37 | + <div className="flex h-8 w-8 items-center justify-center rounded-full bg-primary/20"> |
| 38 | + <Target className="h-4 w-4 text-primary" /> |
| 39 | + </div> |
| 40 | + <div className="flex flex-col"> |
| 41 | + <span className="text-xs font-medium text-muted-foreground">{t('goal.currentGoal')}</span> |
| 42 | + <span className="line-clamp-1 text-sm font-semibold leading-tight">{goal.name}</span> |
| 43 | + </div> |
| 44 | + </div> |
| 45 | + <div |
| 46 | + className={cn( |
| 47 | + 'flex items-center gap-1 rounded-full px-2 py-0.5 text-xs font-medium', |
| 48 | + goal.status === 'completed' ? 'bg-green-500/20 text-green-700 dark:text-green-400' : 'bg-amber-500/20 text-amber-700 dark:text-amber-400' |
| 49 | + )} |
| 50 | + > |
| 51 | + <TrendingUp className="h-3 w-3" /> |
| 52 | + {progress.toFixed(0)}% |
| 53 | + </div> |
| 54 | + </div> |
| 55 | + |
| 56 | + {/* Progress Bar */} |
| 57 | + <div className="space-y-1"> |
| 58 | + <Progress value={progress} className="h-2" /> |
| 59 | + <div className="flex items-center justify-between text-xs"> |
| 60 | + <span className="font-medium text-primary"> |
| 61 | + ${goal.paid_amount.toLocaleString()} |
| 62 | + </span> |
| 63 | + <span className="text-muted-foreground"> |
| 64 | + {t('goal.of')} ${goal.price.toLocaleString()} |
| 65 | + </span> |
| 66 | + </div> |
| 67 | + </div> |
| 68 | + |
| 69 | + {/* Details */} |
| 70 | + {goal.detail && ( |
| 71 | + <p className="line-clamp-2 text-xs leading-relaxed text-muted-foreground"> |
| 72 | + {goal.detail} |
| 73 | + </p> |
| 74 | + )} |
| 75 | + |
| 76 | + {/* Remaining */} |
| 77 | + {remaining > 0 && ( |
| 78 | + <div className="flex items-center justify-between rounded-md bg-background/50 px-2 py-1.5"> |
| 79 | + <span className="text-xs font-medium text-muted-foreground"> |
| 80 | + {t('goal.remaining')} |
| 81 | + </span> |
| 82 | + <span className="text-xs font-semibold text-foreground"> |
| 83 | + ${remaining.toLocaleString()} |
| 84 | + </span> |
| 85 | + </div> |
| 86 | + )} |
| 87 | + |
| 88 | + {/* CTA Button */} |
| 89 | + <a |
| 90 | + href="https://donate.pasarguard.org" |
| 91 | + target="_blank" |
| 92 | + rel="noopener noreferrer" |
| 93 | + className="flex w-full items-center justify-center gap-2 rounded-md bg-primary px-3 py-2 text-xs font-semibold text-primary-foreground transition-all hover:bg-primary/90 hover:shadow-md" |
| 94 | + > |
| 95 | + <Target className="h-3.5 w-3.5" /> |
| 96 | + {t('goal.contribute')} |
| 97 | + </a> |
| 98 | + </div> |
| 99 | + </CardContent> |
| 100 | + </Card> |
| 101 | + ) |
| 102 | +} |
| 103 | + |
0 commit comments