// Copyright 2022 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only import React from 'react'; import type { LocalizerType, ReplacementValuesType } from '../types/Util'; import { SECOND } from '../util/durations'; import { Toast } from './Toast'; import { ToastMessageBodyTooLong } from './ToastMessageBodyTooLong'; import { ToastType } from '../state/ducks/toast'; import { missingCaseError } from '../util/missingCaseError'; export type PropsType = { hideToast: () => unknown; i18n: LocalizerType; toast?: { toastType: ToastType; parameters?: ReplacementValuesType; }; }; const SHORT_TIMEOUT = 3 * SECOND; export function ToastManager({ hideToast, i18n, toast, }: PropsType): JSX.Element | null { if (toast === undefined) { return null; } const { toastType } = toast; if (toastType === ToastType.Error) { return ( window.showDebugLog(), }} > {i18n('Toast--error')} ); } if (toastType === ToastType.MessageBodyTooLong) { return ; } if (toastType === ToastType.StoryReact) { return ( {i18n('Stories__toast--sending-reaction')} ); } if (toastType === ToastType.StoryReply) { return ( {i18n('Stories__toast--sending-reply')} ); } if (toastType === ToastType.StoryMuted) { return ( {i18n('Stories__toast--hasNoSound')} ); } if (toastType === ToastType.StoryVideoTooLong) { return ( {i18n('StoryCreator__error--video-too-long')} ); } if (toastType === ToastType.StoryVideoUnsupported) { return ( {i18n('StoryCreator__error--video-unsupported')} ); } if (toastType === ToastType.StoryVideoError) { return ( {i18n('StoryCreator__error--video-error')} ); } if (toastType === ToastType.AddingUserToGroup) { return ( {i18n( 'AddUserToAnotherGroupModal__toast--adding-user-to-group', toast.parameters )} ); } if (toastType === ToastType.UserAddedToGroup) { return ( {i18n( 'AddUserToAnotherGroupModal__toast--user-added-to-group', toast.parameters )} ); } if (toastType === ToastType.FailedToDeleteUsername) { return ( {i18n('ProfileEditor--username--delete-general-error')} ); } if (toastType === ToastType.CopiedUsername) { return ( {i18n('ProfileEditor--username--copied-username')} ); } if (toastType === ToastType.CopiedUsernameLink) { return ( {i18n('ProfileEditor--username--copied-username-link')} ); } throw missingCaseError(toastType); }