import { pushModal, showConfirm } from '@/modals'; import { type RouterOutputs, api } from '@/trpc/client'; import type { NotificationRule } from '@openpanel/db'; import type { IChartRange, IInterval } from '@openpanel/validation'; import { useQueryClient } from '@tanstack/react-query'; import { getQueryKey } from '@trpc/react-query'; import { AsteriskIcon, FilterIcon } from 'lucide-react'; import { Fragment } from 'react'; import { toast } from 'sonner'; import { ColorSquare } from '../color-square'; import { IntegrationCardFooter, IntegrationCardHeader, } from '../integrations/integration-card'; import { PingBadge } from '../ping'; import { Badge } from '../ui/badge'; import { Button } from '../ui/button'; import { Tooltiper } from '../ui/tooltip'; function EventBadge({ event, }: { event: NotificationRule['config']['events'][number] }) { return ( {event.filters.map((filter) => (
{filter.name} {filter.operator} {JSON.stringify(filter.value)}
))} } > {event.name} {Boolean(event.filters.length) && ( )}
); } export function RuleCard({ rule, }: { rule: RouterOutputs['notification']['rules'][number] }) { const client = useQueryClient(); const deletion = api.notification.deleteRule.useMutation({ onSuccess() { toast.success('Rule deleted'); client.refetchQueries(getQueryKey(api.notification.rules)); }, }); const renderConfig = () => { switch (rule.config.type) { case 'events': return (
Get notified when
{rule.config.events.map((event) => ( ))}
occurs
); case 'funnel': return (
Get notified when a session has completed this funnel
{rule.config.events.map((event, index) => (
{index + 1}
))}
); } }; return (
{rule.name}
{renderConfig()}
{rule.integrations.map((integration) => ( {integration.name} ))}
); }