Skip to content

Commit

Permalink
Merge branch 'main' into home_front2
Browse files Browse the repository at this point in the history
  • Loading branch information
PopDaph authored Nov 6, 2023
2 parents 97e804e + 890760f commit a174d12
Show file tree
Hide file tree
Showing 23 changed files with 310 additions and 113 deletions.
7 changes: 4 additions & 3 deletions front/components/PlansTables.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Button, PriceTable, RocketIcon, SparklesIcon } from "@dust-tt/sparkle";
import { Tab } from "@headlessui/react";
import React from "react";

import { PRO_PLAN_SEAT_29_CODE } from "@app/lib/plans/plan_codes";
import { classNames } from "@app/lib/utils";
import { PlanType } from "@app/types/plan";

Expand Down Expand Up @@ -30,7 +31,7 @@ function FreePriceTable({ size }: { size: "sm" | "xs" }) {
<PriceTable.Item label="Privacy and Data Security" />
<PriceTable.Item label="Advanced LLM models (GPT-4, Claude…)" />
<PriceTable.Item label="Unlimited custom assistants" />
<PriceTable.Item label="100 assistant messages" variant="dash" />
<PriceTable.Item label="50 assistant messages" variant="dash" />
<PriceTable.Item label="50 documents as data sources" variant="dash" />
<PriceTable.Item label="No connections" variant="xmark" />
</PriceTable>
Expand Down Expand Up @@ -74,13 +75,13 @@ function ProPriceTable({
<PriceTable.Item label="Assistants can execute actions" />
<PriceTable.Item label="Workspace role and permissions" variant="dash" />
<PriceTable.ActionContainer>
{plan && plan.code !== "PRO_PLAN_SEAT_29" && (
{plan.code !== PRO_PLAN_SEAT_29_CODE && (
<Button
variant="primary"
size={biggerButtonSize}
label="Start now"
icon={RocketIcon}
disabled={isProcessing || plan.code === "PRO_PLAN_SEAT_29"}
disabled={isProcessing || plan.code === PRO_PLAN_SEAT_29_CODE}
onClick={onClick}
/>
)}
Expand Down
5 changes: 1 addition & 4 deletions front/lib/plans/enterprise_plans.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Attributes } from "sequelize";

import { Plan } from "@app/lib/models";
import { ENT_PLAN_FAKE_CODE } from "@app/lib/plans/plan_codes";

export type PlanAttributes = Omit<
Attributes<Plan>,
Expand All @@ -17,10 +18,6 @@ export type PlanAttributes = Omit<
* As entreprise plans are custom, we won't create them in this file, but directly from Poké.
*/

/**
* ENT_PLAN_FAKE is not subscribable and is only used to display the Enterprise plan in the UI (hence it's not stored on the db).
*/
export const ENT_PLAN_FAKE_CODE = "ENT_PLAN_FAKE_CODE";
export const ENT_PLAN_FAKE_DATA: PlanAttributes = {
code: ENT_PLAN_FAKE_CODE,
name: "Entreprise",
Expand Down
10 changes: 5 additions & 5 deletions front/lib/plans/free_plans.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { Attributes } from "sequelize";

import { Plan } from "@app/lib/models";
import {
FREE_TEST_PLAN_CODE,
FREE_UPGRADED_PLAN_CODE,
} from "@app/lib/plans/plan_codes";

export type PlanAttributes = Omit<
Attributes<Plan>,
Expand All @@ -16,10 +20,6 @@ export type PlanAttributes = Omit<
* This file about Free plans.
*/

// Current free plans:
export const FREE_TEST_PLAN_CODE = "FREE_TEST_PLAN";
export const FREE_UPGRADED_PLAN_CODE = "FREE_UPGRADED_PLAN";

/**
* FREE_TEST plan is our default plan: this is the plan used by all workspaces until they subscribe to a plan.
* It is not stored in the database (as we don't create a subsription).
Expand All @@ -29,7 +29,7 @@ export const FREE_TEST_PLAN_DATA: PlanAttributes = {
name: "Free",
stripeProductId: null,
billingType: "free",
maxMessages: 100,
maxMessages: 50,
maxUsersInWorkspace: 1,
isSlackbotAllowed: false,
isManagedSlackAllowed: false,
Expand Down
11 changes: 11 additions & 0 deletions front/lib/plans/plan_codes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Current free plans:
export const FREE_UPGRADED_PLAN_CODE = "FREE_UPGRADED_PLAN";
export const FREE_TEST_PLAN_CODE = "FREE_TEST_PLAN";

// Current pro plans:
export const PRO_PLAN_SEAT_29_CODE = "PRO_PLAN_SEAT_29";

/**
* ENT_PLAN_FAKE is not subscribable and is only used to display the Enterprise plan in the UI (hence it's not stored on the db).
*/
export const ENT_PLAN_FAKE_CODE = "ENT_PLAN_FAKE_CODE";
22 changes: 10 additions & 12 deletions front/lib/plans/pro_plans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { Attributes } from "sequelize";
import { isDevelopment } from "@app/lib/development";
import { Plan } from "@app/lib/models";

import { PRO_PLAN_SEAT_29_CODE } from "./plan_codes";

export type PlanAttributes = Omit<
Attributes<Plan>,
"id" | "createdAt" | "updatedAt"
Expand All @@ -17,23 +19,19 @@ export type PlanAttributes = Omit<
* This file about Pro plans.
*/

// Current pro plans:
export const PRO_PLAN_MAU_29_CODE = "PRO_PLAN_MAU_29";
export const PRO_PLAN_FIXED_1000_CODE = "PRO_PLAN_FIXED_1000";

/**
* Paid plans are stored in the database.
* We can update existing plans or add new one but never remove anything from this list.
* Entreprise custom plans will be created from Poké.
*/

const PRO_PLANS_DATA: PlanAttributes[] = [
{
code: "PRO_PLAN_SEAT_29",
const PRO_PLANS_DATA: PlanAttributes[] = [];

if (isDevelopment()) {
PRO_PLANS_DATA.push({
code: PRO_PLAN_SEAT_29_CODE,
name: "Pro",
stripeProductId: isDevelopment()
? "prod_OvrzyxfSDz5Jqd" // Pro plan in Stripe Test env
: "prod_OvrkkwZwLUOlpx", // Pro plan in Stripe Prod env
stripeProductId: "prod_OwKvN4XrUwFw5a",
billingType: "per_seat",
maxMessages: -1,
maxUsersInWorkspace: 1000,
Expand All @@ -45,8 +43,8 @@ const PRO_PLANS_DATA: PlanAttributes[] = [
maxDataSourcesCount: -1,
maxDataSourcesDocumentsCount: -1,
maxDataSourcesDocumentsSizeMb: 2,
},
];
});
}

/**
* Function to call when we edit something in FREE_PLANS_DATA to update the database. It will create or update the plans.
Expand Down
5 changes: 2 additions & 3 deletions front/lib/plans/subscription.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { Authenticator } from "@app/lib/auth";
import { front_sequelize } from "@app/lib/databases";
import { Plan, Subscription, Workspace } from "@app/lib/models";
import { FREE_TEST_PLAN_DATA, PlanAttributes } from "@app/lib/plans/free_plans";
import {
FREE_TEST_PLAN_CODE,
FREE_TEST_PLAN_DATA,
FREE_UPGRADED_PLAN_CODE,
PlanAttributes,
} from "@app/lib/plans/free_plans";
} from "@app/lib/plans/plan_codes";
import {
createCheckoutSession,
updateStripeSubscriptionQuantity,
Expand Down
2 changes: 1 addition & 1 deletion front/migrations/20231023_create_plan_subscriptions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Op } from "sequelize";

import { Plan, Subscription, Workspace } from "@app/lib/models";
import { FREE_UPGRADED_PLAN_CODE } from "@app/lib/plans/free_plans";
import { FREE_UPGRADED_PLAN_CODE } from "@app/lib/plans/plan_codes";
import { generateModelSId } from "@app/lib/utils";

async function main() {
Expand Down
11 changes: 7 additions & 4 deletions front/pages/api/stripe/webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ async function handler(
},
`[Stripe Webhook] Received checkout.session.completed with status "${session.status}". Ignoring event.`
);
return;
return res.status(200).json({ success: true });
}
if (session.status !== "complete") {
logger.error(
Expand All @@ -113,7 +113,7 @@ async function handler(
},
`[Stripe Webhook] Received checkout.session.completed with unkown status "${session.status}". Ignoring event.`
);
return;
return res.status(200).json({ success: true });
}

try {
Expand Down Expand Up @@ -142,7 +142,7 @@ async function handler(
);
}

return await front_sequelize.transaction(async (t) => {
await front_sequelize.transaction(async (t) => {
const now = new Date();
const activeSubscription = await Subscription.findOne({
where: { workspaceId: workspace.id, status: "active" },
Expand Down Expand Up @@ -188,6 +188,8 @@ async function handler(
{ transaction: t }
);
});

return res.status(200).json({ success: true });
} catch (error) {
logger.error(
{
Expand All @@ -199,6 +201,7 @@ async function handler(
},
"Error creating subscription."
);

return apiError(req, res, {
status_code: 500,
api_error: {
Expand Down Expand Up @@ -267,7 +270,7 @@ async function handler(
// Unhandled event type
}

return;
return res.status(200).json({ success: true });

default:
return apiError(req, res, {
Expand Down
3 changes: 1 addition & 2 deletions front/pages/poke/[wId]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { getDataSources } from "@app/lib/api/data_sources";
import { Authenticator, getSession, getUserFromSession } from "@app/lib/auth";
import { ConnectorsAPI } from "@app/lib/connectors_api";
import { CoreAPI } from "@app/lib/core_api";
import { FREE_TEST_PLAN_CODE } from "@app/lib/plans/plan_codes";
import { timeAgoFrom } from "@app/lib/utils";
import { DataSourceType } from "@app/types/data_source";
import { PlanType } from "@app/types/plan";
Expand Down Expand Up @@ -253,8 +254,6 @@ const WorkspacePage = ({
(ds) => !!ds.connectorProvider
);

const FREE_TEST_PLAN_CODE = "FREE_TEST_PLAN";

return (
<div className="min-h-screen bg-structure-50">
<PokeNavbar />
Expand Down
48 changes: 35 additions & 13 deletions front/pages/w/[wId]/builder/data-sources/[name]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,8 @@ function StandardDataSourceView({
<div className="relative mt-0 flex-none">
<Popup
show={showDocumentsLimitPopup}
chipLabel="Free plan"
description={`You have reached the limit of documents per data source (${plan.limits.dataSources.documents.count} documents). Upgrade to a paid plan for unlimited documents and data sources.`}
chipLabel={`${plan.name} plan`}
description={`You have reached the limit of documents per data source (${plan.limits.dataSources.documents.count} documents). Upgrade your plan for unlimited documents and data sources.`}
buttonLabel="Check Dust plans"
buttonClick={() => {
void router.push(`/w/${owner.sId}/subscription`);
Expand Down Expand Up @@ -341,21 +341,23 @@ function SlackBotEnableView({
readOnly,
isAdmin,
dataSource,
plan,
}: {
owner: WorkspaceType;
readOnly: boolean;
isAdmin: boolean;
dataSource: DataSourceType;
plan: PlanType;
}) {
const { botEnabled, mutateBotEnabled } = useConnectorBotEnabled({
owner: owner,
dataSource,
});

const sendNotification = useContext(SendNotificationsContext);

const router = useRouter();
const [loading, setLoading] = useState(false);

const [showNoSlackBotPopup, setShowNoSlackBotPopup] = useState(false);
const handleSetBotEnabled = async (botEnabled: boolean) => {
setLoading(true);
const res = await fetch(
Expand Down Expand Up @@ -389,14 +391,31 @@ function SlackBotEnableView({
title="Slack Bot"
visual={<ContextItem.Visual visual={SlackLogo} />}
action={
<SliderToggle
size="sm"
onClick={async () => {
await handleSetBotEnabled(!botEnabled);
}}
selected={botEnabled || false}
disabled={readOnly || !isAdmin || loading}
/>
<div className="relative">
<SliderToggle
size="sm"
onClick={async () => {
if (!plan.limits.assistant.isSlackBotAllowed)
setShowNoSlackBotPopup(true);
else await handleSetBotEnabled(!botEnabled);
}}
selected={botEnabled || false}
disabled={readOnly || !isAdmin || loading}
/>
<Popup
show={showNoSlackBotPopup}
className="absolute bottom-8 right-0"
chipLabel={`${plan.name} plan`}
description="Your plan does not allow for the Slack bot to be enabled. Upgrade your plan to chat with Dust assistants on Slack."
buttonLabel="Check Dust plans"
buttonClick={() => {
void router.push(`/w/${owner.sId}/subscription`);
}}
onClose={() => {
setShowNoSlackBotPopup(false);
}}
/>
</div>
}
>
<ContextItem.Description>
Expand Down Expand Up @@ -435,6 +454,7 @@ function ManagedDataSourceView({
connector,
nangoConfig,
githubAppUrl,
plan,
}: {
owner: WorkspaceType;
readOnly: boolean;
Expand All @@ -448,6 +468,7 @@ function ManagedDataSourceView({
googleDriveConnectorId: string;
};
githubAppUrl: string;
plan: PlanType;
}) {
const router = useRouter();

Expand Down Expand Up @@ -670,7 +691,7 @@ function ManagedDataSourceView({

{connectorProvider === "slack" && (
<SlackBotEnableView
{...{ owner, readOnly, isAdmin, dataSource }}
{...{ owner, readOnly, isAdmin, dataSource, plan }}
/>
)}
</>
Expand Down Expand Up @@ -751,6 +772,7 @@ export default function DataSourceView({
connector,
nangoConfig,
githubAppUrl,
plan,
}}
/>
) : (
Expand Down
Loading

0 comments on commit a174d12

Please sign in to comment.