Show internal error toast on CDS errors

This commit is contained in:
Fedor Indutny 2022-08-30 17:03:42 -07:00 committed by GitHub
parent 39354b11b7
commit 7632f31cf2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 142 additions and 81 deletions

View file

@ -1,31 +0,0 @@
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import React from 'react';
import { action } from '@storybook/addon-actions';
import { ToastDecryptionError } from './ToastDecryptionError';
import { setupI18n } from '../util/setupI18n';
import enMessages from '../../_locales/en/messages.json';
const i18n = setupI18n('en', enMessages);
const defaultProps = {
deviceId: 3,
i18n,
name: 'Someone Somewhere',
onClose: action('onClose'),
onShowDebugLog: action('onShowDebugLog'),
};
export default {
title: 'Components/ToastDecryptionError',
};
export const _ToastDecryptionError = (): JSX.Element => (
<ToastDecryptionError {...defaultProps} />
);
_ToastDecryptionError.story = {
name: 'ToastDecryptionError',
};

View file

@ -1,43 +0,0 @@
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import React from 'react';
import type { LocalizerType } from '../types/Util';
import { Toast } from './Toast';
export type ToastPropsType = {
deviceId: number;
name: string;
onShowDebugLog: () => unknown;
};
type PropsType = {
i18n: LocalizerType;
onClose: () => unknown;
} & ToastPropsType;
export const ToastDecryptionError = ({
deviceId,
i18n,
name,
onClose,
onShowDebugLog,
}: PropsType): JSX.Element => {
return (
<Toast
autoDismissDisabled
className="decryption-error"
onClose={onClose}
style={{ maxWidth: '500px' }}
toastAction={{
label: i18n('decryptionErrorToastAction'),
onClick: onShowDebugLog,
}}
>
{i18n('decryptionErrorToast', {
name,
deviceId,
})}
</Toast>
);
};

View file

@ -0,0 +1,48 @@
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import React from 'react';
import { action } from '@storybook/addon-actions';
import {
ToastInternalError,
ToastInternalErrorKind,
} from './ToastInternalError';
import { setupI18n } from '../util/setupI18n';
import enMessages from '../../_locales/en/messages.json';
const i18n = setupI18n('en', enMessages);
const defaultProps = {
i18n,
onClose: action('onClose'),
onShowDebugLog: action('onShowDebugLog'),
};
export default {
title: 'Components/ToastInternalError',
};
export const ToastDecryptionError = (): JSX.Element => (
<ToastInternalError
kind={ToastInternalErrorKind.DecryptionError}
deviceId={3}
name="Someone Somewhere"
{...defaultProps}
/>
);
ToastDecryptionError.story = {
name: 'ToastDecryptionError',
};
export const ToastCDSMirroringError = (): JSX.Element => (
<ToastInternalError
kind={ToastInternalErrorKind.CDSMirroringError}
{...defaultProps}
/>
);
ToastDecryptionError.story = {
name: 'ToastCDSMirroringError',
};

View file

@ -0,0 +1,63 @@
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import React from 'react';
import type { LocalizerType } from '../types/Util';
import { missingCaseError } from '../util/missingCaseError';
import { Toast } from './Toast';
export enum ToastInternalErrorKind {
DecryptionError = 'DecryptionError',
CDSMirroringError = 'CDSMirroringError',
}
export type ToastPropsType = {
onShowDebugLog: () => unknown;
} & (
| {
kind: ToastInternalErrorKind.DecryptionError;
deviceId: number;
name: string;
}
| {
kind: ToastInternalErrorKind.CDSMirroringError;
}
);
type PropsType = {
i18n: LocalizerType;
onClose: () => unknown;
} & ToastPropsType;
export const ToastInternalError = (props: PropsType): JSX.Element => {
const { kind, i18n, onClose, onShowDebugLog } = props;
let body: string;
if (kind === ToastInternalErrorKind.DecryptionError) {
const { deviceId, name } = props;
body = i18n('decryptionErrorToast', {
name,
deviceId,
});
} else if (kind === ToastInternalErrorKind.CDSMirroringError) {
body = i18n('cdsMirroringErrorToast');
} else {
throw missingCaseError(kind);
}
return (
<Toast
autoDismissDisabled
className="internal-error-toast"
onClose={onClose}
style={{ maxWidth: '500px' }}
toastAction={{
label: i18n('decryptionErrorToastAction'),
onClick: onShowDebugLog,
}}
>
{body}
</Toast>
);
};