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
69 changes: 37 additions & 32 deletions apps/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@
"deploy:trigger-prod": "npx trigger.dev@latest deploy"
},
"dependencies": {
"@ai-sdk/openai": "^1.1.12",
"@ai-sdk/provider": "^1.0.7",
"@ai-sdk/react": "^1.1.21",
"@ai-sdk/openai": "^1.2.5",
"@ai-sdk/provider": "^1.0.11",
"@ai-sdk/react": "^1.1.23",
"@aws-sdk/client-s3": "^3.758.0",
"@aws-sdk/s3-request-presigner": "^3.758.0",
"@browserbasehq/sdk": "^2.3.0",
"@browserbasehq/sdk": "^2.4.0",
"@bubba/notifications": "workspace:*",
"@date-fns/tz": "^1.2.0",
"@hookform/resolvers": "^3.10.0",
"@nangohq/frontend": "^0.53.1",
"@novu/headless": "^2.6.5",
"@novu/react": "^2.6.5",
"@prisma/instrumentation": "^6.3.1",
"@tanstack/react-query": "^5.66.0",
"@nangohq/frontend": "^0.53.2",
"@novu/headless": "^2.6.6",
"@novu/react": "^2.6.6",
"@prisma/instrumentation": "^6.5.0",
"@tanstack/react-query": "^5.68.0",
"@tanstack/react-table": "^8.21.2",
"@tiptap/extension-table": "^2.11.5",
"@tiptap/extension-table-cell": "^2.11.5",
Expand All @@ -36,48 +36,48 @@
"@trigger.dev/react-hooks": "3.3.17",
"@trigger.dev/sdk": "3.3.17",
"@types/d3": "^7.4.3",
"@uploadthing/react": "^7.2.0",
"@uploadthing/react": "^7.3.0",
"@upstash/ratelimit": "^2.0.5",
"ai": "^4.1.54",
"ai": "^4.1.61",
"argon2": "^0.41.1",
"bun": "^1.2.2",
"bun": "^1.2.5",
"crypto": "^1.0.1",
"d3": "^7.9.0",
"dub": "^0.46.29",
"framer-motion": "^12.4.7",
"framer-motion": "^12.5.0",
"geist": "^1.3.1",
"highlight.js": "^11.11.1",
"ky": "^1.7.5",
"languine": "^3.0.4",
"languine": "^3.1.2",
"marked": "^15.0.7",
"next": "^15.2.0",
"next": "^15.2.2",
"next-auth": "^5.0.0-beta.25",
"next-international": "^1.3.1",
"next-intl": "^3.26.3",
"next-safe-action": "^7.10.3",
"next-themes": "^0.4.4",
"next-intl": "^3.26.5",
"next-safe-action": "^7.10.4",
"next-themes": "^0.4.6",
"novel": "^1.0.2",
"novu": "^2.6.5",
"nuqs": "^2.3.2",
"playwright-core": "^1.50.1",
"posthog-js": "^1.217.2",
"posthog-node": "^4.5.2",
"puppeteer-core": "^24.2.0",
"novu": "^2.6.6",
"nuqs": "^2.4.1",
"playwright-core": "^1.51.0",
"posthog-js": "^1.231.0",
"posthog-node": "^4.10.1",
"puppeteer-core": "^24.4.0",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"react-hook-form": "^7.54.2",
"react-hotkeys-hook": "^4.6.1",
"react-intersection-observer": "^9.15.1",
"react-markdown": "^9.0.3",
"react-textarea-autosize": "^8.5.7",
"react-intersection-observer": "^9.16.0",
"react-markdown": "^9.1.0",
"react-textarea-autosize": "^8.5.8",
"react-use-draggable-scroll": "^0.4.7",
"remark-gfm": "^4.0.1",
"remark-parse": "^11.0.0",
"resend": "^4.1.2",
"sonner": "^1.7.4",
"stripe": "^17.6.0",
"stripe": "^17.7.0",
"tiptap-markdown": "^0.8.10",
"ts-pattern": "^5.6.2",
"uploadthing": "^7.5.0",
"use-debounce": "^10.0.4",
"use-long-press": "^3.2.0",
"uuid": "^11.1.0",
Expand All @@ -88,16 +88,21 @@
"devDependencies": {
"@bubba/db": "workspace:*",
"@trigger.dev/build": "3.3.17",
"@types/node": "^22.13.2",
"@types/node": "^22.13.10",
"@types/react": "19.0.10",
"@types/react-dom": "19.0.4",
"@types/uuid": "^10.0.0",
"postcss": "^8.5.2",
"postcss": "^8.5.3",
"tailwindcss": "^3.4.17",
"typescript": "^5.7.3"
"typescript": "^5.8.2"
},
"resolutions": {
"@types/react": "19.0.10",
"@types/react-dom": "19.0.4"
},
"pnpm": {
"overrides": {
"tiptap-extension-global-drag-handle": "^0.1.18"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,102 +4,101 @@ import { authActionClient } from "@/actions/safe-action";
import type { ActionResponse } from "@/actions/types";
import { auth } from "@/auth";
import { db } from "@bubba/db";
import { revalidatePath } from "next/cache";
import { appErrors, updatePolicySchema } from "../types";

export const updatePolicy = authActionClient
.schema(updatePolicySchema)
.metadata({
name: "update-policy",
track: {
event: "update-policy",
channel: "server",
},
})
.action(async ({ parsedInput }): Promise<ActionResponse> => {
const { policyId, content, status } = parsedInput;
.schema(updatePolicySchema)
.metadata({
name: "update-policy",
track: {
event: "update-policy",
channel: "server",
},
})
.action(async ({ parsedInput }): Promise<ActionResponse> => {
const { policyId, content, status } = parsedInput;

const session = await auth();
const organizationId = session?.user.organizationId;
const session = await auth();
const organizationId = session?.user.organizationId;

if (!organizationId) {
return {
success: false,
error: appErrors.UNAUTHORIZED.message,
};
}
if (!organizationId) {
return {
success: false,
error: appErrors.UNAUTHORIZED.message,
};
}

try {
const existingPolicy = await db.organizationPolicy.findUnique({
where: {
id: policyId,
organizationId,
},
});
try {
const existingPolicy = await db.organizationPolicy.findUnique({
where: {
id: policyId,
organizationId,
},
});

if (!existingPolicy) {
return {
success: false,
error: appErrors.NOT_FOUND.message,
};
}
if (!existingPolicy) {
return {
success: false,
error: appErrors.NOT_FOUND.message,
};
}

const updateData: Record<string, any> = {};
const updateData: Record<string, any> = {};

if (content !== undefined) {
console.log("CONTENT TYPE:", typeof content);
if (content !== undefined) {
console.log("CONTENT TYPE:", typeof content);

if (typeof content === "object" && content !== null) {
if (
"type" in content &&
content.type === "doc" &&
"content" in content &&
Array.isArray(content.content)
) {
updateData.content = content.content;
console.log("Extracted content array from TipTap doc");
} else if (Array.isArray(content)) {
updateData.content = content;
} else {
console.log("Unknown content format - using as is");
updateData.content = content;
}
} else {
updateData.content = content;
}
}
if (typeof content === "object" && content !== null) {
if (
"type" in content &&
content.type === "doc" &&
"content" in content &&
Array.isArray(content.content)
) {
updateData.content = content.content;
console.log("Extracted content array from TipTap doc");
} else if (Array.isArray(content)) {
updateData.content = content;
} else {
console.log("Unknown content format - using as is");
updateData.content = content;
}
} else {
updateData.content = content;
}
}

if (status) {
updateData.status = status;
}
if (status) {
updateData.status = status;
}

if (Object.keys(updateData).length === 0) {
return {
success: true,
data: { id: policyId, status: existingPolicy.status },
};
}
if (Object.keys(updateData).length === 0) {
return {
success: true,
data: { id: policyId, status: existingPolicy.status },
};
}

const updatedPolicy = await db.organizationPolicy.update({
where: {
id: policyId,
},
data: updateData,
select: {
id: true,
status: true,
},
});
const updatedPolicy = await db.organizationPolicy.update({
where: {
id: policyId,
},
data: updateData,
select: {
id: true,
status: true,
},
});

return {
success: true,
data: updatedPolicy,
};
} catch (error) {
console.error("Error updating policy:", error);
return {
success: false,
error: appErrors.UNEXPECTED_ERROR.message,
};
}
});
return {
success: true,
data: updatedPolicy,
};
} catch (error) {
console.error("Error updating policy:", error);
return {
success: false,
error: appErrors.UNEXPECTED_ERROR.message,
};
}
});
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
"use client";

import { useI18n } from "@/locales/client";
import { Card, CardContent, CardHeader } from "@bubba/ui/card";
import { Skeleton } from "@bubba/ui/skeleton";
import { redirect } from "next/navigation";
import { useState } from "react";
import { PolicyEditor } from "@/components/editor/policy-editor";
import { usePolicyDetails } from "../../../(overview)/hooks/usePolicy";
import type { JSONContent } from "@tiptap/react";
import "@bubba/ui/editor.css";

interface PolicyDetailsProps {
policyId: string;
}

export function PolicyDetails({ policyId }: PolicyDetailsProps) {
const t = useI18n();
const { policy, isLoading, error, updatePolicy } = usePolicyDetails(policyId);
const [saveStatus, setSaveStatus] = useState<"Saved" | "Saving" | "Unsaved">(
"Saved",
);
const [wordCount, setWordCount] = useState<number>(0);
const { policy, isLoading, updatePolicy } = usePolicyDetails(policyId);

if (isLoading) {
return (
Expand Down Expand Up @@ -56,23 +50,19 @@ export function PolicyDetails({ policyId }: PolicyDetailsProps) {
if (!policy) return;

try {
setSaveStatus("Saving");
await updatePolicy({
...policy,
content,
});
setSaveStatus("Saved");
} catch (error) {
console.error("Error saving policy:", error);
setSaveStatus("Unsaved");
throw error;
}
};

return (
<div className="flex flex-col h-full mx-auto">
<PolicyEditor
policyId={policyId}
content={formattedContent}
onSave={handleSavePolicy}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { auth } from "@/auth";
import { Title } from "@/components/title";
import { getI18n } from "@/locales/server";
import { db } from "@bubba/db";
import { SecondaryMenu } from "@bubba/ui/secondary-menu";
Expand Down
Loading