The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
Show different copy on Metabot AI purchase page after trial (#66706)
Dennis Schridde9e3e43f14a94
diff --git a/enterprise/frontend/src/metabase-enterprise/metabot/components/MetabotAdmin/MetabotPurchasePage/MetabotPurchasePage.unit.spec.tsx b/enterprise/frontend/src/metabase-enterprise/metabot/components/MetabotAdmin/MetabotPurchasePage/MetabotPurchasePage.unit.spec.tsxindex 99332b44a95..93be835f6dc 100644--- a/enterprise/frontend/src/metabase-enterprise/metabot/components/MetabotAdmin/MetabotPurchasePage/MetabotPurchasePage.unit.spec.tsx+++ b/enterprise/frontend/src/metabase-enterprise/metabot/components/MetabotAdmin/MetabotPurchasePage/MetabotPurchasePage.unit.spec.tsx@@ -19,23 +19,35 @@ import { createMockSettingsState } from "metabase-types/store/mocks";import { MetabotPurchasePage } from ".";const nonStoreUserPageRegex = /Please ask a Metabase Store Admin/;-const storeUserPageRegex = /After 14 days of free trial an additional amount/;+const storeUserTrialPageRegex =+ /After 14 days of free trial an additional amount/;+const storeUserNoTrialPageRegex = /An additional amount/;const errorPageRegex = /Error fetching information/;const expectNonStoreUserPage = async () => {expect(await screen.findByText(nonStoreUserPageRegex)).toBeVisible();- expect(screen.queryByText(storeUserPageRegex)).not.toBeInTheDocument();+ expect(screen.queryByText(storeUserTrialPageRegex)).not.toBeInTheDocument();+ expect(screen.queryByText(storeUserNoTrialPageRegex)).not.toBeInTheDocument();expect(screen.queryByText(errorPageRegex)).not.toBeInTheDocument();};-const expectStoreUserPage = async () => {+const expectStoreUserTrialPage = async () => {expect(screen.queryByText(nonStoreUserPageRegex)).not.toBeInTheDocument();- expect(await screen.findByText(storeUserPageRegex)).toBeVisible();+ expect(await screen.findByText(storeUserTrialPageRegex)).toBeVisible();+ expect(screen.queryByText(storeUserNoTrialPageRegex)).not.toBeInTheDocument();+ expect(screen.queryByText(errorPageRegex)).not.toBeInTheDocument();+};++const expectStoreUserNoTrialPage = async () => {+ expect(screen.queryByText(nonStoreUserPageRegex)).not.toBeInTheDocument();+ expect(screen.queryByText(storeUserTrialPageRegex)).not.toBeInTheDocument();+ expect(await screen.findByText(storeUserNoTrialPageRegex)).toBeVisible();expect(screen.queryByText(errorPageRegex)).not.toBeInTheDocument();};const expectErrorPage = async () => {expect(screen.queryByText(nonStoreUserPageRegex)).not.toBeInTheDocument();- expect(screen.queryByText(storeUserPageRegex)).not.toBeInTheDocument();+ expect(screen.queryByText(storeUserTrialPageRegex)).not.toBeInTheDocument();+ expect(screen.queryByText(storeUserNoTrialPageRegex)).not.toBeInTheDocument();expect(await screen.findByText(errorPageRegex)).toBeVisible();};@@ -64,11 +76,13 @@ const setupRefreshableProperties = ({const setup = async ({current_user_matches_store_user,billing_period_months,+ had_metabot,simulate_http_get_error,simulate_http_post_error,}: {current_user_matches_store_user: boolean;billing_period_months: number;+ had_metabot: false | "trial" | "tiered";simulate_http_get_error: boolean;simulate_http_post_error: false | "error-no-quantity" | "error-no-connection";}) => {@@ -79,7 +93,11 @@ const setup = async ({const user = createMockUser({ email: "[email protected]" });setupCurrentUserEndpoint(user);- setupStoreEEBillingEndpoint(billing_period_months, simulate_http_get_error);+ setupStoreEEBillingEndpoint(+ billing_period_months,+ had_metabot,+ simulate_http_get_error,+ );setupStoreEECloudAddOnsEndpoint(billing_period_months,simulate_http_get_error,@@ -102,6 +120,7 @@ describe("MetabotPurchasePage", () => {await setup({current_user_matches_store_user: false,billing_period_months: 12,+ had_metabot: false,simulate_http_get_error: false,simulate_http_post_error: false,});@@ -113,6 +132,7 @@ describe("MetabotPurchasePage", () => {await setup({current_user_matches_store_user: true,billing_period_months: 12,+ had_metabot: false,simulate_http_get_error: true,simulate_http_post_error: false,});@@ -124,6 +144,7 @@ describe("MetabotPurchasePage", () => {await setup({current_user_matches_store_user: false,billing_period_months: 12,+ had_metabot: false,simulate_http_get_error: true,simulate_http_post_error: false,});@@ -131,15 +152,40 @@ describe("MetabotPurchasePage", () => {await expectNonStoreUserPage();});+ it("does not show trial page when metabot was trialed previously", async () => {+ await setup({+ current_user_matches_store_user: true,+ billing_period_months: 1,+ had_metabot: "trial",+ simulate_http_get_error: false,+ simulate_http_post_error: false,+ });++ await expectStoreUserNoTrialPage();+ });++ it("does not show trial page when metabot was purchased previously", async () => {+ await setup({+ current_user_matches_store_user: true,+ billing_period_months: 1,+ had_metabot: "tiered",+ simulate_http_get_error: false,+ simulate_http_post_error: false,+ });++ await expectStoreUserNoTrialPage();+ });+it("shows monthly tiers according to own billing period", async () => {await setup({current_user_matches_store_user: true,billing_period_months: 1,+ had_metabot: false,simulate_http_get_error: false,simulate_http_post_error: false,});- await expectStoreUserPage();+ await expectStoreUserTrialPage();const metabase_ai_tier1 = screen.getByRole("radio", {name: /up to 1234 requests\/month/,@@ -157,11 +203,12 @@ describe("MetabotPurchasePage", () => {await setup({current_user_matches_store_user: true,billing_period_months: 12,+ had_metabot: false,simulate_http_get_error: false,simulate_http_post_error: false,});- await expectStoreUserPage();+ await expectStoreUserTrialPage();const metabase_ai_tier3 = screen.getByRole("radio", {name: /up to 3456 requests\/month/,@@ -179,11 +226,12 @@ describe("MetabotPurchasePage", () => {await setup({current_user_matches_store_user: true,billing_period_months: 12,+ had_metabot: false,simulate_http_get_error: false,simulate_http_post_error: false,});- await expectStoreUserPage();+ await expectStoreUserTrialPage();// This add-on product tier has `is_default = true`:expect(@@ -240,11 +288,12 @@ describe("MetabotPurchasePage", () => {await setup({current_user_matches_store_user: true,billing_period_months: 12,+ had_metabot: false,simulate_http_get_error: false,simulate_http_post_error: false,});- await expectStoreUserPage();+ await expectStoreUserTrialPage();await userEvent.click(screen.getByRole("radio", { name: /up to 3456 requests/ }),@@ -272,11 +321,12 @@ describe("MetabotPurchasePage", () => {await setup({current_user_matches_store_user: true,billing_period_months: 12,+ had_metabot: false,simulate_http_get_error: false,simulate_http_post_error: "error-no-quantity",});- await expectStoreUserPage();+ await expectStoreUserTrialPage();await userEvent.click(screen.getByRole("checkbox", { name: /Terms of Service/ }),@@ -299,11 +349,12 @@ describe("MetabotPurchasePage", () => {await setup({current_user_matches_store_user: true,billing_period_months: 12,+ had_metabot: false,simulate_http_get_error: false,simulate_http_post_error: "error-no-connection",});- await expectStoreUserPage();+ await expectStoreUserTrialPage();await userEvent.click(screen.getByRole("checkbox", { name: /Terms of Service/ }),diff --git a/enterprise/frontend/src/metabase-enterprise/metabot/components/MetabotAdmin/MetabotPurchasePage/MetabotPurchasePageForStoreUser.tsx b/enterprise/frontend/src/metabase-enterprise/metabot/components/MetabotAdmin/MetabotPurchasePage/MetabotPurchasePageForStoreUser.tsxindex fa99b760658..93db4ad6137 100644--- a/enterprise/frontend/src/metabase-enterprise/metabot/components/MetabotAdmin/MetabotPurchasePage/MetabotPurchasePageForStoreUser.tsx+++ b/enterprise/frontend/src/metabase-enterprise/metabot/components/MetabotAdmin/MetabotPurchasePage/MetabotPurchasePageForStoreUser.tsx@@ -24,8 +24,14 @@ import { useAddOnsBilling } from "./hooks";import type { IMetabotPurchaseFormFields } from "./types";export const MetabotPurchasePageForStoreUser = () => {- const { isLoading, error, billingPeriodMonths, tiers, defaultQuantity } =- useAddOnsBilling();+ const {+ isLoading,+ error,+ billingPeriodMonths,+ defaultQuantity,+ hadMetabot,+ tiers,+ } = useAddOnsBilling();const hasData =billingPeriodMonths !== undefined &&defaultQuantity !== undefined &&@@ -98,12 +104,16 @@ export const MetabotPurchasePageForStoreUser = () => {{t`Your browser does not support the video tag.`}</video><SettingsSection- title={t`Start free 14-day trial of Metabot`}+ title={+ hadMetabot+ ? t`Pick Metabot usage limit`+ : t`Start free 14-day trial of Metabot`+ }description={<Text mt="sm">{t`Pick a usage limit below. Usage is measured in Metabot requests.`}<br />- {t`If a chat has multiple questions, they are counted as separate Metabot requests.`}+ {t`Each message sent to Metabot is counted as a request. `}<br />{t`Usage limit applies to your whole organization.`}</Text>@@ -145,8 +155,13 @@ export const MetabotPurchasePageForStoreUser = () => {/></Card>- {/* eslint-disable-next-line no-literal-metabase-strings -- This string only shows for admins. */}- <Text>{t`After 14 days of free trial an additional amount for the add-on will be added to your next billing period invoice. You can cancel the add-on anytime in Metabase Store.`}</Text>+ <Text>+ {hadMetabot+ ? /* eslint-disable-next-line no-literal-metabase-strings -- This string only shows for admins. */+ t`An additional amount for the add-on will be added to your next billing period invoice. You can cancel the add-on anytime in Metabase Store.`+ : /* eslint-disable-next-line no-literal-metabase-strings -- This string only shows for admins. */+ t`After 14 days of free trial an additional amount for the add-on will be added to your next billing period invoice. You can cancel the add-on anytime in Metabase Store.`}+ </Text><FormSubmitButtondisabled={!values.terms_of_service}diff --git a/enterprise/frontend/src/metabase-enterprise/metabot/components/MetabotAdmin/MetabotPurchasePage/hooks.ts b/enterprise/frontend/src/metabase-enterprise/metabot/components/MetabotAdmin/MetabotPurchasePage/hooks.tsindex a09d7e81a3d..d054316cd82 100644--- a/enterprise/frontend/src/metabase-enterprise/metabot/components/MetabotAdmin/MetabotPurchasePage/hooks.ts+++ b/enterprise/frontend/src/metabase-enterprise/metabot/components/MetabotAdmin/MetabotPurchasePage/hooks.ts@@ -4,11 +4,17 @@ import {} from "metabase-enterprise/api";import type { ICloudAddOnProductTier } from "metabase-types/api";+const METABASE_AI_PRODUCT_TYPES = [+ "metabase-ai",+ "metabase-ai-tiered",+] as const;+export function useAddOnsBilling(): {error: unknown;isLoading: boolean;billingPeriodMonths: number | undefined;defaultQuantity: number | undefined;+ hadMetabot: boolean;tiers: ICloudAddOnProductTier[];} {const {@@ -25,6 +31,13 @@ export function useAddOnsBilling(): {const billingPeriodMonths =billingInfo?.data?.billing_period_months ?? undefined;+ const hadMetabot =+ billingInfo?.data?.previous_add_ons?.some(+ ({ product_type, self_service }) =>+ METABASE_AI_PRODUCT_TYPES.includes(+ product_type as (typeof METABASE_AI_PRODUCT_TYPES)[number],+ ) && self_service,+ ) ?? false;const tiers =addOns?.find(({ active, billing_period_months, product_type, self_service }) =>@@ -42,5 +55,6 @@ export function useAddOnsBilling(): {billingPeriodMonths,defaultQuantity,tiers,+ hadMetabot,};}diff --git a/frontend/src/metabase-types/api/store.ts b/frontend/src/metabase-types/api/store.tsindex 1e68ecff399..1a5b958e1e4 100644--- a/frontend/src/metabase-types/api/store.ts+++ b/frontend/src/metabase-types/api/store.ts@@ -37,6 +37,7 @@ export type BillingInfoLineItem = BillingInfoFormatType &interface IBillingInfoData {billing_period_months?: number | null;+ previous_add_ons?: { product_type: string; self_service: boolean }[] | null;}export type BillingInfo = {diff --git a/frontend/test/__support__/server-mocks/store.ts b/frontend/test/__support__/server-mocks/store.tsindex eed085585a9..3ab579d9a48 100644--- a/frontend/test/__support__/server-mocks/store.ts+++ b/frontend/test/__support__/server-mocks/store.ts@@ -1,21 +1,25 @@import fetchMock from "fetch-mock";import { match } from "ts-pattern";-import type { StoreTokenStatus } from "metabase-types/api";import { createMockCloudAddOns } from "metabase-types/api/mocks/add-ons";-export function setupStoreTokenEndpoint(tokenStatus: StoreTokenStatus) {- fetchMock.get("path:/api/premium-features/token/status", tokenStatus);-}-export function setupStoreEEBillingEndpoint(billing_period_months: number,+ had_metabot: false | "trial" | "tiered" = false,simulate_http_get_error: boolean = false,) {fetchMock.get("path:/api/ee/billing", {body: {version: "v1",- data: { billing_period_months },+ data: {+ billing_period_months,+ previous_add_ons:+ had_metabot === "trial"+ ? [{ product_type: "metabase-ai", self_service: true }]+ : had_metabot === "tiered"+ ? [{ product_type: "metabase-ai-tiered", self_service: true }]+ : null,+ },},status: simulate_http_get_error ? 500 : 200,});