| 1 | import type { Metadata } from 'next' |
| 2 | import { headers } |
| 3 | import { projectsService } |
| 4 | import { teamService } |
| 5 | import { createMetadata } |
| 6 | import { auth } |
| 7 | import { requirePermission, resolveOrgContext |
| 8 | import { ClientsPageClient } |
| 9 | import type { PendingInvitation |
| 10 | |
| 11 | export const metadata: |
| 12 | title: 'Clients', |
| 13 | description: 'Manage client relationships and project access.', |
| 14 | openGraph: { |
| 15 | images: ['/api/og?page=Clients'], |
| 16 | }, |
| 17 | twitter: { |
| 18 | images: ['/api/og?page=Clients'], |
| 19 | }, |
| 20 | }) |
| 21 | |
| 22 | export default async function |
| 23 | params, |
| 24 | }: PageProps< |
| 25 | const { org |
| 26 | const { organization, |
| 27 | |
| 28 | requirePermission( |
| 29 | role, |
| 30 | { member: ['create' |
| 31 | 'You do not have permission to view clients' |
| 32 | ) |
| 33 | |
| 34 | const canManage = |
| 35 | |
| 36 | const [clients, |
| 37 | teamService.getOrgClients(organization |
| 38 | projectsService.listByOrganization(organization |
| 39 | canManage |
| 40 | ? auth.api. |
| 41 | headers: await headers |
| 42 | query: { organizationId: organization |
| 43 | }) |
| 44 | : Promise.resolve([]) |
| 45 | ]) |
| 46 | |
| 47 | const pendingInvitations: |
| 48 | .filter((i) |
| 49 | .map((i) |
| 50 | id: i.id |
| 51 | email: i.email |
| 52 | role: i.role |
| 53 | status: i.status |
| 54 | expiresAt: i.expiresAt |
| 55 | })) |
| 56 | |
| 57 | const projects = |
| 58 | projectId: p.id |
| 59 | projectName: p.name |
| 60 | projectSlug: p.slug |
| 61 | })) |
| 62 | |
| 63 | return ( |
| 64 | <ClientsPageClient |
| 65 | canManage={canManage} |
| 66 | clients={clients} |
| 67 | invitations={pendingInvitations} |
| 68 | organizationId={organization.id |
| 69 | orgSlug={org} |
| 70 | projects={projects} |
| 71 | /> |
| 72 | ) |
| 73 | } |