mirror of
https://github.com/yusufipk/OpenFrame.git
synced 2026-09-11 09:36:08 +00:00
- Added billing-related fields to the User model in the database. - Implemented functions for managing billing access, including trial periods and subscription statuses. - Created new billing utility functions for Stripe integration. - Updated onboarding page to include billing overview and workspace creation eligibility. - Enhanced route access checks to require billing access for certain actions. - Implemented cleanup scripts for expired billing workspaces and associated media. - Updated header component to conditionally show app navigation based on billing access. - Added new migrations for billing-related database changes.
79 lines
2.2 KiB
TypeScript
79 lines
2.2 KiB
TypeScript
import { auth } from '@/lib/auth';
|
|
import { redirect } from 'next/navigation';
|
|
import { db } from '@/lib/db';
|
|
import { buildBillingAccessWhereInput, getBillingOverview } from '@/lib/billing';
|
|
import { hasCollaboratorBillingBackedAccess, requireBillingAccessOrRedirect } from '@/lib/route-access';
|
|
import { WorkspacesClient } from './workspaces-client';
|
|
|
|
export default async function WorkspacesPage({
|
|
searchParams,
|
|
}: {
|
|
searchParams: Promise<{ page?: string }>
|
|
}) {
|
|
const session = await auth();
|
|
if (!session?.user?.id) {
|
|
redirect('/login');
|
|
}
|
|
|
|
const hasCollaboratorAccess = await hasCollaboratorBillingBackedAccess(session.user.id);
|
|
if (!hasCollaboratorAccess) {
|
|
await requireBillingAccessOrRedirect({ userId: session.user.id });
|
|
}
|
|
|
|
const resolvedSearchParams = await searchParams;
|
|
const page = Number(resolvedSearchParams?.page) || 1;
|
|
const pageSize = 20;
|
|
const skip = (page - 1) * pageSize;
|
|
|
|
const [workspaces, totalWorkspaces, billing] = await Promise.all([
|
|
db.workspace.findMany({
|
|
skip,
|
|
take: pageSize,
|
|
where: {
|
|
OR: [
|
|
{ ownerId: session.user.id, owner: buildBillingAccessWhereInput() },
|
|
{ members: { some: { userId: session.user.id } }, owner: buildBillingAccessWhereInput() },
|
|
],
|
|
},
|
|
include: {
|
|
owner: { select: { id: true, name: true } },
|
|
_count: {
|
|
select: {
|
|
projects: true,
|
|
members: true,
|
|
},
|
|
},
|
|
},
|
|
orderBy: { updatedAt: 'desc' },
|
|
}),
|
|
db.workspace.count({
|
|
where: {
|
|
OR: [
|
|
{ ownerId: session.user.id, owner: buildBillingAccessWhereInput() },
|
|
{ members: { some: { userId: session.user.id } }, owner: buildBillingAccessWhereInput() },
|
|
],
|
|
}
|
|
}),
|
|
getBillingOverview(session.user.id),
|
|
]);
|
|
|
|
const totalPages = Math.ceil(totalWorkspaces / pageSize);
|
|
|
|
const serializedWorkspaces = workspaces.map((w) => ({
|
|
id: w.id,
|
|
name: w.name,
|
|
description: w.description,
|
|
updatedAt: w.updatedAt.toISOString(),
|
|
_count: w._count
|
|
}));
|
|
|
|
return (
|
|
<WorkspacesClient
|
|
workspaces={serializedWorkspaces}
|
|
totalPages={totalPages}
|
|
currentPage={page}
|
|
workspaceCreation={billing.workspaceCreation}
|
|
/>
|
|
);
|
|
}
|