'use client'; import {useEffect, useMemo, useState} from 'react'; import Link from 'next/link'; import {Progress, Skeleton} from 'antd'; import {CheckCircleOutlined, ClockCircleOutlined, FileTextOutlined} from '@ant-design/icons'; import type {CustomerOrder} from '@/types/account'; import {useAuth} from '@/app/context/AuthContext'; import {useLanguage} from '@/app/context/LanguageContext'; import {accountCopy} from '@/data/account'; import {getOrders} from '@/services/orders'; import OrderCard from '@/components/dashboard/OrderCard'; export default function DashboardPage() { const auth = useAuth(); const {locale} = useLanguage(); const copy = accountCopy[locale]; const [orders, setOrders] = useState(null); useEffect(() => { if (auth.session) getOrders(auth.session.profile).then(setOrders); }, [auth.session]); const completion = useMemo(() => { if (!auth.session) return 0; const profile = auth.session.profile; const required = [ profile.firstName, profile.lastName, profile.province, profile.city, profile.address, profile.postalCode, ]; return Math.round((required.filter(Boolean).length / required.length) * 100); }, [auth.session]); if (!orders) return ; const activeOrders = orders.filter(order => !['delivered', 'cancelled'].includes(order.status)).length; const cards = [ { label: copy.profileCompletion, value: `${completion.toLocaleString(locale === 'fa' ? 'fa-IR' : 'en-US')}٪`, icon: , extra: , }, { label: copy.activeOrders, value: activeOrders.toLocaleString(locale === 'fa' ? 'fa-IR' : 'en-US'), icon: , }, { label: copy.totalOrders, value: orders.length.toLocaleString(locale === 'fa' ? 'fa-IR' : 'en-US'), icon: , }, ]; return ( <>

{copy.welcome} {auth.session?.profile.firstName}

{copy.dashboardDescription}

{cards.map(card => (
{card.icon}

{card.label}

{card.value} {card.extra &&
{card.extra}
}
))}

{copy.recentOrders}

{copy.viewAll}
{orders.slice(0, 2).map(order => ( ))}
); }