import { Box, CopyClipboard, Popover, Text, TextButton, TextSize, } from '@wix/design-system'; import React, { useEffect, useMemo } from 'react'; import { DuplicateSmall, InfoCircleSmall } from '@wix/wix-ui-icons-common'; export interface RequestIdProps { /** * Request ID value. * @external */ value: string; /** * Appearance of the component. * @external */ appearance?: 'standard' | 'light'; /** * Locale to use for translations. * @external */ locale: string; /** * Data hook for testing purposes * @external */ dataHook?: string; } export const RequestId = (props: RequestIdProps) => { const { value, appearance, locale, dataHook = 'request-id' } = props; const firstValue = value.split(',')[0]; const [messages, setMessages] = React.useState<{ description: string; cta: string; copiedSuccess: string; } | null>(null); useEffect(() => { const loadMessages = async () => { try { const module = await import( /* webpackChunkName: `request-id-locale-messages-[request]-json` */ `./assets/locale/messages_${locale}.json` ); setMessages(module.default); } catch (error) { setMessages(require('./assets/locale/messages_en.json')); } }; loadMessages(); }, [locale]); const [shown, setShown] = React.useState(false); const openPopover = () => setShown(true); const closePopover = () => setShown(false); const appearanceStyle = useMemo(() => { if (appearance === 'light') { return { infoIconColor: 'var(--wsr-color-D40, #868aa5)', textSize: 'small' as TextSize, textLight: true, }; } return { infoIconColor: 'var(--wsr-color-100, #116DFF)', textSize: 'tiny' as TextSize, textLight: false, }; }, [appearance]); return ( {`Request ID: ${firstValue}`} openPopover()} onMouseLeave={() => closePopover()} dataHook="request-id-popover" zIndex={6000} // showToast z-index is 5500 appendTo="window" > } />
{messages?.description}
{({ isCopied, copyToClipboard }) => ( } size="small" onClick={() => copyToClipboard()} dataHook="request-id-copy-button" > {isCopied ? messages?.copiedSuccess : messages?.cta} )}
); };