forked from rajun/ar-test
feat: add project detail page
This commit is contained in:
parent
f7a741b54e
commit
e8bc35d443
44
app/routes/admin/projects/$id.tsx
Normal file
44
app/routes/admin/projects/$id.tsx
Normal file
@ -0,0 +1,44 @@
|
||||
import { redirect, useLoaderData } from 'react-router';
|
||||
import { toast } from 'sonner';
|
||||
import type { Route } from './+types/$id';
|
||||
import { AssetList } from '~/components/assets/list/asset-list';
|
||||
import { ProjectHeader } from '~/components/projects/detail/project-header';
|
||||
import { ROUTES } from '~/data/routes';
|
||||
import { useAdminDialogs } from '~/hooks/admin/use-admin-dialogs';
|
||||
import { getErrorMessage, isNotFound } from '~/lib/errors';
|
||||
import { getPage } from '~/lib/pagination';
|
||||
import { listAssets } from '~/services/assets';
|
||||
import { getProject } from '~/services/projects';
|
||||
|
||||
export async function clientLoader({ params, request }: Route.ClientLoaderArgs) {
|
||||
try {
|
||||
const [project, assets] = await Promise.all([getProject(params.id), listAssets(getPage(request), params.id)]);
|
||||
return { project, assets };
|
||||
} catch (error) {
|
||||
toast.error(isNotFound(error) ? 'Project not found' : getErrorMessage(error));
|
||||
return redirect(ROUTES.projects);
|
||||
}
|
||||
}
|
||||
|
||||
export default function ProjectPage() {
|
||||
const { project, assets } = useLoaderData<typeof clientLoader>();
|
||||
const { openProject, openAsset } = useAdminDialogs();
|
||||
|
||||
return (
|
||||
<div className='flex flex-col gap-[22px]'>
|
||||
<ProjectHeader
|
||||
project={project}
|
||||
assetCount={assets.totalItems}
|
||||
onEdit={() => openProject(project)}
|
||||
onNewAsset={() => openAsset({ projectId: project.id })}
|
||||
/>
|
||||
<div className='h-px bg-border-divider' />
|
||||
<AssetList
|
||||
assets={assets}
|
||||
showProject={false}
|
||||
emptyTitle='No assets yet'
|
||||
emptyMessage='Add a model to this project — its AR page will carry the client logo.'
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user