import type { FC } from '../../lib/teact/teact'; import React, { memo, useMemo } from '../../lib/teact/teact'; import { getActions } from '../../global'; import buildClassName from '../../util/buildClassName'; import { copyTextToClipboard } from '../../util/clipboard'; import useAppLayout from '../../hooks/useAppLayout'; import useLastCallback from '../../hooks/useLastCallback'; import useOldLang from '../../hooks/useOldLang'; import Button from '../ui/Button'; import DropdownMenu from '../ui/DropdownMenu'; import MenuItem from '../ui/MenuItem'; import Icon from './icons/Icon'; import styles from './LinkField.module.scss'; type OwnProps = { title?: string; link: string; isDisabled?: boolean; className?: string; withShare?: boolean; onRevoke?: VoidFunction; }; const InviteLink: FC = ({ title, link, isDisabled, className, withShare, onRevoke, }) => { const lang = useOldLang(); const { showNotification, openChatWithDraft } = getActions(); const { isMobile } = useAppLayout(); const isOnlyCopy = !onRevoke; const copyLink = useLastCallback(() => { copyTextToClipboard(link); showNotification({ message: { key: 'LinkCopied', }, }); }); const handleCopyClick = useLastCallback(() => { if (isDisabled) return; copyLink(); }); const handleShare = useLastCallback(() => { openChatWithDraft({ text: { text: link } }); }); const PrimaryLinkMenuButton: FC<{ onTrigger: () => void; isOpen?: boolean }> = useMemo(() => { return ({ onTrigger, isOpen }) => ( ); }, [isMobile, lang]); return (

{lang(title || 'InviteLink.InviteLink')}

{isOnlyCopy ? ( ) : ( {lang('Copy')} {onRevoke && ( {lang('RevokeButton')} )} )}
{withShare && ( )}
); }; export default memo(InviteLink);