signal-desktop/ts/components/GlobalModalContainer.tsx

173 lines
4.7 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,
2022-07-01 00:52:03 +00:00
ForwardMessagePropsType,
UserNotFoundModalStateType,
SafetyNumberChangedBlockingDataType,
2021-11-12 01:17:29 +00:00
} from '../state/ducks/globalModals';
import type { LocalizerType, ThemeType } from '../types/Util';
import { missingCaseError } from '../util/missingCaseError';
2021-11-12 01:17:29 +00:00
import { ButtonVariant } from './Button';
import { ConfirmationDialog } from './ConfirmationDialog';
import { SignalConnectionsModal } from './SignalConnectionsModal';
import { WhatsNewModal } from './WhatsNewModal';
2021-09-21 22:37:10 +00:00
export type PropsType = {
i18n: LocalizerType;
theme: ThemeType;
2021-09-21 22:37:10 +00:00
// ContactModal
contactModalState?: ContactModalStateType;
renderContactModal: () => JSX.Element;
2022-07-01 00:52:03 +00:00
// ForwardMessageModal
forwardMessageProps?: ForwardMessagePropsType;
renderForwardMessageModal: () => JSX.Element;
2021-07-19 19:26:06 +00:00
// ProfileEditor
isProfileEditorVisible: boolean;
renderProfileEditor: () => JSX.Element;
// SafetyNumberModal
safetyNumberModalContactId?: string;
renderSafetyNumber: () => JSX.Element;
// AddUserToAnotherGroupModal
addUserToAnotherGroupModalContactId?: string;
renderAddUserToAnotherGroup: () => JSX.Element;
// SignalConnectionsModal
isSignalConnectionsVisible: boolean;
toggleSignalConnectionsModal: () => unknown;
// StickerPackPreviewModal
stickerPackPreviewId?: string;
renderStickerPreviewModal: () => JSX.Element | null;
// StoriesSettings
isStoriesSettingsVisible: boolean;
renderStoriesSettings: () => JSX.Element;
// SendAnywayDialog
hasSafetyNumberChangeModal: boolean;
safetyNumberChangedBlockingData?: SafetyNumberChangedBlockingDataType;
renderSendAnywayDialog: () => JSX.Element;
// UserNotFoundModal
hideUserNotFoundModal: () => unknown;
userNotFoundModalState?: UserNotFoundModalStateType;
// WhatsNewModal
isWhatsNewVisible: boolean;
hideWhatsNewModal: () => unknown;
2021-05-28 16:15:17 +00:00
};
2022-11-18 00:45:19 +00:00
export function GlobalModalContainer({
i18n,
2021-09-21 22:37:10 +00:00
// ContactModal
contactModalState,
renderContactModal,
2022-07-01 00:52:03 +00:00
// ForwardMessageModal
forwardMessageProps,
renderForwardMessageModal,
2021-07-19 19:26:06 +00:00
// ProfileEditor
isProfileEditorVisible,
renderProfileEditor,
// SafetyNumberModal
safetyNumberModalContactId,
renderSafetyNumber,
// AddUserToAnotherGroupModal
addUserToAnotherGroupModalContactId,
renderAddUserToAnotherGroup,
// SignalConnectionsModal
isSignalConnectionsVisible,
toggleSignalConnectionsModal,
// StickerPackPreviewModal
stickerPackPreviewId,
renderStickerPreviewModal,
// StoriesSettings
isStoriesSettingsVisible,
renderStoriesSettings,
// SendAnywayDialog
hasSafetyNumberChangeModal,
safetyNumberChangedBlockingData,
renderSendAnywayDialog,
// UserNotFoundModal
hideUserNotFoundModal,
userNotFoundModalState,
// WhatsNewModal
hideWhatsNewModal,
isWhatsNewVisible,
2022-11-18 00:45:19 +00:00
}: PropsType): JSX.Element | null {
// We want the send anyway dialog to supersede most modals since this is an
// immediate action the user needs to take.
if (hasSafetyNumberChangeModal || safetyNumberChangedBlockingData) {
return renderSendAnywayDialog();
}
if (safetyNumberModalContactId) {
return renderSafetyNumber();
}
if (addUserToAnotherGroupModalContactId) {
return renderAddUserToAnotherGroup();
}
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);
}
2021-11-12 01:17:29 +00:00
return (
<ConfirmationDialog
2022-09-27 20:24:21 +00:00
dialogName="GlobalModalContainer.userNotFound"
2021-11-12 01:17:29 +00:00
cancelText={i18n('ok')}
cancelButtonVariant={ButtonVariant.Secondary}
i18n={i18n}
onClose={hideUserNotFoundModal}
2021-11-12 01:17:29 +00:00
>
{content}
2021-11-12 01:17:29 +00:00
</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} />;
}
2022-07-01 00:52:03 +00:00
if (forwardMessageProps) {
return renderForwardMessageModal();
}
if (isSignalConnectionsVisible) {
return (
<SignalConnectionsModal
i18n={i18n}
onClose={toggleSignalConnectionsModal}
/>
);
}
if (isStoriesSettingsVisible) {
return renderStoriesSettings();
}
if (stickerPackPreviewId) {
return renderStickerPreviewModal();
}
2021-05-28 16:15:17 +00:00
return null;
2022-11-18 00:45:19 +00:00
}