Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
3fc5fba
feat(trust-portal): add Trust Portal settings page and components, in…
carhartlewis May 9, 2025
4a7cbc5
fix(trust-portal): optimize getTrustPortal function by caching sessio…
carhartlewis May 9, 2025
1e899a4
feat(trust-portal): enhance Next.js configuration and add new compone…
carhartlewis May 10, 2025
c7475e2
feat(turbo): add build:trust configuration to manage environment vari…
carhartlewis May 10, 2025
95569ae
feat(turbo): rename build:trust to trust:build and add it to the buil…
carhartlewis May 10, 2025
42480c8
Merge branch 'main' of github.com:trycompai/comp into lewis/comp-trust
carhartlewis May 10, 2025
c4c9193
Merge pull request #549 from trycompai/lewis/comp-trust
carhartlewis May 10, 2025
f869e51
refactor(turbo): remove deprecated trust:build configuration from tur…
carhartlewis May 10, 2025
3864223
refactor(turbo): remove trust:build from turbo.json to simplify build…
carhartlewis May 10, 2025
a9a5a19
refactor(trust-portal): simplify TrustPortalSettings component by rem…
carhartlewis May 10, 2025
648076f
Merge branch 'release' of github.com:trycompai/comp into lewis/comp-t…
carhartlewis May 10, 2025
75c0e49
fix(package): add missing newline at end of file in package.json
carhartlewis May 10, 2025
29c03da
refactor(db): simplify PrismaClient configuration by consolidating da…
carhartlewis May 10, 2025
4facc5c
feat(trust-portal): implement TrustPortalSettings component with dyna…
carhartlewis May 10, 2025
6c06392
Merge branch 'main' into lewis/comp-trust-fix
carhartlewis May 10, 2025
878f770
Merge pull request #552 from trycompai/lewis/comp-trust-fix
carhartlewis May 10, 2025
0fdb96e
chore(turbo): add 'data:build' to outputs in turbo.json for enhanced …
carhartlewis May 10, 2025
b76227e
Merge branch 'main' into lewis/comp-fix-trust-portal
carhartlewis May 10, 2025
a0e330a
Merge pull request #553 from trycompai/lewis/comp-fix-trust-portal
carhartlewis May 10, 2025
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 @@ -32,6 +32,10 @@ export default async function Layout({
path: `/${orgId}/settings`,
label: t("settings.general.title"),
},
{
path: `/${orgId}/settings/trust-portal`,
label: "Trust Portal",
},
{
path: `/${orgId}/settings/api-keys`,
label: t("settings.api_keys.title"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// update-organization-name-action.ts

"use server";

import { db } from "@comp/db";
import { revalidatePath, revalidateTag } from "next/cache";
import { authActionClient } from "@/actions/safe-action";
import { z } from "zod";

const trustPortalSwitchSchema = z.object({
enabled: z.boolean(),
});

export const trustPortalSwitchAction = authActionClient
.schema(trustPortalSwitchSchema)
.metadata({
name: "trust-portal-switch",
track: {
event: "trust-portal-switch",
channel: "server",
},
})
.action(async ({ parsedInput, ctx }) => {
const { enabled } = parsedInput;
const { activeOrganizationId } = ctx.session;

if (!activeOrganizationId) {
throw new Error("No active organization");
}

try {
await db.trust.upsert({
where: { organizationId: activeOrganizationId },
update: { status: enabled ? "published" : "draft" },
create: {
organizationId: activeOrganizationId,
status: enabled ? "published" : "draft",
},
});

revalidatePath("/settings/trust-portal");
revalidateTag(`organization_${activeOrganizationId}`);

return {
success: true,
};
} catch (error) {
console.error(error);
throw new Error("Failed to update organization name");
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
"use client";

import { useI18n } from "@/locales/client";
import {
Card,
CardContent,
CardDescription,
CardFooter,
CardHeader,
CardTitle,
} from "@comp/ui/card";
import {
Form,
FormControl,
FormDescription,
FormField,
FormItem,
FormLabel,
FormMessage,
} from "@comp/ui/form";
import { Switch } from "@comp/ui/switch";
import { zodResolver } from "@hookform/resolvers/zod";
import { useAction } from "next-safe-action/hooks";
import { useForm } from "react-hook-form";
import { toast } from "sonner";
import { z } from "zod";
import { trustPortalSwitchAction } from "../actions/trust-portal-switch";

const trustPortalSwitchSchema = z.object({
enabled: z.boolean(),
});

export function TrustPortalSwitch({
enabled,
slug,
}: {
enabled: boolean;
slug: string;
}) {
const t = useI18n();

const trustPortalSwitch = useAction(trustPortalSwitchAction, {
onSuccess: () => {
toast.success("Trust portal status updated");
},
onError: () => {
toast.error("Failed to update trust portal status");
},
});

const form = useForm<z.infer<typeof trustPortalSwitchSchema>>({
resolver: zodResolver(trustPortalSwitchSchema),
defaultValues: {
enabled: enabled,
},
});

const onSubmit = async (data: z.infer<typeof trustPortalSwitchSchema>) => {
await trustPortalSwitch.execute(data);
};

const onChange = (checked: boolean) => {
form.setValue("enabled", checked);
trustPortalSwitch.execute({ enabled: checked });
};

return (
<Form {...form}>
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4">
<Card>
<CardHeader>
<CardTitle>Trust Portal Configuration</CardTitle>
<CardDescription className="space-y-4 flex flex-row justify-between">
<div className="max-w-[600px]">
Enable the trust portal for your organization.
</div>
</CardDescription>
</CardHeader>
<CardContent>
<FormField
control={form.control}
name="enabled"
render={({ field }) => (
<FormItem className="flex flex-row items-center justify-between rounded-lg border p-3 shadow-sm">
<div className="space-y-0.5">
<FormLabel>Publish Trust Portal</FormLabel>
<FormDescription>
Enable the trust portal for your organization.
</FormDescription>
</div>
<FormControl>
<Switch
checked={field.value}
onCheckedChange={onChange}
disabled={trustPortalSwitch.status === "executing"}
/>
</FormControl>
</FormItem>
)}
/>
</CardContent>
<CardFooter className="flex justify-between">
<div className="text-xs text-muted-foreground">
Your trust portal will be live & accessible at https://trust.trycomp.ai/{slug}
</div>
</CardFooter>
</Card>
</form>
</Form>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { LogoSpinner } from "@/components/logo-spinner";
import { getI18n } from "@/locales/server";
import { Button } from "@comp/ui/button";
import {
Card,
CardContent,
CardDescription,
CardFooter,
CardHeader,
CardTitle,
} from "@comp/ui/card";
import { Plus } from "lucide-react";

export default async function Loading() {
const t = await getI18n();

return (
<div className="mx-auto max-w-7xl">
<Card>
<CardHeader className="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4">
<div>
<CardTitle>
{t("settings.api_keys.list_title")}
</CardTitle>
<CardDescription>
{t("settings.api_keys.list_description")}
</CardDescription>
</div>
<Button
className="flex items-center gap-1 self-start sm:self-auto"
disabled
aria-label={t("settings.api_keys.create")}
>
<Plus className="h-4 w-4" />
{t("settings.api_keys.create")}
</Button>
</CardHeader>
<CardContent>
<LogoSpinner />
</CardContent>
<CardFooter className="text-sm text-muted-foreground">
{t("settings.api_keys.security_note")}
</CardFooter>
</Card>
</div>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { auth } from "@/utils/auth";
import { headers } from "next/headers";
import { cache } from "react";
import { getI18n } from "@/locales/server";
import { db } from "@comp/db";
import type { Metadata } from "next";
import { setStaticParamsLocale } from "next-international/server";
import { TrustPortalSwitch } from "./components/TrustPortalSwitch";

export default async function TrustPortalSettings({
params,
}: {
params: Promise<{ locale: string }>;
}) {
const { locale } = await params;
setStaticParamsLocale(locale);
const t = await getI18n();

const trustPortal = await getTrustPortal();

return (
<div className="mx-auto max-w-7xl">
<TrustPortalSwitch enabled={trustPortal?.enabled ?? false} slug={trustPortal?.slug ?? ""} />
</div>
);
}

export async function generateMetadata({
params,
}: {
params: Promise<{ locale: string }>;
}): Promise<Metadata> {
const { locale } = await params;
setStaticParamsLocale(locale);
const t = await getI18n();

return {
title: "Trust Portal",
};
}
const getTrustPortal = cache(async () => {
const session = await auth.api.getSession({
headers: await headers(),
});

if (!session?.session.activeOrganizationId) {
return null;
}

const slug = await db.organization.findUnique({
where: {
id: session.session.activeOrganizationId,
},
select: {
slug: true,
},
});

const trustPortal = await db.trust.findUnique({
where: {
organizationId: session.session.activeOrganizationId,
status: "published",
},
});

if (!trustPortal) {
return {
enabled: false,
slug: slug?.slug,
};
}

return {
enabled: true,
slug: slug?.slug,
};
});
2 changes: 1 addition & 1 deletion apps/framework-editor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@comp/framework-editor",
"private": true,
"scripts": {
"dev": "next dev",
"dev": "next dev --port 3004",
"build": "next build",
"start": "next start",
"lint": "next lint",
Expand Down
41 changes: 41 additions & 0 deletions apps/trust/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/versions

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*

# env files (can opt-in for committing if needed)
.env*

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts
36 changes: 36 additions & 0 deletions apps/trust/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app).

## Getting Started

First, run the development server:

```bash
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.

This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel.

## Learn More

To learn more about Next.js, take a look at the following resources:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome!

## Deploy on Vercel

The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.

Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details.
Loading
Loading