Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trial banner boilerplate fe #4554

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 55 additions & 3 deletions dashboard/src/main/home/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import ConfirmOverlay from "components/ConfirmOverlay";
import Loading from "components/Loading";
import NoClusterPlaceHolder from "components/NoClusterPlaceHolder";
import Button from "components/porter/Button";
import Link from "components/porter/Link";
import Modal from "components/porter/Modal";
import Spacer from "components/porter/Spacer";
import Text from "components/porter/Text";
Expand Down Expand Up @@ -56,6 +57,7 @@ import CreateClusterForm from "./infrastructure-dashboard/forms/CreateClusterFor
import Integrations from "./integrations/Integrations";
import LaunchWrapper from "./launch/LaunchWrapper";
import ModalHandler from "./ModalHandler";
import BillingModal from "./modals/BillingModal";
import Navbar from "./navbar/Navbar";
import { NewProjectFC } from "./new-project/NewProject";
import Onboarding from "./onboarding/Onboarding";
Expand Down Expand Up @@ -108,6 +110,7 @@ const Home: React.FC<Props> = (props) => {
setShouldRefreshClusters,
} = useContext(Context);

const [showBillingModal, setShowBillingModal] = useState(false);
const [showWelcome, setShowWelcome] = useState(false);
const [forceRefreshClusters, setForceRefreshClusters] = useState(false);
const [ghRedirect, setGhRedirect] = useState(false);
Expand Down Expand Up @@ -363,13 +366,52 @@ const Home: React.FC<Props> = (props) => {
pushFiltered(props, "/dashboard", []);
};

const showCardBanner = true;
const trialExpired = true;

const { cluster, baseRoute } = props.match.params as any;
return (
<ThemeProvider
theme={currentProject?.simplified_view_enabled ? midnight : standard}
>
<DeploymentTargetProvider>
<StyledHome>
<StyledHome showCardBanner={showCardBanner}>
{!currentProject?.sandbox_enabled && showCardBanner && (
<>
<GlobalBanner>
<i className="material-icons-round">warning</i>
Please
<Spacer width="5px" inline />
<Link
hasunderline
onClick={() => {
setShowBillingModal(true);
}}
>
connect a valid payment method
</Link>
. Your project has 127 free days remaining.
</GlobalBanner>
{!trialExpired && showBillingModal && (
<BillingModal
back={() => {
setShowBillingModal(false);
}}
onCreate={async () => {
setShowBillingModal(false);
}}
/>
)}
{trialExpired && (
<BillingModal
trialExpired
onCreate={async () => {
setShowBillingModal(false);
}}
/>
)}
</>
)}
<ModalHandler setRefreshClusters={setForceRefreshClusters} />
{currentOverlay &&
createPortal(
Expand Down Expand Up @@ -620,9 +662,10 @@ const GlobalBanner = styled.div`
z-index: 999;
position: fixed;
top: 0;
color: #fefefe;
left: 0;
height: 35px;
background: #263061;
background: #4752ba;
display: flex;
align-items: center;
justify-content: center;
Expand All @@ -633,6 +676,12 @@ const GlobalBanner = styled.div`
height: 16px;
margin-right: 10px;
}

> i {
margin-right: 10px;
font-size: 16px;
opacity: 0.8;
}
`;

const ViewWrapper = styled.div`
Expand All @@ -657,13 +706,16 @@ const DashboardWrapper = styled.div`
height: fit-content;
`;

const StyledHome = styled.div`
const StyledHome = styled.div<{
showCardBanner: boolean;
}>`
width: 100vw;
height: 100vh;
position: fixed;
top: 0;
left: 0;
margin: 0;
padding-top: ${(props) => (props.showCardBanner ? "35px" : "0")};
user-select: none;
display: flex;
justify-content: center;
Expand Down
51 changes: 37 additions & 14 deletions dashboard/src/main/home/modals/BillingModal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react";
import React, { useContext } from "react";
import { Elements } from "@stripe/react-stripe-js";
import { loadStripe } from "@stripe/stripe-js";

Expand All @@ -8,15 +8,20 @@ import Spacer from "components/porter/Spacer";
import Text from "components/porter/Text";
import { usePublishableKey } from "lib/hooks/useStripe";

import { Context } from "shared/Context";

import PaymentSetupForm from "./PaymentSetupForm";

const BillingModal = ({
back,
onCreate,
trialExpired,
}: {
back: (value: React.SetStateAction<boolean>) => void;
back?: (value: React.SetStateAction<boolean>) => void;
onCreate: () => Promise<void>;
trialExpired?: boolean;
}) => {
const { currentProject } = useContext(Context);
const { publishableKey } = usePublishableKey();
const stripePromise = loadStripe(publishableKey);

Expand Down Expand Up @@ -44,20 +49,38 @@ const BillingModal = ({
return (
<Modal closeModal={back}>
<div id="checkout">
<Text size={16}>Add payment method</Text>
<Spacer y={1} />
<Text color="helper">
<Text style={{ fontWeight: 500 }}>
You will not be charged until you have an app deployed and have run
out of credits.
</Text>{" "}
A payment method is required to begin deploying applications on
Porter. You can learn more about our pricing{" "}
<Link target="_blank" to="https://porter.run/pricing">
here
</Link>
<Text size={16}>
{trialExpired
? "Your Porter trial has expired"
: "Add payment method"}
</Text>
<Spacer y={1} />
{currentProject?.sandbox_enabled ? (
<Text color="helper">
<Text style={{ fontWeight: 500 }}>
You will not be charged until you have an app deployed and have
run out of credits.
</Text>{" "}
A payment method is required to begin deploying applications on
Porter. You can learn more about our pricing{" "}
<Link target="_blank" to="https://porter.run/pricing">
here
</Link>
</Text>
) : (
<Text color="helper">
{trialExpired
? `Your applications will continue to run but you will not be able to access your project until you link a payment method. `
: "Link a payment method to your Porter project."}
<br />
<br />
{`You can learn more about our pricing under "For Businesses" `}
<Link target="_blank" to="https://porter.run/pricing">
here
</Link>
</Text>
)}
<Spacer y={1} />
<Elements
stripe={stripePromise}
options={options}
Expand Down
Loading