Skip to content

Commit

Permalink
filter out helicone users
Browse files Browse the repository at this point in the history
  • Loading branch information
chitalian committed Sep 18, 2024
1 parent b4d0f3e commit 8600a4d
Show file tree
Hide file tree
Showing 9 changed files with 138 additions and 47 deletions.
11 changes: 9 additions & 2 deletions valhalla/jawn/src/managers/organization/OrganizationManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,9 @@ export class OrganizationManager extends BaseManager {
return ok(layout);
}

async getMemberCount(): Promise<Result<number, string>> {
async getMemberCount(
filterHeliconeEmails: boolean = false
): Promise<Result<number, string>> {
const { data: members, error: membersError } =
await this.organizationStore.getOrganizationMembers(
this.authParams.organizationId
Expand All @@ -367,7 +369,12 @@ export class OrganizationManager extends BaseManager {
if (membersError !== null) {
return err(membersError);
}
return ok(members.length);
return ok(
members.filter(
(member) =>
!filterHeliconeEmails || !member.email.endsWith("@helicone.ai")
).length
);
}

async getOrganizationMembers(
Expand Down
22 changes: 5 additions & 17 deletions valhalla/jawn/src/managers/stripe/StripeManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ import { dbExecute } from "../../lib/shared/db/dbExecute";
import { clickhouseDb } from "../../lib/db/ClickhouseWrapper";
import { buildFilterWithAuthClickHouse } from "../../lib/shared/filters/filters";
import { UpgradeToProRequest } from "../../controllers/public/stripeController";
import { OrganizationManager } from "../organization/OrganizationManager";

const proProductPrices = {
"request-volume": process.env.PRICE_PROD_REQUEST_VOLUME_ID!,
"request-volume": process.env.PRICE_PROD_REQUEST_VOLUME_ID!, //(This is just growth)
"pro-users": process.env.PRICE_PROD_PRO_USERS_ID!,
prompts: process.env.PRICE_PROD_PROMPTS_ID!,
alerts: process.env.PRICE_PROD_ALERTS_ID!,
};

const EARLY_ADOPTER_COUPON = "WlDg28Kf"; // WlDg28Kf | prod: 9ca5IeEs
const EARLY_ADOPTER_COUPON = "9ca5IeEs"; // WlDg28Kf | prod: 9ca5IeEs

export class StripeManager extends BaseManager {
private stripe: Stripe;
Expand Down Expand Up @@ -45,10 +46,6 @@ export class StripeManager extends BaseManager {
return err("User does not have an email");
}

const getStripeCustomer = await this.stripe.customers.list({
email: user.data?.user?.email ?? "",
});
console.log(getStripeCustomer);
const customer = await this.stripe.customers.create({
email: user.data.user.email,
});
Expand Down Expand Up @@ -201,17 +198,8 @@ WHERE (${builtFilter.filter})`,
}
}
private async getOrgMemberCount(): Promise<Result<number, string>> {
const members = await supabaseServer.client
.from("organization_member")
.select("*", { count: "exact" })
.eq("organization", this.authParams.organizationId);

if (members.error) {
console.log(members.error);
return err("Error getting organization members");
}

return ok(members.count!);
const organizationManager = new OrganizationManager(this.authParams);
return await organizationManager.getMemberCount(true);
}

private shouldApplyCoupon(): boolean {
Expand Down
6 changes: 3 additions & 3 deletions web/components/layout/auth/DesktopSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ const DesktopSidebar = ({ NAVIGATION }: SidebarProps) => {
>
<div className="w-full flex flex-grow flex-col overflow-y-auto border-r dark:border-gray-700 justify-between">
<div className="flex items-center gap-2 h-14 border-b dark:border-gray-700">
<div className="flex items-center gap-2 w-fill">
<div className="flex items-center gap-2 w-full">
{!isCollapsed && <OrgDropdown />}
</div>
<div className={cn("mx-auto", isCollapsed ? "w-fit" : "mr-2")}>
Expand Down Expand Up @@ -276,7 +276,7 @@ const DesktopSidebar = ({ NAVIGATION }: SidebarProps) => {
</>
)}
</div>
{tier === "free" &&
{/* {tier === "free" &&
org?.currentOrg?.organization_type !== "customer" && (
<div className={cn("p-2", isCollapsed && "hidden")}>
<Link href="/settings/billing">
Expand All @@ -294,7 +294,7 @@ const DesktopSidebar = ({ NAVIGATION }: SidebarProps) => {
</Button>
</Link>
</div>
)}
)} */}
</div>
</div>
</>
Expand Down
2 changes: 1 addition & 1 deletion web/components/layout/orgDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export default function OrgDropdown({}: OrgDropdownProps) {
<DropdownMenuTrigger asChild>
<Button
variant="ghost"
className="flex items-center justify-between w-full ml-1 p-2"
className="flex items-center justify-start w-full ml-1 p-2"
>
{currentIcon && (
<currentIcon.icon
Expand Down
23 changes: 13 additions & 10 deletions web/components/shared/ProBlockerComponents/ProFeatureWrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, forwardRef, useMemo } from "react";
import React, { useState, forwardRef, useMemo, useCallback } from "react";
import { useOrg } from "@/components/layout/organizationContext";
import {
Dialog,
Expand Down Expand Up @@ -49,15 +49,18 @@ export const ProFeatureWrapper = forwardRef<
);
}, [org?.currentOrg?.tier, org?.currentOrg?.stripe_metadata, enabled]);

const handleClick = (e: React.MouseEvent) => {
if (!hasAccess) {
e.preventDefault();
e.stopPropagation();
setIsDialogOpen(true);
} else if (children.props.onClick) {
children.props.onClick(e);
}
};
const handleClick = useCallback(
(e: React.MouseEvent) => {
if (!hasAccess) {
e.preventDefault();
e.stopPropagation();
setIsDialogOpen(true);
} else if (children.props.onClick) {
children.props.onClick(e);
}
},
[hasAccess, children.props, setIsDialogOpen]
);

const handleUpgrade = () => {
setIsDialogOpen(false);
Expand Down
70 changes: 70 additions & 0 deletions web/components/templates/organization/plan/EnterprisePlanCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { Col } from "@/components/layout/common";
import { Button } from "@/components/ui/button";
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from "@/components/ui/card";
import Link from "next/link";
import { PlanFeatureCard } from "./PlanFeatureCard";

export const EnterprisePlanCard = () => {
return (
<div className="flex gap-6 lg:flex-row flex-col">
<Card className="max-w-3xl w-full h-fit">
<CardHeader>
<CardTitle className="text-lg font-medium flex items-end">
Enterprise{" "}
<span className="text-sm bg-purple-100 text-purple-700 px-2 py-1 rounded-md ml-2 font-medium">
Current plan
</span>
</CardTitle>
<CardDescription>
Your custom Enterprise plan tailored for your organization{"'"}s
needs.
</CardDescription>
</CardHeader>
<CardContent className="space-y-6">
<Col className="gap-4">
<p className="text-sm text-gray-500">
For detailed information about your Enterprise plan, including
custom features, limits, and support options, please contact your
account manager.
</p>
<Link href="mailto:[email protected]">
<Button variant="outline">Contact Enterprise Support</Button>
</Link>
</Col>
</CardContent>
</Card>

<div className="space-y-6 w-full lg:w-[450px]">
<PlanFeatureCard
title="Need to adjust your plan?"
description="We're here to help you optimize your Enterprise plan for your evolving needs."
buttonText="Schedule a Call"
onClick={() =>
window.open(
"https://cal.com/team/helicone/helicone-discovery",
"_blank"
)
}
/>

<PlanFeatureCard
title="Looking for documentation?"
description="Access our comprehensive Enterprise documentation and guides."
buttonText="View Enterprise Docs"
onClick={() =>
window.open(
"https://docs.helicone.ai/advanced-usage/enterprise-features",
"_blank"
)
}
/>
</div>
</div>
);
};
2 changes: 2 additions & 0 deletions web/components/templates/organization/plan/billingPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { FreePlanCard } from "./freeBillingPage";
import { ProPlanCard } from "./proBillingPage";
import { MigrateGrowthToPro } from "./MigrateGrowthToPro";
import { UnknownTierCard } from "./UnknownTierCard";
import { EnterprisePlanCard } from "./EnterprisePlanCard";

interface OrgPlanPageProps {}

Expand All @@ -26,6 +27,7 @@ const BillingPlanPage = (props: OrgPlanPageProps) => {
!knownTiers.includes(org?.currentOrg?.tier) && (
<UnknownTierCard tier={org?.currentOrg?.tier} />
)}
{org?.currentOrg?.tier === "enterprise" && <EnterprisePlanCard />}
{/* <Card className="bg-[#F9F9F9] p-4 max-w-lg">
<div className="text-[#334155] font-medium">
Looking for something else?
Expand Down
24 changes: 18 additions & 6 deletions web/components/templates/pricing/upgradeToProCTA.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Label } from "@/components/ui/label";
import { Switch } from "@/components/ui/switch";
import { getJawnClient } from "@/lib/clients/jawn";
import { useMutation, useQuery } from "@tanstack/react-query";
import { useState } from "react";
import { useMemo, useState } from "react";

export const UpgradeToProCTA = ({
defaultPrompts = false,
Expand Down Expand Up @@ -43,6 +43,10 @@ export const UpgradeToProCTA = ({
},
});

const isPro = useMemo(() => {
return org?.currentOrg?.tier === "pro-20240913";
}, [org?.currentOrg?.tier]);

return (
<div>
{showAddons && (
Expand Down Expand Up @@ -88,17 +92,25 @@ export const UpgradeToProCTA = ({

<Button
onClick={async () => {
const result = await upgradeToPro.mutateAsync();
if (result.data) {
window.open(result.data, "_blank");
if (isPro) {
window.open("/settings/billing", "_blank");
} else {
console.error("No URL returned from upgrade mutation");
const result = await upgradeToPro.mutateAsync();
if (result.data) {
window.open(result.data, "_blank");
} else {
console.error("No URL returned from upgrade mutation");
}
}
}}
className="w-full mt-4"
disabled={upgradeToPro.isLoading}
>
{upgradeToPro.isLoading ? "Loading..." : "Start 14-day free trial"}
{upgradeToPro.isLoading
? "Loading..."
: isPro
? "Upgrade"
: "Start 14-day free trial"}
</Button>
</div>
);
Expand Down
25 changes: 17 additions & 8 deletions web/components/templates/prompts/promptsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,10 @@ const PromptsPage = (props: PromptsPageProps) => {

const hasAccess = useMemo(() => {
return (
org?.currentOrg?.tier === "pro-20240913" ||
org?.currentOrg?.tier === "growth" ||
(org?.currentOrg?.stripe_metadata as { addons?: { prompts?: boolean } })
?.addons?.prompts
(org?.currentOrg?.tier === "pro-20240913" &&
(org?.currentOrg?.stripe_metadata as { addons?: { prompts?: boolean } })
?.addons?.prompts)
);
}, [org?.currentOrg?.tier, org?.currentOrg?.stripe_metadata]);

Expand Down Expand Up @@ -204,17 +204,26 @@ const PromptsPage = (props: PromptsPageProps) => {

<Dialog>
<DialogTrigger asChild className="w-min">
<ProFeatureWrapper
featureName="Prompts"
enabled={hasAccess}
>
{hasAccess ? (
<HcButton
variant={"primary"}
size={"sm"}
title={"Create new prompt"}
icon={DocumentPlusIcon}
/>
</ProFeatureWrapper>
) : (
<ProFeatureWrapper
featureName="Prompts"
enabled={false}
>
<HcButton
variant={"primary"}
size={"sm"}
title={"Create new prompt"}
icon={DocumentPlusIcon}
/>
</ProFeatureWrapper>
)}
</DialogTrigger>
<DialogContent className="w-[900px] ">
<DialogHeader className="flex flex-row justify-between items-center">
Expand Down

0 comments on commit 8600a4d

Please sign in to comment.