|
| 1 | +'use client'; |
| 2 | + |
| 3 | +import { useParams } from 'next/navigation'; |
| 4 | +import { useAgenticPay } from '@/lib/hooks/useAgenticPay'; |
| 5 | +import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; |
| 6 | +import { Button } from '@/components/ui/button'; |
| 7 | +import { ArrowLeft, ExternalLink, Download } from 'lucide-react'; |
| 8 | +import Link from 'next/link'; |
| 9 | +import { Skeleton } from '@/components/ui/skeleton'; |
| 10 | + |
| 11 | +export default function InvoiceDetailPage() { |
| 12 | + const params = useParams(); |
| 13 | + const rawId = params.id as string; |
| 14 | + const projectId = rawId.startsWith('INV-') ? rawId.replace('INV-', '') : rawId; |
| 15 | + |
| 16 | + const { useProjectDetail } = useAgenticPay(); |
| 17 | + const { project, loading } = useProjectDetail(projectId); |
| 18 | + |
| 19 | + if (loading) { |
| 20 | + return ( |
| 21 | + <div className="space-y-6"> |
| 22 | + <Skeleton className="h-10 w-32" /> |
| 23 | + <Card> |
| 24 | + <CardHeader> |
| 25 | + <Skeleton className="h-8 w-64 mb-2" /> |
| 26 | + </CardHeader> |
| 27 | + <CardContent className="space-y-6"> |
| 28 | + <Skeleton className="h-32 w-full" /> |
| 29 | + </CardContent> |
| 30 | + </Card> |
| 31 | + </div> |
| 32 | + ); |
| 33 | + } |
| 34 | + |
| 35 | + if (!project || (!project.invoiceUri && project.status !== 'completed')) { |
| 36 | + return ( |
| 37 | + <div className="flex flex-col items-center justify-center h-64"> |
| 38 | + <p className="text-gray-600 mb-4">Invoice not found</p> |
| 39 | + <Link href="/dashboard/invoices"> |
| 40 | + <Button>Back to Invoices</Button> |
| 41 | + </Link> |
| 42 | + </div> |
| 43 | + ); |
| 44 | + } |
| 45 | + |
| 46 | + // Construct display status |
| 47 | + const status = project.status === 'completed' ? 'paid' : 'pending'; |
| 48 | + |
| 49 | + return ( |
| 50 | + <div className="space-y-6"> |
| 51 | + <Link href="/dashboard/invoices"> |
| 52 | + <Button variant="ghost" className="mb-4"> |
| 53 | + <ArrowLeft className="h-4 w-4 mr-2" /> |
| 54 | + Back to Invoices |
| 55 | + </Button> |
| 56 | + </Link> |
| 57 | + |
| 58 | + <Card> |
| 59 | + <CardHeader> |
| 60 | + <div className="flex justify-between items-start"> |
| 61 | + <div> |
| 62 | + <CardTitle className="text-2xl mb-2">Invoice #{rawId}</CardTitle> |
| 63 | + <p className="text-gray-600">{project.title}</p> |
| 64 | + </div> |
| 65 | + <span |
| 66 | + className={`px-4 py-2 rounded-full text-sm font-medium ${status === 'paid' |
| 67 | + ? 'bg-green-100 text-green-700' |
| 68 | + : 'bg-yellow-100 text-yellow-700' |
| 69 | + }`} |
| 70 | + > |
| 71 | + {status.toUpperCase()} |
| 72 | + </span> |
| 73 | + </div> |
| 74 | + </CardHeader> |
| 75 | + <CardContent className="space-y-6"> |
| 76 | + <div className="grid grid-cols-2 gap-6"> |
| 77 | + <div> |
| 78 | + <p className="text-sm text-gray-600 mb-1">Amount</p> |
| 79 | + <p className="text-2xl font-bold"> |
| 80 | + {project.totalAmount} {project.currency} |
| 81 | + </p> |
| 82 | + </div> |
| 83 | + <div> |
| 84 | + <p className="text-sm text-gray-600 mb-1">Milestone</p> |
| 85 | + <p className="text-lg font-medium">Full Project</p> |
| 86 | + </div> |
| 87 | + </div> |
| 88 | + |
| 89 | + <div className="border-t pt-6 space-y-4"> |
| 90 | + <div> |
| 91 | + <p className="text-sm text-gray-600 mb-2">Client</p> |
| 92 | + <p className="font-medium">{project.client.name}</p> |
| 93 | + <p className="text-sm text-gray-500 font-mono">{project.client.address}</p> |
| 94 | + </div> |
| 95 | + <div> |
| 96 | + <p className="text-sm text-gray-600 mb-2">Freelancer</p> |
| 97 | + <p className="font-medium">{project.freelancer.name}</p> |
| 98 | + <p className="text-sm text-gray-500 font-mono">{project.freelancer.address}</p> |
| 99 | + </div> |
| 100 | + </div> |
| 101 | + |
| 102 | + <div className="border-t pt-6 space-y-2"> |
| 103 | + <div className="flex justify-between text-sm"> |
| 104 | + <span className="text-gray-600">Generated</span> |
| 105 | + <span className="font-medium"> |
| 106 | + {new Date(project.createdAt).toLocaleString()} |
| 107 | + </span> |
| 108 | + </div> |
| 109 | + </div> |
| 110 | + |
| 111 | + <div className="flex gap-3 pt-4"> |
| 112 | + <Button variant="outline"> |
| 113 | + <Download className="h-4 w-4 mr-2" /> |
| 114 | + Download PDF |
| 115 | + </Button> |
| 116 | + </div> |
| 117 | + </CardContent> |
| 118 | + </Card> |
| 119 | + </div> |
| 120 | + ); |
| 121 | +} |
0 commit comments