import { useEffect, useState } from "react"; import { faPencil, faPlus, faX } from "@fortawesome/free-solid-svg-icons"; import { plans } from "public/data/frequentConstants"; import { usePopUp } from "../../../hooks/usePopUp"; import getOrganizationSubscriptions from "../../../pages/api/organization/GetOrgSubscription"; import Button from "../buttons/Button"; import { AddUpdateEnvironmentDialog } from "../dialog/AddUpdateEnvironmentDialog"; import DeleteActionModal from "../dialog/DeleteActionModal"; import UpgradePlanModal from "../dialog/UpgradePlan"; type Env = { name: string; slug: string }; type Props = { data: Env[]; onCreateEnv: (arg0: Env) => Promise; onUpdateEnv: (oldSlug: string, arg0: Env) => Promise; onDeleteEnv: (slug: string) => Promise; }; const EnvironmentTable = ({ data = [], onCreateEnv, onDeleteEnv, onUpdateEnv }: Props) => { const { popUp, handlePopUpOpen, handlePopUpClose } = usePopUp([ "createUpdateEnv", "deleteEnv", "upgradePlan" ] as const); const [plan, setPlan] = useState(""); const host = window.location.origin; useEffect(() => { // on initial load - run auth check (async () => { const orgId = localStorage.getItem("orgData.id") as string; const subscriptions = await getOrganizationSubscriptions({ orgId }); if (subscriptions) { setPlan(subscriptions.data[0].plan.product) } })(); // eslint-disable-next-line react-hooks/exhaustive-deps }, []); const onEnvCreateCB = async (env: Env) => { try { await onCreateEnv(env); handlePopUpClose("createUpdateEnv"); } catch (error) { console.error(error); } }; const onEnvUpdateCB = async (env: Env) => { try { await onUpdateEnv((popUp.createUpdateEnv?.data as Pick)?.slug, env); handlePopUpClose("createUpdateEnv"); } catch (error) { console.error(error); } }; const onEnvDeleteCB = async () => { try { await onDeleteEnv((popUp.deleteEnv?.data as Pick)?.slug); handlePopUpClose("deleteEnv"); } catch (error) { console.error(error); } }; return ( <>

Project Environments

Choose which environments will show up in your dashboard like development, staging, production

Note: the text in slugs shows how these environmant should be accessed in CLI.

{data?.length > 0 ? ( data.map(({ name, slug }) => ( )) ) : ( )}
Name Slug
{name} {slug}
No environments found
handlePopUpClose("deleteEnv")} onSubmit={onEnvDeleteCB} /> handlePopUpClose("createUpdateEnv")} onCreateSubmit={onEnvCreateCB} onEditSubmit={onEnvUpdateCB} /> handlePopUpClose("upgradePlan")} text="You can add custom environments if you switch to Infisical's Team plan." />
); }; export default EnvironmentTable;