Skip to content

Commit dc3f77c

Browse files
committed
chore(client):extract upgrade button to a separate component
1 parent 558fd1d commit dc3f77c

File tree

3 files changed

+142
-114
lines changed

3 files changed

+142
-114
lines changed

.vscode/settings.json

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"loglevel",
3030
"microservices",
3131
"nestjs",
32+
"novu",
3233
"nrwl",
3334
"oclif",
3435
"Octokit",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
import { useCallback, useContext, useMemo } from "react";
2+
import { useUpgradeButtonData } from "../hooks/useUpgradeButtonData";
3+
import {
4+
Button,
5+
ButtonProgress,
6+
EnumButtonStyle,
7+
} from "@amplication/ui/design-system";
8+
9+
import { GET_CONTACT_US_LINK } from "../queries/workspaceQueries";
10+
import { useQuery } from "@apollo/client";
11+
import { useTracking } from "../../util/analytics";
12+
import { AnalyticsEventNames } from "../../util/analytics-events.types";
13+
import { AppContext } from "../../context/appContext";
14+
import { FeatureIndicator } from "../../Components/FeatureIndicator";
15+
import { BillingFeature } from "@amplication/util-billing-types";
16+
import { CompletePreviewSignupButton } from "../../User/CompletePreviewSignupButton";
17+
18+
const CLASS_NAME = "workspace-header";
19+
const TALK_TO_US_LINK =
20+
"https://meetings-eu1.hubspot.com/paz-yanover/product-overview-vp-product";
21+
22+
const UpgradeCtaButton = () => {
23+
const { currentWorkspace } = useContext(AppContext);
24+
25+
const { trackEvent } = useTracking();
26+
const upgradeButtonData = useUpgradeButtonData(currentWorkspace);
27+
28+
const { data } = useQuery(GET_CONTACT_US_LINK, {
29+
variables: { id: currentWorkspace.id },
30+
});
31+
32+
const daysLeftText = useMemo(() => {
33+
return `${upgradeButtonData.trialDaysLeft} day${
34+
upgradeButtonData.trialDaysLeft !== 1 ? "s" : ""
35+
} left for the free trial`;
36+
}, [upgradeButtonData.trialDaysLeft]);
37+
const handleUpgradeClick = useCallback(() => {
38+
trackEvent({
39+
eventName: AnalyticsEventNames.UpgradeClick,
40+
eventOriginLocation: "workspace-header",
41+
workspace: currentWorkspace.id,
42+
});
43+
}, [currentWorkspace.id, trackEvent]);
44+
45+
const handleContactUsClick = useCallback(() => {
46+
window.open(data?.contactUsLink, "_blank");
47+
trackEvent({
48+
eventName: AnalyticsEventNames.HelpMenuItemClick,
49+
action: "Contact Us",
50+
eventOriginLocation: "workspace-header-help-menu",
51+
});
52+
}, [data?.contactUsLink, trackEvent]);
53+
54+
return (
55+
<>
56+
{upgradeButtonData.isCompleted &&
57+
upgradeButtonData.showUpgradeTrialButton && (
58+
<a
59+
href={TALK_TO_US_LINK}
60+
target="_blank"
61+
rel="noopener noreferrer"
62+
className={`${CLASS_NAME}__version`}
63+
>
64+
<ButtonProgress
65+
className={`${CLASS_NAME}__upgrade__btn`}
66+
onClick={handleUpgradeClick}
67+
progress={upgradeButtonData.trialLeftProgress}
68+
leftValue={daysLeftText}
69+
yellowColorThreshold={50}
70+
redColorThreshold={0}
71+
>
72+
Talk to us
73+
</ButtonProgress>
74+
</a>
75+
)}
76+
{upgradeButtonData.isCompleted &&
77+
upgradeButtonData.showUpgradeDefaultButton && (
78+
<a
79+
href={TALK_TO_US_LINK}
80+
target="_blank"
81+
rel="noopener noreferrer"
82+
className={`${CLASS_NAME}__version`}
83+
>
84+
<Button
85+
className={`${CLASS_NAME}__upgrade__btn`}
86+
buttonStyle={EnumButtonStyle.Outline}
87+
onClick={handleUpgradeClick}
88+
>
89+
Talk to us
90+
</Button>
91+
</a>
92+
)}
93+
{upgradeButtonData.isCompleted &&
94+
upgradeButtonData.isPreviewPlan &&
95+
!upgradeButtonData.showUpgradeDefaultButton && (
96+
<>
97+
<FeatureIndicator
98+
featureName={BillingFeature.CodeGenerationBuilds}
99+
textStart="Generate production-ready code for this architecture with just a few simple clicks"
100+
showTooltipLink={false}
101+
element={<CompletePreviewSignupButton />}
102+
/>
103+
<Button
104+
className={`${CLASS_NAME}__upgrade__btn`}
105+
buttonStyle={EnumButtonStyle.Outline}
106+
onClick={handleContactUsClick}
107+
>
108+
Contact us
109+
</Button>
110+
</>
111+
)}
112+
</>
113+
);
114+
};
115+
116+
export default UpgradeCtaButton;

