Files
myeasycms-v2/apps/web/app/[locale]/home/[account]/site-builder/posts/page.tsx
T. Zehetbauer c6d564836f
Some checks failed
Workflow / ʦ TypeScript (push) Failing after 17m4s
Workflow / ⚫️ Test (push) Has been skipped
fix: add missing newlines at the end of JSON files; clean up formatting in page components
2026-04-02 11:02:58 +02:00

104 lines
3.2 KiB
TypeScript

import Link from 'next/link';
import { Plus } from 'lucide-react';
import { getTranslations } from 'next-intl/server';
interface SitePost {
id: string;
title: string;
status: string;
created_at: string | null;
}
import { formatDate } from '@kit/shared/dates';
import { createSiteBuilderApi } from '@kit/site-builder/api';
import { getSupabaseServerClient } from '@kit/supabase/server-client';
import { Badge } from '@kit/ui/badge';
import { Button } from '@kit/ui/button';
import { Card, CardContent } from '@kit/ui/card';
import { AccountNotFound } from '~/components/account-not-found';
import { CmsPageShell } from '~/components/cms-page-shell';
import { EmptyState } from '~/components/empty-state';
interface Props {
params: Promise<{ account: string }>;
}
export default async function PostsManagerPage({ params }: Props) {
const { account } = await params;
const client = getSupabaseServerClient();
const t = await getTranslations('siteBuilder');
const { data: acct } = await client
.from('accounts')
.select('id')
.eq('slug', account)
.single();
if (!acct) return <AccountNotFound />;
const api = createSiteBuilderApi(client);
const posts = await api.listPosts(acct.id);
return (
<CmsPageShell
account={account}
title={t('posts.title')}
description={t('posts.manage')}
>
<div className="space-y-6">
<div className="flex justify-end">
<Button data-test="site-new-post-btn">
<Plus className="mr-2 h-4 w-4" />
{t('posts.newPost')}
</Button>
</div>
{posts.length === 0 ? (
<EmptyState
title={t('posts.noPosts2')}
description={t('posts.noPostDesc')}
actionLabel={t('posts.createPostLabel')}
/>
) : (
<div className="overflow-x-auto rounded-md border">
<table className="w-full min-w-[640px] text-sm">
<thead>
<tr className="bg-muted/50 border-b">
<th scope="col" className="p-3 text-left">
{t('posts.colTitle')}
</th>
<th scope="col" className="p-3 text-left">
{t('posts.colStatus')}
</th>
<th scope="col" className="p-3 text-left">
{t('posts.colCreated')}
</th>
</tr>
</thead>
<tbody>
{(posts as SitePost[]).map((post) => (
<tr key={post.id} className="hover:bg-muted/30 border-b">
<td className="p-3 font-medium">{post.title}</td>
<td className="p-3">
<Badge
variant={
post.status === 'published' ? 'default' : 'secondary'
}
>
{post.status}
</Badge>
</td>
<td className="text-muted-foreground p-3 text-xs">
{formatDate(post.created_at)}
</td>
</tr>
))}
</tbody>
</table>
</div>
)}
</div>
</CmsPageShell>
);
}