-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Expand file tree
/
Copy pathpartner-risk-indicator.tsx
More file actions
82 lines (72 loc) · 2.15 KB
/
Copy pathpartner-risk-indicator.tsx
File metadata and controls
82 lines (72 loc) · 2.15 KB
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
import { FRAUD_SEVERITY_CONFIG } from "@/lib/api/fraud/constants";
import { useFraudGroupCount } from "@/lib/swr/use-fraud-groups-count";
import { FraudGroupCountByPartner } from "@/lib/types";
import { ButtonLink } from "@/ui/placeholders/button-link";
import { DynamicTooltipWrapper, Flag } from "@dub/ui";
import { cn } from "@dub/utils";
import { useParams, usePathname } from "next/navigation";
interface PartnerRiskIndicatorProps {
partnerId: string;
}
export function PartnerRiskIndicator({ partnerId }: PartnerRiskIndicatorProps) {
const { slug } = useParams();
const pathname = usePathname();
const { fraudGroupCount, loading } = useFraudGroupCount<
FraudGroupCountByPartner[]
>({
query: {
groupBy: "partnerId",
status: "pending",
},
enabled: !!partnerId,
ignoreParams: true,
});
if (loading) {
return null;
}
const currentPartnerFraudEvents = fraudGroupCount?.find(
(event) => event.partnerId === partnerId,
);
if (!currentPartnerFraudEvents || currentPartnerFraudEvents._count === 0) {
return null;
}
const source = pathname?.includes("/applications")
? "applications"
: "partners";
const tooltipContent = (
<div className="grid max-w-44 gap-2 rounded-2xl p-3 text-center">
{source === "applications" ? (
<span className="text-xs font-medium leading-4 text-neutral-600">
This partner has been flagged for potential risk.
</span>
) : (
<span className="text-sm leading-4 text-neutral-600">
Risk events detected
</span>
)}
<ButtonLink
variant="secondary"
className="h-6 w-full items-center justify-center rounded-md px-1.5 py-2 text-sm font-medium"
href={`/${slug}/program/risks?partnerId=${partnerId}`}
target="_blank"
>
Review events
</ButtonLink>
</div>
);
return (
<DynamicTooltipWrapper
tooltipProps={{
content: tooltipContent,
}}
>
<Flag
variant="fill"
className={cn(
"size-3.5 cursor-pointer",
FRAUD_SEVERITY_CONFIG["high"].fg,
)}
/>
</DynamicTooltipWrapper>
);
}