All files / src/utils/components/feature-access PlanChip.jsx

76.47% Statements 13/17
57.14% Branches 12/21
100% Functions 2/2
86.66% Lines 13/15

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56                      9x 99x 99x           9x                 99x 99x   99x   99x 99x 99x 99x 99x       99x                            
import WorkspacePremiumIcon from "@mui/icons-material/WorkspacePremium";
import { Chip } from "@mui/material";
import { useTheme } from "@mui/material/styles";
import {
    getPlanChipSx,
    getPlanLabel,
    getPlanOnPrimaryChipSx,
    resolvePlanKey,
} from "@/utils/features/featureAccess";
import { formatProfilePlanLabel } from "@/utils/helpers/organizationDisplay";
 
export const formatPlanChipLabel = (plan, planName = null) => {
    Eif (planName) {
        return formatProfilePlanLabel(planName);
    }
    if (!plan) return null;
    return `${getPlanLabel(plan)} Plan`;
};
 
const PlanChip = ({
    plan,
    planName = null,
    size = "sm",
    onPrimary = false,
    showIcon = true,
    sx,
    ...props
}) => {
    const theme = useTheme();
    const label = formatPlanChipLabel(plan, planName);
 
    Iif (!label) return null;
 
    const chipSize = size === "md" ? "medium" : "small";
    const iconSize = size === "md" ? 14 : 13;
    const icon = showIcon ? <WorkspacePremiumIcon sx={{ fontSize: iconSize }} /> : undefined;
    const planKey = resolvePlanKey(plan, planName);
    const chipSx = onPrimary
        ? getPlanOnPrimaryChipSx(theme, plan, planName, size)
        : getPlanChipSx(theme, plan, planName, size);
 
    return (
        <Chip
            {...props}
            icon={icon}
            label={label}
            size={chipSize}
            variant="soft"
            data-plan={planKey || undefined}
            sx={{ ...chipSx, ...sx }}
        />
    );
};
 
export default PlanChip;