Skip to content

Commit

Permalink
Clean up fair limits SQL schema + remove legacy dialog (#4358)
Browse files Browse the repository at this point in the history
* Clean up fair limits SQL schema + remove legacy dialog

* Move to a dedicated component

* 👕
  • Loading branch information
flvndvd authored Mar 19, 2024
1 parent 0929f63 commit cec2055
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 59 deletions.
64 changes: 64 additions & 0 deletions front/components/app/ReachedLimitPopup.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { Dialog } from "@dust-tt/sparkle";
import type { SubscriptionType } from "@dust-tt/types";
import { useRouter } from "next/router";

import { isTrial } from "@app/lib/plans/trial";

function getUpsellDialogDetailsForFreeTrial() {
return {
title: "You’ve reach the Free Trial daily messages limit",
validateLabel: "Skip trial & upgrade now",
children: (
<p className="text-sm font-normal text-element-800">
Come back tomorrow for a fresh start or{" "}
<span className="font-bold">skip the trial and start paying now.</span>
</p>
),
};
}

function getUpsellDialogDetailsForFreePlan() {
return {
title: "You’ve reach the messages limit",
validateLabel: "Check Dust plans",
children: (
<p className="text-sm font-normal text-element-800">
Looks like you've used up all your messages. Check out our paid plans to
get unlimited messages.
</p>
),
};
}

export function ReachedLimitPopup({
isOpened,
onClose,
subscription,
workspaceId,
}: {
isOpened: boolean;
onClose: () => void;
subscription: SubscriptionType;
workspaceId: string;
}) {
const router = useRouter();

const { children, title, validateLabel } = isTrial(subscription)
? getUpsellDialogDetailsForFreeTrial()
: getUpsellDialogDetailsForFreePlan();

return (
<Dialog
isOpen={isOpened}
title={title}
onValidate={() => {
void router.push(`/w/${workspaceId}/subscription`);
}}
onCancel={() => onClose()}
cancelLabel="Close"
validateLabel={validateLabel}
>
{children}
</Dialog>
);
}
3 changes: 1 addition & 2 deletions front/lib/models/plan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ Plan.init(
},
maxMessagesTimeframe: {
type: DataTypes.ENUM("day", "lifetime"),
// TODO(2024-03-18 flav) Set to false, once migrated.
allowNull: true,
allowNull: false,
},
maxUsersInWorkspace: {
type: DataTypes.INTEGER,
Expand Down
1 change: 0 additions & 1 deletion front/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions front/pages/w/[wId]/assistant/[cId]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useRouter } from "next/router";
import type { ReactElement } from "react";
import { useContext, useEffect, useState } from "react";

import { ReachedLimitPopup } from "@app/components/app/ReachedLimitPopup";
import { AssistantDetails } from "@app/components/assistant/AssistantDetails";
import Conversation from "@app/components/assistant/conversation/Conversation";
import type { ConversationLayoutProps } from "@app/components/assistant/conversation/ConversationLayout";
Expand All @@ -13,7 +14,6 @@ import { FixedAssistantInputBar } from "@app/components/assistant/conversation/i
import { submitMessage } from "@app/components/assistant/conversation/lib";
import { SendNotificationsContext } from "@app/components/sparkle/Notification";
import { withDefaultUserAuthRequirements } from "@app/lib/iam/session";
import { LimitReachedPopup } from "@app/pages/w/[wId]/assistant/new";

const { URL = "", GA_TRACKING_ID = "" } = process.env;

Expand Down Expand Up @@ -154,7 +154,7 @@ export default function AssistantConversation({
stickyMentions={stickyMentions}
conversationId={conversationId}
/>
<LimitReachedPopup
<ReachedLimitPopup
isOpened={planLimitReached}
onClose={() => setPlanLimitReached(false)}
subscription={subscription}
Expand Down
56 changes: 2 additions & 54 deletions front/pages/w/[wId]/assistant/new.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,15 @@ import {
Button,
ChatBubbleBottomCenterTextIcon,
CloudArrowLeftRightIcon,
Dialog,
FolderOpenIcon,
Page,
Popup,
QuestionMarkCircleIcon,
RobotSharedIcon,
} from "@dust-tt/sparkle";
import type {
ConversationType,
LightAgentConfigurationType,
MentionType,
SubscriptionType,
UserType,
} from "@dust-tt/types";
import type { InferGetServerSidePropsType } from "next";
Expand All @@ -24,6 +21,7 @@ import { useRouter } from "next/router";
import type { ReactElement } from "react";
import { useContext, useEffect, useState } from "react";

import { ReachedLimitPopup } from "@app/components/app/ReachedLimitPopup";
import { AssistantDetails } from "@app/components/assistant/AssistantDetails";
import type { ConversationLayoutProps } from "@app/components/assistant/conversation/ConversationLayout";
import ConversationLayout from "@app/components/assistant/conversation/ConversationLayout";
Expand All @@ -39,7 +37,6 @@ import { compareAgentsForSort } from "@app/lib/assistant";
import { getRandomGreetingForName } from "@app/lib/client/greetings";
import { useSubmitFunction } from "@app/lib/client/utils";
import { withDefaultUserAuthRequirements } from "@app/lib/iam/session";
import { isTrial } from "@app/lib/plans/trial";
import { useAgentConfigurations, useUserMetadata } from "@app/lib/swr";
import { setUserMetadataFromClient } from "@app/lib/user";

Expand Down Expand Up @@ -446,7 +443,7 @@ export default function AssistantNew({
onSubmit={handleSubmit}
conversationId={null}
/>
<LimitReachedPopup
<ReachedLimitPopup
isOpened={planLimitReached}
onClose={() => setPlanLimitReached(false)}
subscription={subscription}
Expand All @@ -456,55 +453,6 @@ export default function AssistantNew({
);
}

export function LimitReachedPopup({
isOpened,
onClose,
subscription,
workspaceId,
}: {
isOpened: boolean;
onClose: () => void;
subscription: SubscriptionType;
workspaceId: string;
}) {
const router = useRouter();

if (isTrial(subscription)) {
return (
<Dialog
isOpen={isOpened}
title="You’ve reach the Free Trial daily messages limit"
onValidate={() => {
void router.push(`/w/${workspaceId}/subscription`);
}}
onCancel={() => onClose()}
cancelLabel="Close"
validateLabel="Skip trial & upgrade now"
>
<p className="text-sm font-normal text-element-800">
Come back tomorrow for a fresh start or{" "}
<span className="font-bold">
skip the trial and start paying now.
</span>
</p>
</Dialog>
);
}

return (
<Popup
show={isOpened}
chipLabel="Free plan"
description="Looks like you've used up all your messages. Check out our paid plans to get unlimited messages."
buttonLabel="Check Dust plans"
buttonClick={() => {
void router.push(`/w/${workspaceId}/subscription`);
}}
className="fixed bottom-16 right-16"
/>
);
}

AssistantNew.getLayout = (
page: ReactElement,
pageProps: ConversationLayoutProps
Expand Down

0 comments on commit cec2055

Please sign in to comment.