// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. import React, {type ComponentType, type MouseEvent, type ReactNode} from 'react'; import {useIntl} from 'react-intl'; import {useDispatch} from 'react-redux'; import {openModal} from 'actions/views/modals'; type Props = { ariaLabel?: string; children: ReactNode; modalId: string; dialogType: ComponentType; dialogProps?: Record; onClick?: () => void; className?: string; showUnread?: boolean; disabled?: boolean; id?: string; role?: string; }; const ToggleModalButton = ({ ariaLabel, children, modalId, dialogType, dialogProps = {}, onClick, className = '', showUnread, disabled, id, role, }: Props) => { const intl = useIntl(); const dispatch = useDispatch(); const show = (e: MouseEvent) => { if (e) { e.preventDefault(); } const modalData = { modalId, dialogProps, dialogType, }; dispatch(openModal(modalData)); }; const ariaLabelElement = ariaLabel ? intl.formatMessage({ id: 'accessibility.button.dialog', defaultMessage: '{dialogName} dialog', }, { dialogName: ariaLabel, }) : undefined; const badge = showUnread ? : null; // allow callers to provide an onClick which will be called before the modal is shown const clickHandler = (e: MouseEvent) => { onClick?.(); show(e); }; return ( ); }; export default ToggleModalButton;