Skip to content

Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.

refactor: update dataroom trial

Marc Seitzaa5d3c20d971
diff --git a/components/datarooms/dataroom-trial-modal.tsx b/components/datarooms/dataroom-trial-modal.tsx
index ac0826fd..33253d0e 100644
--- a/components/datarooms/dataroom-trial-modal.tsx
+++ b/components/datarooms/dataroom-trial-modal.tsx
@@ -14,10 +14,8 @@ import { useTeam } from "@/context/team-context";
import { useState } from "react";
import { toast } from "sonner";
import { UpgradePlanModal } from "../billing/upgrade-plan-modal";
-import { usePlan } from "@/lib/swr/use-billing";
import { useAnalytics } from "@/lib/analytics";
import { mutate } from "swr";
-import { log } from "@/lib/utils";
import {
Select,
SelectContent,
@@ -27,12 +25,15 @@ import {
} from "../ui/select";
import { PhoneInput } from "../ui/phone-input";
import { E164Number } from "libphonenumber-js/types.cjs";
+import { useRouter } from "next/router";
export function DataroomTrialModal({
children,
}: {
children?: React.ReactNode;
}) {
+ const router = useRouter();
+
const [industry, setIndustry] = useState<string>("");
const [companySize, setCompanySize] = useState<string>("");
const [name, setName] = useState<string>("");
@@ -56,11 +57,6 @@ export function DataroomTrialModal({
setLoading(true);
try {
- await log({
- message: `Dataroom Trial: ${teamInfo?.currentTeam?.id} \n\nName: ${name} \nCompany Name: ${companyName} \nIndustry: ${industry} \nCompany Size: ${companySize} \nPhone Number: ${phoneNumber}`,
- type: "info",
- mention: true,
- });
const response = await fetch(
`/api/teams/${teamInfo?.currentTeam?.id}/datarooms/trial`,
{
@@ -70,6 +66,11 @@ export function DataroomTrialModal({
},
body: JSON.stringify({
name: "Dataroom Demo Trial",
+ fullName: name,
+ companyName,
+ industry,
+ companySize,
+ phoneNumber,
}),
},
);
@@ -88,7 +89,8 @@ export function DataroomTrialModal({
});
toast.success("Dataroom successfully created! 🎉");
- mutate(`/api/teams/${teamInfo?.currentTeam?.id}/datarooms`);
+ await mutate(`/api/teams/${teamInfo?.currentTeam?.id}/datarooms`);
+ router.push("/datarooms");
} catch (error) {
setLoading(false);
toast.error("Error adding dataroom. Please try again.");
diff --git a/components/welcome/dataroom-trial.tsx b/components/welcome/dataroom-trial.tsx
index c3cd8c55..bb23dcce 100644
--- a/components/welcome/dataroom-trial.tsx
+++ b/components/welcome/dataroom-trial.tsx
@@ -1,9 +1,7 @@
import { useRouter } from "next/router";
import { motion } from "framer-motion";
-import { File as DocumentIcon, ServerIcon } from "lucide-react";
import { STAGGER_CHILD_VARIANTS } from "@/lib/constants";
import { Button } from "@/components/ui/button";
-import { DataroomTrialModal } from "@/components/datarooms/dataroom-trial-modal";
import { Label } from "@/components/ui/label";
import {
Select,
@@ -18,7 +16,6 @@ import { useAnalytics } from "@/lib/analytics";
import { mutate } from "swr";
import { toast } from "sonner";
import { useState } from "react";
-import { log } from "@/lib/utils";
import { E164Number } from "libphonenumber-js/types.cjs";
import { UpgradePlanModal } from "../billing/upgrade-plan-modal";
import { Input } from "../ui/input";
@@ -47,11 +44,6 @@ export default function DataroomTrial() {
setLoading(true);
try {
- await log({
- message: `Dataroom Trial: ${teamInfo?.currentTeam?.id} \n\nName: ${name} \nCompany Name: ${companyName} \nIndustry: ${industry} \nCompany Size: ${companySize} \nPhone Number: ${phoneNumber}`,
- type: "info",
- mention: true,
- });
const response = await fetch(
`/api/teams/${teamInfo?.currentTeam?.id}/datarooms/trial`,
{
@@ -61,6 +53,11 @@ export default function DataroomTrial() {
},
body: JSON.stringify({
name: "Dataroom Demo Trial",
+ fullName: name,
+ companyName,
+ industry,
+ companySize,
+ phoneNumber,
}),
},
);
diff --git a/lib/utils.ts b/lib/utils.ts
index 1f1d5dbb..92d97460 100644
--- a/lib/utils.ts
+++ b/lib/utils.ts
@@ -49,7 +49,7 @@ export const log = async ({
mention = false,
}: {
message: string;
- type: "info" | "cron" | "links" | "error";
+ type: "info" | "cron" | "links" | "error" | "trial";
mention?: boolean;
}) => {
/* If in development or env variable not set, log to the console */
@@ -63,6 +63,27 @@ export const log = async ({
/* Log a message to channel */
try {
+ if (type === "trial" && process.env.PPMK_TRIAL_SLACK_WEBHOOK_URL) {
+ return await fetch(`${process.env.PPMK_TRIAL_SLACK_WEBHOOK_URL}`, {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify({
+ blocks: [
+ {
+ type: "section",
+ text: {
+ type: "mrkdwn",
+ // prettier-ignore
+ text: `${mention ? "<@U05BTDUKPLZ> " : ""}${message}`,
+ },
+ },
+ ],
+ }),
+ });
+ }
+
return await fetch(`${process.env.PPMK_SLACK_WEBHOOK_URL}`, {
method: "POST",
headers: {
diff --git a/pages/api/teams/[teamId]/datarooms/trial.ts b/pages/api/teams/[teamId]/datarooms/trial.ts
index d4b4fb83..981b8757 100644
--- a/pages/api/teams/[teamId]/datarooms/trial.ts
+++ b/pages/api/teams/[teamId]/datarooms/trial.ts
@@ -4,6 +4,7 @@ import prisma from "@/lib/prisma";
import { authOptions } from "@/pages/api/auth/[...nextauth]";
import { CustomUser } from "@/lib/types";
import { newId } from "@/lib/id-helper";
+import { log } from "@/lib/utils";
export default async function handle(
req: NextApiRequest,
@@ -20,7 +21,15 @@ export default async function handle(
const userId = (session.user as CustomUser).id;
const { teamId } = req.query as { teamId: string };
- const { name } = req.body as { name: string };
+ const { name, fullName, companyName, industry, companySize, phoneNumber } =
+ req.body as {
+ name: string;
+ fullName: string;
+ companyName: string;
+ industry: string;
+ companySize: string;
+ phoneNumber: string;
+ };
try {
const team = await prisma.team.findUnique({
@@ -53,6 +62,12 @@ export default async function handle(
.json({ message: "Trial data room already exists" });
}
+ await log({
+ message: `Dataroom Trial: ${teamId} \n\nEmail: ${(session.user as CustomUser).email} \nName: ${fullName} \nCompany Name: ${companyName} \nIndustry: ${industry} \nCompany Size: ${companySize} \nPhone Number: ${phoneNumber}`,
+ type: "trial",
+ mention: true,
+ });
+
await prisma.team.update({
where: { id: teamId },
data: {