import { faGlobe, faPencil, faXmark } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { UpgradePlanModal } from "@app/components/license/UpgradePlanModal"; import { ProjectPermissionCan } from "@app/components/permissions"; import { EmptyState, IconButton, Table, TableContainer, TableSkeleton, TBody, Td, Th, THead, Tr } from "@app/components/v2"; import { ProjectPermissionActions, ProjectPermissionSub, useSubscription, useWorkspace } from "@app/context"; import { useGetTrustedIps } from "@app/hooks/api"; import { UsePopUpState } from "@app/hooks/usePopUp"; type Props = { popUp: UsePopUpState<["upgradePlan"]>; handlePopUpOpen: ( popUpName: keyof UsePopUpState<["trustedIp", "deleteTrustedIp", "upgradePlan"]>, data?: { trustedIpId: string; ipAddress?: string; comment?: string; isActive?: boolean; prefix?: number; } ) => void; handlePopUpToggle: (popUpName: keyof UsePopUpState<["upgradePlan"]>, state?: boolean) => void; }; export const IPAllowlistTable = ({ popUp, handlePopUpOpen, handlePopUpToggle }: Props) => { const { subscription } = useSubscription(); const { currentWorkspace } = useWorkspace(); const { data, isPending } = useGetTrustedIps(currentWorkspace?.id ?? ""); const formatType = (type: string, prefix?: number) => { return `${type.slice(0, 2).toUpperCase() + type.slice(2)} ${ prefix !== undefined ? "CIDR" : "" }`; }; return (
{/* */} {!isPending && data && data?.length > 0 && data .sort((a, b) => a.ipAddress.localeCompare(b.ipAddress)) .map(({ id, ipAddress, comment, type, prefix, isActive }) => { return ( {/* */} ); })} {isPending && ( )} {!isPending && data && data?.length === 0 && ( )}
IP Address / Range Format CommentStatus
{`${ipAddress}${prefix !== undefined ? `/${prefix}` : ""}`} {formatType(type, prefix)} {comment}

Active

{(isAllowed) => ( { if (subscription?.ipAllowlisting) { handlePopUpOpen("trustedIp", { trustedIpId: id, ipAddress, comment, prefix, isActive }); } else { handlePopUpOpen("upgradePlan"); } }} colorSchema="primary" variant="plain" ariaLabel="update" isDisabled={!isAllowed} > )} {(isAllowed) => ( { if (subscription?.ipAllowlisting) { handlePopUpOpen("deleteTrustedIp", { trustedIpId: id }); } else { handlePopUpOpen("upgradePlan"); } }} size="lg" colorSchema="danger" variant="plain" ariaLabel="update" isDisabled={!isAllowed} > )}
handlePopUpToggle("upgradePlan", isOpen)} text="You can use IP allowlisting if you switch to Infisical's Pro plan." />
); };