// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 import { I18n } from '@aws-amplify/core'; import { useEffect } from 'react'; import Button from 'react-bootstrap/Button'; import Modal from 'react-bootstrap/Modal'; import { MessageModalProps, MessageModalType } from '../util/types'; /** * Renders the message modal. * @param props The message modal properties * @returns The message modal */ export default function MessageModal(props: MessageModalProps): JSX.Element { const { show, hide, message, modalType, confirmAction } = props; /** * React useEffect hook. */ useEffect(() => { if (modalType === MessageModalType.CONFIRM && typeof confirmAction === 'undefined') { throw Error(I18n.get('error.message.missing.action')); } }, [modalType, confirmAction]); /** * For the confirm type, it already checks if confirmAction exists, * so there's no need to check again to throw an error. */ async function handleConfirm() { if (typeof confirmAction !== 'undefined') { if (confirmAction.constructor.name === 'AsyncFunction') await confirmAction(); else confirmAction(); } hide(); } return ( hide()} id="message-modal" animation={false} centered={true}> {message} {modalType === MessageModalType.MESSAGE && ( )} {modalType === MessageModalType.CONFIRM && ( <> )} ); }