import React from 'react'; import type { MessageBlock } from '@/store/commStore'; interface ActionCardBlockProps { block: MessageBlock; } interface ActionItem { label: string; action: string; type?: 'primary' | 'secondary'; } const ActionCardBlock: React.FC = ({ block }) => { const { title, body, actions } = block.block_data; const cardTitle: string = title || ''; const cardBody: string = body || ''; const actionList: ActionItem[] = Array.isArray(actions) ? actions : []; const handleActionClick = (action: ActionItem) => { if (action.action === 'dismiss') { // Frontend handles dismiss — no-op here, parent component can wire up return; } // Validate URL — only allow http: and https: protocols to prevent javascript: URLs const url = action.action; try { const parsed = new URL(url); if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') return; } catch { return; // Invalid URL } window.open(url, '_blank', 'noopener,noreferrer'); }; return (
{cardTitle && (

{cardTitle}

)} {cardBody && (

{cardBody}

)} {actionList.length > 0 && (
{actionList.map((action, idx) => { const isPrimary = action.type !== 'secondary'; return ( ); })}
)}
); }; export default ActionCardBlock;