From cec2055a44addb46eaebce072088e01b96cbff93 Mon Sep 17 00:00:00 2001 From: Flavien David Date: Tue, 19 Mar 2024 11:12:53 +0100 Subject: [PATCH] Clean up fair limits SQL schema + remove legacy dialog (#4358) * Clean up fair limits SQL schema + remove legacy dialog * Move to a dedicated component * :shirt: --- front/components/app/ReachedLimitPopup.tsx | 64 +++++++++++++++++++ front/lib/models/plan.ts | 3 +- front/package-lock.json | 1 - front/pages/w/[wId]/assistant/[cId]/index.tsx | 4 +- front/pages/w/[wId]/assistant/new.tsx | 56 +--------------- 5 files changed, 69 insertions(+), 59 deletions(-) create mode 100644 front/components/app/ReachedLimitPopup.tsx diff --git a/front/components/app/ReachedLimitPopup.tsx b/front/components/app/ReachedLimitPopup.tsx new file mode 100644 index 000000000000..e811ec29c44a --- /dev/null +++ b/front/components/app/ReachedLimitPopup.tsx @@ -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: ( +

+ Come back tomorrow for a fresh start or{" "} + skip the trial and start paying now. +

+ ), + }; +} + +function getUpsellDialogDetailsForFreePlan() { + return { + title: "You’ve reach the messages limit", + validateLabel: "Check Dust plans", + children: ( +

+ Looks like you've used up all your messages. Check out our paid plans to + get unlimited messages. +

+ ), + }; +} + +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 ( + { + void router.push(`/w/${workspaceId}/subscription`); + }} + onCancel={() => onClose()} + cancelLabel="Close" + validateLabel={validateLabel} + > + {children} + + ); +} diff --git a/front/lib/models/plan.ts b/front/lib/models/plan.ts index 60968294c1ec..2a7c278c5b2d 100644 --- a/front/lib/models/plan.ts +++ b/front/lib/models/plan.ts @@ -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, diff --git a/front/package-lock.json b/front/package-lock.json index 460f7a390191..4425d11bae8c 100644 --- a/front/package-lock.json +++ b/front/package-lock.json @@ -150,7 +150,6 @@ "devDependencies": { "@tsconfig/recommended": "^1.0.3", "@types/uuid": "^9.0.7", - "sequelize": "^6.31.0", "tslib": "^2.6.2", "typescript": "^5.0.3" }, diff --git a/front/pages/w/[wId]/assistant/[cId]/index.tsx b/front/pages/w/[wId]/assistant/[cId]/index.tsx index 14e8a3941bbf..5ec349c67587 100644 --- a/front/pages/w/[wId]/assistant/[cId]/index.tsx +++ b/front/pages/w/[wId]/assistant/[cId]/index.tsx @@ -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"; @@ -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; @@ -154,7 +154,7 @@ export default function AssistantConversation({ stickyMentions={stickyMentions} conversationId={conversationId} /> - setPlanLimitReached(false)} subscription={subscription} diff --git a/front/pages/w/[wId]/assistant/new.tsx b/front/pages/w/[wId]/assistant/new.tsx index 25a75076d17d..b84ad7d94133 100644 --- a/front/pages/w/[wId]/assistant/new.tsx +++ b/front/pages/w/[wId]/assistant/new.tsx @@ -4,10 +4,8 @@ import { Button, ChatBubbleBottomCenterTextIcon, CloudArrowLeftRightIcon, - Dialog, FolderOpenIcon, Page, - Popup, QuestionMarkCircleIcon, RobotSharedIcon, } from "@dust-tt/sparkle"; @@ -15,7 +13,6 @@ import type { ConversationType, LightAgentConfigurationType, MentionType, - SubscriptionType, UserType, } from "@dust-tt/types"; import type { InferGetServerSidePropsType } from "next"; @@ -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"; @@ -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"; @@ -446,7 +443,7 @@ export default function AssistantNew({ onSubmit={handleSubmit} conversationId={null} /> - setPlanLimitReached(false)} subscription={subscription} @@ -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 ( - { - void router.push(`/w/${workspaceId}/subscription`); - }} - onCancel={() => onClose()} - cancelLabel="Close" - validateLabel="Skip trial & upgrade now" - > -

- Come back tomorrow for a fresh start or{" "} - - skip the trial and start paying now. - -

-
- ); - } - - return ( - { - void router.push(`/w/${workspaceId}/subscription`); - }} - className="fixed bottom-16 right-16" - /> - ); -} - AssistantNew.getLayout = ( page: ReactElement, pageProps: ConversationLayoutProps