add page to view owner toy list and status
This commit is contained in:
parent
7738ad28ae
commit
ae1d9d269e
|
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"IDX.aI.enableInlineCompletion": true,
|
||||||
|
"IDX.aI.enableCodebaseIndexing": true
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,85 @@
|
||||||
|
import Link from 'next/link';
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import ToyList from '@/components/toys/ToyList';
|
||||||
|
import { mockToys } from '@/lib/mockData';
|
||||||
|
import type { Toy } from '@/types';
|
||||||
|
import { getI18n, getStaticParams as getLocaleStaticParams } from '@/locales/server';
|
||||||
|
import { ArrowLeft, Home } from 'lucide-react';
|
||||||
|
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||||
|
import { ToyBrick } from 'lucide-react';
|
||||||
|
|
||||||
|
interface OwnerToysPageProps {
|
||||||
|
params: { ownerId: string; locale: string };
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getOwnerToys(ownerId: string): Promise<Toy[]> {
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 100)); // Simulate fetch
|
||||||
|
return mockToys.filter(toy => toy.ownerId === ownerId);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default async function OwnerToysPage({ params }: OwnerToysPageProps) {
|
||||||
|
const t = await getI18n();
|
||||||
|
const ownerToys = await getOwnerToys(params.ownerId);
|
||||||
|
|
||||||
|
let ownerName: string | undefined;
|
||||||
|
if (ownerToys.length > 0) {
|
||||||
|
ownerName = ownerToys[0].ownerName;
|
||||||
|
} else {
|
||||||
|
// Attempt to find owner name even if they have no toys, if we had a user list
|
||||||
|
// For now, we rely on toys or show a generic message if ownerId itself is unknown
|
||||||
|
const ownerFromAnyToy = mockToys.find(toy => toy.ownerId === params.ownerId);
|
||||||
|
if (ownerFromAnyToy) {
|
||||||
|
ownerName = ownerFromAnyToy.ownerName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const pageTitle = ownerName
|
||||||
|
? t('owner_toys.title', { ownerName })
|
||||||
|
: t('owner_toys.owner_not_found');
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-8">
|
||||||
|
<div className="flex justify-between items-center">
|
||||||
|
<h1 className="text-3xl font-bold font-headline text-primary">{pageTitle}</h1>
|
||||||
|
<Link href="/" passHref>
|
||||||
|
<Button variant="outline">
|
||||||
|
<Home className="mr-2 h-4 w-4" />
|
||||||
|
{t('owner_toys.back_to_home')}
|
||||||
|
</Button>
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{ownerToys.length > 0 ? (
|
||||||
|
<ToyList toys={ownerToys.map(toy => ({...toy, dataAiHint: toy.category.toLowerCase()}))} />
|
||||||
|
) : (
|
||||||
|
<Card className="text-center py-12 shadow-md">
|
||||||
|
<CardHeader>
|
||||||
|
<ToyBrick className="h-16 w-16 mx-auto text-muted-foreground mb-4" />
|
||||||
|
<CardTitle>
|
||||||
|
{ownerName ? t('owner_toys.no_toys_listed_by', { ownerName }) : t('owner_toys.owner_not_found')}
|
||||||
|
</CardTitle>
|
||||||
|
{ownerName && <CardDescription>{t('home.explore_toys')}</CardDescription>}
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent>
|
||||||
|
<Link href="/" passHref>
|
||||||
|
<Button size="lg">
|
||||||
|
{t('home.explore_toys')}
|
||||||
|
</Button>
|
||||||
|
</Link>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function generateStaticParams() {
|
||||||
|
const localeParams = getLocaleStaticParams(); // e.g. [{ locale: 'en' }, { locale: 'zh-TW' }]
|
||||||
|
|
||||||
|
const ownerIds = Array.from(new Set(mockToys.map(toy => toy.ownerId)));
|
||||||
|
const ownerParams = ownerIds.map(id => ({ ownerId: id }));
|
||||||
|
|
||||||
|
return localeParams.flatMap(lang =>
|
||||||
|
ownerParams.map(owner => ({ ...lang, ...owner }))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
@ -144,4 +144,9 @@ export default {
|
||||||
'dashboard.requests.status_pending': 'Pending',
|
'dashboard.requests.status_pending': 'Pending',
|
||||||
'dashboard.requests.status_approved': 'Approved',
|
'dashboard.requests.status_approved': 'Approved',
|
||||||
'dashboard.requests.status_declined': 'Declined',
|
'dashboard.requests.status_declined': 'Declined',
|
||||||
|
'owner_toys.title': "{ownerName}'s Shared Toys",
|
||||||
|
'owner_toys.no_toys_listed_by': '{ownerName} has not listed any toys yet.',
|
||||||
|
'owner_toys.owner_not_found': 'Owner not found or has no toys listed.',
|
||||||
|
'owner_toys.back_to_home': 'Back to Home',
|
||||||
|
'owner_toys.unknown_owner': 'Unknown Owner',
|
||||||
} as const;
|
} as const;
|
||||||
|
|
|
||||||
|
|
@ -144,4 +144,9 @@ export default {
|
||||||
'dashboard.requests.status_pending': '待處理',
|
'dashboard.requests.status_pending': '待處理',
|
||||||
'dashboard.requests.status_approved': '已批准',
|
'dashboard.requests.status_approved': '已批准',
|
||||||
'dashboard.requests.status_declined': '已拒絕',
|
'dashboard.requests.status_declined': '已拒絕',
|
||||||
|
'owner_toys.title': '{ownerName} 分享的玩具',
|
||||||
|
'owner_toys.no_toys_listed_by': '{ownerName} 目前沒有列出任何玩具。',
|
||||||
|
'owner_toys.owner_not_found': '找不到擁有者或該擁有者沒有列出任何玩具。',
|
||||||
|
'owner_toys.back_to_home': '返回首頁',
|
||||||
|
'owner_toys.unknown_owner': '未知擁有者',
|
||||||
} as const;
|
} as const;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue