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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | 24x 222x 222x 222x 222x 222x 222x 222x 222x 24x 24x | import { Stack, SxProps } from "@mui/material";
import GiveChip, { TChipColors } from "@shared/Chip/GiveChip";
import { styled, useAppTheme } from "@theme/v2/Provider";
import { useMerchantSidePanelContext } from "features/Merchants/MerchantSidePanel/Provider/MerchantSidePanelProvider";
import { CheckIcon, DetectiveIcon, SirenIcon } from "@phosphor-icons/react";
import { capitalize } from "lodash";
import {
TRiskLevel,
TRiskStatus,
} from "@components/Merchants/MerchantPreview/RiskProfile/types";
import GiveTooltip from "@shared/Tooltip/GiveTooltip";
import {
MANUAL_OVERRIDE_CHIP_LABEL,
manualOverrideTooltip,
} from "./manualRiskLevel/constants";
type Props = {
chipSx?: SxProps;
points?: number;
effectiveLevel?: TRiskLevel;
computedLevel?: TRiskLevel;
isManualOverride?: boolean;
manualSetByName?: string | null;
riskStatusName?: TRiskStatus;
};
const RiskSummaryLabels = ({
points,
chipSx,
effectiveLevel,
computedLevel,
isManualOverride,
manualSetByName,
riskStatusName: riskStatusNameProp,
}: Props) => {
const { palette } = useAppTheme();
const { data } = useMerchantSidePanelContext();
const { level, riskStatusName: contextRiskStatusName } =
data?.riskProfile || {};
const riskLabel = effectiveLevel || level || "low";
const riskStatusName =
riskStatusNameProp ?? contextRiskStatusName ?? "routine_monitoring";
const secondChip: Record<
string,
{ label: string; Icon: JSX.Element; chipColor: TChipColors }
> = {
routine_monitoring: {
label: "Routine Monitoring",
Icon: <CheckIcon fill={palette?.primitive?.success[100]} size="16px" />,
chipColor: "success",
},
active_monitoring: {
label: "Active Monitoring",
Icon: (
<DetectiveIcon fill={palette?.primitive?.error[100]} size="16px" />
),
chipColor: "error",
},
alerted: {
label: "Alerted",
Icon: <SirenIcon fill={palette?.primitive?.warning[100]} size="16px" />,
chipColor: "warning",
},
};
const { label, chipColor, Icon } =
secondChip[riskStatusName as keyof typeof secondChip];
return (
<Stack
direction="row"
alignItems="center"
gap={1}
flexWrap="wrap"
// GiveTooltip wraps the Manual chip in a full-width anchor that would
// otherwise take the whole row and push the chip onto its own line.
// Constrain that anchor (the direct-child Stack, not the chips) to its
// content width so the chips stay inline and only wrap when the column is
// genuinely too narrow (e.g. mobile).
sx={{ "& > .MuiStack-root": { width: "fit-content" } }}
>
<StyledGiveChip
label={
capitalize(riskLabel) +
(points !== undefined ? ` (${points} points)` : "")
}
color={
(riskLevelColor[
riskLabel?.toLowerCase() as keyof typeof riskLevelColor
] as TChipColors) || "default"
}
variant="outline"
sx={chipSx}
/>
<StyledGiveChip
icon={Icon}
label={label}
color={chipColor}
variant="outline"
sx={chipSx}
/>
{isManualOverride && (
<GiveTooltip
title={manualOverrideTooltip(
capitalize(riskLabel),
capitalize(computedLevel || riskLabel),
manualSetByName,
)}
placement="top"
color="default"
>
<Stack data-testid="manual-override-indicator">
<StyledGiveChip
label={MANUAL_OVERRIDE_CHIP_LABEL}
color="darken5"
sx={chipSx}
/>
</Stack>
</GiveTooltip>
)}
</Stack>
);
};
const riskLevelColor = {
low: "success",
critical: "error",
medium: "warning",
high: "warning2",
};
const StyledGiveChip = styled(GiveChip)({
fontSize: "12px",
"&.MuiChip-root": {
gap: "4px",
paddingInline: "7px",
},
"& .MuiChip-icon": {
margin: 0,
fontSize: "16px",
},
"& span": {
lineHeight: "normal",
},
});
export default RiskSummaryLabels;
|