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
Trial ups (#68478)
Filipe Silva5166c30ea530
diff --git a/.clj-kondo/config/modules/config.edn b/.clj-kondo/config/modules/config.ednindex 06d522ca6a2..3cbad054890 100644--- a/.clj-kondo/config/modules/config.edn+++ b/.clj-kondo/config/modules/config.edn@@ -1936,6 +1936,14 @@utilenterprise/harbormaster}}+ enterprise/cloud-proxy+ {:team "Cloud"+ :api #{metabase-enterprise.cloud-proxy.api}+ :uses #{api+ premium-features+ util+ enterprise/harbormaster}}+enterprise/content-translation{:team "UX West":api #{metabase-enterprise.content-translation.routes}diff --git a/enterprise/backend/src/metabase_enterprise/api_routes/routes.clj b/enterprise/backend/src/metabase_enterprise/api_routes/routes.cljindex aa055513bd9..08fe29fc651 100644--- a/enterprise/backend/src/metabase_enterprise/api_routes/routes.clj+++ b/enterprise/backend/src/metabase_enterprise/api_routes/routes.clj@@ -16,6 +16,7 @@[metabase-enterprise.audit-app.api.routes][metabase-enterprise.billing.api.routes][metabase-enterprise.cloud-add-ons.api]+ [metabase-enterprise.cloud-proxy.api][metabase-enterprise.content-translation.routes][metabase-enterprise.content-verification.api.routes][metabase-enterprise.data-studio.api]@@ -112,6 +113,7 @@"/billing" metabase-enterprise.billing.api.routes/routes"/content-translation" (premium-handler metabase-enterprise.content-translation.routes/routes :content-translation)"/cloud-add-ons" metabase-enterprise.cloud-add-ons.api/routes+ "/cloud-proxy" metabase-enterprise.cloud-proxy.api/routes"/data-studio" (premium-handler metabase-enterprise.data-studio.api/routes :data-studio)"/database-replication" (-> database-replication.api/routes ;; database-replication requires all these features.(premium-handler :attached-dwh)diff --git a/enterprise/backend/src/metabase_enterprise/cloud_proxy/api.clj b/enterprise/backend/src/metabase_enterprise/cloud_proxy/api.cljnew file mode 100644index 00000000000..c1106bbade4--- /dev/null+++ b/enterprise/backend/src/metabase_enterprise/cloud_proxy/api.clj@@ -0,0 +1,48 @@+(ns metabase-enterprise.cloud-proxy.api+ "`/api/ee/cloud-proxy` endpoints for proxying calls to the Metabase Store."+ (:require+ [metabase-enterprise.harbormaster.client :as hm.client]+ [metabase.api.common :as api]+ [metabase.api.macros :as api.macros]+ [metabase.premium-features.core :as premium-features]+ [metabase.util :as m.util]+ [metabase.util.malli.schema :as ms]))++(set! *warn-on-reflection* true)++;; Allowlist of superuser operation-ids+(def ^:private allowed-superuser-operations+ #{"mb-plan-trial-up"+ "mb-plan-trial-up-available"+ "mb-plan-change-plan"+ "mb-plan-change-plan-preview"})++;; Allowlist of non-superuser operation-ids+(def ^:private allowed-public-operations+ #{"list-plans"+ "get-plan"+ "list-addons"})++#_{:clj-kondo/ignore [:metabase/validate-defendpoint-has-response-schema]}+(api.macros/defendpoint :post "/:operation-id"+ "Proxy a call to the Metabase Store API via harbormaster client.+ This endpoint is used only for hosted instances, and calls Harbormaster Store using a OpenAPI client.+ :operation-id is the operation-id of the Harbormaster Store endpoint.+ All parameters for the operation are taken in the POST body."+ [{:keys [operation-id]} :- [:map [:operation-id ms/NonBlankString]]+ _query-params+ body :- [:maybe :map]]+ (when-not (premium-features/is-hosted?)+ (throw (ex-info "This endpoint is only available for hosted instances" {:status-code 400})))+ (when-not (contains? (into allowed-public-operations allowed-superuser-operations) operation-id)+ (throw (ex-info "Invalid operation-id" {:status-code 400})))+ (when-not (contains? allowed-public-operations operation-id)+ (api/check-superuser))+ (->> body+ m.util/deep-kebab-keys+ (hm.client/call operation-id)+ m.util/deep-snake-keys))++(def routes+ "`/api/ee/cloud-proxy` routes."+ (api.macros/ns-handler *ns*))diff --git a/enterprise/backend/src/metabase_enterprise/harbormaster/client.clj b/enterprise/backend/src/metabase_enterprise/harbormaster/client.cljindex 33c1a603bff..bab0b13f466 100644--- a/enterprise/backend/src/metabase_enterprise/harbormaster/client.clj+++ b/enterprise/backend/src/metabase_enterprise/harbormaster/client.clj@@ -7,6 +7,7 @@[martian.clj-http :as martian-http][martian.core :as martian][medley.core :as m]+ [metabase.api.common :as api][metabase.api.settings :as api.auth][metabase.store-api.core :as store-api][metabase.util :as m.util]@@ -128,13 +129,18 @@{:name ::add-bearer-token:enter (fn [ctx] (assoc-in ctx [:request :headers "Authorization"] (str "Bearer " secret)))})+(defn- user-email-header []+ {:name ::add-user-email+ :enter (fn [ctx] (assoc-in ctx [:request :headers "X-Metabase-User-Email"] (:email @api/*current-user*)))})+(defn- create-client[store-api-url api-key](martian-http/bootstrap-openapi(str store-api-url "/openapi.json");; martian options for calling operations(merge {:server-url store-api-url}- (when api-key {:interceptors (into [(bearer-auth api-key)] martian-http/default-interceptors)}))+ (when api-key {:interceptors (into [(bearer-auth api-key) (user-email-header)]+ martian-http/default-interceptors)}));; clj-http options for loading the openapi.json itself{:headers (merge {} (when api-key {"Authorization" (str "Bearer " api-key)}))}))diff --git a/enterprise/backend/test/metabase_enterprise/cloud_proxy/api_test.clj b/enterprise/backend/test/metabase_enterprise/cloud_proxy/api_test.cljnew file mode 100644index 00000000000..5554a57b15e--- /dev/null+++ b/enterprise/backend/test/metabase_enterprise/cloud_proxy/api_test.clj@@ -0,0 +1,112 @@+(ns metabase-enterprise.cloud-proxy.api-test+ (:require+ [clojure.test :refer [deftest is testing]]+ [metabase-enterprise.harbormaster.client :as hm.client]+ [metabase.test :as mt]))++(set! *warn-on-reflection* true)++(def mock-responses+ {"mb-plan-trial-up-available"+ {:available true+ :plan-alias "pro-cloud"}++ "mb-plan-trial-up"+ {:status "ok"}++ "mb-plan-change-plan-preview"+ {:amount-due-now 0+ :next-payment-amount 57500+ :next-payment-date "2026-02-10T12:00:00Z"+ :warnings nil}++ "mb-plan-change-plan"+ {:instance-status "active"}++ "get-plan"+ {:description "Metabase Pro Cloud"+ :trial-days 14+ :token-features ["no-upsell" "whitelabel"]+ :name "Metabase Pro Cloud"+ :per-user-price "$12.00"+ :billing-period-months 1+ :hosting-features ["custom-domain"]+ :product "prod_K79Voj2md354w8"+ :alias "pro-cloud"+ :can-purchase true+ :id 16+ :users-included 10+ :price "$575.00"}++ "list-plans"+ [{:id 1 :name "Starter"}+ {:id 2 :name "Pro"}]++ "list-addons"+ [{:id 1 :name "AI Addon"}]})++(defn- mock-hm-call [operation-id _body]+ (get mock-responses operation-id {:operation-id operation-id}))++(deftest hosted-only-test+ (testing "endpoint requires hosted instance"+ (mt/with-premium-features #{} ; not hosted+ (is (= "This endpoint is only available for hosted instances"+ (mt/user-http-request :crowberto :post 400 "ee/cloud-proxy/mb-plan-trial-up-available"))))))++(deftest invalid-operation-test+ (testing "endpoint rejects invalid operation-id"+ (mt/with-premium-features #{:hosting}+ (is (= "Invalid operation-id"+ (mt/user-http-request :crowberto :post 400 "ee/cloud-proxy/invalid-operation"))))))++(deftest superuser-operations-test+ (testing "superuser operations require superuser"+ (mt/with-premium-features #{:hosting}+ (with-redefs [hm.client/call mock-hm-call]+ (doseq [op ["mb-plan-trial-up" "mb-plan-trial-up-available"+ "mb-plan-change-plan" "mb-plan-change-plan-preview"]]+ (testing (str "operation " op " requires superuser")+ (is (= "You don't have permissions to do that."+ (mt/user-http-request :rasta :post 403 (str "ee/cloud-proxy/" op)))))))))++ (testing "superuser can access superuser operations"+ (mt/with-premium-features #{:hosting}+ (with-redefs [hm.client/call mock-hm-call]+ (doseq [op ["mb-plan-trial-up" "mb-plan-trial-up-available"+ "mb-plan-change-plan" "mb-plan-change-plan-preview"]]+ (testing (str "superuser can access " op)+ (is (map? (mt/user-http-request :crowberto :post 200 (str "ee/cloud-proxy/" op))))))))))++(deftest request-key-conversion-test+ (testing "request body keys are converted to kebab-case for harbormaster"+ (mt/with-premium-features #{:hosting}+ (let [received-body (atom nil)]+ (with-redefs [hm.client/call (fn [_op body]+ (reset! received-body body)+ {:status "ok"})]+ (mt/user-http-request :crowberto :post 200 "ee/cloud-proxy/mb-plan-change-plan-preview"+ {:new_plan_alias "pro-cloud"+ :force_end_trial true})+ (is (= {:new-plan-alias "pro-cloud"+ :force-end-trial true}+ @received-body)))))))++(deftest response-key-conversion-test+ (testing "response keys are converted to snake_case for frontend"+ (mt/with-premium-features #{:hosting}+ (with-redefs [hm.client/call mock-hm-call]+ (let [resp (mt/user-http-request :crowberto :post 200 "ee/cloud-proxy/mb-plan-trial-up-available")]+ (is (contains? resp :plan_alias))+ (is (not (contains? resp :plan-alias))))++ (let [resp (mt/user-http-request :crowberto :post 200 "ee/cloud-proxy/mb-plan-change-plan-preview")]+ (is (contains? resp :amount_due_now))+ (is (contains? resp :next_payment_date))+ (is (not (contains? resp :amount-due-now))))++ (let [resp (mt/user-http-request :crowberto :post 200 "ee/cloud-proxy/get-plan")]+ (is (contains? resp :per_user_price))+ (is (contains? resp :billing_period_months))+ (is (contains? resp :users_included))+ (is (not (contains? resp :per-user-price))))))))diff --git a/enterprise/backend/test/metabase_enterprise/harbormaster/client_test.clj b/enterprise/backend/test/metabase_enterprise/harbormaster/client_test.cljindex ed201b7ce0c..25f76fc4b3f 100644--- a/enterprise/backend/test/metabase_enterprise/harbormaster/client_test.clj+++ b/enterprise/backend/test/metabase_enterprise/harbormaster/client_test.clj@@ -1,10 +1,12 @@(ns metabase-enterprise.harbormaster.client-test(:require[clojure.test :refer [deftest is testing]]+ [martian.clj-http :as martian-http]+ [martian.core :as martian][metabase-enterprise.harbormaster.client :as hm.client][metabase.settings.core :as setting][metabase.settings.models.setting]- [metabase.test.util :as mt]))+ [metabase.test :as mt]))(deftest ->config-good-test(testing "Both needed values are present and pulled from settings"@@ -33,3 +35,40 @@(is (thrown-with-msg? Exception#"Missing api-key."(#'hm.client/->config))))))++(defn- mock-client+ "Creates a martian client with the same interceptors as the real client but without fetching an openapi.json."+ [api-key]+ (martian/bootstrap "http://test.example.com"+ [{:route-name :test-op+ :path-parts ["/test"]+ :method :get}]+ {:interceptors (into [(#'hm.client/bearer-auth api-key)+ (#'hm.client/user-email-header)]+ martian-http/default-interceptors)}))++(deftest request-bearer-auth-test+ (testing "bearer-auth interceptor adds Authorization header with the api-key"+ (let [api-key "test-api-key-123"+ client (mock-client api-key)]+ (with-redefs [hm.client/client (constantly client)]+ (mt/with-current-user (mt/user->id :rasta)+ (let [req (hm.client/request :test-op)]+ (is (= (str "Bearer " api-key)+ (get-in req [:headers "Authorization"])))))))))++(deftest request-user-email-header-test+ (testing "user-email-header uses the current user at request time, not client creation time"+ ;; The mock client is created once, outside any user binding.+ ;; Both requests use the same client, so any difference in the email header+ ;; proves it's read at request time.+ (let [client (mock-client "test-key")]+ (with-redefs [hm.client/client (constantly client)]+ (mt/with-current-user (mt/user->id :rasta)+ (let [req (hm.client/request :test-op)]+ (is (= "[email protected]"+ (get-in req [:headers "X-Metabase-User-Email"])))))+ (mt/with-current-user (mt/user->id :crowberto)+ (let [req (hm.client/request :test-op)]+ (is (= "[email protected]"+ (get-in req [:headers "X-Metabase-User-Email"])))))))))diff --git a/frontend/src/metabase-types/store/modal.ts b/frontend/src/metabase-types/store/modal.tsindex 0412f9c50cc..f76f466af76 100644--- a/frontend/src/metabase-types/store/modal.ts+++ b/frontend/src/metabase-types/store/modal.ts@@ -7,6 +7,7 @@ export type ModalName =| "action"| "help"| "embed"+ | "upgrade"| typeof STATIC_LEGACY_EMBEDDING_TYPE;export type ModalState<TProps = Record<string, unknown>> = {diff --git a/frontend/src/metabase/admin/upsells/components/UpgradeModal/UpgradeModal.tsx b/frontend/src/metabase/admin/upsells/components/UpgradeModal/UpgradeModal.tsxnew file mode 100644index 00000000000..704407520ac--- /dev/null+++ b/frontend/src/metabase/admin/upsells/components/UpgradeModal/UpgradeModal.tsx@@ -0,0 +1,153 @@+import { useCallback, useEffect, useState } from "react";++import {+ useChangePlanMutation,+ useCheckTrialAvailableQuery,+ useGetChangePlanPreviewQuery,+ useGetPlanQuery,+ useStartTrialMutation,+} from "metabase/api/cloud-proxy";+import { Center, Loader, Modal } from "metabase/ui";++import { UpgradeModalError } from "./UpgradeModalError";+import { UpgradeModalInitial } from "./UpgradeModalInitial";+import { UpgradeModalLoading } from "./UpgradeModalLoading";+import type { ModalStep, UpgradeFlow } from "./types";++interface UpgradeModalProps {+ opened: boolean;+ onClose: () => void;+}++function formatCentsToDollars(cents: number): string {+ return `$${Math.round(cents / 100)}`;+}++export function UpgradeModal({ opened, onClose }: UpgradeModalProps) {+ const [step, setStep] = useState<ModalStep>("initial");++ // Check if trial is available (always needed)+ const {+ data: trialData,+ isLoading: isTrialLoading,+ isError: isTrialError,+ } = useCheckTrialAvailableQuery(undefined, { skip: !opened });++ const isTrialAvailable = trialData?.available ?? false;+ const flow: UpgradeFlow = isTrialAvailable ? "trial" : "upgrade";+ const planAlias = trialData?.plan_alias;++ // Get pricing preview - only needed when trial is NOT available (states 2 & 3)+ const {+ data: previewData,+ isLoading: isPreviewLoading,+ isError: isPreviewError,+ } = useGetChangePlanPreviewQuery(+ { new_plan_alias: planAlias ?? "" },+ { skip: !opened || !planAlias || isTrialAvailable },+ );++ // Determine if user is currently on trial (amount due is $0 when upgrading)+ const isOnTrial = previewData?.amount_due_now === 0;++ // Get plan details - only needed when NOT trial available AND on trial (state 2)+ const {+ data: planData,+ isLoading: isPlanLoading,+ isError: isPlanError,+ } = useGetPlanQuery(+ { plan_alias: planAlias ?? "" },+ { skip: !opened || !planAlias || isTrialAvailable || !isOnTrial },+ );++ // For trial available (state 1), show $0.00; otherwise use preview data+ const dueToday = isTrialAvailable+ ? "$0.00"+ : previewData+ ? formatCentsToDollars(previewData.amount_due_now)+ : "";++ // Only show plan pricing for state 2 (not available + on trial)+ const showPlanPricing = !isTrialAvailable && isOnTrial;++ // Check if any required API call failed+ const hasQueryError =+ isTrialError ||+ (!isTrialAvailable && isPreviewError) ||+ (showPlanPricing && isPlanError);++ const planPricing = planData+ ? {+ price: planData.price,+ includedUsers: planData.users_included,+ pricePerAdditionalUser: planData.per_user_price,+ billingPeriodMonths: planData.billing_period_months,+ }+ : undefined;++ const [startTrial] = useStartTrialMutation();+ const [changePlan] = useChangePlanMutation();++ // Reset step when modal opens+ useEffect(() => {+ if (opened) {+ setStep("initial");+ }+ }, [opened]);++ const handleConfirm = useCallback(async () => {+ setStep("loading");++ try {+ if (flow === "trial") {+ await startTrial().unwrap();+ } else if (planAlias) {+ await changePlan({ new_plan_alias: planAlias }).unwrap();+ }+ // Stay in loading state - UpgradeModalLoading will poll for the+ // no-upsell feature and show success when it arrives+ } catch {+ setStep("error");+ }+ }, [flow, planAlias, startTrial, changePlan]);++ const handleClose = useCallback(() => {+ setStep("initial");+ onClose();+ }, [onClose]);++ // Loading state depends on which calls are needed:+ // State 1 (trial up available): only wait for trial up check+ // State 2 (trial up not available + on trial): wait for all 3+ // State 3 (trial up not available + not on trial): wait for trial up check + preview+ const isDataLoading =+ isTrialLoading ||+ (!isTrialAvailable && isPreviewLoading) ||+ (showPlanPricing && isPlanLoading);++ return (+ <Modal opened={opened} onClose={handleClose} size="md" padding="lg">+ {step === "initial" && isDataLoading && !hasQueryError && (+ <Center h={200}>+ <Loader />+ </Center>+ )}+ {step === "initial" && !isDataLoading && !hasQueryError && (+ <UpgradeModalInitial+ flow={flow}+ dueToday={dueToday}+ showPlanPricing={showPlanPricing}+ planPricing={planPricing}+ onCancel={handleClose}+ onConfirm={handleConfirm}+ />+ )}+ {step === "loading" && (+ <UpgradeModalLoading flow={flow} onDone={handleClose} />+ )}+ {(step === "error" || (step === "initial" && hasQueryError)) && (+ <UpgradeModalError onClose={handleClose} />+ )}+ </Modal>+ );+}diff --git a/frontend/src/metabase/admin/upsells/components/UpgradeModal/UpgradeModal.unit.spec.tsx b/frontend/src/metabase/admin/upsells/components/UpgradeModal/UpgradeModal.unit.spec.tsxnew file mode 100644index 00000000000..65cf116539c--- /dev/null+++ b/frontend/src/metabase/admin/upsells/components/UpgradeModal/UpgradeModal.unit.spec.tsx@@ -0,0 +1,260 @@+import userEvent from "@testing-library/user-event";+import fetchMock from "fetch-mock";++import {+ setupChangePlanPreviewEndpoint,+ setupGetPlanEndpoint,+ setupTrialAvailableEndpoint,+} from "__support__/server-mocks";+import { renderWithProviders, screen } from "__support__/ui";+import { createMockUser } from "metabase-types/api/mocks";+import { createMockState } from "metabase-types/store/mocks";++import { UpgradeModal } from "./UpgradeModal";++const setup = ({ opened = true }: { opened?: boolean } = {}) => {+ const onClose = jest.fn();++ renderWithProviders(<UpgradeModal opened={opened} onClose={onClose} />, {+ storeInitialState: createMockState({+ currentUser: createMockUser({ is_superuser: true }),+ }),+ });++ return { onClose };+};++describe("UpgradeModal", () => {+ // State 1: Trial up available+ describe("state 1: trial up available", () => {+ beforeEach(() => {+ setupTrialAvailableEndpoint({+ available: true,+ plan_alias: "pro-cloud",+ });+ });++ it("should show trial UI with $0.00 due today", async () => {+ setup();++ expect(+ await screen.findByText("Start your 14-day trial of Pro"),+ ).toBeInTheDocument();+ expect(screen.getByText("$0.00")).toBeInTheDocument();+ expect(+ screen.getByRole("button", { name: "Start your free trial" }),+ ).toBeInTheDocument();+ });++ it("should show the no-charge message instead of plan pricing", async () => {+ setup();++ await screen.findByText("Start your 14-day trial of Pro");++ expect(+ screen.getByText(/we won't charge you automatically/),+ ).toBeInTheDocument();+ expect(+ screen.queryByText(/After your trial ends:/),+ ).not.toBeInTheDocument();+ });++ it("should only call trial-up-available API", async () => {+ setup();++ await screen.findByText("Start your 14-day trial of Pro");++ expect(+ fetchMock.callHistory.called(+ "path:/api/ee/cloud-proxy/mb-plan-trial-up-available",+ ),+ ).toBe(true);+ expect(+ fetchMock.callHistory.called(+ "path:/api/ee/cloud-proxy/mb-plan-change-plan-preview",+ ),+ ).toBe(false);+ expect(+ fetchMock.callHistory.called("path:/api/ee/cloud-proxy/get-plan"),+ ).toBe(false);+ });++ it("should close modal when clicking Cancel", async () => {+ const { onClose } = setup();++ await screen.findByText("Start your 14-day trial of Pro");+ await userEvent.click(screen.getByRole("button", { name: "Cancel" }));++ expect(onClose).toHaveBeenCalled();+ });+ });++ // State 2: Trial up not available, but currently on trial+ describe("state 2: trial up not available, on trial", () => {+ beforeEach(() => {+ setupTrialAvailableEndpoint({+ available: false,+ plan_alias: "pro-cloud",+ });+ setupChangePlanPreviewEndpoint({+ amount_due_now: 0,+ next_payment_date: "2026-02-15T00:00:00Z",+ next_payment_amount: 57500,+ warnings: null,+ });+ setupGetPlanEndpoint({+ id: 16,+ name: "Metabase Pro Cloud",+ description: "Metabase Pro Cloud",+ alias: "pro-cloud",+ product: "prod_K79Voj2md354w8",+ price: "$575.00",+ per_user_price: "$12.00",+ users_included: 10,+ trial_days: 14,+ billing_period_months: 1,+ can_purchase: true,+ token_features: ["no-upsell"],+ hosting_features: ["custom-domain"],+ });+ });++ it("should show upgrade UI with $0 due and plan pricing", async () => {+ setup();++ expect(+ await screen.findByText("Upgrade to Metabase Pro"),+ ).toBeInTheDocument();+ expect(screen.getByText("$0")).toBeInTheDocument();+ expect(screen.getByText(/After your trial ends:/)).toBeInTheDocument();+ expect(screen.getByText("$575/mo + tax")).toBeInTheDocument();+ expect(+ screen.getByText("Incl. 10 users, then $12/user/mo"),+ ).toBeInTheDocument();+ });++ it("should call all 3 APIs", async () => {+ setup();++ await screen.findByText("Upgrade to Metabase Pro");++ expect(+ fetchMock.callHistory.called(+ "path:/api/ee/cloud-proxy/mb-plan-trial-up-available",+ ),+ ).toBe(true);+ expect(+ fetchMock.callHistory.called(+ "path:/api/ee/cloud-proxy/mb-plan-change-plan-preview",+ ),+ ).toBe(true);+ expect(+ fetchMock.callHistory.called("path:/api/ee/cloud-proxy/get-plan"),+ ).toBe(true);+ });+ });++ // State 3: Trial up not available, not on trial+ describe("state 3: trial up not available, not on trial", () => {+ beforeEach(() => {+ setupTrialAvailableEndpoint({+ available: false,+ plan_alias: "pro-cloud",+ });+ setupChangePlanPreviewEndpoint({+ amount_due_now: 50000,+ next_payment_date: "2026-02-15T00:00:00Z",+ next_payment_amount: 57500,+ warnings: null,+ });+ });++ it("should show upgrade UI with amount due", async () => {+ setup();++ expect(+ await screen.findByText("Upgrade to Metabase Pro"),+ ).toBeInTheDocument();+ expect(screen.getByText("$500")).toBeInTheDocument();+ expect(+ screen.getByRole("button", { name: "Upgrade to Pro" }),+ ).toBeInTheDocument();+ });++ it("should not show plan pricing", async () => {+ setup();++ await screen.findByText("Upgrade to Metabase Pro");++ expect(+ screen.queryByText(/After your trial ends:/),+ ).not.toBeInTheDocument();+ });++ it("should only call trial-up-available and preview APIs", async () => {+ setup();++ await screen.findByText("Upgrade to Metabase Pro");++ expect(+ fetchMock.callHistory.called(+ "path:/api/ee/cloud-proxy/mb-plan-trial-up-available",+ ),+ ).toBe(true);+ expect(+ fetchMock.callHistory.called(+ "path:/api/ee/cloud-proxy/mb-plan-change-plan-preview",+ ),+ ).toBe(true);+ expect(+ fetchMock.callHistory.called("path:/api/ee/cloud-proxy/get-plan"),+ ).toBe(false);+ });++ it("should use plan_alias from trial check for preview request", async () => {+ setup();++ await screen.findByText("Upgrade to Metabase Pro");++ const call = fetchMock.callHistory.lastCall(+ "path:/api/ee/cloud-proxy/mb-plan-change-plan-preview",+ { method: "POST" },+ );+ const body = await call?.request?.json();+ expect(body).toEqual({ "new-plan-alias": "pro-cloud" });+ });+ });++ // Error state+ describe("error state", () => {+ it("should show error UI when trial-up-available API fails", async () => {+ fetchMock.post("path:/api/ee/cloud-proxy/mb-plan-trial-up-available", {+ status: 500,+ body: { message: "Internal server error" },+ });++ setup();++ expect(+ await screen.findByText("Something went wrong"),+ ).toBeInTheDocument();+ expect(screen.getByText("Please try again later.")).toBeInTheDocument();+ expect(screen.getByText("Close")).toBeInTheDocument();+ });++ it("should close modal when clicking Close on error", async () => {+ fetchMock.post("path:/api/ee/cloud-proxy/mb-plan-trial-up-available", {+ status: 500,+ body: { message: "Internal server error" },+ });++ const { onClose } = setup();++ await screen.findByText("Something went wrong");+ // Click the Close button in the error content (not the modal close button)+ await userEvent.click(screen.getByText("Close"));++ expect(onClose).toHaveBeenCalled();+ });+ });+});diff --git a/frontend/src/metabase/admin/upsells/components/UpgradeModal/UpgradeModalError.tsx b/frontend/src/metabase/admin/upsells/components/UpgradeModal/UpgradeModalError.tsxnew file mode 100644index 00000000000..de382ef5151--- /dev/null+++ b/frontend/src/metabase/admin/upsells/components/UpgradeModal/UpgradeModalError.tsx@@ -0,0 +1,39 @@+import { t } from "ttag";++import { Button, Flex, Icon, Stack, Text, Title } from "metabase/ui";++interface UpgradeModalErrorProps {+ onClose: () => void;+}++export function UpgradeModalError({ onClose }: UpgradeModalErrorProps) {+ return (+ <Stack align="center" gap="lg" py="xl">+ <Flex+ align="center"+ justify="center"+ w={64}+ h={64}+ bg="error"+ style={{ borderRadius: "50%" }}+ >+ <Icon name="warning" c="white" size={32} />+ </Flex>++ <Stack align="center" gap="xs">+ <Title order={3} ta="center">+ {t`Something went wrong`}+ </Title>+ <Text c="text-secondary" ta="center">+ {t`Please try again later.`}+ </Text>+ </Stack>++ <Flex justify="center" w="100%">+ <Button variant="filled" color="brand" onClick={onClose}>+ {t`Close`}+ </Button>+ </Flex>+ </Stack>+ );+}diff --git a/frontend/src/metabase/admin/upsells/components/UpgradeModal/UpgradeModalInitial.tsx b/frontend/src/metabase/admin/upsells/components/UpgradeModal/UpgradeModalInitial.tsxnew file mode 100644index 00000000000..9f8b002849a--- /dev/null+++ b/frontend/src/metabase/admin/upsells/components/UpgradeModal/UpgradeModalInitial.tsx@@ -0,0 +1,139 @@+import { t } from "ttag";++import { ExternalLink } from "metabase/common/components/ExternalLink";+import {+ Anchor,+ Box,+ Button,+ Divider,+ Flex,+ Icon,+ List,+ Stack,+ Text,+ Title,+} from "metabase/ui";++import { UpsellGem } from "../UpsellGem";++import type { UpgradeFlow } from "./types";++// Strip cents from price strings like "$575.00" → "$575"+function formatPriceNoCents(price: string): string {+ return price.replace(/\.00$/, "");+}++interface PlanPricing {+ price: string;+ includedUsers: number;+ pricePerAdditionalUser: string;+ billingPeriodMonths: number;+}++interface UpgradeModalInitialProps {+ flow: UpgradeFlow;+ dueToday: string;+ showPlanPricing?: boolean;+ planPricing?: PlanPricing;+ onCancel: () => void;+ onConfirm: () => void;+}++export function UpgradeModalInitial({+ flow,+ dueToday,+ showPlanPricing,+ planPricing,+ onCancel,+ onConfirm,+}: UpgradeModalInitialProps) {+ const isTrial = flow === "trial";+ const title = isTrial+ ? t`Start your 14-day trial of Pro`+ : t`Upgrade to Metabase Pro`;+ const buttonText = isTrial ? t`Start your free trial` : t`Upgrade to Pro`;+ const proFeatures = [+ t`Whitelabeling`,+ t`Advanced Permissions`,+ t`Usage Analytics, and more`,+ ];++ return (+ <Stack gap="lg">+ <Flex align="center" gap="sm">+ <UpsellGem size={24} />+ <Title order={2}>{title}</Title>+ </Flex>++ <Box+ bg="background-secondary"+ p="lg"+ style={{ borderRadius: "var(--mantine-radius-md)" }}+ >+ <Stack gap="md">+ <Flex justify="space-between" align="center">+ <Title order={4}>{t`Metabase Pro`}</Title>+ <ExternalLink href="https://www.metabase.com/pricing">+ <Anchor component="span">{t`See all features`}</Anchor>+ </ExternalLink>+ </Flex>++ <List+ spacing="xs"+ icon={<Icon name="check" c="text-primary" size={16} />}+ pl={0}+ >+ {proFeatures.map((feature) => (+ <List.Item key={feature}>+ <Text c="text-secondary">{feature}</Text>+ </List.Item>+ ))}+ </List>++ <Divider />++ <Stack gap="xs">+ <Flex justify="space-between" align="center">+ <Text c="text-secondary">{t`Due today:`}</Text>+ <Text fw="bold" size="lg">+ {dueToday}+ </Text>+ </Flex>+ {showPlanPricing && planPricing && (+ <Flex justify="space-between" align="flex-start">+ <Text c="text-secondary">{t`After your trial ends:`}</Text>+ <Stack gap={0} align="flex-end">+ <Text fw="bold" size="md">+ {planPricing.billingPeriodMonths === 12+ ? t`${formatPriceNoCents(planPricing.price)}/year + tax`+ : t`${formatPriceNoCents(planPricing.price)}/mo + tax`}+ </Text>+ <Text c="text-secondary" size="sm">+ {planPricing.billingPeriodMonths === 12+ ? t`Incl. ${planPricing.includedUsers} users, then ${formatPriceNoCents(planPricing.pricePerAdditionalUser)}/user/year`+ : t`Incl. ${planPricing.includedUsers} users, then ${formatPriceNoCents(planPricing.pricePerAdditionalUser)}/user/mo`}+ </Text>+ </Stack>+ </Flex>+ )}+ </Stack>+ </Stack>+ </Box>++ {isTrial && (+ <Text c="text-secondary">+ {t`After your free trial ends, we won't charge you automatically – you decide if you'd like to keep the Pro plan.`}+ </Text>+ )}++ <Flex justify="flex-end" gap="md">+ <Button variant="subtle" onClick={onCancel}>+ {t`Cancel`}+ </Button>+ <Button variant="filled" color="brand" onClick={onConfirm}>+ {buttonText}+ </Button>+ </Flex>+ </Stack>+ );+}diff --git a/frontend/src/metabase/admin/upsells/components/UpgradeModal/UpgradeModalLoading.tsx b/frontend/src/metabase/admin/upsells/components/UpgradeModal/UpgradeModalLoading.tsxnew file mode 100644index 00000000000..e7d78a30ea3--- /dev/null+++ b/frontend/src/metabase/admin/upsells/components/UpgradeModal/UpgradeModalLoading.tsx@@ -0,0 +1,95 @@+import { t } from "ttag";++import { useGetSettingsQuery } from "metabase/api";+import { useTokenRefreshUntil } from "metabase/api/utils";+import { Button, Flex, Icon, Loader, Stack, Text, Title } from "metabase/ui";++import type { UpgradeFlow } from "./types";++interface UpgradeModalLoadingProps {+ flow: UpgradeFlow;+ onDone: () => void;+}++export function UpgradeModalLoading({+ flow,+ onDone,+}: UpgradeModalLoadingProps) {+ // Poll every second until no-upsell feature appears+ useTokenRefreshUntil("no-upsell", { intervalMs: 1000 });++ const { data: settings } = useGetSettingsQuery();+ const tokenFeatures = settings?.["token-status"]?.features ?? [];+ const isSettingUp = !tokenFeatures.includes("no-upsell");++ const isTrial = flow === "trial";++ if (isSettingUp) {+ const title = isTrial+ ? t`Setting up your free trial, please wait`+ : t`Setting up Metabase Pro, please wait`;++ return (+ <Stack align="center" gap="lg" py="xl">+ <Loader size="xl" />++ <Stack align="center" gap="xs">+ <Title order={3} ta="center">+ {title}+ </Title>+ <Text c="text-secondary" ta="center">+ {t`This will take just a minute or so`}+ </Text>+ </Stack>++ <Flex justify="center" w="100%">+ <Button variant="filled" color="brand" disabled>+ {t`Done`}+ </Button>+ </Flex>+ </Stack>+ );+ }++ // Success state - feature has arrived+ const successTitle = isTrial+ ? t`Your free trial is ready`+ : t`Metabase Pro is ready to use`;++ return (+ <Stack align="center" gap="lg" py="xl">+ <Flex+ align="center"+ justify="center"+ w={64}+ h={64}+ bg="success"+ style={{ borderRadius: "50%" }}+ >+ <Icon name="check" c="white" size={32} />+ </Flex>++ <Stack align="center" gap="xs">+ <Title order={3} ta="center">+ {successTitle}+ </Title>+ <Text c="text-secondary" ta="center">+ {t`Happy exploring!`}+ </Text>+ </Stack>++ <Flex justify="center" w="100%">+ <Button+ variant="filled"+ color="brand"+ onClick={() => {+ onDone();+ window.location.reload();+ }}+ >+ {t`Done`}+ </Button>+ </Flex>+ </Stack>+ );+}diff --git a/frontend/src/metabase/admin/upsells/components/UpgradeModal/index.ts b/frontend/src/metabase/admin/upsells/components/UpgradeModal/index.tsnew file mode 100644index 00000000000..0a034a22897--- /dev/null+++ b/frontend/src/metabase/admin/upsells/components/UpgradeModal/index.ts@@ -0,0 +1,2 @@+export { UpgradeModal } from "./UpgradeModal";+export { useUpgradeAction } from "./use-upgrade-action";diff --git a/frontend/src/metabase/admin/upsells/components/UpgradeModal/types.ts b/frontend/src/metabase/admin/upsells/components/UpgradeModal/types.tsnew file mode 100644index 00000000000..8133ff9f8b1--- /dev/null+++ b/frontend/src/metabase/admin/upsells/components/UpgradeModal/types.ts@@ -0,0 +1,2 @@+export type ModalStep = "initial" | "loading" | "error";+export type UpgradeFlow = "trial" | "upgrade";diff --git a/frontend/src/metabase/admin/upsells/components/UpgradeModal/use-upgrade-action.tsx b/frontend/src/metabase/admin/upsells/components/UpgradeModal/use-upgrade-action.tsxnew file mode 100644index 00000000000..2cdbd75a08c--- /dev/null+++ b/frontend/src/metabase/admin/upsells/components/UpgradeModal/use-upgrade-action.tsx@@ -0,0 +1,47 @@+import { useCallback } from "react";++import { useSetting } from "metabase/common/hooks";+import { useDispatch } from "metabase/lib/redux";+import { setOpenModal } from "metabase/redux/ui";++import { UPGRADE_URL } from "../../constants";+import { useUpsellLink } from "../use-upsell-link";++interface UseUpgradeActionProps {+ url: string;+ campaign: string;+ location: string;+}++interface UseUpgradeActionResult {+ onClick: (() => void) | undefined;+ url: string | undefined;+}++export function useUpgradeAction({+ url,+ campaign,+ location,+}: UseUpgradeActionProps): UseUpgradeActionResult {+ const dispatch = useDispatch();+ const isHosted = useSetting("is-hosted?");+ const urlWithParams = useUpsellLink({ url, campaign, location });++ const openModal = useCallback(() => {+ dispatch(setOpenModal("upgrade"));+ }, [dispatch]);++ const shouldUseModal = isHosted && url === UPGRADE_URL;++ if (shouldUseModal) {+ return {+ onClick: openModal,+ url: undefined,+ };+ }++ return {+ onClick: undefined,+ url: urlWithParams,+ };+}diff --git a/frontend/src/metabase/admin/upsells/components/UpsellBanner.tsx b/frontend/src/metabase/admin/upsells/components/UpsellBanner.tsxindex 41ee56e0e60..7230534a780 100644--- a/frontend/src/metabase/admin/upsells/components/UpsellBanner.tsx+++ b/frontend/src/metabase/admin/upsells/components/UpsellBanner.tsx@@ -14,6 +14,7 @@ import {import { UPGRADE_URL } from "../constants";+import { useUpgradeAction } from "./UpgradeModal";import S from "./UpsellBanner.module.css";import {type DismissibleProps,@@ -23,7 +24,6 @@ import { UpsellCta } from "./UpsellCta";import { UpsellGem } from "./UpsellGem";import { UpsellWrapper } from "./UpsellWrapper";import { trackUpsellClicked, trackUpsellViewed } from "./analytics";-import { useUpsellLink } from "./use-upsell-link";type CardLinkProps =| {@@ -62,7 +62,7 @@ export const UpsellBannerInner: React.FC<UpsellBannerProps> = ({onClick,...props}: UpsellBannerProps) => {- const urlWithParams = useUpsellLink({+ const { onClick: upgradeOnClick, url: upgradeUrl } = useUpgradeAction({url: buttonLink ?? UPGRADE_URL,campaign,location,@@ -78,6 +78,9 @@ export const UpsellBannerInner: React.FC<UpsellBannerProps> = ({: { dismissible: false, onDismiss: () => {} };const gemSize = large ? 24 : undefined;+ // Use onClick if provided, otherwise use upgrade action+ const handleClick = onClick ?? upgradeOnClick;+return (<BoxclassName={cx(S.UpsellBannerComponent, large && S.Large)}@@ -100,8 +103,8 @@ export const UpsellBannerInner: React.FC<UpsellBannerProps> = ({<Flex align="center" gap="md"><UpsellCta- onClick={onClick}- url={buttonLink ? urlWithParams : undefined}+ onClick={handleClick}+ url={upgradeUrl}internalLink={internalLink}buttonText={buttonText}onClickCapture={() => trackUpsellClicked({ location, campaign })}diff --git a/frontend/src/metabase/admin/upsells/components/UpsellBigCard.tsx b/frontend/src/metabase/admin/upsells/components/UpsellBigCard.tsxindex 52c7bb23b1a..543ca9dd7cb 100644--- a/frontend/src/metabase/admin/upsells/components/UpsellBigCard.tsx+++ b/frontend/src/metabase/admin/upsells/components/UpsellBigCard.tsx@@ -1,18 +1,17 @@import cx from "classnames";import { useMount } from "react-use";-import { P, match } from "ts-pattern";import { ExternalLink } from "metabase/common/components/ExternalLink";import { Box, Flex, Image, Stack, Text, Title } from "metabase/ui";import { UPGRADE_URL } from "../constants";+import { useUpgradeAction } from "./UpgradeModal";import S from "./UpsellBigCard.module.css";import StylesUpsellCtaLink from "./UpsellCta.module.css";import { UpsellGem } from "./UpsellGem";import { UpsellWrapper } from "./UpsellWrapper";import { trackUpsellClicked, trackUpsellViewed } from "./analytics";-import { useUpsellLink } from "./use-upsell-link";export type UpsellBigCardProps = React.PropsWithChildren<{title: string;@@ -44,10 +43,7 @@ export const UpsellBigCardInner: React.FC<UpsellBigCardProps> = ({children,...props}: UpsellBigCardProps) => {- const url = useUpsellLink({- // The fallback url only applies when the button opens a modal instead of- // navigating to an external url. The value is not used otherwise. It is- // there only because we cannot conditionally skip the hook.+ const { onClick: upgradeOnClick, url: upgradeUrl } = useUpgradeAction({url: buttonLink ?? UPGRADE_URL,campaign,location,@@ -62,6 +58,34 @@ export const UpsellBigCardInner: React.FC<UpsellBigCardProps> = ({StylesUpsellCtaLink.Large,);+ // Use onClick if provided, otherwise use upgrade action+ const handleClick = onClick ?? upgradeOnClick;++ const renderCta = () => {+ if (handleClick) {+ return (+ <Box+ component="button"+ className={ctaClassnames}+ onClick={handleClick}+ onClickCapture={() => trackUpsellClicked({ location, campaign })}+ >+ {buttonText}+ </Box>+ );+ }++ return (+ <ExternalLink+ className={ctaClassnames}+ href={upgradeUrl}+ onClickCapture={() => trackUpsellClicked({ location, campaign })}+ >+ {buttonText}+ </ExternalLink>+ );+ };+return (<Boxdata-testid="upsell-big-card"@@ -78,30 +102,7 @@ export const UpsellBigCardInner: React.FC<UpsellBigCardProps> = ({<Text lh="xl" mb="lg">{children}</Text>- {match(onClick)- .with(P.nonNullable, () => (- <Box- component="button"- className={ctaClassnames}- onClickCapture={() =>- trackUpsellClicked({ location, campaign })- }- onClick={onClick}- >- {buttonText}- </Box>- ))- .otherwise(() => (- <ExternalLink- className={ctaClassnames}- href={url}- onClickCapture={() =>- trackUpsellClicked({ location, campaign })- }- >- {buttonText}- </ExternalLink>- ))}+ {renderCta()}</Stack></Flex>{illustrationSrc && (diff --git a/frontend/src/metabase/admin/upsells/components/UpsellPill.tsx b/frontend/src/metabase/admin/upsells/components/UpsellPill.tsxindex 9c1d0eea7d8..80b73352c7f 100644--- a/frontend/src/metabase/admin/upsells/components/UpsellPill.tsx+++ b/frontend/src/metabase/admin/upsells/components/UpsellPill.tsx@@ -3,11 +3,11 @@ import { useMount } from "react-use";import { ExternalLink } from "metabase/common/components/ExternalLink";import { UnstyledButton } from "metabase/ui";+import { useUpgradeAction } from "./UpgradeModal";import { UpsellGem } from "./UpsellGem";import S from "./UpsellPill.module.css";import { UpsellWrapper } from "./UpsellWrapper";import { trackUpsellClicked, trackUpsellViewed } from "./analytics";-import { useUpsellLink } from "./use-upsell-link";export function UpsellPillInner({children,@@ -22,7 +22,7 @@ export function UpsellPillInner({source: string;onClick?: () => void;}) {- const url = useUpsellLink({+ const { onClick: upgradeOnClick, url: upgradeUrl } = useUpgradeAction({url: link,campaign,location,@@ -32,14 +32,16 @@ export function UpsellPillInner({trackUpsellViewed({ location, campaign });});- if (onClick) {+ // Use onClick if provided, otherwise use upgrade action+ const handleClick = onClick ?? upgradeOnClick;++ if (handleClick) {return (<UnstyledButton- onClick={() => {- trackUpsellClicked({ location, campaign });- onClick();- }}+ onClick={handleClick}+ onClickCapture={() => trackUpsellClicked({ location, campaign })}className={S.UpsellPillComponent}+ data-testid="upsell-pill"><UpsellGem />{children}@@ -49,7 +51,7 @@ export function UpsellPillInner({return (<ExternalLink- href={url}+ href={upgradeUrl}onClickCapture={() => trackUpsellClicked({ location, campaign })}data-testid="upsell-pill"className={S.UpsellPillComponent}diff --git a/frontend/src/metabase/api/cloud-proxy.ts b/frontend/src/metabase/api/cloud-proxy.tsnew file mode 100644index 00000000000..c50d204204b--- /dev/null+++ b/frontend/src/metabase/api/cloud-proxy.ts@@ -0,0 +1,114 @@+import { Api } from "./api";++// Response types matching harbormaster/server/store/api.clj schemas++export interface TrialUpAvailableResponse {+ available: boolean;+ plan_alias: string;+}++export interface TrialUpResponse {+ status: string;+}++export interface ChangePlanPreviewResponse {+ amount_due_now: number; // cents+ next_payment_date?: string;+ next_payment_amount: number; // cents+ warnings?: string[];+}++export interface ChangePlanResponse {+ instance_status: string;+}++export interface GetPlanResponse {+ id: number;+ name: string;+ description: string;+ alias: string;+ product: string;+ price: string; // formatted, e.g. "$575.00"+ per_user_price: string; // formatted, e.g. "$12.00"+ users_included: number;+ trial_days: number;+ billing_period_months: number;+ can_purchase: boolean;+ token_features: string[];+ hosting_features: string[];+}++// Request types+interface ChangePlanRequest {+ new_plan_alias: string;+ force_end_trial?: boolean;+}++interface GetPlanRequest {+ plan_alias: string;+}++export const cloudProxyApi = Api.injectEndpoints({+ endpoints: (builder) => ({+ checkTrialAvailable: builder.query<TrialUpAvailableResponse, void>({+ query: () => ({+ method: "POST",+ url: "/api/ee/cloud-proxy/mb-plan-trial-up-available",+ body: {},+ }),+ }),++ startTrial: builder.mutation<TrialUpResponse, void>({+ query: () => ({+ method: "POST",+ url: "/api/ee/cloud-proxy/mb-plan-trial-up",+ body: {},+ }),+ }),++ getChangePlanPreview: builder.query<+ ChangePlanPreviewResponse,+ ChangePlanRequest+ >({+ query: ({ new_plan_alias, force_end_trial }) => ({+ method: "POST",+ url: "/api/ee/cloud-proxy/mb-plan-change-plan-preview",+ body: {+ "new-plan-alias": new_plan_alias,+ ...(force_end_trial !== undefined && {+ "force-end-trial": force_end_trial,+ }),+ },+ }),+ }),++ changePlan: builder.mutation<ChangePlanResponse, ChangePlanRequest>({+ query: ({ new_plan_alias, force_end_trial }) => ({+ method: "POST",+ url: "/api/ee/cloud-proxy/mb-plan-change-plan",+ body: {+ "new-plan-alias": new_plan_alias,+ ...(force_end_trial !== undefined && {+ "force-end-trial": force_end_trial,+ }),+ },+ }),+ }),++ getPlan: builder.query<GetPlanResponse, GetPlanRequest>({+ query: ({ plan_alias }) => ({+ method: "POST",+ url: "/api/ee/cloud-proxy/get-plan",+ body: { "plan-alias": plan_alias },+ }),+ }),+ }),+});++export const {+ useCheckTrialAvailableQuery,+ useStartTrialMutation,+ useGetChangePlanPreviewQuery,+ useChangePlanMutation,+ useGetPlanQuery,+} = cloudProxyApi;diff --git a/frontend/src/metabase/common/components/UpsellCard/UpsellCard.tsx b/frontend/src/metabase/common/components/UpsellCard/UpsellCard.tsxindex 1907f46d72c..9286a2a4941 100644--- a/frontend/src/metabase/common/components/UpsellCard/UpsellCard.tsx+++ b/frontend/src/metabase/common/components/UpsellCard/UpsellCard.tsx@@ -3,6 +3,7 @@ import { useMount } from "react-use";import { Box, Flex, Image, Stack, Text, Title } from "metabase/ui";+import { useUpgradeAction } from "../../../admin/upsells/components/UpgradeModal";import { UpsellCta } from "../../../admin/upsells/components/UpsellCta";import { UpsellGem } from "../../../admin/upsells/components/UpsellGem";import { UpsellWrapper } from "../../../admin/upsells/components/UpsellWrapper";@@ -10,7 +11,6 @@ import {trackUpsellClicked,trackUpsellViewed,} from "../../../admin/upsells/components/analytics";-import { useUpsellLink } from "../../../admin/upsells/components/use-upsell-link";import { UPGRADE_URL } from "../../../admin/upsells/constants";import S from "./UpsellCard.module.css";@@ -69,7 +69,7 @@ export const UpsellCardInner: React.FC<UpsellCardProps> = ({buttonStyle,...props}: UpsellCardProps) => {- const urlWithParams = useUpsellLink({+ const { onClick: upgradeOnClick, url: upgradeUrl } = useUpgradeAction({url: buttonLink ?? UPGRADE_URL,campaign,location,@@ -89,6 +89,9 @@ export const UpsellCardInner: React.FC<UpsellCardProps> = ({const normalizedMaxWidth =maxWidth === "initial" ? undefined : `${maxWidth ?? 200}px`;+ // Use onClick if provided, otherwise use upgrade action+ const handleClick = onClick ?? upgradeOnClick;+return (<Boxdata-testid="upsell-card"@@ -112,8 +115,8 @@ export const UpsellCardInner: React.FC<UpsellCardProps> = ({<Box mx="md" mb="lg"><UpsellCtastyle={buttonStyle}- onClick={onClick}- url={buttonLink ? urlWithParams : undefined}+ onClick={handleClick}+ url={upgradeUrl}internalLink={internalLink}buttonText={buttonText}onClickCapture={() => trackUpsellClicked({ location, campaign })}diff --git a/frontend/src/metabase/new/components/NewModals/NewModals.tsx b/frontend/src/metabase/new/components/NewModals/NewModals.tsxindex 407a670f46a..f6e127a71f7 100644--- a/frontend/src/metabase/new/components/NewModals/NewModals.tsx+++ b/frontend/src/metabase/new/components/NewModals/NewModals.tsx@@ -5,6 +5,7 @@ import { push } from "react-router-redux";import { useLocation } from "react-use";import ActionCreator from "metabase/actions/containers/ActionCreator";+import { UpgradeModal } from "metabase/admin/upsells/components/UpgradeModal";import CreateCollectionModal from "metabase/collections/containers/CreateCollectionModal";import { Modal } from "metabase/common/components/Modal";import { CreateDashboardModal } from "metabase/dashboard/containers/CreateDashboardModal";@@ -116,6 +117,8 @@ export const NewModals = withRouter((props: WithRouterProps) => {/>);}+ case "upgrade":+ return <UpgradeModal opened onClose={handleModalClose} />;default:return (<PaletteShortcutsModaldiff --git a/frontend/test/__support__/server-mocks/cloud-proxy.ts b/frontend/test/__support__/server-mocks/cloud-proxy.tsnew file mode 100644index 00000000000..04dc8d94be5--- /dev/null+++ b/frontend/test/__support__/server-mocks/cloud-proxy.ts@@ -0,0 +1,67 @@+import fetchMock from "fetch-mock";++export interface TrialAvailableResponse {+ available: boolean;+ plan_alias: string;+}++export interface ChangePlanPreviewResponse {+ amount_due_now: number;+ next_payment_date: string;+ next_payment_amount: number;+ warnings: string[] | null;+}++export interface GetPlanResponse {+ id: number;+ name: string;+ description: string;+ alias: string;+ product: string;+ price: string;+ per_user_price: string;+ users_included: number;+ trial_days: number;+ billing_period_months: number;+ can_purchase: boolean;+ token_features: string[];+ hosting_features: string[];+}++export function setupTrialAvailableEndpoint(+ response: TrialAvailableResponse,+): void {+ fetchMock.post(+ "path:/api/ee/cloud-proxy/mb-plan-trial-up-available",+ response,+ { name: "cloud-proxy-trial-available" },+ );+}++export function setupChangePlanPreviewEndpoint(+ response: ChangePlanPreviewResponse,+): void {+ fetchMock.post(+ "path:/api/ee/cloud-proxy/mb-plan-change-plan-preview",+ response,+ { name: "cloud-proxy-change-plan-preview" },+ );+}++export function setupGetPlanEndpoint(response: GetPlanResponse): void {+ fetchMock.post("path:/api/ee/cloud-proxy/get-plan", response, {+ name: "cloud-proxy-get-plan",+ });+}++export function setupStartTrialEndpoint(): void {+ fetchMock.post("path:/api/ee/cloud-proxy/mb-plan-start-trial", 200, {+ name: "cloud-proxy-start-trial",+ });+}++export function setupChangePlanEndpoint(): void {+ fetchMock.post("path:/api/ee/cloud-proxy/mb-plan-change-plan", 200, {+ name: "cloud-proxy-change-plan",+ });+}diff --git a/frontend/test/__support__/server-mocks/index.ts b/frontend/test/__support__/server-mocks/index.tsindex 3a5ed7d2a40..bb84aa6e61c 100644--- a/frontend/test/__support__/server-mocks/index.ts+++ b/frontend/test/__support__/server-mocks/index.ts@@ -9,6 +9,7 @@ export * from "./automagic-dashboards";export * from "./bookmark";export * from "./bug-report";export * from "./card";+export * from "./cloud-proxy";export * from "./collection";export * from "./comment";export * from "./constants";