import { useCallback, useEffect, useState } from 'react'; import { Badge, Box, Button, Separator, Stack, Text } from '@jtl-software/platform-ui-react'; import { Activity } from 'lucide-react'; import IPanelEventsPageProps from './IPanelEventsPageProps'; type LogEntry = { source: string; detail: string }; /** * Panel demo: a panel reacts to what the user does in the ERP page it is docked to. The App Bridge * pushes events (the user selected a different customer) and lets the panel pull the current context * on demand. This page subscribes to `CustomerChanged` and logs what it receives. */ const PanelEventsPage: React.FC = ({ appBridge }) => { const [customerId, setCustomerId] = useState(undefined); const [log, setLog] = useState([]); const addLog = useCallback((entry: LogEntry) => setLog(prev => [entry, ...prev]), []); useEffect(() => { // The ERP publishes CustomerChanged whenever the user selects a different customer. const unsubscribe = appBridge.event.subscribe('CustomerChanged', (data: unknown) => { const id = (data as { customerId?: string }).customerId; setCustomerId(id); addLog({ source: 'CustomerChanged', detail: id ?? '(none)' }); }); return () => unsubscribe(); }, [appBridge, addLog]); const getCurrentCustomer = useCallback(async () => { const id = (await appBridge.method.call('getCurrentCustomerId')) as string | undefined; setCustomerId(id); addLog({ source: 'getCurrentCustomerId', detail: id ?? '(none)' }); }, [appBridge, addLog]); return ( Panel Events A panel reacts to what the user does in the ERP: the App Bridge delivers events, and lets you pull the current context on demand. SELECTED CUSTOMER