Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,22 @@ interface EligibilityResponse {
}

export default async function DevPlanCancellationFeedbackPage() {
const userData = await fetchServerData<{ user: { id: string } } | null>(
const userDataPromise = fetchServerData<{ user: { id: string } } | null>(
"GET",
"/user/me",
);
const eligibilityPromise = fetchServerData<EligibilityResponse>(
"GET",
"/dev-plan-cancellation-feedback/eligibility",
);

const userData = await userDataPromise;

if (!userData?.user) {
redirect("/login?returnUrl=/dashboard/feedback/dev-plan-cancellation");
}

const eligibility = await fetchServerData<EligibilityResponse>(
"GET",
"/dev-plan-cancellation-feedback/eligibility",
);
const eligibility = await eligibilityPromise;

return (
<div className="min-h-screen bg-background py-12">
Expand Down
13 changes: 8 additions & 5 deletions apps/code/src/app/dashboard/survey/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,22 @@ export const metadata = {
};

export default async function SurveyPage() {
const userData = await fetchServerData<{ user: { id: string } } | null>(
const userDataPromise = fetchServerData<{ user: { id: string } } | null>(
"GET",
"/user/me",
);
const eligibilityPromise = fetchServerData<SurveyEligibility>(
"GET",
"/model-survey/eligibility",
);

const userData = await userDataPromise;

if (!userData?.user) {
redirect("/login?returnUrl=/dashboard/survey");
}

const eligibility = await fetchServerData<SurveyEligibility>(
"GET",
"/model-survey/eligibility",
);
const eligibility = await eligibilityPromise;

if (!eligibility || eligibility.topModels.length === 0) {
const year = eligibility?.year ?? new Date().getUTCFullYear();
Expand Down
53 changes: 24 additions & 29 deletions apps/playground/src/app/audio/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,36 +32,31 @@ export default async function AudioPage({
cookieStore.get(AUDIO_MODEL_COOKIE)?.value,
);

const [models, providers] = await Promise.all([
fetchModels(),
fetchProviders(),
]);

// Ensure the dedicated Chat org exists, then list it so it can back the
// default billing context for the playground.
await fetchServerData("GET", "/playground/chat-org");
const initialOrganizationsData = await fetchServerData("GET", "/orgs", {
params: { query: { includeChat: "true" } },
});

let initialProjectsData: { projects: Project[] } | null = null;
if (orgId) {
try {
initialProjectsData = (await fetchServerData(
"GET",
"/orgs/{id}/projects",
{
params: {
path: {
id: orgId,
const [models, providers, initialOrganizationsData, orgIdProjectsData] =
await Promise.all([
fetchModels(),
fetchProviders(),
// Ensure the dedicated Chat org exists, then list it so it can back the
// default billing context for the playground.
fetchServerData("GET", "/playground/chat-org").then(() =>
fetchServerData("GET", "/orgs", {
params: { query: { includeChat: "true" } },
}),
),
orgId
? fetchServerData("GET", "/orgs/{id}/projects", {
params: {
path: {
id: orgId,
},
},
},
},
)) as { projects: Project[] };
} catch (error) {
console.warn("Failed to fetch projects for organization:", orgId, error);
}
}
})
: null,
]);

let initialProjectsData = (orgIdProjectsData ?? null) as {
projects: Project[];
} | null;

if (
projectId &&
Expand Down
53 changes: 24 additions & 29 deletions apps/playground/src/app/canvas/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,36 +32,31 @@ export default async function CanvasPage({
cookieStore.get(CANVAS_MODEL_COOKIE)?.value,
);

const [models, providers] = await Promise.all([
fetchModels(),
fetchProviders(),
]);

// Ensure the dedicated Chat org exists, then list it so it can back the
// default billing context for the playground.
await fetchServerData("GET", "/playground/chat-org");
const initialOrganizationsData = await fetchServerData("GET", "/orgs", {
params: { query: { includeChat: "true" } },
});

let initialProjectsData: { projects: Project[] } | null = null;
if (orgId) {
try {
initialProjectsData = (await fetchServerData(
"GET",
"/orgs/{id}/projects",
{
params: {
path: {
id: orgId,
const [models, providers, initialOrganizationsData, orgIdProjectsData] =
await Promise.all([
fetchModels(),
fetchProviders(),
// Ensure the dedicated Chat org exists, then list it so it can back the
// default billing context for the playground.
fetchServerData("GET", "/playground/chat-org").then(() =>
fetchServerData("GET", "/orgs", {
params: { query: { includeChat: "true" } },
}),
),
orgId
? fetchServerData("GET", "/orgs/{id}/projects", {
params: {
path: {
id: orgId,
},
},
},
},
)) as { projects: Project[] };
} catch (error) {
console.warn("Failed to fetch projects for organization:", orgId, error);
}
}
})
: null,
]);

let initialProjectsData = (orgIdProjectsData ?? null) as {
projects: Project[];
} | null;

const allOrganizations = (
initialOrganizationsData &&
Expand Down
53 changes: 24 additions & 29 deletions apps/playground/src/app/image/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,36 +32,31 @@ export default async function ImagePage({
cookieStore.get(IMAGE_MODEL_COOKIE)?.value,
);

const [models, providers] = await Promise.all([
fetchModels(),
fetchProviders(),
]);

// Ensure the dedicated Chat org exists, then list it so it can back the
// default billing context for the playground.
await fetchServerData("GET", "/playground/chat-org");
const initialOrganizationsData = await fetchServerData("GET", "/orgs", {
params: { query: { includeChat: "true" } },
});

let initialProjectsData: { projects: Project[] } | null = null;
if (orgId) {
try {
initialProjectsData = (await fetchServerData(
"GET",
"/orgs/{id}/projects",
{
params: {
path: {
id: orgId,
const [models, providers, initialOrganizationsData, orgIdProjectsData] =
await Promise.all([
fetchModels(),
fetchProviders(),
// Ensure the dedicated Chat org exists, then list it so it can back the
// default billing context for the playground.
fetchServerData("GET", "/playground/chat-org").then(() =>
fetchServerData("GET", "/orgs", {
params: { query: { includeChat: "true" } },
}),
),
orgId
? fetchServerData("GET", "/orgs/{id}/projects", {
params: {
path: {
id: orgId,
},
},
},
},
)) as { projects: Project[] };
} catch (error) {
console.warn("Failed to fetch projects for organization:", orgId, error);
}
}
})
: null,
]);

let initialProjectsData = (orgIdProjectsData ?? null) as {
projects: Project[];
} | null;

if (
projectId &&
Expand Down
9 changes: 7 additions & 2 deletions apps/playground/src/app/playground-shell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ export async function renderPlaygroundShell({
redirect(`/?${newParams.toString()}`);
}

// Start the model catalogue fetches immediately — they don't depend on any
// of the org/billing lookups below, so they resolve while those run.
const modelsPromise = fetchModels();
const providersPromise = fetchProviders();

const initialOrganizationsData = await fetchServerData("GET", "/orgs");
const allOrganizations = (
initialOrganizationsData &&
Expand Down Expand Up @@ -201,8 +206,8 @@ export async function renderPlaygroundShell({

const projects = (initialProjectsData?.projects ?? []) as Project[];
const [models, providers] = await Promise.all([
fetchModels(),
fetchProviders(),
modelsPromise,
providersPromise,
]);

let selectedProject: Project | null = null;
Expand Down
5 changes: 2 additions & 3 deletions apps/playground/src/app/realtime/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,12 @@ export default async function RealtimePage({
cookieStore.get(REALTIME_MODEL_COOKIE)?.value,
);

const [models, providers] = await Promise.all([
const [models, providers, initialOrganizationsData] = await Promise.all([
fetchModels(),
fetchProviders(),
fetchServerData("GET", "/orgs"),
]);

const initialOrganizationsData = await fetchServerData("GET", "/orgs");

const allOrganizations = (
initialOrganizationsData &&
typeof initialOrganizationsData === "object" &&
Expand Down
53 changes: 24 additions & 29 deletions apps/playground/src/app/video/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,36 +32,31 @@ export default async function VideoPage({
cookieStore.get(VIDEO_MODEL_COOKIE)?.value,
);

const [models, providers] = await Promise.all([
fetchModels(),
fetchProviders(),
]);

// Ensure the dedicated Chat org exists, then list it so it can back the
// default billing context for the playground.
await fetchServerData("GET", "/playground/chat-org");
const initialOrganizationsData = await fetchServerData("GET", "/orgs", {
params: { query: { includeChat: "true" } },
});

let initialProjectsData: { projects: Project[] } | null = null;
if (orgId) {
try {
initialProjectsData = (await fetchServerData(
"GET",
"/orgs/{id}/projects",
{
params: {
path: {
id: orgId,
const [models, providers, initialOrganizationsData, orgIdProjectsData] =
await Promise.all([
fetchModels(),
fetchProviders(),
// Ensure the dedicated Chat org exists, then list it so it can back the
// default billing context for the playground.
fetchServerData("GET", "/playground/chat-org").then(() =>
fetchServerData("GET", "/orgs", {
params: { query: { includeChat: "true" } },
}),
),
orgId
? fetchServerData("GET", "/orgs/{id}/projects", {
params: {
path: {
id: orgId,
},
},
},
},
)) as { projects: Project[] };
} catch (error) {
console.warn("Failed to fetch projects for organization:", orgId, error);
}
}
})
: null,
]);

let initialProjectsData = (orgIdProjectsData ?? null) as {
projects: Project[];
} | null;

if (
projectId &&
Expand Down
27 changes: 15 additions & 12 deletions apps/ui/src/app/dashboard/[orgId]/[projectId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,18 @@ export default async function Dashboard({
}>;
}) {
const { orgId, projectId } = await params;

// Project-scoped "developer" members don't get the project-wide dashboard —
// send them to their personal usage view.
const orgsData = await fetchServerData<{
organizations?: { id: string; role?: string }[];
}>("GET", "/orgs");
const role = orgsData?.organizations?.find((o) => o.id === orgId)?.role;
if (role === "developer") {
redirect(`/dashboard/${orgId}/${projectId}/me`);
}

const searchParamsData = searchParams ? await searchParams : {};

const today = new Date();
const fromParam =
searchParamsData?.from ?? format(subDays(today, 6), "yyyy-MM-dd");
const toParam = searchParamsData?.to ?? format(today, "yyyy-MM-dd");

const initialActivityData = await fetchServerData<ActivitT>(
const orgsDataPromise = fetchServerData<{
organizations?: { id: string; role?: string }[];
}>("GET", "/orgs");

const initialActivityDataPromise = fetchServerData<ActivitT>(
"GET",
"/activity",
{
Expand All @@ -50,6 +43,16 @@ export default async function Dashboard({
},
);

// Project-scoped "developer" members don't get the project-wide dashboard —
// send them to their personal usage view.
const orgsData = await orgsDataPromise;
const role = orgsData?.organizations?.find((o) => o.id === orgId)?.role;
if (role === "developer") {
redirect(`/dashboard/${orgId}/${projectId}/me`);
}

const initialActivityData = await initialActivityDataPromise;

return (
<DashboardClient initialActivityData={initialActivityData ?? undefined} />
);
Expand Down
Loading
Loading