signal-desktop/ts/components/ErrorModal.tsx

52 lines
1.2 KiB
TypeScript
Raw Normal View History

2023-01-03 19:55:46 +00:00
// Copyright 2020 Signal Messenger, LLC
2020-10-30 20:34:04 +00:00
// SPDX-License-Identifier: AGPL-3.0-only
2020-10-06 17:06:34 +00:00
import * as React from 'react';
import type { LocalizerType } from '../types/Util';
import { Modal } from './Modal';
import { Button, ButtonVariant } from './Button';
2020-10-06 17:06:34 +00:00
export type PropsType = {
2024-02-22 21:19:50 +00:00
buttonVariant?: ButtonVariant;
description?: string;
2024-10-09 16:35:24 +00:00
title?: string | null;
2020-10-06 17:06:34 +00:00
onClose: () => void;
i18n: LocalizerType;
};
function focusRef(el: HTMLElement | null) {
if (el) {
el.focus();
}
}
2022-11-18 00:45:19 +00:00
export function ErrorModal(props: PropsType): JSX.Element {
2024-02-22 21:19:50 +00:00
const { buttonVariant, description, i18n, onClose, title } = props;
2020-10-06 17:06:34 +00:00
const footer = (
2024-02-22 21:19:50 +00:00
<Button
onClick={onClose}
ref={focusRef}
variant={buttonVariant || ButtonVariant.Secondary}
>
2023-03-30 00:03:25 +00:00
{i18n('icu:Confirmation--confirm')}
</Button>
);
2020-10-06 17:06:34 +00:00
return (
<Modal
2022-09-27 20:24:21 +00:00
modalName="ErrorModal"
2020-10-06 17:06:34 +00:00
i18n={i18n}
onClose={onClose}
2024-10-16 17:08:44 +00:00
title={title == null ? undefined : title || i18n('icu:ErrorModal--title')}
modalFooter={footer}
2020-10-06 17:06:34 +00:00
>
<div className="module-error-modal__description">
2023-03-30 00:03:25 +00:00
{description || i18n('icu:ErrorModal--description')}
</div>
</Modal>
2020-10-06 17:06:34 +00:00
);
2022-11-18 00:45:19 +00:00
}