packages/amplication-client/src/Workspaces/WorkspaceHeader/WorkspaceHeader.tsx

+25-114
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import {
22
Breadcrumbs,
3-
ButtonProgress,
43
Dialog,
54
Icon,
65
SelectMenu,
@@ -9,6 +8,7 @@ import {
98
SelectMenuModal,
109
Tooltip,
1110
} from "@amplication/ui/design-system";
11+
import { BillingFeature } from "@amplication/util-billing-types";
1212
import { useApolloClient, useQuery } from "@apollo/client";
1313
import {
1414
ButtonTypeEnum,
@@ -18,20 +18,15 @@ import {
1818
PopoverNotificationCenter,
1919
} from "@novu/notification-center";
2020
import { useStiggContext } from "@stigg/react-sdk";
21-
import React, {
22-
useCallback,
23-
useContext,
24-
useMemo,
25-
useRef,
26-
useState,
27-
} from "react";
21+
import React, { useCallback, useContext, useState } from "react";
2822
import { isMacOs } from "react-device-detect";
29-
import { Link, useHistory } from "react-router-dom";
23+
import { Link } from "react-router-dom";
3024
import CommandPalette from "../../CommandPalette/CommandPalette";
3125
import { Button, EnumButtonStyle } from "../../Components/Button";
3226
import UserBadge from "../../Components/UserBadge";
3327
import BreadcrumbsContext from "../../Layout/BreadcrumbsContext";
3428
import ProfileForm from "../../Profile/ProfileForm";
29+
import NoNotifications from "../../assets/images/no-notification.svg";
3530
import { unsetToken } from "../../authentication/authentication";
3631
import { AppContext } from "../../context/appContext";
3732
import {
@@ -45,16 +40,12 @@ import {
4540
AMPLICATION_DOC_URL,
4641
} from "../../util/constants";
4742
import { version } from "../../util/version";
43+
import useFetchGithubStars from "../hooks/useFetchGithubStars";
44+
import { GET_CONTACT_US_LINK } from "../queries/workspaceQueries";
45+
import UpgradeCtaButton from "./UpgradeCtaButton";
4846
import WorkspaceBanner from "./WorkspaceBanner";
49-
import styles from "./notificationStyle";
50-
import NoNotifications from "../../assets/images/no-notification.svg";
5147
import "./WorkspaceHeader.scss";
52-
import { BillingFeature } from "@amplication/util-billing-types";
53-
import { useUpgradeButtonData } from "../hooks/useUpgradeButtonData";
54-
import { GET_CONTACT_US_LINK } from "../queries/workspaceQueries";
55-
import { FeatureIndicator } from "../../Components/FeatureIndicator";
56-
import { CompletePreviewSignupButton } from "../../User/CompletePreviewSignupButton";
57-
import useFetchGithubStars from "../hooks/useFetchGithubStars";
48+
import styles from "./notificationStyle";
5849

5950
const CLASS_NAME = "workspace-header";
6051
const AMP_GITHUB_URL = "https://github.com/amplication/amplication";
@@ -86,31 +77,18 @@ const HELP_MENU_LIST: HelpMenuItem[] = [
8677
},
8778
];
8879

89-
const talkToUsLink =
90-
"https://meetings-eu1.hubspot.com/paz-yanover/product-overview-vp-product";
91-
9280
const WorkspaceHeader: React.FC = () => {
93-
const { currentWorkspace, currentProject, openHubSpotChat } =
94-
useContext(AppContext);
95-
const upgradeButtonData = useUpgradeButtonData(currentWorkspace);
81+
const { currentWorkspace, currentProject } = useContext(AppContext);
9682

9783
const { data } = useQuery(GET_CONTACT_US_LINK, {
9884
variables: { id: currentWorkspace.id },
9985
});
10086

10187
const apolloClient = useApolloClient();
102-
const history = useHistory();
10388
const { stigg } = useStiggContext();
10489
const { trackEvent } = useTracking();
105-
const novuBellRef = useRef(null);
10690
const stars = useFetchGithubStars();
10791

108-
const daysLeftText = useMemo(() => {
109-
return `${upgradeButtonData.trialDaysLeft} day${
110-
upgradeButtonData.trialDaysLeft !== 1 ? "s" : ""
111-
} left for the free trial`;
112-
}, [upgradeButtonData.trialDaysLeft]);
113-
11492
const breadcrumbsContext = useContext(BreadcrumbsContext);
11593

11694
const [novuCenterState, setNovuCenterState] = useState(false);
@@ -121,26 +99,26 @@ const WorkspaceHeader: React.FC = () => {
12199
const [showProfileFormDialog, setShowProfileFormDialog] =
122100
useState<boolean>(false);
123101

124-
const [showCompleteSignupDialog, setShowCompleteSignupDialog] =
125-
useState<boolean>(false);
126-
127102
const handleSignOut = useCallback(() => {
128103
unsetToken();
129104
apolloClient.clearStore();
130105

131106
window.location.replace(REACT_APP_AUTH_LOGOUT_URI);
132-
}, [history, apolloClient]);
107+
}, [apolloClient]);
133108

134-
const onNotificationClick = useCallback((message: IMessage) => {
135-
trackEvent({
136-
eventName: AnalyticsEventNames.ClickNotificationMessage,
137-
messageType: message.templateIdentifier,
138-
});
109+
const onNotificationClick = useCallback(
110+
(message: IMessage) => {
111+
trackEvent({
112+
eventName: AnalyticsEventNames.ClickNotificationMessage,
113+
messageType: message.templateIdentifier,
114+
});
139115

140-
if (message?.cta?.data?.url) {
141-
// window.location.href = message.cta.data.url;
142-
}
143-
}, []);
116+
if (message?.cta?.data?.url) {
117+
// window.location.href = message.cta.data.url;
118+
}
119+
},
120+
[trackEvent]
121+
);
144122

145123
const onBuildNotificationClick = useCallback(
146124
(templateIdentifier: string, type: ButtonTypeEnum, message: IMessage) => {
@@ -149,22 +127,14 @@ const WorkspaceHeader: React.FC = () => {
149127
[]
150128
);
151129

152-
const handleUpgradeClick = useCallback(() => {
153-
trackEvent({
154-
eventName: AnalyticsEventNames.UpgradeClick,
155-
eventOriginLocation: "workspace-header",
156-
workspace: currentWorkspace.id,
157-
});
158-
}, [currentWorkspace.id, trackEvent]);
159-
160130
const handleContactUsClick = useCallback(() => {
161131
window.open(data?.contactUsLink, "_blank");
162132
trackEvent({
163133
eventName: AnalyticsEventNames.HelpMenuItemClick,
164134
action: "Contact Us",
165135
eventOriginLocation: "workspace-header-help-menu",
166136
});
167-
}, [openHubSpotChat]);
137+
}, [data?.contactUsLink, trackEvent]);
168138

169139
const handleItemDataClicked = useCallback(
170140
(itemData: ItemDataCommand) => {
@@ -179,18 +149,14 @@ const WorkspaceHeader: React.FC = () => {
179149
setShowProfileFormDialog(!showProfileFormDialog);
180150
}, [showProfileFormDialog, setShowProfileFormDialog]);
181151

182-
const handleShowCompleteSignupDialog = useCallback(() => {
183-
setShowCompleteSignupDialog(!showCompleteSignupDialog);
184-
}, [showCompleteSignupDialog]);
185-
186152
const handleBellClick = useCallback(() => {
187153
if (!novuCenterState) {
188154
trackEvent({
189155
eventName: AnalyticsEventNames.OpenNotificationCenter,
190156
});
191157
}
192158
setNovuCenterState(!novuCenterState);
193-
}, [novuBellRef, novuCenterState]);
159+
}, [novuCenterState, trackEvent]);
194160

195161
const Footer = () => <div></div>;
196162

@@ -254,62 +220,7 @@ const WorkspaceHeader: React.FC = () => {
254220
<div className={`${CLASS_NAME}__center`}></div>
255221
<div className={`${CLASS_NAME}__right`}>
256222
<div className={`${CLASS_NAME}__links`}>
257-
{upgradeButtonData.isCompleted &&
258-
upgradeButtonData.showUpgradeTrialButton && (
259-
<a
260-
href={talkToUsLink}
261-
target="_blank"
262-
rel="noopener noreferrer"
263-
className={`${CLASS_NAME}__version`}
264-
>
265-
<ButtonProgress
266-
className={`${CLASS_NAME}__upgrade__btn`}
267-
onClick={handleUpgradeClick}
268-
progress={upgradeButtonData.trialLeftProgress}
269-
leftValue={daysLeftText}
270-
yellowColorThreshold={50}
271-
redColorThreshold={0}
272-
>
273-
Talk to us
274-
</ButtonProgress>
275-
</a>
276-
)}
277-
{upgradeButtonData.isCompleted &&
278-
upgradeButtonData.showUpgradeDefaultButton && (
279-
<a
280-
href={talkToUsLink}
281-
target="_blank"
282-
rel="noopener noreferrer"
283-
className={`${CLASS_NAME}__version`}
284-
>
285-
<Button
286-
className={`${CLASS_NAME}__upgrade__btn`}
287-
buttonStyle={EnumButtonStyle.Outline}
288-
onClick={handleUpgradeClick}
289-
>
290-
Talk to us
291-
</Button>
292-
</a>
293-
)}
294-
{upgradeButtonData.isCompleted &&
295-
upgradeButtonData.isPreviewPlan &&
296-
!upgradeButtonData.showUpgradeDefaultButton && (
297-
<>
298-
<FeatureIndicator
299-
featureName={BillingFeature.CodeGenerationBuilds}
300-
textStart="Generate production-ready code for this architecture with just a few simple clicks"
301-
showTooltipLink={false}
302-
element={<CompletePreviewSignupButton />}
303-
/>
304-
<Button
305-
className={`${CLASS_NAME}__upgrade__btn`}
306-
buttonStyle={EnumButtonStyle.Outline}
307-
onClick={handleContactUsClick}
308-
>
309-
Contact us
310-
</Button>
311-
</>
312-
)}
223+
<UpgradeCtaButton />
313224
</div>
314225
<hr className={`${CLASS_NAME}__vertical_border`} />
315226

0 commit comments

Comments
 (0)