2022-07-12 16:41:41 +00:00
|
|
|
// Copyright 2022 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import React from 'react';
|
2022-09-26 16:24:52 +00:00
|
|
|
import type { LocalizerType, ReplacementValuesType } from '../types/Util';
|
2022-07-12 16:41:41 +00:00
|
|
|
import { SECOND } from '../util/durations';
|
|
|
|
import { Toast } from './Toast';
|
|
|
|
import { ToastMessageBodyTooLong } from './ToastMessageBodyTooLong';
|
2022-10-18 17:12:02 +00:00
|
|
|
import { missingCaseError } from '../util/missingCaseError';
|
2022-12-15 00:48:36 +00:00
|
|
|
import { ToastType } from '../types/Toast';
|
2022-07-12 16:41:41 +00:00
|
|
|
|
|
|
|
export type PropsType = {
|
|
|
|
hideToast: () => unknown;
|
|
|
|
i18n: LocalizerType;
|
2022-12-14 18:12:04 +00:00
|
|
|
openFileInFolder: (target: string) => unknown;
|
2022-09-26 16:24:52 +00:00
|
|
|
toast?: {
|
|
|
|
toastType: ToastType;
|
|
|
|
parameters?: ReplacementValuesType;
|
|
|
|
};
|
2022-07-12 16:41:41 +00:00
|
|
|
};
|
|
|
|
|
2022-09-26 16:24:52 +00:00
|
|
|
const SHORT_TIMEOUT = 3 * SECOND;
|
|
|
|
|
2022-11-18 00:45:19 +00:00
|
|
|
export function ToastManager({
|
2022-07-12 16:41:41 +00:00
|
|
|
hideToast,
|
|
|
|
i18n,
|
2022-12-14 18:12:04 +00:00
|
|
|
openFileInFolder,
|
2022-09-26 16:24:52 +00:00
|
|
|
toast,
|
2022-11-18 00:45:19 +00:00
|
|
|
}: PropsType): JSX.Element | null {
|
2022-10-18 17:12:02 +00:00
|
|
|
if (toast === undefined) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const { toastType } = toast;
|
2022-12-06 17:31:44 +00:00
|
|
|
|
|
|
|
if (toastType === ToastType.AddingUserToGroup) {
|
|
|
|
return (
|
|
|
|
<Toast onClose={hideToast} timeout={SHORT_TIMEOUT}>
|
|
|
|
{i18n(
|
|
|
|
'AddUserToAnotherGroupModal__toast--adding-user-to-group',
|
|
|
|
toast.parameters
|
|
|
|
)}
|
|
|
|
</Toast>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-12-08 07:43:48 +00:00
|
|
|
if (toastType === ToastType.Blocked) {
|
|
|
|
return <Toast onClose={hideToast}>{i18n('unblockToSend')}</Toast>;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (toastType === ToastType.BlockedGroup) {
|
|
|
|
return <Toast onClose={hideToast}>{i18n('unblockGroupToSend')}</Toast>;
|
|
|
|
}
|
|
|
|
|
2022-12-08 01:26:59 +00:00
|
|
|
if (toastType === ToastType.CannotMixMultiAndNonMultiAttachments) {
|
|
|
|
return (
|
|
|
|
<Toast onClose={hideToast}>
|
|
|
|
{i18n('cannotSelectPhotosAndVideosAlongWithFiles')}
|
|
|
|
</Toast>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-12-06 17:31:44 +00:00
|
|
|
if (toastType === ToastType.CannotStartGroupCall) {
|
|
|
|
return (
|
|
|
|
<Toast onClose={hideToast}>
|
|
|
|
{i18n('GroupV2--cannot-start-group-call', toast.parameters)}
|
|
|
|
</Toast>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (toastType === ToastType.CopiedUsername) {
|
|
|
|
return (
|
|
|
|
<Toast onClose={hideToast} timeout={3 * SECOND}>
|
|
|
|
{i18n('ProfileEditor--username--copied-username')}
|
|
|
|
</Toast>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (toastType === ToastType.CopiedUsernameLink) {
|
|
|
|
return (
|
|
|
|
<Toast onClose={hideToast} timeout={3 * SECOND}>
|
|
|
|
{i18n('ProfileEditor--username--copied-username-link')}
|
|
|
|
</Toast>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-12-08 01:26:59 +00:00
|
|
|
if (toastType === ToastType.DangerousFileType) {
|
|
|
|
return <Toast onClose={hideToast}>{i18n('dangerousFileType')}</Toast>;
|
|
|
|
}
|
|
|
|
|
2022-12-06 17:31:44 +00:00
|
|
|
if (toastType === ToastType.DeleteForEveryoneFailed) {
|
|
|
|
return <Toast onClose={hideToast}>{i18n('deleteForEveryoneFailed')}</Toast>;
|
|
|
|
}
|
|
|
|
|
2022-10-18 17:12:02 +00:00
|
|
|
if (toastType === ToastType.Error) {
|
2022-07-29 00:10:07 +00:00
|
|
|
return (
|
|
|
|
<Toast
|
|
|
|
autoDismissDisabled
|
|
|
|
onClose={hideToast}
|
|
|
|
toastAction={{
|
|
|
|
label: i18n('Toast--error--action'),
|
|
|
|
onClick: () => window.showDebugLog(),
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{i18n('Toast--error')}
|
|
|
|
</Toast>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-12-08 07:43:48 +00:00
|
|
|
if (toastType === ToastType.Expired) {
|
|
|
|
return <Toast onClose={hideToast}>{i18n('expiredWarning')}</Toast>;
|
|
|
|
}
|
|
|
|
|
2022-12-06 17:31:44 +00:00
|
|
|
if (toastType === ToastType.FailedToDeleteUsername) {
|
|
|
|
return (
|
|
|
|
<Toast onClose={hideToast}>
|
|
|
|
{i18n('ProfileEditor--username--delete-general-error')}
|
|
|
|
</Toast>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-12-14 18:12:04 +00:00
|
|
|
if (toastType === ToastType.FileSaved) {
|
|
|
|
return (
|
|
|
|
<Toast
|
|
|
|
onClose={hideToast}
|
|
|
|
toastAction={{
|
|
|
|
label: i18n('attachmentSavedShow'),
|
|
|
|
onClick: () => {
|
|
|
|
if (toast.parameters && 'fullPath' in toast.parameters) {
|
|
|
|
openFileInFolder(String(toast.parameters.fullPath));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{i18n('attachmentSaved')}
|
|
|
|
</Toast>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-12-08 01:26:59 +00:00
|
|
|
if (toastType === ToastType.FileSize) {
|
|
|
|
return (
|
|
|
|
<Toast onClose={hideToast}>
|
|
|
|
{i18n('icu:fileSizeWarning', toast?.parameters)}
|
|
|
|
</Toast>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-12-08 07:43:48 +00:00
|
|
|
if (toastType === ToastType.InvalidConversation) {
|
|
|
|
return <Toast onClose={hideToast}>{i18n('invalidConversation')}</Toast>;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (toastType === ToastType.LeftGroup) {
|
|
|
|
return <Toast onClose={hideToast}>{i18n('youLeftTheGroup')}</Toast>;
|
|
|
|
}
|
|
|
|
|
2022-12-08 01:26:59 +00:00
|
|
|
if (toastType === ToastType.MaxAttachments) {
|
|
|
|
return <Toast onClose={hideToast}>{i18n('maximumAttachments')}</Toast>;
|
|
|
|
}
|
|
|
|
|
2022-10-18 17:12:02 +00:00
|
|
|
if (toastType === ToastType.MessageBodyTooLong) {
|
2022-07-12 16:41:41 +00:00
|
|
|
return <ToastMessageBodyTooLong i18n={i18n} onClose={hideToast} />;
|
|
|
|
}
|
|
|
|
|
2022-12-06 19:03:09 +00:00
|
|
|
if (toastType === ToastType.ReportedSpamAndBlocked) {
|
|
|
|
return (
|
|
|
|
<Toast onClose={hideToast}>
|
|
|
|
{i18n('MessageRequests--block-and-report-spam-success-toast')}
|
|
|
|
</Toast>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-12-07 01:00:02 +00:00
|
|
|
if (toastType === ToastType.PinnedConversationsFull) {
|
|
|
|
return <Toast onClose={hideToast}>{i18n('pinnedConversationsFull')}</Toast>;
|
|
|
|
}
|
|
|
|
|
2022-12-06 17:31:44 +00:00
|
|
|
if (toastType === ToastType.StoryMuted) {
|
|
|
|
return (
|
|
|
|
<Toast onClose={hideToast} timeout={SHORT_TIMEOUT}>
|
|
|
|
{i18n('Stories__toast--hasNoSound')}
|
|
|
|
</Toast>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-10-18 17:12:02 +00:00
|
|
|
if (toastType === ToastType.StoryReact) {
|
2022-07-12 16:41:41 +00:00
|
|
|
return (
|
2022-09-26 16:24:52 +00:00
|
|
|
<Toast onClose={hideToast} timeout={SHORT_TIMEOUT}>
|
2022-07-12 16:41:41 +00:00
|
|
|
{i18n('Stories__toast--sending-reaction')}
|
|
|
|
</Toast>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-10-18 17:12:02 +00:00
|
|
|
if (toastType === ToastType.StoryReply) {
|
2022-07-12 16:41:41 +00:00
|
|
|
return (
|
2022-09-26 16:24:52 +00:00
|
|
|
<Toast onClose={hideToast} timeout={SHORT_TIMEOUT}>
|
2022-07-12 16:41:41 +00:00
|
|
|
{i18n('Stories__toast--sending-reply')}
|
|
|
|
</Toast>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-12-06 17:31:44 +00:00
|
|
|
if (toastType === ToastType.StoryVideoError) {
|
2022-07-29 19:27:02 +00:00
|
|
|
return (
|
2022-12-06 17:31:44 +00:00
|
|
|
<Toast onClose={hideToast}>
|
|
|
|
{i18n('StoryCreator__error--video-error')}
|
2022-07-29 19:27:02 +00:00
|
|
|
</Toast>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-10-18 17:12:02 +00:00
|
|
|
if (toastType === ToastType.StoryVideoTooLong) {
|
2022-08-12 23:44:10 +00:00
|
|
|
return (
|
|
|
|
<Toast onClose={hideToast}>
|
|
|
|
{i18n('StoryCreator__error--video-too-long')}
|
|
|
|
</Toast>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-10-18 17:12:02 +00:00
|
|
|
if (toastType === ToastType.StoryVideoUnsupported) {
|
2022-08-12 23:44:10 +00:00
|
|
|
return (
|
|
|
|
<Toast onClose={hideToast}>
|
|
|
|
{i18n('StoryCreator__error--video-unsupported')}
|
|
|
|
</Toast>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-12-08 01:26:59 +00:00
|
|
|
if (toastType === ToastType.UnableToLoadAttachment) {
|
|
|
|
return <Toast onClose={hideToast}>{i18n('unableToLoadAttachment')}</Toast>;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (toastType === ToastType.UnsupportedMultiAttachment) {
|
|
|
|
return (
|
|
|
|
<Toast onClose={hideToast}>
|
|
|
|
{i18n('cannotSelectPhotosAndVideosAlongWithFiles')}
|
|
|
|
</Toast>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-10-18 17:12:02 +00:00
|
|
|
if (toastType === ToastType.UserAddedToGroup) {
|
2022-09-26 16:24:52 +00:00
|
|
|
return (
|
2022-09-27 00:09:50 +00:00
|
|
|
<Toast onClose={hideToast}>
|
2022-09-26 16:24:52 +00:00
|
|
|
{i18n(
|
|
|
|
'AddUserToAnotherGroupModal__toast--user-added-to-group',
|
|
|
|
toast.parameters
|
|
|
|
)}
|
|
|
|
</Toast>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-10-18 17:12:02 +00:00
|
|
|
throw missingCaseError(toastType);
|
2022-11-18 00:45:19 +00:00
|
|
|
}
|