MCPcopy Create free account
hub / github.com/dailydotdev/apps / HelpWidget

Function HelpWidget

packages/shared/src/components/help/HelpWidget.tsx:35–225  ·  view source on GitHub ↗
({
  sidebarExpanded,
}: HelpWidgetProps)

Source from the content-addressed store, hash-verified

33}
34
35export function HelpWidget({
36 sidebarExpanded,
37}: HelpWidgetProps): ReactElement | null {
38 const { user } = useAuthContext();
39 const { marketingCtas, dismiss } = useMarketingCtas(
40 MarketingCtaVariant.HelpGuide,
41 );
42 const { logEvent } = useLogContext();
43 const [popoverOpen, setPopoverOpen] = useState(false);
44 const [activeIndex, setActiveIndex] = useState(0);
45 const [isExiting, setIsExiting] = useState(false);
46 const popoverRef = useRef<HTMLDivElement>(null);
47 const triggerRef = useRef<HTMLDivElement>(null);
48 const trackedImpressionIds = useRef<Set<string>>(new Set());
49
50 const itemCount = marketingCtas.length;
51 const activeItem =
52 itemCount > 0 ? marketingCtas[activeIndex % itemCount] : undefined;
53
54 // Keep activeIndex in bounds when the underlying list shrinks (e.g. after dismiss).
55 useEffect(() => {
56 if (itemCount > 0 && activeIndex >= itemCount) {
57 setActiveIndex(0);
58 }
59 }, [activeIndex, itemCount]);
60
61 // Log Impression once per campaign — first time the user actually sees its content in the popover.
62 useEffect(() => {
63 if (!popoverOpen || !activeItem) {
64 return;
65 }
66 if (trackedImpressionIds.current.has(activeItem.campaignId)) {
67 return;
68 }
69
70 logEvent({
71 event_name: LogEvent.Impression,
72 target_type: TargetType.MarketingCtaHelpGuide,
73 target_id: activeItem.campaignId,
74 });
75 trackedImpressionIds.current.add(activeItem.campaignId);
76 }, [popoverOpen, activeItem, logEvent]);
77
78 useEffect(() => {
79 const handleClickOutside = (e: MouseEvent) => {
80 if (
81 popoverRef.current &&
82 !popoverRef.current.contains(e.target as Node) &&
83 triggerRef.current &&
84 !triggerRef.current.contains(e.target as Node)
85 ) {
86 setPopoverOpen(false);
87 }
88 };
89
90 if (popoverOpen) {
91 document.addEventListener('mousedown', handleClickOutside);
92 }

Callers

nothing calls this directly

Calls 5

useAuthContextFunction · 0.90
useMarketingCtasFunction · 0.90
useLogContextFunction · 0.90
logEventFunction · 0.85
dismissFunction · 0.50

Tested by

no test coverage detected