Initial commit: PodcastYes — AI podcast platform
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
"use server";
|
||||
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { z } from "zod";
|
||||
import { getServerSession } from "@/lib/auth/guards";
|
||||
import { prisma } from "@/lib/db";
|
||||
|
||||
const brandingSchema = z.object({
|
||||
brandName: z.string().max(60).optional(),
|
||||
primaryColor: z
|
||||
.string()
|
||||
.regex(/^#([0-9a-fA-F]{6})$/, "Use a hex colour like #7c3aed")
|
||||
.optional()
|
||||
.or(z.literal("")),
|
||||
logoUrl: z.string().url().optional().or(z.literal("")),
|
||||
removePoweredBy: z.boolean().optional(),
|
||||
});
|
||||
|
||||
export async function saveBrandingAction(
|
||||
organizationId: string,
|
||||
data: z.infer<typeof brandingSchema>
|
||||
): Promise<{ ok: boolean; error?: string }> {
|
||||
const session = await getServerSession();
|
||||
if (!session) return { ok: false, error: "You must be signed in." };
|
||||
|
||||
const member = await prisma.member.findFirst({
|
||||
where: { organizationId, userId: session.user.id },
|
||||
select: { role: true },
|
||||
});
|
||||
if (!member || !["owner", "admin"].includes(member.role)) {
|
||||
return { ok: false, error: "Only workspace owners can edit branding." };
|
||||
}
|
||||
|
||||
const parsed = brandingSchema.safeParse(data);
|
||||
if (!parsed.success) return { ok: false, error: parsed.error.issues[0]?.message ?? "Invalid input." };
|
||||
|
||||
const payload = {
|
||||
brandName: parsed.data.brandName || null,
|
||||
primaryColor: parsed.data.primaryColor || null,
|
||||
logoUrl: parsed.data.logoUrl || null,
|
||||
removePoweredBy: parsed.data.removePoweredBy ?? false,
|
||||
};
|
||||
|
||||
await prisma.orgBranding.upsert({
|
||||
where: { organizationId },
|
||||
create: { organizationId, ...payload },
|
||||
update: payload,
|
||||
});
|
||||
revalidatePath("/team");
|
||||
return { ok: true };
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
import type { Metadata } from "next";
|
||||
import { requireAuth } from "@/lib/auth/guards";
|
||||
import { getEffectivePlan, subjectHasFeature } from "@/lib/billing/subscription";
|
||||
import { prisma } from "@/lib/db";
|
||||
import { PageHeader } from "@/components/app/page-header";
|
||||
import { UpgradeGate } from "@/components/app/upgrade-gate";
|
||||
import { TeamClient } from "@/components/app/team-client";
|
||||
|
||||
export const metadata: Metadata = { title: "Team" };
|
||||
|
||||
export default async function TeamPage() {
|
||||
const session = await requireAuth();
|
||||
const allowed = await subjectHasFeature(
|
||||
session.user.id,
|
||||
"team_workspace",
|
||||
session.session.activeOrganizationId
|
||||
);
|
||||
|
||||
if (!allowed) {
|
||||
return (
|
||||
<>
|
||||
<PageHeader title="Team workspace" description="Collaborate with your team." />
|
||||
<UpgradeGate
|
||||
title="Team workspaces are an Agency feature"
|
||||
description="Upgrade to Agency for a 5-seat workspace, white-label mode, and custom branding."
|
||||
requiredPlan="Agency"
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
const { plan } = await getEffectivePlan(session.user.id, session.session.activeOrganizationId);
|
||||
const membership = await prisma.member.findFirst({
|
||||
where: { userId: session.user.id },
|
||||
include: {
|
||||
organization: {
|
||||
include: {
|
||||
branding: true,
|
||||
members: { include: { user: { select: { name: true, email: true } } } },
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
const org = membership?.organization ?? null;
|
||||
const members =
|
||||
org?.members.map((m) => ({ id: m.id, name: m.user.name, email: m.user.email, role: m.role })) ?? [];
|
||||
|
||||
return (
|
||||
<>
|
||||
<PageHeader title="Team workspace" description="Members, seats, and white-label branding." />
|
||||
<TeamClient
|
||||
org={org ? { id: org.id, name: org.name } : null}
|
||||
members={members}
|
||||
branding={
|
||||
org?.branding
|
||||
? {
|
||||
brandName: org.branding.brandName,
|
||||
primaryColor: org.branding.primaryColor,
|
||||
logoUrl: org.branding.logoUrl,
|
||||
removePoweredBy: org.branding.removePoweredBy,
|
||||
}
|
||||
: null
|
||||
}
|
||||
seats={plan.limits.seats}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user