signal-desktop/ts/components/GlobalModalContainer.tsx

87 lines
2.2 KiB
TypeScript
Raw Normal View History

2021-05-28 16:15:17 +00:00
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import React from 'react';
2021-11-12 01:17:29 +00:00
import type {
ContactModalStateType,
UsernameNotFoundModalStateType,
} from '../state/ducks/globalModals';
import type { LocalizerType } from '../types/Util';
2021-11-12 01:17:29 +00:00
import { ButtonVariant } from './Button';
import { ConfirmationDialog } from './ConfirmationDialog';
import { WhatsNewModal } from './WhatsNewModal';
2021-09-21 22:37:10 +00:00
2021-05-28 16:15:17 +00:00
type PropsType = {
i18n: LocalizerType;
2021-09-21 22:37:10 +00:00
// ContactModal
contactModalState?: ContactModalStateType;
renderContactModal: () => JSX.Element;
2021-07-19 19:26:06 +00:00
// ProfileEditor
isProfileEditorVisible: boolean;
renderProfileEditor: () => JSX.Element;
// SafetyNumberModal
safetyNumberModalContactId?: string;
renderSafetyNumber: () => JSX.Element;
2021-11-12 01:17:29 +00:00
// UsernameNotFoundModal
hideUsernameNotFoundModal: () => unknown;
usernameNotFoundModalState?: UsernameNotFoundModalStateType;
// WhatsNewModal
isWhatsNewVisible: boolean;
hideWhatsNewModal: () => unknown;
2021-05-28 16:15:17 +00:00
};
export const GlobalModalContainer = ({
i18n,
2021-09-21 22:37:10 +00:00
// ContactModal
contactModalState,
renderContactModal,
2021-07-19 19:26:06 +00:00
// ProfileEditor
isProfileEditorVisible,
renderProfileEditor,
// SafetyNumberModal
safetyNumberModalContactId,
renderSafetyNumber,
2021-11-12 01:17:29 +00:00
// UsernameNotFoundModal
hideUsernameNotFoundModal,
usernameNotFoundModalState,
// WhatsNewModal
hideWhatsNewModal,
isWhatsNewVisible,
2021-05-28 16:15:17 +00:00
}: PropsType): JSX.Element | null => {
if (safetyNumberModalContactId) {
return renderSafetyNumber();
}
2021-11-12 01:17:29 +00:00
if (usernameNotFoundModalState) {
return (
<ConfirmationDialog
cancelText={i18n('ok')}
cancelButtonVariant={ButtonVariant.Secondary}
i18n={i18n}
onClose={hideUsernameNotFoundModal}
>
{i18n('startConversation--username-not-found', {
atUsername: i18n('at-username', {
username: usernameNotFoundModalState.username,
}),
})}
</ConfirmationDialog>
);
}
2021-09-21 22:37:10 +00:00
if (contactModalState) {
return renderContactModal();
}
2021-07-19 19:26:06 +00:00
if (isProfileEditorVisible) {
return renderProfileEditor();
}
if (isWhatsNewVisible) {
return <WhatsNewModal hideWhatsNewModal={hideWhatsNewModal} i18n={i18n} />;
}
2021-05-28 16:15:17 +00:00
return null;
};