@camunda/camunda-composite-components 0.4.2-rc.3 → 0.4.2-rc.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,7 +4,7 @@
4
4
  "type": "git",
5
5
  "url": "https://github.com/camunda-cloud/camunda-composite-components.git"
6
6
  },
7
- "version": "0.4.2-rc.2",
7
+ "version": "0.4.2-rc.3",
8
8
  "scripts": {
9
9
  "clean": "rimraf lib/",
10
10
  "build": "yarn clean && tsc",
@@ -0,0 +1,9 @@
1
+ export type StartingPrice = {
2
+ amount: number;
3
+ currency: string;
4
+ interval: string;
5
+ };
6
+ export declare const getStartingPrice: ({ token, audience, }: {
7
+ token: string;
8
+ audience: string;
9
+ }) => Promise<StartingPrice>;
@@ -0,0 +1,6 @@
1
+ import { request } from "./api";
2
+ export const getStartingPrice = async ({ token, audience, }) => request({
3
+ url: `https://accounts.${audience}/external/organizations/startingPrice`,
4
+ camundaAuth: { token },
5
+ responseType: "json",
6
+ });
@@ -1,10 +1,15 @@
1
- import React from "react";
1
+ import React, { useEffect, useState } from "react";
2
2
  import { C3AppTeaser, teaserApps, } from "./c3-app-teaser";
3
3
  import { canCreateCluster, canUpgradePlan, isTrialExpired, } from "../../utils/camunda";
4
4
  import { useC3Profile } from "../c3-user-configuration/c3-profile-provider/c3-profile-provider";
5
5
  import { Loading } from "@carbon/react";
6
- export const C3AppTeaserPage = ({ appName: app, ...props }) => {
6
+ import { getStartingPrice } from "../../api/organizations";
7
+ import { useC3UserConfiguration } from "../c3-user-configuration/c3-user-configuration-provider";
8
+ export const C3AppTeaserPage = ({ appName: app, redirectToCreateCluster, redirectToCheckout, }) => {
9
+ const { activeOrganizationId, decodedAudience, analyticsTrack, userToken } = useC3UserConfiguration();
7
10
  const { activeOrg } = useC3Profile();
11
+ const [pricing, setPricing] = useState(null);
12
+ const [hasTrialExpired, setHasTrialExpired] = useState(false);
8
13
  let appName = app || null;
9
14
  if (!appName) {
10
15
  const href = window.location.href;
@@ -15,5 +20,43 @@ export const C3AppTeaserPage = ({ appName: app, ...props }) => {
15
20
  ? lastUrlSegment
16
21
  : null;
17
22
  }
18
- return activeOrg ? (React.createElement(C3AppTeaser, { appName: appName, canCreateCluster: canCreateCluster(activeOrg), canUpgradePlan: canUpgradePlan(activeOrg), hasTrialExpired: isTrialExpired(activeOrg), ...props })) : (React.createElement(Loading, { withOverlay: false }));
23
+ useEffect(() => {
24
+ if (!userToken || !decodedAudience)
25
+ return;
26
+ (async () => {
27
+ const res = await getStartingPrice({
28
+ token: userToken,
29
+ audience: decodedAudience,
30
+ });
31
+ if (res) {
32
+ setPricing(res);
33
+ }
34
+ })();
35
+ }, [userToken, decodedAudience]);
36
+ useEffect(() => {
37
+ if (activeOrg)
38
+ setHasTrialExpired(isTrialExpired(activeOrg));
39
+ }, [activeOrg]);
40
+ const onClickCta = () => {
41
+ if (hasTrialExpired) {
42
+ analyticsTrack?.("checkout:open", { appTeaser: appName });
43
+ if (redirectToCheckout) {
44
+ redirectToCheckout();
45
+ }
46
+ else {
47
+ window.location.href = `https://console.${decodedAudience}/org/${activeOrganizationId}/checkout`;
48
+ }
49
+ }
50
+ else {
51
+ analyticsTrack?.("clusters:create:open", { appTeaser: appName });
52
+ if (redirectToCreateCluster) {
53
+ redirectToCreateCluster();
54
+ }
55
+ else {
56
+ window.location.href = `https://console.${decodedAudience}/org/${activeOrganizationId}/clusters/create`;
57
+ }
58
+ }
59
+ };
60
+ console.log(pricing);
61
+ return activeOrg ? (React.createElement(C3AppTeaser, { appName: appName, canCreateCluster: canCreateCluster(activeOrg), canUpgradePlan: canUpgradePlan(activeOrg), hasTrialExpired: hasTrialExpired, onClickCta: onClickCta, pricing: pricing })) : (React.createElement(Loading, { withOverlay: false }));
19
62
  };
@@ -0,0 +1,20 @@
1
+ import { expect, test } from "@playwright/test";
2
+ import { getStory } from "../test-utils";
3
+ test.describe("App teaser page", () => {
4
+ test("Paid plan", async ({ page }) => {
5
+ await getStory(page, "components-c3appteaser--paid-plan");
6
+ await expect(page).toHaveScreenshot();
7
+ });
8
+ test("Trial expired", async ({ page }) => {
9
+ await getStory(page, "components-c3appteaser--trial-expired");
10
+ await expect(page).toHaveScreenshot();
11
+ });
12
+ test("Cannot create cluster", async ({ page }) => {
13
+ await getStory(page, "components-c3appteaser--cannot-create-cluster");
14
+ await expect(page).toHaveScreenshot();
15
+ });
16
+ test("Cannot upgrade plan", async ({ page }) => {
17
+ await getStory(page, "components-c3appteaser--cannot-upgrade-plan");
18
+ await expect(page).toHaveScreenshot();
19
+ });
20
+ });
@@ -1,4 +1,5 @@
1
1
  import { FC } from "react";
2
+ import { StartingPrice } from "../../api/organizations";
2
3
  export declare const teaserApps: readonly ["tasklist", "operate", "optimize"];
3
4
  export type TeaserApp = (typeof teaserApps)[number];
4
5
  export type C3AppTeaserProps = {
@@ -6,7 +7,7 @@ export type C3AppTeaserProps = {
6
7
  canCreateCluster: boolean;
7
8
  canUpgradePlan: boolean;
8
9
  hasTrialExpired: boolean;
9
- redirectToCheckout?: () => void;
10
- redirectToCreateCluster?: () => void;
10
+ onClickCta: () => void;
11
+ pricing: StartingPrice | null;
11
12
  };
12
13
  export declare const C3AppTeaser: FC<C3AppTeaserProps>;
@@ -3,32 +3,10 @@ import { Add, ArrowUp } from "@carbon/react/icons";
3
3
  import { AppTeaserCards } from "./app-teaser-cards";
4
4
  import { getReadableAppName } from "../../utils/camunda";
5
5
  import { operatePreviewBase64, optimizePreviBase64, tasklistPreviewBase64, } from "../../assets/appTeaserPreviews";
6
- import { useC3UserConfiguration } from "../c3-user-configuration/c3-user-configuration-provider";
7
6
  export const teaserApps = ["tasklist", "operate", "optimize"];
8
7
  const base64Src = (src) => `data:image/jpeg;base64,${src}`;
9
- export const C3AppTeaser = ({ appName: app, hasTrialExpired, canUpgradePlan, canCreateCluster, redirectToCheckout, redirectToCreateCluster, }) => {
8
+ export const C3AppTeaser = ({ appName: app, hasTrialExpired, canUpgradePlan, canCreateCluster, onClickCta, pricing, }) => {
10
9
  const appName = app ? getReadableAppName(app) : "";
11
- const { activeOrganizationId, decodedAudience, analyticsTrack } = useC3UserConfiguration();
12
- const onClickCta = () => {
13
- if (hasTrialExpired) {
14
- analyticsTrack?.("checkout:open", { appTeaser: appName });
15
- if (redirectToCheckout) {
16
- redirectToCheckout();
17
- }
18
- else {
19
- window.location.href = `https://console.${decodedAudience}/org/${activeOrganizationId}/checkout`;
20
- }
21
- }
22
- else {
23
- analyticsTrack?.("clusters:create:open", { appTeaser: appName });
24
- if (redirectToCreateCluster) {
25
- redirectToCreateCluster();
26
- }
27
- else {
28
- window.location.href = `https://console.${decodedAudience}/org/${activeOrganizationId}/clusters/create`;
29
- }
30
- }
31
- };
32
10
  return (React.createElement(AppTeaserCards, { title: hasTrialExpired
33
11
  ? `Upgrade your plan${appName ? ` to use ${appName}` : ""} `
34
12
  : `Create a Cluster${appName ? ` to use ${appName}` : ""}`, subtitle: hasTrialExpired ? (React.createElement(React.Fragment, null,
@@ -37,7 +15,9 @@ export const C3AppTeaser = ({ appName: app, hasTrialExpired, canUpgradePlan, can
37
15
  "create a Cluster or access the following apps and features.")) : (React.createElement(React.Fragment, null,
38
16
  "The apps displayed below require a Cluster to run. ",
39
17
  React.createElement("br", null),
40
- "Begin by creating your Cluster.")), subtext: hasTrialExpired ? "Plans starting at €99/month" : "", cta: {
18
+ "Begin by creating your Cluster.")), subtext: hasTrialExpired && pricing
19
+ ? `Plans starting at ${pricing.currency || ""}${pricing.amount || ""}${pricing.interval ? `/${pricing.interval}` : ""}`
20
+ : "", cta: {
41
21
  action: onClickCta,
42
22
  text: hasTrialExpired ? "Upgrade plan" : "Create Cluster",
43
23
  renderIcon: hasTrialExpired ? ArrowUp : Add,
@@ -13,25 +13,6 @@ export function createAppProps() {
13
13
  export function createAppBarProps(options = {}) {
14
14
  return {
15
15
  isOpen: Boolean(options?.isOpen),
16
- appTeaserRouteProps: options.useElementsFromConfig
17
- ? {
18
- operate: {
19
- routeProps: {
20
- onClick: () => console.log("Redirecting to Operate app teaser page..."),
21
- },
22
- },
23
- optimize: {
24
- routeProps: {
25
- onClick: () => console.log("Redirecting to Optimize app teaser page..."),
26
- },
27
- },
28
- tasklist: {
29
- routeProps: {
30
- onClick: () => console.log("Redirecting to Tasklist app teaser page..."),
31
- },
32
- },
33
- }
34
- : undefined,
35
16
  elements: options.useElementsFromConfig
36
17
  ? undefined
37
18
  : options?.elements ?? [
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "type": "git",
5
5
  "url": "https://github.com/camunda-cloud/camunda-composite-components.git"
6
6
  },
7
- "version": "0.4.2-rc.3",
7
+ "version": "0.4.2-rc.4",
8
8
  "scripts": {
9
9
  "clean": "rimraf lib/",
10
10
  "build": "yarn clean && tsc",