// Copyright 2021 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only import React from 'react'; import type { ContactModalStateType, UserNotFoundModalStateType, } from '../state/ducks/globalModals'; import type { LocalizerType } from '../types/Util'; import { missingCaseError } from '../util/missingCaseError'; import { ButtonVariant } from './Button'; import { ConfirmationDialog } from './ConfirmationDialog'; import { WhatsNewModal } from './WhatsNewModal'; type PropsType = { i18n: LocalizerType; // ContactModal contactModalState?: ContactModalStateType; renderContactModal: () => JSX.Element; // ProfileEditor isProfileEditorVisible: boolean; renderProfileEditor: () => JSX.Element; // SafetyNumberModal safetyNumberModalContactId?: string; renderSafetyNumber: () => JSX.Element; // UserNotFoundModal hideUserNotFoundModal: () => unknown; userNotFoundModalState?: UserNotFoundModalStateType; // WhatsNewModal isWhatsNewVisible: boolean; hideWhatsNewModal: () => unknown; }; export const GlobalModalContainer = ({ i18n, // ContactModal contactModalState, renderContactModal, // ProfileEditor isProfileEditorVisible, renderProfileEditor, // SafetyNumberModal safetyNumberModalContactId, renderSafetyNumber, // UserNotFoundModal hideUserNotFoundModal, userNotFoundModalState, // WhatsNewModal hideWhatsNewModal, isWhatsNewVisible, }: PropsType): JSX.Element | null => { if (safetyNumberModalContactId) { return renderSafetyNumber(); } if (userNotFoundModalState) { let content: string; if (userNotFoundModalState.type === 'phoneNumber') { content = i18n('startConversation--phone-number-not-found', { phoneNumber: userNotFoundModalState.phoneNumber, }); } else if (userNotFoundModalState.type === 'username') { content = i18n('startConversation--username-not-found', { atUsername: i18n('at-username', { username: userNotFoundModalState.username, }), }); } else { throw missingCaseError(userNotFoundModalState); } return ( {content} ); } if (contactModalState) { return renderContactModal(); } if (isProfileEditorVisible) { return renderProfileEditor(); } if (isWhatsNewVisible) { return ; } return null; };