'use client';
import { api } from '@/lib/api';
import { formatCurrency, formatTimeRemaining } from '@/lib/utils';
import { useQuery } from '@tanstack/react-query';
import { motion } from 'framer-motion';
import { AlertCircle, ArrowLeft, Award, CheckCircle2, Clock, Users, Wallet } from 'lucide-react';
import Link from 'next/link';
import { useParams } from 'next/navigation';
import { LoadingSpinner } from '@/components/ui/LoadingSpinner';
export default function TaskDetailsPage() {
const params = useParams();
const taskId = params.taskId as string;
const { data, isLoading } = useQuery({
queryKey: ['task', taskId],
queryFn: () => api.tasks.getById(taskId),
});
if (isLoading) {
return (
);
}
const task = data?.data;
if (!task) {
return (
{/* Background */}
Task Not Found
This task may have been removed or doesn't exist.
Back to Tasks
);
}
const progressPercentage = ((task.maxSubmissions - task.spotsRemaining) / task.maxSubmissions) * 100;
return (
{/* Animated Background */}
{/* Back Button */}
Back to Tasks
{/* Main Card */}
{/* Header Section */}
{task.title}
{task.taskType.replace('_', ' ')}
{formatCurrency(task.paymentAmount)}
{task.isExpiringSoon && (
Expiring Soon
)}
{/* Progress Bar */}
{task.maxSubmissions - task.spotsRemaining} completed
{task.spotsRemaining} spots left
{/* Content Section */}
{/* Description */}
Description
{task.description}
{/* Requirements */}
{task.verificationCriteria?.requiredFields && task.verificationCriteria.requiredFields.length > 0 && (
Requirements
{task.verificationCriteria.requiredFields.map((field: string, index: number) => (
{field}
))}
)}
{/* Stats Grid */}
{[
{ icon: Wallet, label: 'Payment', value: formatCurrency(task.paymentAmount), color: 'from-green-500 to-green-600' },
{ icon: Users, label: 'Spots Left', value: `${task.spotsRemaining}/${task.maxSubmissions}`, color: 'from-green-600 to-green-700' },
{ icon: Clock, label: 'Time Left', value: formatTimeRemaining(task.expiresAt), color: 'from-green-400 to-green-500' },
{ icon: Award, label: 'Submissions', value: task.submissionCount.toString(), color: 'from-green-500 to-green-600' },
].map((stat, index) => (
{stat.label}
{stat.value}
))}
{/* Requester Info */}
Posted by
{task.requester.walletAddress}
Reputation:
{task.requester.reputationScore}
{/* Action Button */}
0 && task.canSubmit ? { scale: 1.02 } : {}}
whileTap={task.spotsRemaining > 0 && task.canSubmit ? { scale: 0.98 } : {}}
disabled={task.spotsRemaining === 0 || !task.canSubmit}
className="w-full py-5 bg-linear-to-r from-green-500 to-green-600 text-white font-bold text-lg hover:from-green-600 hover:to-green-700 transition-all disabled:from-gray-400 disabled:to-gray-500 disabled:cursor-not-allowed shadow-lg shadow-green-500/25 disabled:shadow-none"
>
{task.spotsRemaining === 0 ? 'No Spots Available' : !task.canSubmit ? 'Cannot Submit' : 'Submit Task'}
);
}