Files
plane/web/ee/components/license/cloud-badge.tsx
Nikhil 4e8bfe0024 dev: feature flagging implementation (#443)
* dev: initialize feature flagging

* dev: feature flagging workspace active cycles

* dev: update feature flag implementation

* dev: add `FEATURE_FLAG_SERVER_AUTH_TOKEN` env

* dev: add feature flagging for backend apis

* dev: setup feature flags store and hooks. (#558)

* dev: setup feature flags store and hooks.

* minor improvements for swr key and flags enum.

* dev: workspace active cycles feature flag. (#562)

* dev: add task for cancelling the workspace subscription when the workspace is deleted

* dev: rename feaure flagging component

* dev: update feature flagging function for spaces

* dev: add feature flags for bulk ops, issue embeds and page publish. (#589)

* dev: add logging for member sync task

* dev: restrict workspace from deleting if the subscription is active

* dev: workspace delete check endpoint

* dev: subscription endpoint check

* dev: update subscriptions

* chore: plane pro billing and plans page updates.

* dev: update pro pill display logic.

* dev: fix feature flagging

* chore: minor improvement in cloud-badge to avoid API calls to `products` endpoint if user has PRO subscription.

---------

Co-authored-by: Prateek Shourya <prateekshourya29@gmail.com>
Co-authored-by: sriram veeraghanta <veeraghanta.sriram@gmail.com>
2024-07-11 15:14:18 +05:30

90 lines
2.9 KiB
TypeScript

import { useState } from "react";
import { observer } from "mobx-react";
import Image from "next/image";
import { useParams } from "next/navigation";
import useSWR from "swr";
// ui
import { Button, Loader } from "@plane/ui";
// hooks
import { useEventTracker } from "@/hooks/store";
// enterprise imports
import { CloudProductsModal, ProPlanDetailsModal } from "@/plane-web/components/license";
import { useWorkspaceSubscription } from "@/plane-web/hooks/store";
// assets
import PlaneLogo from "@/public/plane-logos/blue-without-text.png";
export const CloudEditionBadge = observer(() => {
// params
const { workspaceSlug } = useParams();
// states
const [isProPlanDetailsModalOpen, setProPlanDetailsModalOpen] = useState(false);
// hooks
const { captureEvent } = useEventTracker();
const { isProPlanModalOpen, currentWorkspaceSubscribedPlanDetail, toggleProPlanModal, fetchWorkspaceSubscribedPlan } =
useWorkspaceSubscription();
// fetch workspace current plane information
useSWR(
workspaceSlug && process.env.NEXT_PUBLIC_DISCO_BASE_URL ? `WORKSPACE_CURRENT_PLAN_${workspaceSlug}` : null,
workspaceSlug && process.env.NEXT_PUBLIC_DISCO_BASE_URL
? () => fetchWorkspaceSubscribedPlan(workspaceSlug.toString())
: null,
{
errorRetryCount: 2,
revalidateOnFocus: false,
revalidateIfStale: false,
}
);
const handleProPlanPurchaseModalOpen = () => {
toggleProPlanModal(true);
captureEvent("pro_plan_modal_opened", {});
};
const handleProPlanDetailsModalOpen = () => {
setProPlanDetailsModalOpen(true);
captureEvent("pro_plan_details_modal_opened", {});
};
if (!currentWorkspaceSubscribedPlanDetail)
return (
<Loader className="flex h-full">
<Loader.Item height="30px" width="95%" />
</Loader>
);
return (
<>
{currentWorkspaceSubscribedPlanDetail.product === "FREE" && (
<>
<CloudProductsModal isOpen={isProPlanModalOpen} handleClose={() => toggleProPlanModal(false)} />
<Button
tabIndex={-1}
variant="accent-primary"
className="w-full cursor-pointer rounded-2xl px-4 py-1.5 text-center text-sm font-medium outline-none"
onClick={handleProPlanPurchaseModalOpen}
>
Upgrade to Pro
</Button>
</>
)}
{currentWorkspaceSubscribedPlanDetail.product === "PRO" && (
<>
<ProPlanDetailsModal
isOpen={isProPlanDetailsModalOpen}
handleClose={() => setProPlanDetailsModalOpen(false)}
/>
<Button
tabIndex={-1}
variant="accent-primary"
className="w-full cursor-pointer rounded-2xl px-3 py-1.5 text-center text-sm font-medium outline-none"
onClick={handleProPlanDetailsModalOpen}
>
<Image src={PlaneLogo} alt="Plane Pro" width={14} height={14} />
{"Plane Pro"}
</Button>
</>
)}
</>
);
});